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

cManaStones.cpp 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 cManaStones.cpp
  19. * Implements functionality for mana stones.
  20. *
  21. * This class is referenced whenever a mana stone 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 mana stones in the world.
  32. *
  33. * This function is called whenever a mana stone should be created in the world for a client.
  34. *
  35. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  36. */
  37. cMessage cManaStones::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 0x00000001 -- ModelNumber
  83. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  84. cmReturn << dwModel;
  85. // SeaGreens
  86. WORD wNuminteracts = 0x0;
  87. WORD wNumbubbles = 0x0;
  88. WORD wNumJumps = 0x0;
  89. WORD wNumOverrides = 0x0;
  90. WORD wUnkFlag8 = 0x0;
  91. WORD wUnkFlag10 = 0x0;
  92. cmReturn << m_wPositionSequence
  93. << m_wNumAnims //wNuminteracts
  94. << wNumbubbles
  95. << wNumJumps
  96. << m_wNumPortals
  97. << m_wNumAnims
  98. << wNumOverrides
  99. << wUnkFlag8
  100. << m_wNumLogins
  101. << wUnkFlag10;
  102. DWORD dwFlags2 = 0x10280018;
  103. cmReturn << dwFlags2;
  104. cmReturn << Name( ); // Objects Name
  105. cmReturn << pcModel->m_wModel; // Objects Model
  106. cmReturn << pcModel->m_wIcon; // Objects Icon
  107. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  108. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  109. //Lockpicks flag2 - 00280c18
  110. // Mask 0x0008 - Value
  111. if(pcModel->m_dwFlags2 & 0x00000008)
  112. {
  113. cmReturn << pcModel->m_dwValue;
  114. }
  115. // Mask 0x0010 dwUnknown_v2
  116. cmReturn << DWORD(0x000A0008);
  117. // Mase 0x080000 Useable On
  118. if(pcModel->m_dwFlags2 & 0x00080000)
  119. {
  120. cmReturn << 0x891FL;
  121. }
  122. // Mase 0x0080 Icon Highlight
  123. if(pcModel->m_dwFlags2 & 0x00000080)
  124. {
  125. cmReturn << pcModel->m_dwIconHighlight;
  126. }
  127. // Mask 0x00200000 - Burden
  128. if(pcModel->m_dwFlags2 & 0x00200000)
  129. {
  130. cmReturn << pcModel->m_wBurden;
  131. }
  132. //Mask 0x100000000 - Hooks
  133. if(pcModel->m_dwFlags2 & 0x10000000)
  134. {
  135. cmReturn << pcModel->m_wHooks;
  136. }
  137. return cmReturn;
  138. }
  139. /**
  140. * Handles the message sent for the creation of mana stones in a container.
  141. *
  142. * This function is called whenever a mana stone should be created in the inventory of another object.
  143. *
  144. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  145. */
  146. cMessage cManaStones::CreatePacketContainer(DWORD Container, DWORD ItemModelID)
  147. {
  148. cMessage cmReturn;
  149. cItemModels *pcModel = cItemModels::FindModel( ItemModelID );
  150. cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  151. if( pcModel )
  152. {
  153. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11); //0x11 is a constant
  154. cmReturn << pcModel->m_bPaletteChange
  155. << pcModel->m_bTextureChange
  156. << pcModel->m_bModelChange;
  157. // The Model Vectors
  158. if ( pcModel->m_bPaletteChange != 0)
  159. {
  160. for (int i = 0; i < pcModel->m_bPaletteChange; i++)
  161. {
  162. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorPal[i],sizeof(pcModel->m_vectorPal[i]));
  163. }
  164. }
  165. if (pcModel->m_bPaletteChange != 0)
  166. {
  167. //Cubem0j0: Test code for armor only.
  168. cmReturn << WORD( 0x0C50 );
  169. }
  170. if ( pcModel->m_bTextureChange != 0)
  171. {
  172. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  173. {
  174. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  175. }
  176. }
  177. if ( pcModel->m_bModelChange != 0)
  178. {
  179. for (int i = 0; i < pcModel->m_bModelChange; i++)
  180. {
  181. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  182. }
  183. }
  184. }
  185. cmReturn.pasteAlign(4);
  186. cmReturn << pcModel->m_dwFlags1 << 0x414L << 0x65L;
  187. // MASK 0x00008000 -- Location
  188. if ( !m_fIsOwned )
  189. cmReturn.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  190. // MASK 0x00000001 -- ModelNumber
  191. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  192. cmReturn << dwModel;
  193. // SeaGreens
  194. WORD wNuminteracts = 0x0;
  195. WORD wNumbubbles = 0x0;
  196. WORD wNumJumps = 0x0;
  197. WORD wNumOverrides = 0x0;
  198. WORD wUnkFlag8 = 0x0;
  199. WORD wUnkFlag10 = 0x0;
  200. cmReturn << m_wPositionSequence
  201. << m_wNumAnims //wNuminteracts
  202. << wNumbubbles
  203. << wNumJumps
  204. << m_wNumPortals
  205. << m_wNumAnims
  206. << wNumOverrides
  207. << wUnkFlag8
  208. << m_wNumLogins
  209. << wUnkFlag10;
  210. cmReturn << pcModel->m_dwFlags2; // Object Flags
  211. cmReturn << Name( ); // Objects Name
  212. cmReturn << pcModel->m_wModel; // Objects Model
  213. cmReturn << pcModel->m_wIcon; // Objects Icon
  214. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  215. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  216. // Mask 0x0008 - Value
  217. if(pcModel->m_dwFlags2 & 0x00000008)
  218. {
  219. cmReturn << pcModel->m_dwValue;
  220. }
  221. // Mask 0x0010 dwUnknown_v2
  222. cmReturn << DWORD(0x000A0008);
  223. // Mase 0x080000 Useable On
  224. if(pcModel->m_dwFlags2 & 0x00080000)
  225. {
  226. cmReturn << 0x891FL;
  227. }
  228. // Mase 0x0080 Icon Highlight
  229. if(pcModel->m_dwFlags2 & 0x00000080)
  230. {
  231. cmReturn << pcModel->m_dwIconHighlight;
  232. }
  233. // Mask 0x4000 Container ID
  234. if(pcModel->m_dwFlags2 & 0x00004000)
  235. {
  236. cmReturn << Container;
  237. }
  238. // Mask 0x00200000 - Burden
  239. if(pcModel->m_dwFlags2 & 0x00200000)
  240. {
  241. cmReturn << pcModel->m_wBurden;
  242. }
  243. //Mask 0x100000000 - Hooks
  244. if(pcModel->m_dwFlags2 & 0x10000000)
  245. {
  246. cmReturn << pcModel->m_wHooks;
  247. }
  248. return cmReturn;
  249. }
  250. /**
  251. * Handles the actions of mana stone objects.
  252. *
  253. * This function is called whenever a mana stone is used or should perform an action.
  254. */
  255. void cManaStones::Action(cClient *who)
  256. {
  257. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  258. cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  259. cMessage cmActionComplete;
  260. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  261. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  262. if(pcModel->m_wUses == 0)
  263. {
  264. //Remove the item
  265. who->m_pcAvatar->DeleteFromInventory(pcObject);
  266. cMessage cmRemoveItem;
  267. cmRemoveItem << 0x0024L << m_dwGUID;
  268. who->AddPacket(WORLD_SERVER,cmRemoveItem,4);
  269. }
  270. }
  271. /**
  272. * Handles the assessment of mana stone objects.
  273. *
  274. * This function is called whenever a mana stone is assessed by a client.
  275. *
  276. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  277. */
  278. void cManaStones::Assess( cClient *pcAssesser )
  279. {
  280. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  281. cMessage cmAssess;
  282. DWORD flags = 0x00000009;
  283. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID
  284. << flags
  285. << 0x01L
  286. << WORD(0x05)
  287. << WORD(0x10)
  288. << 0x13L
  289. << pcModel->m_dwValue
  290. << 0x05L
  291. << DWORD(pcModel->m_wBurden)
  292. << 0x6BL //Current mana
  293. << 0x00L
  294. << WORD(0x01)
  295. << WORD(0x08)
  296. << 0x89L //Chance of Destruction
  297. << float(50.0)
  298. << WORD(0x01)
  299. << WORD(0x08)
  300. << 0x0EL
  301. << pcModel->m_strDescription.c_str();
  302. pcAssesser->AddPacket(WORLD_SERVER, cmAssess,4);
  303. cMessage cmActionComplete;
  304. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  305. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  306. }