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

cWeapon.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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 cWeapon.cpp
  19. * Implements functionality for weapons.
  20. *
  21. * This class is referenced whenever a weapons is created, used, or assessed.
  22. * Inherits from the cObject class.
  23. */
  24. #include "avatar.h"
  25. #include "object.h"
  26. #include "cItemModels.h"
  27. #include "client.h"
  28. #include "WorldManager.h"
  29. #include "MasterServer.h"
  30. /**
  31. * Handles the message sent for the creation of weapons in the world.
  32. *
  33. * This function is called whenever a weapon should be created in the world for a client.
  34. *
  35. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  36. */
  37. cMessage cWeapon::CreatePacket( )
  38. {
  39. cMessage cmReturn;
  40. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  41. cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  42. if( pcModel )
  43. {
  44. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11); //0x11 is a constant
  45. cmReturn << pcModel->m_bPaletteChange
  46. << pcModel->m_bTextureChange
  47. << pcModel->m_bModelChange;
  48. // The Model Vectors
  49. if ( pcModel->m_bPaletteChange != 0)
  50. {
  51. for (int i = 0; i < pcModel->m_bPaletteChange; i++)
  52. {
  53. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorPal[i],sizeof(pcModel->m_vectorPal[i]));
  54. }
  55. }
  56. if (pcModel->m_bPaletteChange != 0)
  57. {
  58. //Cubem0j0: Test code for armor only.
  59. cmReturn << WORD( 0x0C50 );
  60. }
  61. if ( pcModel->m_bTextureChange != 0)
  62. {
  63. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  64. {
  65. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  66. }
  67. }
  68. if ( pcModel->m_bModelChange != 0)
  69. {
  70. for (int i = 0; i < pcModel->m_bModelChange; i++)
  71. {
  72. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  73. }
  74. }
  75. }
  76. cmReturn.pasteAlign(4);
  77. cmReturn << 0x00029801 << 0x414L << 0x65L;
  78. // MASK 0x00008000 -- Location
  79. if ( !m_fIsOwned )
  80. cmReturn.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  81. // MASK 0x00000800 -- Sound Set
  82. DWORD dwSoundSet = 0x20000014L + pcModel->m_wSoundSet;
  83. cmReturn << dwSoundSet;
  84. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  85. cmReturn << 0x3400002B + pcModel->m_dwUnknown_Blue;
  86. // MASK 0x00000001 -- ModelNumber
  87. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  88. cmReturn << dwModel;
  89. // SeaGreens
  90. WORD wNuminteracts = 0x0;
  91. WORD wNumbubbles = 0x0;
  92. WORD wNumJumps = 0x0;
  93. WORD wNumOverrides = 0x0;
  94. WORD wUnkFlag8 = 0x0;
  95. WORD wUnkFlag10 = 0x0;
  96. cmReturn << m_wPositionSequence
  97. << m_wNumAnims //wNuminteracts
  98. << wNumbubbles
  99. << wNumJumps
  100. << m_wNumPortals
  101. << m_wNumAnims
  102. << wNumOverrides
  103. << wUnkFlag8
  104. << m_wNumLogins
  105. << wUnkFlag10;
  106. // Flags2
  107. // DWORD dwFlags2 = 0x91210298;
  108. cmReturn << pcModel->m_dwFlags2;
  109. cmReturn << Name( ); // Objects Name
  110. cmReturn << pcModel->m_wModel; // Objects Model
  111. cmReturn << pcModel->m_wIcon; // Objects Icon
  112. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  113. cmReturn << pcModel->m_dwObjectFlags2;
  114. // Masked against dwFlags2
  115. // Mask 0x0008 - Value
  116. if(pcModel->m_dwFlags2 & 0x00000008)
  117. {
  118. cmReturn << pcModel->m_dwValue;
  119. }
  120. // Mask 0x0010 dwUnknown_v2
  121. if(pcModel->m_dwFlags2 & 0x00000010)
  122. {
  123. cmReturn << pcModel->m_dwUnknown_v2;
  124. }
  125. // Mask 0x0080 Icon Highlight
  126. if(pcModel->m_dwFlags2 & 0x00000080)
  127. {
  128. cmReturn << pcModel->m_dwIconHighlight;
  129. }
  130. // Mask 0x0200 Wield Type
  131. if(pcModel->m_dwFlags2 & 0x00000200)
  132. {
  133. cmReturn << pcModel->m_bWieldType;
  134. }
  135. // Mask 0x1000 Stack
  136. if(pcModel->m_dwFlags2 & 0x00001000)
  137. {
  138. cmReturn << pcModel->m_wStack;
  139. }
  140. // Mask 0x2000 Stack Limit
  141. if(pcModel->m_dwFlags2 & 0x00002000)
  142. {
  143. cmReturn << pcModel->m_wStackLimit;
  144. }
  145. // Mask 0x10000 Equip Possible
  146. if(pcModel->m_dwFlags2 & 0x00010000)
  147. {
  148. cmReturn << DWORD(0x100000);
  149. //cmReturn << pcModel->m_dwEquipPossible;
  150. }
  151. // Mask 0x00200000 - Burden
  152. if(pcModel->m_dwFlags2 & 0x00200000)
  153. {
  154. cmReturn << pcModel->m_wBurden;
  155. }
  156. // Mask 0x01000000 - Workmanship
  157. if(pcModel->m_dwFlags2 & 0x01000000)
  158. {
  159. cmReturn << pcModel->m_fWorkmanship;
  160. }
  161. // Mask 0x10000000 - Hookable
  162. if(pcModel->m_dwFlags2 & 0x10000000)
  163. {
  164. cmReturn << pcModel->m_wHooks;
  165. }
  166. // Mask 0x80000000 - Material
  167. cmReturn << WORD(0x0000);
  168. cmReturn << BYTE(0x00);
  169. /*
  170. // Masked against dwFlags2
  171. // Mask 0x0008 - Value
  172. cmReturn << DWORD(0x88);
  173. // Mask 0x0010 dwUnknown_v2
  174. cmReturn << DWORD(0x00000001);
  175. // Mask 0x0080 Icon Highlight
  176. cmReturn << DWORD(0x40);
  177. // Mask 0x0200 Wield Type
  178. cmReturn << BYTE(0x01);
  179. // Mask 0x10000 Equip Possible
  180. cmReturn << DWORD(0x100000);
  181. // Mask 0x00200000 - Burden
  182. cmReturn << WORD(0x0040);
  183. // Mask 0x01000000 - Workmanship
  184. cmReturn << float(4.0);
  185. // Mask 0x10000000 - Hookable
  186. cmReturn << WORD(0x0001);
  187. // Mask 0x80000000 - Material
  188. cmReturn << DWORD(0x33);
  189. */
  190. return cmReturn;
  191. }
  192. /**
  193. * Handles the message sent for the creation of weapons in a container.
  194. *
  195. * This function is called whenever a weapon should be created in the inventory of another object.
  196. *
  197. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  198. */
  199. cMessage cWeapon::CreatePacketContainer( DWORD Container, DWORD ItemModelID )
  200. {
  201. cMessage cmReturn;
  202. cItemModels *pcModel = cItemModels::FindModel( ItemModelID );
  203. cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  204. if( pcModel )
  205. {
  206. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11) //0x11 is a constant
  207. << pcModel->m_bPaletteChange
  208. << pcModel->m_bTextureChange
  209. << pcModel->m_bModelChange;
  210. // The Model Vectors
  211. if ( pcModel->m_bPaletteChange != 0)
  212. {
  213. for (int i = 0; i < pcModel->m_bPaletteChange; i++)
  214. {
  215. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorPal[i],sizeof(pcModel->m_vectorPal[i]));
  216. }
  217. }
  218. if (pcModel->m_bPaletteChange != 0)
  219. {
  220. cmReturn << WORD( pcModel->m_wUnknown1 );
  221. }
  222. if ( pcModel->m_bTextureChange != 0)
  223. {
  224. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  225. {
  226. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  227. }
  228. }
  229. if ( pcModel->m_bModelChange != 0)
  230. {
  231. for (int i = 0; i < pcModel->m_bModelChange; i++)
  232. {
  233. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  234. }
  235. }
  236. }
  237. cmReturn.pasteAlign(4);
  238. cmReturn << 0x00021801L << 0x414L << 0x65L;
  239. // MASK 0x00008000 -- Location
  240. // if ( !m_fIsOwned )
  241. // cmReturn.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  242. // MASK 0x00000800 -- Sound Set
  243. DWORD dwSoundSet = 0x20000014L;
  244. cmReturn << dwSoundSet;
  245. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  246. cmReturn << 0x3400002BL;
  247. // MASK 0x00000001 -- ModelNumber
  248. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  249. cmReturn << dwModel;
  250. // SeaGreens
  251. WORD wNuminteracts = 0x1;
  252. WORD wNumbubbles = 0x0;
  253. WORD wNumJumps = 0x0;
  254. WORD wNumOverrides = 0x0;
  255. WORD wUnkFlag8 = 0x0;
  256. WORD wUnkFlag10 = 0x0;
  257. cmReturn << m_wPositionSequence
  258. << m_wNumAnims //wNuminteracts
  259. << wNumbubbles
  260. << wNumJumps
  261. << m_wNumPortals
  262. << m_wNumAnims
  263. << wNumOverrides
  264. << wUnkFlag8
  265. << m_wNumLogins
  266. << wUnkFlag10;
  267. // Flags2
  268. // DWORD dwFlags2 = 0x91214298;
  269. cmReturn << pcModel->m_dwFlags2;
  270. cmReturn << Name( ); // Objects Name
  271. cmReturn << pcModel->m_wModel; // Objects Model
  272. cmReturn << pcModel->m_wIcon; // Objects Icon
  273. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  274. cmReturn << pcModel->m_dwObjectFlags2;
  275. // Masked against dwFlags2
  276. // Mask 0x0008 - Value
  277. if(pcModel->m_dwFlags2 & 0x00000008)
  278. {
  279. cmReturn << pcModel->m_dwValue;
  280. }
  281. // Mask 0x0010 dwUnknown_v2
  282. if(pcModel->m_dwFlags2 & 0x00000010)
  283. {
  284. cmReturn << pcModel->m_dwUnknown_v2;
  285. }
  286. // Mask 0x0080 Icon Highlight
  287. if(pcModel->m_dwFlags2 & 0x00000080)
  288. {
  289. cmReturn << pcModel->m_dwIconHighlight;
  290. }
  291. // Mask 0x0200 Wield Type
  292. if(pcModel->m_dwFlags2 & 0x00000200)
  293. {
  294. cmReturn << pcModel->m_bWieldType;
  295. }
  296. // Mask 0x1000 Stack
  297. if(pcModel->m_dwFlags2 & 0x00001000)
  298. {
  299. cmReturn << pcModel->m_wStack;
  300. }
  301. // Mask 0x2000 Container
  302. if(pcModel->m_dwFlags2 & 0x00002000)
  303. {
  304. cmReturn << pcModel->m_wStackLimit;
  305. }
  306. // Mask 0x4000 Container
  307. if(pcModel->m_dwFlags2 & 0x00004000)
  308. {
  309. cmReturn << Container;
  310. }
  311. // Mask 0x10000 Equip Possible
  312. if(pcModel->m_dwFlags2 & 0x00010000)
  313. {
  314. cmReturn << DWORD(0x100000);
  315. //cmReturn << pcModel->m_dwEquipPossible;
  316. }
  317. // Mask 0x00200000 - Burden
  318. if(pcModel->m_dwFlags2 & 0x00200000)
  319. {
  320. cmReturn << pcModel->m_wBurden;
  321. }
  322. // Mask 0x01000000 - Workmanship
  323. if(pcModel->m_dwFlags2 & 0x01000000)
  324. {
  325. cmReturn << pcModel->m_fWorkmanship;
  326. }
  327. // Mask 0x10000000 - Hookable
  328. if(pcModel->m_dwFlags2 & 0x10000000)
  329. {
  330. cmReturn << pcModel->m_wHooks;
  331. }
  332. // Mask 0x80000000 - Material
  333. cmReturn << WORD(0x0000);
  334. cmReturn << BYTE(0x00);
  335. return cmReturn;
  336. }
  337. /**
  338. * Handles the actions of weapons objects.
  339. *
  340. * This function is called whenever a weapon is used or should perform an action.
  341. */
  342. void cWeapon::Action(cClient *who)
  343. {
  344. }
  345. /**
  346. * Handles the assessment of weapons objects.
  347. *
  348. * This function is called whenever a weapon is assessed by a client.
  349. *
  350. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  351. */
  352. void cWeapon::Assess( cClient *pcAssesser )
  353. {
  354. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  355. cMessage cmAssess;
  356. DWORD flags = 0x0000002D;
  357. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID
  358. << flags << 0x01L << WORD(0x03) << WORD(0x10)
  359. << 0x13L //Value
  360. << this->m_dwValue
  361. << 0x05L //Burden
  362. << DWORD(this->m_wWeight)
  363. << 0x2FL //??
  364. << 0x01L
  365. << WORD(0x01)
  366. << WORD(0x08)
  367. << 0x1DL
  368. << 0x00L
  369. << 0x00L
  370. << 0x00L
  371. << this->m_dwDamageType //Damage type
  372. << this->m_dwWeaponSpeed //Speed
  373. << this->m_dwWeaponSkill //Skill
  374. << this->m_dwWeaponDamage //max damage
  375. << this->m_dWeaponVariance //variance
  376. << double(1.0)
  377. << double(1.0)
  378. << double(0.2);
  379. if(this->m_dWeaponModifier > 1.1)
  380. cmAssess << this->m_dWeaponModifier; //defense mod (1.0 = 0%)
  381. if(this->m_dWeaponAttack > 1.1)
  382. cmAssess << this->m_dWeaponAttack; //attack mod (1.0 = 0%)
  383. pcAssesser->AddPacket(WORLD_SERVER, cmAssess,4);
  384. cMessage cmActionComplete;
  385. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  386. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  387. }