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

cAmmo.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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 cAmmo.cpp
  19. * Implements functionality for ammunition (arrows, darts, clubs, etc).
  20. *
  21. * This class is referenced whenever ammunition 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 ammunition in the world.
  32. *
  33. * This function is called whenever ammunition should be created in the world for a client.
  34. *
  35. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  36. */
  37. cMessage cAmmo::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. pcModel->m_dwFlags1 += 0x00008000;
  78. cmReturn << pcModel->m_dwFlags1 << 0x414L << 0x65L;
  79. // MASK 0x00008000 -- Location
  80. if ( !m_fIsOwned )
  81. cmReturn.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  82. // MASK 0x00000800 -- Sound Set
  83. DWORD dwSoundSet = 0x20000000L + pcModel->m_wSoundSet;
  84. cmReturn << dwSoundSet;
  85. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  86. cmReturn << 0x34000000 + pcModel->m_dwUnknown_Blue;
  87. // MASK 0x00000001 -- ModelNumber
  88. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  89. cmReturn << dwModel;
  90. if(pcModel->m_dwFlags1 & 0x00000080)
  91. {
  92. cmReturn << pcModel->m_flScale;
  93. }
  94. // SeaGreens
  95. WORD wNuminteracts = 0x0;
  96. WORD wNumbubbles = 0x0;
  97. WORD wNumJumps = 0x0;
  98. WORD wNumOverrides = 0x0;
  99. WORD wUnkFlag8 = 0x0;
  100. WORD wUnkFlag10 = 0x0;
  101. cmReturn << m_wPositionSequence
  102. << m_wNumAnims //wNuminteracts
  103. << wNumbubbles
  104. << wNumJumps
  105. << m_wNumPortals
  106. << m_wNumAnims
  107. << wNumOverrides
  108. << wUnkFlag8
  109. << m_wNumLogins
  110. << wUnkFlag10;
  111. if(pcModel->m_dwContainerID != 0)
  112. {
  113. DWORD owned = pcModel->m_dwFlags2 & 0x00004000;
  114. cmReturn << owned;
  115. }
  116. else
  117. {
  118. cmReturn << pcModel->m_dwFlags2; // Object Flags
  119. }
  120. cmReturn << Name( ); // Object's Name
  121. cmReturn << pcModel->m_wModel; // Object's Model
  122. cmReturn << pcModel->m_wIcon; // Object's Icon
  123. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  124. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  125. //Cube: NOTE: For ammo, ammo type comes before value
  126. if(pcModel->m_dwFlags2 & 0x00000100)
  127. {
  128. cmReturn << pcModel->m_wAmmoType;
  129. }
  130. if(pcModel->m_dwFlags2 & 0x00000008)
  131. {
  132. cmReturn << pcModel->m_dwValue;
  133. }
  134. if(pcModel->m_dwFlags2 & 0x00000010)
  135. {
  136. cmReturn << pcModel->m_dwUnknown_v2;
  137. }
  138. if(pcModel->m_dwFlags2 & 0x00000080)
  139. {
  140. cmReturn << pcModel->m_dwIconHighlight;
  141. }
  142. if(pcModel->m_dwFlags2 & 0x00000200)
  143. {
  144. cmReturn << pcModel->m_bWieldType;
  145. }
  146. if(pcModel->m_dwFlags2 & 0x00001000)
  147. {
  148. cmReturn << pcModel->m_wStack;
  149. }
  150. if(pcModel->m_dwFlags2 & 0x00002000)
  151. {
  152. cmReturn << pcModel->m_wStackLimit;
  153. }
  154. if(pcModel->m_dwFlags2 & 0x00004000)
  155. {
  156. cmReturn << m_dwGUID;
  157. }
  158. if(pcModel->m_dwFlags2 & 0x00010000)
  159. {
  160. cmReturn << pcModel->m_dwEquipPossible;
  161. }
  162. if(pcModel->m_dwFlags2 & 0x00200000)
  163. {
  164. cmReturn << pcModel->m_wBurden;
  165. }
  166. if(pcModel->m_dwFlags2 & 0x10000000)
  167. {
  168. cmReturn << pcModel->m_wHooks;
  169. }
  170. //Below is padding: DO NOT REMOVE!
  171. cmReturn
  172. //<< WORD(0x0000)
  173. << BYTE(0x00);
  174. return cmReturn;
  175. }
  176. /**
  177. * Handles the message sent for the creation of ammunition in a container.
  178. *
  179. * This function is called whenever ammunition should be created in the inventory of another object.
  180. *
  181. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  182. */
  183. cMessage cAmmo::CreatePacketContainer( DWORD Container, DWORD ItemModelID )
  184. {
  185. cMessage cmReturn;
  186. cItemModels *pcModel = cItemModels::FindModel( ItemModelID );
  187. cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  188. if( pcModel )
  189. {
  190. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11); //0x11 is a constant
  191. cmReturn << pcModel->m_bPaletteChange
  192. << pcModel->m_bTextureChange
  193. << pcModel->m_bModelChange;
  194. // The Model Vectors
  195. if ( pcModel->m_bPaletteChange != 0)
  196. {
  197. for (int i = 0; i < pcModel->m_bPaletteChange; i++)
  198. {
  199. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorPal[i],sizeof(pcModel->m_vectorPal[i]));
  200. }
  201. }
  202. if (pcModel->m_bPaletteChange != 0)
  203. {
  204. //Cubem0j0: Test code for armor only.
  205. cmReturn << WORD( pcModel->m_wUnknown_1 );
  206. }
  207. if ( pcModel->m_bTextureChange != 0)
  208. {
  209. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  210. {
  211. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  212. }
  213. }
  214. if ( pcModel->m_bModelChange != 0)
  215. {
  216. for (int i = 0; i < pcModel->m_bModelChange; i++)
  217. {
  218. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  219. }
  220. }
  221. }
  222. cmReturn.pasteAlign(4);
  223. cmReturn << pcModel->m_dwFlags1 << 0x414L << 0x65L;
  224. // MASK 0x00008000 -- Location
  225. // if ( !m_fIsOwned )
  226. // cmReturn.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  227. // MASK 0x00000800 -- Sound Set
  228. DWORD dwSoundSet = 0x20000000L + pcModel->m_wSoundSet;
  229. cmReturn << dwSoundSet;
  230. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  231. cmReturn << 0x34000000 + pcModel->m_dwUnknown_Blue;
  232. // MASK 0x00000001 -- ModelNumber
  233. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  234. cmReturn << dwModel;
  235. if(pcModel->m_dwFlags1 & 0x00000080)
  236. cmReturn << pcModel->m_flScale;
  237. // SeaGreens
  238. WORD wNuminteracts = 0x0;
  239. WORD wNumbubbles = 0x0;
  240. WORD wNumJumps = 0x0;
  241. WORD wNumOverrides = 0x0;
  242. WORD wUnkFlag8 = 0x0;
  243. WORD wUnkFlag10 = 0x0;
  244. cmReturn << m_wPositionSequence
  245. << m_wNumAnims //wNuminteracts
  246. << wNumbubbles
  247. << wNumJumps
  248. << m_wNumPortals
  249. << m_wNumAnims
  250. << wNumOverrides
  251. << wUnkFlag8
  252. << m_wNumLogins
  253. << wUnkFlag10;
  254. cmReturn << pcModel->m_dwFlags2; // Object Flags
  255. cmReturn << Name( ); // Object's Name
  256. cmReturn << pcModel->m_wModel; // Object's Model
  257. cmReturn << this->m_wIcon; // Object's Icon
  258. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  259. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  260. //Cube: NOTE: For ammo, ammo type comes before value
  261. if(pcModel->m_dwFlags2 & 0x00000100)
  262. {
  263. cmReturn << pcModel->m_wAmmoType;
  264. }
  265. if(pcModel->m_dwFlags2 & 0x00000008)
  266. {
  267. cmReturn << pcModel->m_dwValue;
  268. }
  269. if(pcModel->m_dwFlags2 & 0x00000010)
  270. {
  271. cmReturn << pcModel->m_dwUnknown_v2;
  272. }
  273. if(pcModel->m_dwFlags2 & 0x00000080)
  274. {
  275. cmReturn << pcModel->m_dwIconHighlight;
  276. }
  277. if(pcModel->m_dwFlags2 & 0x00000200)
  278. {
  279. cmReturn << pcModel->m_bWieldType;
  280. }
  281. if(pcModel->m_dwFlags2 & 0x00001000)
  282. {
  283. cmReturn << pcModel->m_wStack;
  284. }
  285. if(pcModel->m_dwFlags2 & 0x00002000)
  286. {
  287. cmReturn << pcModel->m_wStackLimit;
  288. }
  289. if(pcModel->m_dwFlags2 & 0x00004000)
  290. {
  291. cmReturn << Container;
  292. }
  293. if(pcModel->m_dwFlags2 & 0x00010000)
  294. {
  295. cmReturn << pcModel->m_dwEquipPossible;
  296. }
  297. if(pcModel->m_dwFlags2 & 0x00200000)
  298. {
  299. cmReturn << pcModel->m_wBurden;
  300. }
  301. if(pcModel->m_dwFlags2 & 0x10000000)
  302. {
  303. cmReturn << pcModel->m_wHooks;
  304. }
  305. //Below is padding: DO NOT REMOVE!
  306. cmReturn
  307. << WORD(0x0000)
  308. << BYTE(0x00);
  309. return cmReturn;
  310. }
  311. /**
  312. * Handles the actions of ammunition objects.
  313. *
  314. * This function is called whenever ammunition is used or should perform an action.
  315. */
  316. void cAmmo::Action(cClient *who)
  317. {
  318. }
  319. /**
  320. * Handles the assessment of ammunition objects.
  321. *
  322. * This function is called whenever ammunition is assessed by a client.
  323. *
  324. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  325. */
  326. void cAmmo::Assess( cClient *pcAssesser )
  327. {
  328. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  329. cMessage cmAssess;
  330. DWORD flags = 0x00000009;
  331. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID
  332. << flags
  333. << 0x01L
  334. << WORD(0x02)
  335. << WORD(0x10)
  336. << 0x13L
  337. << pcModel->m_dwValue
  338. << 0x05L
  339. << DWORD(pcModel->m_wBurden)
  340. << WORD(0x01)
  341. << WORD(0x08)
  342. << 0x10L
  343. << pcModel->m_strDescription.c_str();
  344. pcAssesser->AddPacket(WORLD_SERVER, cmAssess,4);
  345. cMessage cmActionComplete;
  346. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  347. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  348. }