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

cHealingCon.cpp 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 cHealingCon.cpp
  19. * Implements functionality for healing containers.
  20. *
  21. * This class is referenced whenever a healing container 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 healing containers in the world.
  32. *
  33. * This function is called whenever a healing container should be created in the world for a client.
  34. *
  35. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  36. */
  37. cMessage cHealingCon::CreatePacket()
  38. {
  39. cMessage cmNull;
  40. return cmNull;
  41. }
  42. /**
  43. * Handles the message sent for the creation of healing containers in a container.
  44. *
  45. * This function is called whenever a healing container should be created in the inventory of another object.
  46. *
  47. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  48. */
  49. cMessage cHealingCon::CreatePacketContainer( DWORD Container, DWORD ItemModelID )
  50. {
  51. cMessage cmReturn;
  52. cItemModels *pcModel = cItemModels::FindModel( ItemModelID );
  53. // cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  54. if( pcModel )
  55. {
  56. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11); //0x11 is a constant
  57. cmReturn << pcModel->m_bPaletteChange
  58. << pcModel->m_bTextureChange
  59. << pcModel->m_bModelChange;
  60. // The Model Vectors
  61. if ( pcModel->m_bPaletteChange != 0)
  62. {
  63. for (int i = 0; i < pcModel->m_bPaletteChange; i++)
  64. {
  65. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorPal[i],sizeof(pcModel->m_vectorPal[i]));
  66. }
  67. }
  68. if (pcModel->m_bPaletteChange != 0)
  69. {
  70. //Cubem0j0: Test code for armor only.
  71. cmReturn << WORD( 0x0C50 );
  72. }
  73. if ( pcModel->m_bTextureChange != 0)
  74. {
  75. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  76. {
  77. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  78. }
  79. }
  80. if ( pcModel->m_bModelChange != 0)
  81. {
  82. for (int i = 0; i < pcModel->m_bModelChange; i++)
  83. {
  84. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  85. }
  86. }
  87. }
  88. cmReturn.pasteAlign(4);
  89. cmReturn << 0x00020001L << 0x414L << 0x65L;
  90. // MASK 0x00008000 -- Location
  91. // if ( !m_fIsOwned )
  92. // cmReturn.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  93. // MASK 0x00000800 -- Sound Set
  94. // DWORD dwSoundSet = 0x20000000L + pcModel->m_wSoundSet;
  95. // cmReturn << dwSoundSet;
  96. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  97. // cmReturn << 0x34000000 + pcModel->m_dwUnknown_Blue;
  98. // MASK 0x00000001 -- ModelNumber
  99. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  100. cmReturn << dwModel;
  101. // SeaGreens
  102. WORD wNuminteracts = 0x0;
  103. WORD wNumbubbles = 0x0;
  104. WORD wNumJumps = 0x0;
  105. WORD wNumOverrides = 0x0;
  106. WORD wUnkFlag8 = 0x0;
  107. WORD wUnkFlag10 = 0x0;
  108. cmReturn << m_wPositionSequence
  109. << m_wNumAnims //wNuminteracts
  110. << wNumbubbles
  111. << wNumJumps
  112. << m_wNumPortals
  113. << m_wNumAnims
  114. << wNumOverrides
  115. << wUnkFlag8
  116. << m_wNumLogins
  117. << wUnkFlag10;
  118. cmReturn << 0x00284c18; // Object Flags
  119. cmReturn << Name( ); // Object's Name
  120. cmReturn << pcModel->m_wModel; // Object's Model
  121. cmReturn << this->m_wIcon; // Object's Icon
  122. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  123. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  124. //Healing Kits flag2 - 00280c18
  125. // Mask 0x0008 - Value
  126. if(pcModel->m_dwFlags2 & 0x00000008)
  127. {
  128. cmReturn << pcModel->m_dwValue;
  129. }
  130. // Mask 0x0010 dwUnknown_v2
  131. cmReturn << DWORD(0x00220008);
  132. cmReturn << DWORD(0x10);
  133. // Mase 0x0400 Uses Remaining
  134. if(pcModel->m_dwFlags2 & 0x00000400)
  135. {
  136. cmReturn << this->m_wUses;
  137. }
  138. // Mase 0x0800 Max # of uses
  139. if(pcModel->m_dwFlags2 & 0x00000800)
  140. {
  141. cmReturn << this->m_wUseLimit;
  142. }
  143. // Mask 0x4000 Container
  144. cmReturn << Container;
  145. // Mask 0x80000 Usable on
  146. //cmReturn << 0x32L;
  147. // Mask 0x00200000 - Burden
  148. if(pcModel->m_dwFlags2 & 0x00200000)
  149. {
  150. cmReturn << pcModel->m_wBurden;
  151. }
  152. return cmReturn;
  153. }
  154. /**
  155. * Handles the actions of healing container objects.
  156. *
  157. * This function is called whenever a healing container is used or should perform an action.
  158. */
  159. void cHealingCon::Action(cClient *who)
  160. {
  161. cObject *pcObject = who->m_pcAvatar->FindInventory( m_dwGUID );
  162. cItemModels *pcModel = cItemModels::FindModel( pcObject->GetItemModelID() );
  163. //Vars
  164. int updated_stats;
  165. int max = who->m_pcAvatar->GetTotalHealth();
  166. DWORD current = who->m_pcAvatar->m_cStats.m_lpcVitals[0].m_lTrueCurrent;
  167. DWORD skill = who->m_pcAvatar->m_cStats.m_lpcSkills[15].m_wStatus;
  168. int ret_heal;
  169. int total;
  170. //If we are not damaged, do nothing.
  171. if (current >= max)
  172. {
  173. //This is the message that tell you that you don't need to be healed.
  174. cMessage cmTest;
  175. cmTest << 0xF7B0L << who->m_pcAvatar->GetGUID() << ++who->m_dwF7B0Sequence << 0x028BL << 0x04FFL << who->m_pcAvatar->m_strName.c_str();
  176. who->AddPacket(WORLD_SERVER,cmTest,4);
  177. }
  178. else
  179. {
  180. //Healing kit animation
  181. //note: 17 is death animation
  182. cMessage aHealingKit = who->m_pcAvatar->Animation(270,1.0f);
  183. cWorldManager::SendToAllInFocus( who->m_pcAvatar->m_Location, aHealingKit, 3 );
  184. who->AddPacket( WORLD_SERVER,aHealingKit,4);
  185. //Figure out how much we healed based on skill
  186. //Healing = 2 * (max health - current health) with 50% base. Example 200 max, 50 current 2* 150 = 300, base 300 skill to have 50% chance to heal.
  187. DWORD amt_healed = (max - current) * 2;
  188. //For now just check if we rolled higher then skill
  189. if (amt_healed > skill)
  190. {
  191. //Return random health between 1 and 25
  192. ret_heal = rand() % 25 + 1;
  193. }
  194. else
  195. {
  196. //Failed, return 0
  197. ret_heal = 0;
  198. }
  199. //Do the health update
  200. cMessage cmHealKit = who->m_pcAvatar->UpdateHealth(ret_heal,updated_stats);
  201. who->AddPacket( WORLD_SERVER,cmHealKit,4);
  202. //Minus one use
  203. this->m_wUses--;
  204. if ( updated_stats > max )
  205. total = 0;
  206. else
  207. total = ret_heal;
  208. cMasterServer::ServerMessage( ColorGreen,who,"You heal yourself for %i Health points. Your %s has %i uses left.",ret_heal,pcModel->m_strName.c_str(),this->m_wUses);
  209. cMessage cmActionComplete;
  210. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  211. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  212. if(this->m_wUses == 0)
  213. {
  214. //Remove the item
  215. who->m_pcAvatar->DeleteFromInventory(pcObject);
  216. cMessage cmRemoveItem;
  217. cmRemoveItem << 0x0024L << m_dwGUID;
  218. who->AddPacket(WORLD_SERVER,cmRemoveItem,4);
  219. }
  220. }
  221. }
  222. /**
  223. * Handles the assessment of healing container objects.
  224. *
  225. * This function is called whenever a healing container is assessed by a client.
  226. *
  227. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  228. */
  229. void cHealingCon::Assess( cClient *pcAssesser )
  230. {
  231. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  232. cObject *pcObject = pcAssesser->m_pcAvatar->FindInventory( m_dwGUID );
  233. cMessage cmAssess;
  234. DWORD flags = 0x00000009;
  235. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID
  236. << flags
  237. << 0x01L
  238. << WORD(0x05)
  239. << WORD(0x10)
  240. << 0x13L
  241. << pcModel->m_dwValue
  242. << 0x05L
  243. << DWORD(pcModel->m_wBurden)
  244. << 0x5AL //Healing kit bonus
  245. << 0x02L
  246. << 0x5BL
  247. << DWORD(this->m_wUseLimit)
  248. << 0x5CL
  249. << DWORD(this->m_wUses)
  250. /* Cubem0j0: This part does not work. The client doesn't seem to know what this is.
  251. << WORD(0x01)
  252. << WORD(0x08)
  253. << 0x64L //Healing kit bonus
  254. << 0x20L
  255. */
  256. << WORD(0x01)
  257. << WORD(0x08)
  258. << 0x10L
  259. << pcModel->m_strDescription.c_str();
  260. pcAssesser->AddPacket(WORLD_SERVER, cmAssess,4);
  261. cMessage cmActionComplete;
  262. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  263. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  264. }