Clone of UAS2 @ https://github.com/drudgedance/uas2

cSpell.h 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /**
  18. * @file cSpell.h
  19. */
  20. #if !defined(AFX_CSPELL_H__08D0B2E9_9DDB_4F52_B2A8_8847149A4EAB__INCLUDED_)
  21. #define AFX_CSPELL_H__08D0B2E9_9DDB_4F52_B2A8_8847149A4EAB__INCLUDED_
  22. #if _MSC_VER > 1000
  23. #pragma once
  24. #endif // _MSC_VER > 1000
  25. #include <winsock2.h>
  26. #include "Shared.h"
  27. #include "Message.h"
  28. #include "Client.h"
  29. #include "WorldManager.h"
  30. #include "MasterServer.h"
  31. class cSpell
  32. {
  33. friend class cMasterServer;
  34. public:
  35. cSpell( DWORD dwSpellID, BOOL fAddToHash = TRUE )
  36. : m_dwSpellID( dwSpellID ),
  37. m_pcPrev ( NULL ),
  38. m_pcNext ( NULL )
  39. {
  40. m_dwIconID = 0x0L;
  41. m_dwEffect = 0x0L;
  42. m_fResearchable = false;
  43. m_dwManaCost = 0x0L;
  44. m_flUnkFloat1 = 0.0f;
  45. m_flUnkFloat2 = 0.0f;
  46. m_dwDifficulty = 0x0L;
  47. m_fEconomy = false;
  48. m_flSpeed = 0;
  49. m_dwType = 0x0L;
  50. m_iDuration = 0;
  51. for (int i = 0; i < 9; i++)
  52. m_dwComponents[i] = 0x0L;
  53. m_dwEffectAnim = 0x0L;
  54. m_dwLevel = 0x0L;
  55. if( fAddToHash )
  56. Hash_Add( this );
  57. }
  58. virtual ~cSpell()
  59. {
  60. if ( m_pcPrev ) m_pcPrev->m_pcNext = m_pcNext;
  61. else m_lpcHashTable[m_dwSpellID] = m_pcNext;
  62. if ( m_pcNext ) m_pcNext->m_pcPrev = m_pcPrev;
  63. }
  64. static inline void Hash_Load( )
  65. {
  66. ZeroMemory( m_lpcHashTable, sizeof( m_lpcHashTable ) );
  67. }
  68. static inline cSpell *Hash_New( DWORD& dwSpellID )
  69. {
  70. cSpell *pcSpell = Hash_Find( dwSpellID );
  71. if ( pcSpell )
  72. return pcSpell;
  73. return new cSpell( dwSpellID ) ;
  74. }
  75. static void Hash_Erase ( );
  76. static void Hash_Remove ( cSpell *pcSpell );
  77. static cSpell *FindSpell ( DWORD dwSpellID );
  78. BYTE GetWindup ( );
  79. int GetWindupDelay ( );
  80. BYTE GetCastAnim ( );
  81. int GetCastAnimDelay ( );
  82. cMessage GetCastWords( );
  83. DWORD m_dwSpellID;
  84. std::string m_strName;
  85. std::string m_strDesc;
  86. std::string m_strSchool;
  87. DWORD m_dwIconID;
  88. DWORD m_dwEffect;
  89. BOOL m_fResearchable;
  90. DWORD m_dwManaCost;
  91. float m_flUnkFloat1;
  92. float m_flUnkFloat2; //Target related, decreases with spell lvl
  93. DWORD m_dwDifficulty; // Skill level required
  94. BOOL m_fEconomy; // does ManaC need to be checked
  95. float m_flSpeed; // Guessing windup speed, increases with spell lvl
  96. DWORD m_dwType;
  97. int m_iDuration;
  98. DWORD m_dwComponents[9];
  99. DWORD m_dwEffectAnim;
  100. DWORD m_dwLevel;
  101. cSpell *m_pcNext;
  102. cSpell *m_pcPrev;
  103. private:
  104. static cSpell *m_lpcHashTable[3000];
  105. static inline Hash_Add( cSpell *pcSpell )
  106. {
  107. const DWORD dwSpellID = pcSpell->m_dwSpellID;
  108. if ( !m_lpcHashTable[dwSpellID] )
  109. m_lpcHashTable[dwSpellID] = pcSpell;
  110. else
  111. {
  112. pcSpell->m_pcNext = m_lpcHashTable[dwSpellID];
  113. m_lpcHashTable[dwSpellID]->m_pcPrev = pcSpell;
  114. m_lpcHashTable[dwSpellID] = pcSpell;
  115. }
  116. }
  117. static inline cSpell *Hash_Find( DWORD& dwSpellID )
  118. {
  119. const DWORD dwSpell = dwSpellID;
  120. cSpell *pcSpell = m_lpcHashTable[dwSpell];
  121. while ( pcSpell )
  122. {
  123. if ( pcSpell->CompareSpell( dwSpellID ) ) return pcSpell;
  124. else
  125. pcSpell = pcSpell->m_pcNext;
  126. }
  127. return NULL;
  128. }
  129. inline BOOL CompareSpell( DWORD& dwSpellID )
  130. {
  131. if ( dwSpellID == m_dwSpellID )
  132. return true;
  133. else
  134. return false;
  135. }
  136. };
  137. class cSpellComp
  138. {
  139. friend class cMasterServer;
  140. friend class cSpell;
  141. public:
  142. cSpellComp( DWORD dwCompID, BOOL fAddToHash = TRUE )
  143. : m_dwCompID( dwCompID ),
  144. m_pcPrev ( NULL ),
  145. m_pcNext ( NULL )
  146. {
  147. m_dwIconID = 0x0L;
  148. m_flChargeID = 0.0f;
  149. m_flBurnRate = 0.0f;
  150. m_dwAnimID = 0x0L;
  151. if( fAddToHash )
  152. Hash_Add( this );
  153. }
  154. virtual ~cSpellComp()
  155. {
  156. if ( m_pcPrev ) m_pcPrev->m_pcNext = m_pcNext;
  157. else m_lpcHashTable[m_dwCompID] = m_pcNext;
  158. if ( m_pcNext ) m_pcNext->m_pcPrev = m_pcPrev;
  159. }
  160. static inline void Hash_Load( )
  161. {
  162. ZeroMemory( m_lpcHashTable, sizeof( m_lpcHashTable ) );
  163. }
  164. static inline cSpellComp *Hash_New( DWORD& dwCompID )
  165. {
  166. cSpellComp *pcComp = Hash_Find( dwCompID );
  167. if ( pcComp )
  168. return pcComp;
  169. return new cSpellComp( dwCompID ) ;
  170. }
  171. static void Hash_Erase ( );
  172. static void Hash_Remove ( cSpellComp *pcComp );
  173. static cSpellComp *FindComp ( DWORD dwCompID );
  174. DWORD m_dwCompID;
  175. std::string m_strName;
  176. std::string m_strType;
  177. std::string m_strWords;
  178. DWORD m_dwIconID;
  179. float m_flChargeID;
  180. float m_flBurnRate;
  181. DWORD m_dwAnimID;
  182. cSpellComp *m_pcNext;
  183. cSpellComp *m_pcPrev;
  184. private:
  185. static cSpellComp *m_lpcHashTable[200];
  186. static inline Hash_Add( cSpellComp *pcComp )
  187. {
  188. const DWORD dwCompID = pcComp->m_dwCompID;
  189. if ( !m_lpcHashTable[dwCompID] )
  190. m_lpcHashTable[dwCompID] = pcComp;
  191. else
  192. {
  193. pcComp->m_pcNext = m_lpcHashTable[dwCompID];
  194. m_lpcHashTable[dwCompID]->m_pcPrev = pcComp;
  195. m_lpcHashTable[dwCompID] = pcComp;
  196. }
  197. }
  198. static inline cSpellComp *Hash_Find( DWORD& dwCompID )
  199. {
  200. const DWORD dwComp = dwCompID;
  201. cSpellComp *pcComp = m_lpcHashTable[dwComp];
  202. while ( pcComp )
  203. {
  204. if ( pcComp->CompareComp( dwCompID ) ) return pcComp;
  205. else
  206. pcComp = pcComp->m_pcNext;
  207. }
  208. return NULL;
  209. }
  210. inline BOOL CompareComp( DWORD& dwCompID )
  211. {
  212. if ( dwCompID == m_dwCompID )
  213. return true;
  214. else
  215. return false;
  216. }
  217. };
  218. class cEnchantment
  219. {
  220. public:
  221. cEnchantment( DWORD dwSpellID, WORD wFamily, DWORD dwDifficulty, double dDuration, DWORD dwCasterGUID, DWORD dwTargetGUID, double dCastTime, DWORD dwFlags, DWORD dwKey, float flValue )
  222. : m_dwSpellID ( dwSpellID ),
  223. m_wFamily ( wFamily ),
  224. m_dwDifficulty ( dwDifficulty ),
  225. m_dDuration ( dDuration ),
  226. m_dwCasterGUID ( dwCasterGUID ),
  227. m_dwTargetGUID ( dwTargetGUID ),
  228. m_dCastTime ( dCastTime ),
  229. m_dwFlags ( dwFlags ),
  230. m_dwKey ( dwKey ),
  231. m_flValue ( flValue )
  232. {
  233. m_wLayer = 0x0001;
  234. m_wUnknown0 = 0x0000;
  235. m_dwUnknown1 = 0x0L;
  236. m_dwUnknown2 = 0x0L;
  237. m_dwUnknown3 = 0x0L;
  238. cObject *pcObject = cWorldManager::FindObject( m_dwTargetGUID );
  239. if (pcObject)
  240. {
  241. for ( iterEnchantment_lst itEnchantment = pcObject->m_lstEnchantments.begin( ); itEnchantment != pcObject->m_lstEnchantments.end( ); ++itEnchantment )
  242. {
  243. if ( (*itEnchantment)->m_dwSpellID == m_dwSpellID && (*itEnchantment)->m_wLayer >= m_wLayer )
  244. m_wLayer = (*itEnchantment)->m_wLayer + 1;
  245. }
  246. pcObject->m_lstEnchantments.push_back( this );
  247. cMasterServer::m_lstEnchantments.push_back( this );
  248. }
  249. else
  250. {
  251. cClient *pcClient = cClient::FindClient( m_dwTargetGUID );
  252. if (pcClient)
  253. {
  254. for ( iterEnchantment_lst itEnchantment = pcClient->m_pcAvatar->m_lstEnchantments.begin( ); itEnchantment != pcClient->m_pcAvatar->m_lstEnchantments.end( ); ++itEnchantment )
  255. {
  256. if ( (*itEnchantment)->m_dwSpellID == m_dwSpellID && (*itEnchantment)->m_wLayer >= m_wLayer )
  257. m_wLayer = (*itEnchantment)->m_wLayer + 1;
  258. }
  259. pcClient->m_pcAvatar->m_lstEnchantments.push_back( this );
  260. cMasterServer::m_lstEnchantments.push_back( this );
  261. pcClient->AddPacket( WORLD_SERVER, pcClient->m_pcAvatar->AddEnchant( ++pcClient->m_dwF7B0Sequence, m_dwSpellID, m_wLayer, m_wFamily, m_dwDifficulty, m_dDuration, m_dwCasterGUID, m_dCastTime, m_dwFlags, m_dwKey, m_flValue ), 4);
  262. }
  263. }
  264. }
  265. ~cEnchantment()
  266. {
  267. cObject *pcObject = cWorldManager::FindObject( m_dwTargetGUID );
  268. if (pcObject)
  269. {
  270. for ( iterEnchantment_lst itEnchantment = pcObject->m_lstEnchantments.begin(); itEnchantment != pcObject->m_lstEnchantments.end( ); ++itEnchantment )
  271. {
  272. if ( (*itEnchantment)->m_dwSpellID == m_dwSpellID && (*itEnchantment)->m_wLayer == m_wLayer )
  273. {
  274. pcObject->m_lstEnchantments.erase( itEnchantment );
  275. itEnchantment = pcObject->m_lstEnchantments.end();
  276. }
  277. }
  278. }
  279. else
  280. {
  281. cClient *pcClient = cClient::FindClient( m_dwTargetGUID );
  282. if (pcClient)
  283. {
  284. for ( iterEnchantment_lst itEnchantment = pcClient->m_pcAvatar->m_lstEnchantments.begin(); itEnchantment != pcClient->m_pcAvatar->m_lstEnchantments.end( ); ++itEnchantment )
  285. {
  286. if ( (*itEnchantment)->m_dwSpellID == m_dwSpellID && (*itEnchantment)->m_wLayer >= m_wLayer )
  287. {
  288. pcClient->m_pcAvatar->m_lstEnchantments.erase( itEnchantment );
  289. itEnchantment = pcClient->m_pcAvatar->m_lstEnchantments.end();
  290. }
  291. }
  292. pcClient->AddPacket( WORLD_SERVER, pcClient->m_pcAvatar->RemoveEnchant( ++pcClient->m_dwF7B0Sequence, m_dwSpellID, m_wLayer ), 4);
  293. }
  294. }
  295. }
  296. DWORD m_dwSpellID;
  297. WORD m_wLayer;
  298. WORD m_wFamily;
  299. WORD m_wUnknown0;
  300. DWORD m_dwDifficulty;
  301. double m_dDuration;
  302. DWORD m_dwCasterGUID;
  303. DWORD m_dwTargetGUID;
  304. DWORD m_dwUnknown1;
  305. DWORD m_dwUnknown2;
  306. double m_dCastTime;
  307. DWORD m_dwFlags;
  308. DWORD m_dwKey;
  309. float m_flValue;
  310. DWORD m_dwUnknown3;
  311. };
  312. #endif // !defined(AFX_CSPELL_H__08D0B2E9_9DDB_4F52_B2A8_8847149A4EAB__INCLUDED_)