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

cChest.cpp 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 cChest.cpp
  19. * Implements functionality for chests (Sturdy Iron Chests, Singularity Troves, etc).
  20. *
  21. * This class is referenced whenever a chest is created, used, or assessed.
  22. * Inherits from the cObject class.
  23. */
  24. #include "Client.h"
  25. #include "MasterServer.h"
  26. #include "Object.h"
  27. #include "WorldManager.h"
  28. /***************
  29. * constructors
  30. **************/
  31. /**
  32. * Handles the creation of chests.
  33. *
  34. * Called whenever a chest object should be initialized.
  35. */
  36. cChest::cChest( WORD type, DWORD dwGUID, cLocation *pcLoc, char *szName, char *szDesc)
  37. {
  38. SetLocation( pcLoc );
  39. m_dwGUID = dwGUID;//cWorldManager::NewGUID_Object( );
  40. m_strName.assign( szName );
  41. m_strDescription.assign( szDesc );
  42. m_dwModel = type;
  43. m_dwType = 0;
  44. m_fStatic = TRUE;
  45. m_dwDoorState = 0x0CL;
  46. }
  47. /**********
  48. * methods
  49. *********/
  50. /**
  51. * Handles the message sent for the creation of chests in the world.
  52. *
  53. * This function is called whenever a chest should be created for a client.
  54. *
  55. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  56. */
  57. cMessage cChest::CreatePacket()
  58. {
  59. cMessage cmCreate;
  60. unsigned char bUnknown[] = {
  61. 0x00, 0x00, // Animation type 0 - 1
  62. 0x3D, 0x00, // Starting Stance 2 - 3
  63. 0x00, 0x00, 0x00, 0x02, // Unknown - Flag 0x00000002 in it 4 - 7
  64. 0x0C, 0x00, 0x00, 0x00, // Status 9 - 11
  65. };
  66. cmCreate << 0xF745L
  67. << m_dwGUID
  68. << BYTE( 0x11 )
  69. << BYTE( 0 )
  70. << BYTE( 0 )
  71. << BYTE( 0 );
  72. DWORD dwFlags = 0x00019803L;
  73. cmCreate << dwFlags;
  74. cmCreate << WORD( 0x0408 );
  75. cmCreate << WORD( 0x000C );
  76. // MASK 0x00010000 unknown Bytes - Starting Animation
  77. cmCreate << 0x0CL;
  78. CopyMemory(&bUnknown[9],&m_dwDoorState,4);
  79. cmCreate.pasteData(bUnknown,sizeof(bUnknown));
  80. //cmCreate << 0x003D0000 << 0x02B4F002 << m_dwDoorState; //0x0000000C; // unknownByte
  81. cmCreate << 0x0L;
  82. // MASK 0x00008000 -- Location
  83. if ( !m_fIsOwned )
  84. cmCreate.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  85. // MASK 0x00000002 -- Animation Set
  86. DWORD dwAnimC = 0x09000000L + m_wAnimConfig;
  87. cmCreate << dwAnimC;
  88. // MASK 0x00000800 -- Sound Set
  89. DWORD dwSoundSet = 0x20000000L + m_wSoundSet;
  90. cmCreate << dwSoundSet;
  91. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  92. cmCreate << 0x3400002BL;//0x00000000L;
  93. // MASK 0x00000001 -- ModelNumber
  94. DWORD dwModel = 0x02000000L + m_dwModel;
  95. cmCreate << dwModel;
  96. // SeaGreens
  97. WORD wNuminteracts = 0x0;
  98. WORD wNumbubbles = 0x0;
  99. WORD wNumJumps = 0x0;
  100. WORD wNumOverrides = 0x0;
  101. WORD wUnkFlag8 = 0x0;
  102. WORD wUnkFlag10 = 0x0;
  103. cmCreate << m_wPositionSequence
  104. << m_wNumAnims //wNuminteracts
  105. << wNumbubbles
  106. << wNumJumps
  107. << m_wNumPortals
  108. << m_wNumAnims
  109. << wNumOverrides
  110. << wUnkFlag8
  111. << m_wNumLogins
  112. << wUnkFlag10;
  113. DWORD dwFlags2 = 0x0020003E;
  114. cmCreate << dwFlags2 << m_strName.c_str( ) << WORD(m_wModel) << WORD(m_wIcon);//WORD( 0x019C ) << WORD( 0x1317 );;//WORD( 0x0116 ) << WORD( 0x1317 );
  115. /* Category of object:
  116. 0x00000001 Melee Weapon
  117. 0x00000002 Armor
  118. 0x00000004 Clothing
  119. 0x00000008 Jewelry
  120. 0x00000010 Creature (Player/NPC/Monster)
  121. 0x00000020 Food
  122. 0x00000040 Pyreals
  123. 0x00000080 Miscellaneous
  124. 0x00000100 Missile Weapons/Ammunition
  125. 0x00000200 Containers
  126. 0x00000400 Wrapped Fletching Supplies, House Decorations
  127. 0x00000800 Gems, Pack dolls, Decorative Statues
  128. 0x00001000 Spell Components
  129. 0x00002000 Books, Parchment, Scrolls, Signs, Statues
  130. 0x00004000 Keys, Lockpicks
  131. 0x00008000 Casting Item (wand, orb, staff)
  132. 0x00010000 Portal
  133. 0x00020000 Lockable
  134. 0x00040000 Trade Notes
  135. 0x00080000 Mana Stones, Mana Charges
  136. 0x00100000 Services
  137. 0x00200000 unknown (no longer plants)
  138. 0x00400000 Cooking Ingredients and Supplies, Plants, Dye Pots
  139. 0x00800000 Loose Fletching Supplies
  140. 0x01000000 unknown
  141. 0x02000000 unknown
  142. 0x04000000 Alchemy Ingredients and Supplies, Oils, Dye Vials
  143. 0x08000000 unknown
  144. 0x10000000 Lifestone
  145. 0x20000000 Ust
  146. 0x40000000 Salvage
  147. 0x80000000 unknown
  148. */
  149. DWORD dwObjectFlags1 = 0x0200L;
  150. cmCreate << dwObjectFlags1;
  151. /* Behavior of object:
  152. 0x00000001 can be opened (false if locked)
  153. 0x00000002 can be inscribed
  154. 0x00000004 cannot be picked up
  155. 0x00000008 is a player
  156. 0x00000010 is not an npc
  157. 0x00000020 unknown
  158. 0x00000040 unknown
  159. 0x00000080 cannot be selected
  160. 0x00000100 can be read
  161. 0x00000200 is a merchant
  162. 0x00000400 is a pk altar
  163. 0x00000800 is an npk altar
  164. 0x00001000 is a door
  165. 0x00002000 is a corpse
  166. 0x00004000 can be attuned to (lifestone)
  167. 0x00008000 adds to health, stamina or mana
  168. 0x00010000 is a healing kit
  169. 0x00020000 is a lockpick
  170. 0x00040000 is a portal
  171. 0x00800000 is a foci
  172. 0x04000000 has an extra flags DWORD
  173. */
  174. DWORD dwObjectFlags2;
  175. if (GetIsLocked() == 1)
  176. {
  177. dwObjectFlags2 = 0x0014L;
  178. }
  179. else
  180. {
  181. dwObjectFlags2 = 0x0015L;
  182. }
  183. cmCreate << dwObjectFlags2;
  184. /* Masked against dwFlags2 in reverse order:
  185. 0x00000002 - Item Slots
  186. 0x00000004 - Pack Slots
  187. 0x00000008 - Value
  188. 0x00000010 - Unknown1
  189. 0x00000020 - Approach Distance
  190. 0x00200000 - Burden
  191. */
  192. cmCreate << BYTE (0x78); //78 is item slots. (120)
  193. cmCreate << BYTE (0x06); //06 is pack slots
  194. cmCreate << DWORD (0x000009C4); //Value
  195. cmCreate << DWORD (0x00000030); //Unknown
  196. cmCreate << float(3.0); //Approach Distance.
  197. cmCreate << WORD (0x0225); //Burden
  198. return cmCreate;
  199. }
  200. /**
  201. * Handles the actions of chest objects.
  202. *
  203. * This function is called whenever a chest is used or should perform an action.
  204. */
  205. void cChest::Action(cClient* who)
  206. {
  207. cMessage cmUseChest,cmRet;
  208. WORD m_wStance;
  209. if(m_wState == 0) //CLOSED
  210. {
  211. m_dwDoorState = 0x0CL;
  212. m_wStance = 0x3D; // Starting Stance
  213. m_wState = 1;
  214. }
  215. else //OPEN
  216. {
  217. m_dwDoorState = 0x0BL;
  218. m_wStance = 0x3D;
  219. m_wState = 0;
  220. }
  221. //Play Animation
  222. cmUseChest << 0xF74CL // Packet type
  223. << m_dwGUID // Door's GUID
  224. << m_wNumLogins // number of logins
  225. << ++m_wPositionSequence // sequence number
  226. << ++m_wNumAnims // Number Animations this login session
  227. << WORD(0x00) // Activity
  228. << WORD(0x00)
  229. << WORD(0x3D) // Starting Stance
  230. << DWORD(0x00000002) // Supposed to be Animation Mask
  231. << m_dwDoorState; // Door state Closed = 0x0C Open = 0x0B
  232. cWorldManager::SendToAllInFocus( who->m_pcAvatar->m_Location, cmUseChest, 3 );
  233. if(GetIsLocked() == 1)
  234. {
  235. cMessage cmLocked;
  236. cmLocked << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x02EBL
  237. << "%s is locked!",this->m_strName.c_str();
  238. who->AddPacket(WORLD_SERVER,cmLocked,4);
  239. cMessage cmActionComplete;
  240. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  241. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  242. }
  243. if(m_wState == 0)
  244. {
  245. //Display the item slots in the chest (0x0196)
  246. cMessage cmSetPackContents;
  247. cmSetPackContents << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x0196L << m_dwGUID;
  248. who->AddPacket(WORLD_SERVER,cmSetPackContents,4);
  249. cMessage cmActionComplete;
  250. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  251. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  252. }
  253. if(m_wState == 1)
  254. {
  255. //Close Container
  256. cMessage cmCloseContainer;
  257. cmCloseContainer << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x0052L << m_dwGUID;
  258. who->AddPacket(WORLD_SERVER,cmCloseContainer,4);
  259. cMessage cmActionComplete;
  260. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  261. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  262. }
  263. }
  264. /**
  265. * Handles the assessment of chest objects.
  266. *
  267. * This function is called whenever a chest is assessed by a client.
  268. *
  269. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  270. */
  271. void cChest::Assess(cClient *pcAssesser)
  272. {
  273. //Cubem0j0: Note - The pack slots and item slots are added automatically to this assess message.
  274. cMessage cmAssess;
  275. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L;
  276. cmAssess << m_dwGUID << 0x00400003L << 1L;
  277. if(this->GetIsLocked())
  278. {
  279. cmAssess << WORD(0x03) << WORD(0x10) << 0x13L << 0x94L << 0x05L << 0x96L <<
  280. WORD(0x01) << WORD(0x08) << 0x03L << 0x01;
  281. }
  282. else
  283. {
  284. cmAssess << WORD(0x02) << WORD(0x10) << 0x13L << 0x94L << 0x05L << 0x96L;
  285. }
  286. pcAssesser->AddPacket(WORLD_SERVER,cmAssess,4);
  287. }