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

cFood.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 cFood.cpp
  19. * Implements functionality for food (apples, bread, etc).
  20. *
  21. * This class is referenced whenever food 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 food in the world.
  32. *
  33. * This function is called whenever food should be created in the world for a client.
  34. *
  35. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  36. */
  37. cMessage cFood::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. cmReturn << WORD( pcModel->m_wUnknown1 );
  59. }
  60. if ( pcModel->m_bTextureChange != 0)
  61. {
  62. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  63. {
  64. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  65. }
  66. }
  67. if ( pcModel->m_bModelChange != 0)
  68. {
  69. for (int i = 0; i < pcModel->m_bModelChange; i++)
  70. {
  71. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  72. }
  73. }
  74. }
  75. cmReturn.pasteAlign(4);
  76. cmReturn << pcModel->m_dwFlags1 << 0x414L << 0x65L;
  77. // MASK 0x00008000 -- Location
  78. if ( !m_fIsOwned )
  79. cmReturn.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  80. // MASK 0x00000800 -- Sound Set
  81. DWORD dwSoundSet = 0x20000000L + pcModel->m_wSoundSet;
  82. cmReturn << dwSoundSet;
  83. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  84. cmReturn << 0x34000000 + pcModel->m_dwUnknown_Blue;
  85. // MASK 0x00000001 -- ModelNumber
  86. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  87. cmReturn << dwModel;
  88. // SeaGreens
  89. WORD wNuminteracts = 0x0;
  90. WORD wNumbubbles = 0x0;
  91. WORD wNumJumps = 0x0;
  92. WORD wNumOverrides = 0x0;
  93. WORD wUnkFlag8 = 0x0;
  94. WORD wUnkFlag10 = 0x0;
  95. cmReturn << m_wPositionSequence
  96. << m_wNumAnims //wNuminteracts
  97. << wNumbubbles
  98. << wNumJumps
  99. << m_wNumPortals
  100. << m_wNumAnims
  101. << wNumOverrides
  102. << wUnkFlag8
  103. << m_wNumLogins
  104. << wUnkFlag10;
  105. cmReturn << pcModel->m_dwFlags2; // Object Flags
  106. cmReturn << Name( ); // Object's Name
  107. cmReturn << pcModel->m_wModel; // Object's Model
  108. cmReturn << pcModel->m_wIcon; // Object's Icon
  109. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  110. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  111. if(pcModel->m_dwFlags2 & 0x00000008)
  112. {
  113. cmReturn << 0x0FL;
  114. }
  115. // Mask 0x0010 dwUnknown_v2
  116. cmReturn << DWORD(0x00000020);
  117. // Mask 0x1000 Stack size
  118. cmReturn << WORD(0x0002);
  119. // Mask 0x2000 Stack Limit
  120. cmReturn << WORD(0x0064);
  121. // Mask 0x00200000 - Burden
  122. cmReturn << WORD(0x0040);
  123. pcObject->SetType(2);
  124. return cmReturn;
  125. }
  126. /**
  127. * Handles the message sent for the creation of food in a container.
  128. *
  129. * This function is called whenever food should be created in the inventory of another object.
  130. *
  131. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  132. */
  133. cMessage cFood::CreatePacketContainer( DWORD Container, DWORD ItemModelID )
  134. {
  135. cMessage cmReturn;
  136. cItemModels *pcModel = cItemModels::FindModel( ItemModelID );
  137. cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  138. if( pcModel )
  139. {
  140. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11) //0x11 is a constant
  141. << pcModel->m_bPaletteChange
  142. << pcModel->m_bTextureChange
  143. << pcModel->m_bModelChange;
  144. // The Model Vectors
  145. if ( pcModel->m_bPaletteChange != 0)
  146. {
  147. for (int i = 0; i < pcModel->m_bPaletteChange; i++)
  148. {
  149. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorPal[i],sizeof(pcModel->m_vectorPal[i]));
  150. }
  151. }
  152. if (pcModel->m_bPaletteChange != 0)
  153. {
  154. cmReturn << WORD( pcModel->m_wUnknown1 );
  155. }
  156. if ( pcModel->m_bTextureChange != 0)
  157. {
  158. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  159. {
  160. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  161. }
  162. }
  163. if ( pcModel->m_bModelChange != 0)
  164. {
  165. for (int i = 0; i < pcModel->m_bModelChange; i++)
  166. {
  167. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  168. }
  169. }
  170. }
  171. cmReturn.pasteAlign(4);
  172. cmReturn << 0x00021801 << 0x414L << 0x65L;
  173. // MASK 0x00000800 -- Sound Set
  174. DWORD dwSoundSet = 0x20000000L + pcModel->m_wSoundSet;
  175. cmReturn << dwSoundSet;
  176. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  177. cmReturn << 0x34000000 + pcModel->m_dwUnknown_Blue;
  178. // MASK 0x00000001 -- ModelNumber
  179. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  180. cmReturn << dwModel;
  181. // SeaGreens
  182. WORD wNuminteracts = 0x0;
  183. WORD wNumbubbles = 0x0;
  184. WORD wNumJumps = 0x0;
  185. WORD wNumOverrides = 0x0;
  186. WORD wUnkFlag8 = 0x0;
  187. WORD wUnkFlag10 = 0x0;
  188. cmReturn << m_wPositionSequence
  189. << m_wNumAnims //wNuminteracts
  190. << wNumbubbles
  191. << wNumJumps
  192. << m_wNumPortals
  193. << m_wNumAnims
  194. << wNumOverrides
  195. << wUnkFlag8
  196. << m_wNumLogins
  197. << wUnkFlag10;
  198. cmReturn << pcModel->m_dwFlags2;
  199. cmReturn << Name( ); // Object's Name
  200. cmReturn << pcModel->m_wModel; // Object's Model
  201. cmReturn << pcModel->m_wIcon; // Object's Icon
  202. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  203. cmReturn << pcModel->m_dwObjectFlags2;
  204. if(pcModel->m_dwFlags2 & 0x00000008)
  205. cmReturn << 0x0L;
  206. if(pcModel->m_dwFlags2 & 0x00000010)
  207. cmReturn << DWORD(0x00000020);
  208. if(pcModel->m_dwFlags2 & 0x00001000)
  209. cmReturn << this->m_wStack;
  210. if(pcModel->m_dwFlags2 & 0x00002000)
  211. cmReturn << pcModel->m_wStackLimit;
  212. if(pcModel->m_dwFlags2 & 0x00004000)
  213. cmReturn << Container;
  214. if(pcModel->m_dwFlags2 & 0x00200000)
  215. cmReturn << pcModel->m_wBurden;
  216. return cmReturn;
  217. }
  218. /**
  219. * Handles the actions of food objects.
  220. *
  221. * This function is called whenever food is used or should perform an action.
  222. */
  223. void cFood::Action(cClient* who)
  224. {
  225. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  226. //cFood *pcObject = reinterpret_cast <cFood *>(cWorldManager::FindObject( m_dwGUID ));
  227. //cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  228. int updated_stats;
  229. int change = who->m_pcAvatar->GetTotalStamina();
  230. int ret_amount;
  231. //Lift to mouth animation
  232. cMessage cAnimation1 = who->m_pcAvatar->Animation(26,1.0f);
  233. cWorldManager::SendToAllInFocus( who->m_pcAvatar->m_Location, cAnimation1, 3 );
  234. //which food is this (CurVitalID)
  235. switch(this->m_dwVitalID)
  236. {
  237. case 0x00000002:
  238. {
  239. //Update Health
  240. cMessage cmEat = who->m_pcAvatar->UpdateHealth(this->m_dwAmount,updated_stats);
  241. who->AddPacket( WORLD_SERVER,cmEat,4);
  242. if ( updated_stats > change )
  243. ret_amount = 0;
  244. else
  245. ret_amount = this->m_dwAmount;
  246. cMasterServer::ServerMessage( ColorGreen,who,"The %s restores %d points of your health.",pcModel->m_strName.c_str(),ret_amount);
  247. }
  248. break;
  249. case 0x00000004:
  250. {
  251. //Update Stamina
  252. cMessage cmEat = who->m_pcAvatar->UpdateStamina(this->m_dwAmount,updated_stats);
  253. who->AddPacket( WORLD_SERVER,cmEat,4);
  254. if ( updated_stats > change )
  255. ret_amount = 0;
  256. else
  257. ret_amount = this->m_dwAmount;
  258. cMasterServer::ServerMessage( ColorGreen,who,"The %s restores %d points of your stamina.",pcModel->m_strName.c_str(),ret_amount);
  259. }
  260. break;
  261. case 0x00000006:
  262. {
  263. //Update Mana
  264. cMessage cmEat = who->m_pcAvatar->UpdateMana(this->m_dwAmount,updated_stats);
  265. who->AddPacket( WORLD_SERVER,cmEat,4);
  266. if ( updated_stats > change )
  267. ret_amount = 0;
  268. else
  269. ret_amount = this->m_dwAmount;
  270. cMasterServer::ServerMessage( ColorGreen,who,"The %s restores %d points of your stamina.",pcModel->m_strName.c_str(),ret_amount);
  271. }
  272. break;
  273. }
  274. //Put hand back down
  275. cMessage cAnimation2 = who->m_pcAvatar->Animation(0,1.0f);
  276. cWorldManager::SendToAllInFocus( who->m_pcAvatar->m_Location, cAnimation2, 3 );
  277. cMessage cmActionComplete;
  278. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++m_dwF7B0Sequence << 0x01C7L << 0L;
  279. who->AddPacket( WORLD_SERVER,cmActionComplete,4);
  280. who->m_pcAvatar->DeleteFromInventory(this);
  281. cDatabase::RemoveFromInventoryDB(who->m_pcAvatar->GetGUID(),m_dwGUID);
  282. cMessage cmRemoveItem;
  283. cmRemoveItem << 0x0024L << m_dwGUID;
  284. who->AddPacket(WORLD_SERVER,cmRemoveItem,4);
  285. }
  286. /**
  287. * Handles the assessment of food objects.
  288. *
  289. * This function is called whenever food is assessed by a client.
  290. *
  291. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  292. */
  293. void cFood::Assess(cClient *pcAssesser)
  294. {
  295. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  296. cMessage cmAssess;
  297. DWORD flags = 0x00000009;
  298. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID
  299. << flags
  300. << 0x01L //Success = 0x01, Failure = 0x00
  301. << WORD(0x0004) //Total number of DWORDS
  302. << WORD(0x0010) //Unknown
  303. << 0x13L //Value
  304. << this->m_dwValue // 4 pyreals
  305. << 0x05L //Burden
  306. << DWORD (this->m_wBurden) //50 bu
  307. << 0x59L //Affects (Vital ID)
  308. << this->m_dwVitalID //0x04 - Stamina
  309. << 0x5AL //Affects (Amount of vital restored when used)
  310. << this->m_wStack //Amount
  311. << WORD(0x0001) //Count (as above) total number of DWORDS
  312. << WORD(0x0008) //Unknown
  313. << 0x0EL //String
  314. << 0x0AL; //This should be amount of characters, but does not seem to affect anything.
  315. pcAssesser->AddPacket(WORLD_SERVER, cmAssess,4);
  316. }