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

cHealingKits.cpp 8.6KB

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