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

WarSpell.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 WarSpell.cpp
  19. */
  20. #include "Object.h"
  21. #include "WorldManager.h"
  22. #include "Job.h"
  23. #include "CorpseCleaner.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[]=__FILE__;
  27. #define new DEBUG_NEW
  28. #endif
  29. /**
  30. * Angle "val" is converted to (160 index), which corresponds to the ring of 16 sonar.
  31. * This index value is then returned.
  32. * Units are 1/10 degrees and 160 index (1/10th of 16).
  33. */
  34. int deg_to_index_160(int val)
  35. {
  36. int idx;
  37. idx = val * 2 / 45; /* (idx = val/22.5) */
  38. if (idx < 0) idx += 160;
  39. return(idx);
  40. }
  41. /**********
  42. * methods
  43. *********/
  44. /**
  45. * Handles the message sent for the creation of war spells.
  46. *
  47. * This function is called whenever a war spells should be created for a client.
  48. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  49. */
  50. cMessage cWarSpell::CreatePacket()
  51. {
  52. cMessage cmReturn;
  53. cMagicModels *pcModel = cMagicModels::FindModel( m_dwSpellModel );
  54. if( pcModel )
  55. {
  56. float flpScale = 0.5f; // Scale used in Packet being Sent
  57. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11); //0x11 is a constant
  58. cmReturn << BYTE(0x0) << BYTE(0x0) << BYTE(0x0);
  59. DWORD dwFlags1 = pcModel->m_dwFlags1;// 0x0000FB85; // Flags 1 defines whats next
  60. cmReturn << dwFlags1;
  61. cmReturn << WORD(0x8B48); // Type of portal
  62. cmReturn << WORD(0x0002); // Unknown
  63. //Flags1 Mask 0x0000FB85
  64. {
  65. //Flags1 & 0x00008000 Location
  66. {
  67. //m_Location.m_flZ = m_Location.m_flZ + 1.4f;
  68. cmReturn.pasteData( (UCHAR*)&m_Location, sizeof(m_Location) ); //Next comes the location
  69. }
  70. //Flags1 & 0x00000800
  71. {
  72. //SoundConfig
  73. cmReturn << 0x20000000 + pcModel->m_wSoundSet;//0x20000039;
  74. }
  75. //Flags1 & 0x00001000
  76. {
  77. //Unknown_Blue // Particle Effect for spell
  78. cmReturn << 0x34000000 + pcModel->m_wParticle; //0x3400000B;
  79. }
  80. //Flags1 & 0x00000001
  81. {
  82. //DWORD dwModel = 0x02000001; //the model.
  83. cmReturn << 0x02000000 + pcModel->m_dwModelNumber;//0x020003F6;
  84. }
  85. //Flags1 & 0x00000080 unknown_green
  86. {
  87. //FLOAT flpScale
  88. cmReturn << pcModel->m_flScale;
  89. }
  90. //Flags1 & 0x00000100
  91. {
  92. //Unkown_darkbrown
  93. cmReturn << 1.0f;//0x3F800000;
  94. }
  95. //Flags1 & 0x00000200
  96. {
  97. //Unknown_BrightPurple
  98. cmReturn << 0x00000000;
  99. }
  100. //Flags1 & 0x00000004
  101. {
  102. //Velocity Vector
  103. float flSpeed = 10;
  104. char Command2[100];
  105. sprintf(Command2,"dx: %f dy: %f dz: %f Speed: %f\r\n", m_Velocity.m_dx, m_Velocity.m_dy, m_Velocity.m_dz, flSpeed);
  106. //UpdateConsole(Command2);
  107. cmReturn << (m_Velocity.m_dx*flSpeed);
  108. cmReturn << (m_Velocity.m_dy*flSpeed);
  109. cmReturn << (m_Velocity.m_dz*flSpeed);
  110. }
  111. //Flags1 & 0x00002000
  112. {
  113. //
  114. cmReturn << 0x00000059;
  115. }
  116. //Flags1 & 0x00004000
  117. {
  118. //
  119. cmReturn << 0x3F800000;
  120. }
  121. }
  122. // SeaGreens
  123. WORD wUnkFlag2 = 0x0000;
  124. WORD wUnkFlag3 = 0x0000;
  125. WORD wUnkFlag4 = 0x0001;
  126. WORD wUnkFlag6 = 0x0000;
  127. WORD wUnkFlag7 = 0x0000;
  128. WORD wUnkFlag8 = 0x0000;
  129. WORD wUnkFlag10 = 0x0000;
  130. cmReturn << m_wPositionSequence //movement 0x0001
  131. << wUnkFlag2 // animations
  132. << wUnkFlag3 // bubble modes
  133. << wUnkFlag4 //num jumps
  134. << m_wNumPortals
  135. << wUnkFlag6 //anim count
  136. << wUnkFlag7 // overrides
  137. << wUnkFlag8
  138. << m_wNumLogins // 0x0D4B
  139. << wUnkFlag10;
  140. DWORD dwFlags2 = 0x00400000; //Flags2 Defines what data comes next
  141. cmReturn << dwFlags2;
  142. cmReturn << pcModel->m_strName;//Name( ); // Object's Name
  143. cmReturn << WORD(pcModel->m_wModel) << WORD(pcModel->m_wIcon); //m_wModelID << m_wIconID;
  144. DWORD dwObjectFlags1 = 0x00000000; // 0x0000 Nothing
  145. DWORD dwObjectFlags2 = 0x00000094; // 0x0004 Can not be picked up, 0x0080 Unknown - Can not be selected 0x0010 Unknown - Can be selected.
  146. // appears to contradict it self sets Can not be Selected and Can be Selected. Housing Item, may set house open/closed
  147. cmReturn << dwObjectFlags1 << dwObjectFlags2;
  148. //Flags2 Mask
  149. {
  150. // 0x00400000 Word Associated Spell
  151. {
  152. WORD wUnknown9 = pcModel->m_wAssociatedSpell;//0x3A;
  153. cmReturn << wUnknown9;
  154. }
  155. }
  156. //cmReturn << WORD(0x0000);
  157. }
  158. else
  159. {
  160. UpdateConsole(" Spell Error! %d\r\n", m_dwSpellModel);
  161. }
  162. return cmReturn;
  163. }
  164. /**
  165. * Handles the movement of war spells.
  166. *
  167. * This function is called whenever a war spell's position should be updated.
  168. */
  169. int cWarSpell::Move( LPVOID wp, LPVOID lp )
  170. {
  171. cSpellMoveParam* SpellMoveParam = (cSpellMoveParam *) wp;
  172. cWarSpell *pcWarSpell = (cWarSpell*) cWorldManager::FindObject( SpellMoveParam->GetWarSpellGUID() );
  173. cClient *pcClient = cClient::FindClient( SpellMoveParam->GetCasterGUID() );
  174. cLocation newLoc = cPhysics::VelocityMove(pcWarSpell->m_Location, pcWarSpell->m_Velocity, 1.0f);
  175. if ( HIWORD(newLoc.m_dwLandBlock) != HIWORD(pcWarSpell->m_Location.m_dwLandBlock) )
  176. {
  177. cWorldManager::MoveRemObject( pcWarSpell );
  178. pcWarSpell->m_Location = newLoc;
  179. cWorldManager::MoveAddObject( pcWarSpell );
  180. }
  181. else
  182. pcWarSpell->m_Location = newLoc;
  183. char Command[100];
  184. sprintf(Command,"Move! X: %f Y: %f\r\n", pcWarSpell->m_Location.m_flX, pcWarSpell->m_Location.m_flY);
  185. //UpdateConsole(Command);
  186. if ( cMonster *CollisionMonster = (cMonster*) cWorldManager::GetCollisionMonster( pcWarSpell->GetGUID(), pcWarSpell->m_Location ) )
  187. {
  188. //UpdateConsole(" Hit!\r\n");
  189. cMessage msgImpact = pcWarSpell->SpellImpact(pcWarSpell,0x0005,1.0f);
  190. cWorldManager::SendToAllInFocus( pcWarSpell->m_Location, msgImpact, 3 );
  191. cMessage msgVis = pcWarSpell->SpellVis(pcWarSpell);
  192. cWorldManager::SendToAllInFocus( pcWarSpell->m_Location, msgVis, 3 );
  193. CollisionMonster->SpellAttack( pcClient , pcWarSpell, ++pcClient->m_dwF7B0Sequence);
  194. SimpleAI::SetUnderAttack( CollisionMonster->GetGUID(), pcClient->m_pcAvatar->GetGUID() );
  195. CorpseCleaner::AddCorpse(pcWarSpell->GetGUID(),2);
  196. SAFEDELETE( SpellMoveParam )
  197. return 2;
  198. }
  199. else if ( pcWarSpell->m_Location.m_flZ < cPhysics::GetLandZ( pcWarSpell->m_Location ) )
  200. {
  201. //UpdateConsole(" Land hit!\r\n");
  202. cMessage msgImpact = pcWarSpell->SpellImpact(pcWarSpell,0x0005,1.0f);
  203. cWorldManager::SendToAllInFocus( pcWarSpell->m_Location, msgImpact, 3 );
  204. cMessage msgVis = pcWarSpell->SpellVis(pcWarSpell);
  205. cWorldManager::SendToAllInFocus( pcWarSpell->m_Location, msgVis, 3 );
  206. CorpseCleaner::AddCorpse(pcWarSpell->GetGUID(),2);
  207. SAFEDELETE( SpellMoveParam )
  208. return 2;
  209. }
  210. if ( cPhysics::Get3DRange( SpellMoveParam->GetCastLocation(), pcWarSpell->m_Location ) > 3.3333 )
  211. {
  212. UpdateConsole(" Dissipate.\r\n");
  213. CorpseCleaner::AddCorpse(pcWarSpell->GetGUID(),2);
  214. SAFEDELETE( SpellMoveParam )
  215. return 2;
  216. }
  217. cMessage msgSpellPosition = pcWarSpell->SetPosition();
  218. //cWorldManager::SendToAllInFocus( pcWarSpell->m_Location, msgSpellPosition, 3 );
  219. return -1;
  220. }
  221. /**
  222. * Handles the general actions of war spell objects.
  223. */
  224. void cWarSpell::Action(cClient *who)
  225. {
  226. }
  227. /**
  228. * Handles the assessment of war spell objects. This should not be called.
  229. */
  230. void cWarSpell::Assess(cClient *pcAssesser)
  231. {
  232. }
  233. /**
  234. * Particle effects for war spell objects.
  235. *
  236. * This function is called when a war spell should display a particle effect.
  237. * @return cMessage - Returns an Apply Visual/Sound Effect (0x0000F755) server message.
  238. */
  239. cMessage cWarSpell::WarParticle(cWarSpell* pcWarSpell,DWORD dwEffect,float flSpeed)
  240. {
  241. cMessage cmWarParticle;
  242. static BYTE cbApplyEffect[] = {
  243. 0x55, 0xF7, 0x00, 0x00,
  244. 0xBA, 0x2E, 0xC5, 0xC2,
  245. 0x04, 0x00, 0x00, 0x00,
  246. 0x3F, 0x80, 0x00, 0x00,
  247. };
  248. CopyMemory( &cbApplyEffect[4], &pcWarSpell->m_dwGUID, 4 );
  249. CopyMemory( &cbApplyEffect[8], &dwEffect, 4 );
  250. CopyMemory( &cbApplyEffect[12], &flSpeed, 4 );
  251. cmWarParticle.CannedData( cbApplyEffect, sizeof( cbApplyEffect ) );
  252. return cmWarParticle;
  253. }
  254. /**
  255. * Impact effects for war spell objects.
  256. *
  257. * This function is called when a war spell should display an impact effect.
  258. * @return cMessage - Returns an Apply Visual/Sound Effect (0x0000F755) server message.
  259. */
  260. cMessage cWarSpell::SpellImpact(cWarSpell* pcWarSpell, DWORD dwEffect, float flSpeed)
  261. {
  262. cMessage cmSpellImpact;
  263. static BYTE cbApplyImpact[] = {
  264. 0x55, 0xF7, 0x00, 0x00,
  265. 0xBA, 0x2E, 0xC5, 0xC2,
  266. 0x04, 0x00, 0x00, 0x00,
  267. 0x3F, 0x80, 0x00, 0x00,
  268. };
  269. CopyMemory( &cbApplyImpact[4], &pcWarSpell->m_dwGUID, 4 );
  270. CopyMemory( &cbApplyImpact[8], &dwEffect, 4 );
  271. CopyMemory( &cbApplyImpact[12], &flSpeed, 4 );
  272. cmSpellImpact.CannedData( cbApplyImpact, sizeof( cbApplyImpact ) );
  273. return cmSpellImpact;
  274. }
  275. /**
  276. * Toggles war spell visibility.
  277. *
  278. * This function is called when the visibility of a war spell should change for a client.
  279. * @return cMessage - Returns a Toggle Object Visibility (0x0000F74B) server message.
  280. */
  281. cMessage cWarSpell::SpellVis(cWarSpell* pcWarSpell)
  282. {
  283. cMessage cmSpellVis;
  284. static BYTE cbApplyVis[] = {
  285. 0x4B, 0xF7, 0x00, 0x00,
  286. 0x01, 0x00, 0x00, 0x00,
  287. 0x74, 0x83, //Portal type
  288. 0x12, 0x00, //Unknown word
  289. 0x06, 0x00, //NumLogins
  290. 0x01, 0x00, //NumPortals
  291. 0x43, 0x3D,
  292. 0x09, 0x01,
  293. };
  294. CopyMemory( &cbApplyVis[4], &pcWarSpell->m_dwGUID, 4 );
  295. cmSpellVis.CannedData( cbApplyVis, sizeof( cbApplyVis ) );
  296. return cmSpellVis;
  297. }
  298. /**
  299. * Sends a war spell animation.
  300. *
  301. * This function is called when an animation for a war spell should sent to a client.
  302. * @return cMessage - Returns a Set Animation (0x0000F74C) server message.
  303. */
  304. cMessage cWarSpell::SpellAnim(cWarSpell* pcWarSpell,WORD wWarAnim,WORD wWarAnim2)
  305. {
  306. cMessage cmSpellAnim;
  307. static BYTE cbSpellAnim[] = {
  308. 0x4C, 0xF7, 0x00, 0x00,
  309. 0xBA, 0x31, 0xC5, 0xC2, //GUID
  310. 0x01, 0x00, //numLogins
  311. 0x03, 0x00, //sequence
  312. 0x03, 0x00, //numAnim
  313. 0x00, 0x00, //activity
  314. 0x00, 0x00, //animation Type
  315. 0x3C, 0x00, //Stance
  316. 0x01, 0xF0, 0x99, 0x02, //flags
  317. 0x3C, 0x00, 0x00, 0x00, //stanceMode2
  318. 0x3F, 0x80, 0x00, 0x00,
  319. };
  320. CopyMemory( &cbSpellAnim[4], &pcWarSpell->m_dwGUID, 4 );
  321. CopyMemory( &cbSpellAnim[18], &wWarAnim, 2 );
  322. CopyMemory( &cbSpellAnim[24], &wWarAnim2, 2 );
  323. cmSpellAnim.pasteData( cbSpellAnim, sizeof( cbSpellAnim ) );
  324. return cmSpellAnim;
  325. }
  326. /**
  327. * Sets the location for war spell objects.
  328. *
  329. * This function is called whenever the location of a war spell should be updated for a client.
  330. * @return cMessage - Returns a Set Position and Motion (0x0000F748) server message.
  331. */
  332. cMessage cWarSpell::SetPosition()
  333. {
  334. cMessage cmSetPosition;
  335. DWORD dwFlags = 0x01L;
  336. cmSetPosition << 0xF748L
  337. << m_dwGUID
  338. << 0x01L;
  339. cmSetPosition << m_Location.m_dwLandBlock
  340. << m_Location.m_flX
  341. << m_Location.m_flY
  342. << m_Location.m_flZ
  343. << m_Location.m_flA
  344. << m_Location.m_flB
  345. << m_Location.m_flC
  346. << m_Location.m_flW
  347. << m_Velocity.m_dx
  348. << m_Velocity.m_dy
  349. << m_Velocity.m_dz;
  350. return cmSetPosition;
  351. }