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

cPyreals.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 cPyreals.cpp
  19. * Implements functionality for pyreals.
  20. *
  21. * This class is referenced whenever a pyreal object is created, used, stacked, split, 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 pyreals in the world.
  32. *
  33. * This function is called whenever a pyreal (or group/stack of pyreals) should be created in the world for a client.
  34. *
  35. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  36. */
  37. cMessage cPyreals::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 << pcModel->m_dwFlags1 << 0x414L << 0x65L;
  78. // MASK 0x00008000 -- Location
  79. if ( !m_fIsOwned )
  80. cmReturn.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  81. /*
  82. // MASK 0x00000800 -- Sound Set
  83. if (pcModel->m_dwFlags1 & 0x00000800 == 0x00000800) {
  84. DWORD dwSoundSet = 0x20000000L + pcModel->m_wSoundSet;
  85. cmReturn << dwSoundSet;
  86. }
  87. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  88. if (pcModel->m_dwFlags1 & 0x00001000 == 0x00001000) {
  89. cmReturn << 0x34000000 + pcModel->m_dwUnknown_Blue;
  90. }
  91. */
  92. // MASK 0x00000001 -- ModelNumber
  93. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  94. cmReturn << dwModel;
  95. // SeaGreens
  96. WORD wNuminteracts = 0x0;
  97. WORD wNumbubbles = 0x0;
  98. WORD wNumJumps = 0x0;
  99. WORD wNumOverrides = 0x0;
  100. WORD wUnkFlag8 = 0x0;
  101. WORD wUnkFlag10 = 0x0;
  102. cmReturn << m_wPositionSequence
  103. << m_wNumAnims //wNuminteracts
  104. << wNumbubbles
  105. << wNumJumps
  106. << m_wNumPortals
  107. << m_wNumAnims
  108. << wNumOverrides
  109. << wUnkFlag8
  110. << m_wNumLogins
  111. << wUnkFlag10;
  112. cmReturn << pcModel->m_dwFlags2;
  113. cmReturn << Name( ); // Objects Name
  114. cmReturn << pcModel->m_wModel; // Objects Model
  115. cmReturn << pcModel->m_wIcon; // Objects Icon
  116. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  117. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  118. if(pcModel->m_dwFlags2 & 0x00000008)
  119. cmReturn << this->m_wStack;
  120. if(pcModel->m_dwFlags2 & 0x00000010)
  121. cmReturn << pcModel->m_dwUnknown_v2;
  122. if(pcModel->m_dwFlags2 & 0x00001000)
  123. cmReturn << this->m_wStack;
  124. if(pcModel->m_dwFlags2 & 0x00002000)
  125. cmReturn << this->m_wStackLimit;
  126. return cmReturn;
  127. }
  128. /**
  129. * Handles the message sent for the creation of pyreals in a container.
  130. *
  131. * This function is called whenever a pyreal (or group/stack of pyreals) should be created in the inventory of another object.
  132. *
  133. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  134. */
  135. cMessage cPyreals::CreatePacketContainer(DWORD Container, DWORD ItemModelID)
  136. {
  137. cMessage cmReturn;
  138. cItemModels *pcModel = cItemModels::FindModel( ItemModelID );
  139. cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  140. if( pcModel )
  141. {
  142. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11); //0x11 is a constant
  143. cmReturn << pcModel->m_bPaletteChange
  144. << pcModel->m_bTextureChange
  145. << pcModel->m_bModelChange;
  146. // The Model Vectors
  147. if ( pcModel->m_bPaletteChange != 0)
  148. {
  149. for (int i = 0; i < pcModel->m_bPaletteChange; i++)
  150. {
  151. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorPal[i],sizeof(pcModel->m_vectorPal[i]));
  152. }
  153. }
  154. if (pcModel->m_bPaletteChange != 0)
  155. {
  156. //Cubem0j0: Test code for armor only.
  157. cmReturn << WORD( 0x0C50 );
  158. }
  159. if ( pcModel->m_bTextureChange != 0)
  160. {
  161. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  162. {
  163. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  164. }
  165. }
  166. if ( pcModel->m_bModelChange != 0)
  167. {
  168. for (int i = 0; i < pcModel->m_bModelChange; i++)
  169. {
  170. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  171. }
  172. }
  173. }
  174. cmReturn.pasteAlign(4);
  175. cmReturn << pcModel->m_dwFlags1 << 0x414L << 0x65L;
  176. // MASK 0x00000001 -- ModelNumber
  177. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  178. cmReturn << dwModel;
  179. // SeaGreens
  180. WORD wNuminteracts = 0x0;
  181. WORD wNumbubbles = 0x0;
  182. WORD wNumJumps = 0x0;
  183. WORD wNumOverrides = 0x0;
  184. WORD wUnkFlag8 = 0x0;
  185. WORD wUnkFlag10 = 0x0;
  186. cmReturn << m_wPositionSequence
  187. << m_wNumAnims //wNuminteracts
  188. << wNumbubbles
  189. << wNumJumps
  190. << m_wNumPortals
  191. << m_wNumAnims
  192. << wNumOverrides
  193. << wUnkFlag8
  194. << m_wNumLogins
  195. << wUnkFlag10;
  196. //DWORD dwFlags2 = 0x00007018;
  197. cmReturn << pcModel->m_dwFlags2;
  198. cmReturn << Name( ); // Objects Name
  199. cmReturn << pcModel->m_wModel; // Objects Model
  200. cmReturn << pcModel->m_wIcon; // Objects Icon
  201. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  202. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  203. DWORD Value = DWORD(this->m_wStack);
  204. if(pcModel->m_dwFlags2 & 0x00000008)
  205. cmReturn << Value;
  206. if(pcModel->m_dwFlags2 & 0x00000010)
  207. cmReturn << pcModel->m_dwUnknown_v2;
  208. if(pcModel->m_dwFlags2 & 0x00001000)
  209. cmReturn << this->m_wStack;
  210. if(pcModel->m_dwFlags2 & 0x00002000)
  211. cmReturn << this->m_wStackLimit;
  212. if(pcModel->m_dwFlags2 & 0x00004000)
  213. cmReturn << Container;
  214. return cmReturn;
  215. }
  216. /**
  217. * Handles the actions of pyreal objects.
  218. *
  219. * This function is called whenever a pyreal is used or should perform an action.
  220. */
  221. void cPyreals::Action(cClient *who)
  222. {
  223. }
  224. /**
  225. * Handles the stacking of pyreal objects.
  226. *
  227. * This function is called whenever pyreals are stacked (one pyreal or group of pyreals added or stacked to another).
  228. */
  229. void cPyreals::Stack(cClient *who, DWORD item1, DWORD item2, DWORD amount)
  230. {
  231. }
  232. /**
  233. * Handles the splitting of pyreal objects.
  234. *
  235. * This function is called whenever pyreals are split (one pyreal or group of pyreals removed from or split with its group).
  236. */
  237. void cPyreals::Split(cClient *who, DWORD item_guid, DWORD slot, DWORD value)
  238. {
  239. cObject *Original = who->m_pcAvatar->FindInventory(item_guid);
  240. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  241. DWORD org_stack = DWORD(this->m_wStack);
  242. DWORD org_value = this->m_dwValue - value;
  243. cMasterServer::ServerMessage(ColorBlue,NULL,"Orig Stack: %ul",org_stack);
  244. //k109: Minus the value from original item
  245. DWORD newstack = org_stack - value;
  246. //k109: Send the 0x0197 message
  247. cMessage AdjustStack;
  248. AdjustStack << 0x0197L << BYTE(0x01) << item_guid << this->m_dwValue - value << org_stack;
  249. who->AddPacket(WORLD_SERVER,AdjustStack,4);
  250. cMasterServer::ServerMessage(ColorBlue,NULL,"Adjust Stack Fired");
  251. //k109: Create the new item, its stack set to value
  252. cPyreals* cash = new cPyreals(cWorldManager::NewGUID_Object(),who->m_pcAvatar->GetGUID(),m_dwItemModelID,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,value,WORD(value),pcModel->m_wStackLimit);
  253. who->AddPacket( WORLD_SERVER, cash->CreatePacketContainer(who->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  254. who->m_pcAvatar->AddInventory(cash);
  255. cMasterServer::ServerMessage(ColorBlue,NULL,"Pyreals Created");
  256. //k109: Add the newly created item to the slot in the message
  257. cMessage cmInsInv;
  258. cmInsInv << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++m_dwF7B0Sequence << 0x0022L << cash->GetGUID() << who->m_pcAvatar->GetGUID( ) << slot << 0L;
  259. who->AddPacket( WORLD_SERVER, cmInsInv, 4 );
  260. cMasterServer::ServerMessage(ColorBlue,NULL,"Insert Inventory");
  261. cMessage cmActionComplete;
  262. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  263. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  264. }
  265. /**
  266. * Handles the assessment of jewelry objects.
  267. *
  268. * This function is called whenever jewelry is assessed by a client.
  269. *
  270. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  271. */
  272. void cPyreals::Assess( cClient *pcAssesser )
  273. {
  274. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  275. cMessage cmAssess;
  276. DWORD flags = 0x0000001;
  277. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID
  278. << flags
  279. << 0x01L //Success = 0x01, Failure = 0x00
  280. << WORD(0x0002)
  281. << WORD(0x0010)
  282. << 0x13L //Value
  283. << DWORD(this->m_wStack) //Amount
  284. << 0x05L //Burden
  285. << 0x00L;
  286. pcAssesser->AddPacket(WORLD_SERVER, cmAssess,4);
  287. cMessage cmActionComplete;
  288. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  289. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  290. }