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

cStorage.cpp 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 cStorage.cpp
  19. * Implements functionality for housing storage.
  20. *
  21. * This class is referenced whenever a housing storage object 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 housing storage chests.
  33. *
  34. * Called whenever a housing storage chest object should be initialized.
  35. */
  36. cStorage::cStorage( WORD type, DWORD dwGUID, DWORD dwHouseID, char *szName, char *szDescription, cLocation *pcLoc )
  37. {
  38. SetLocation( pcLoc );
  39. m_dwGUID = dwGUID;
  40. m_strName.assign( szName );
  41. m_strDescription.assign( szDescription );
  42. m_dwModel = type;
  43. m_fStatic = TRUE;
  44. m_dwDoorState = 0x0CL;
  45. m_dwHouseID = dwHouseID;
  46. m_dwOwnerID = 0x00000000; // TODO: Link with housing
  47. }
  48. /**********
  49. * methods
  50. *********/
  51. /**
  52. * Handles the message sent for the creation of housing storage chests in the world.
  53. *
  54. * This function is called whenever a housing storage chest object should be created in the world for a client.
  55. *
  56. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  57. */
  58. cMessage cStorage::CreatePacket()
  59. {
  60. cMessage cmCreate;
  61. char szCommand[200];
  62. RETCODE retcode;
  63. char OwnerIDBuff[9];
  64. DWORD OwnerID = NULL;
  65. sprintf( szCommand, "SELECT OwnerID FROM houses WHERE wModel = %d;",m_dwHouseID);
  66. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  67. retcode = SQLExecute( cDatabase::m_hStmt );
  68. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_CHAR, OwnerIDBuff, sizeof( OwnerIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  69. // Return SQL_SUCCESS if there is a house that corresponds to the hook's HouseID
  70. if (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) {
  71. sscanf(OwnerIDBuff,"%08x",&OwnerID);
  72. }
  73. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  74. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  75. // float flpScale; // Scale used in Packet being Sent
  76. float flmScale = 0; // Model Data Scale
  77. DWORD dwFlags1 = 0x00019803;
  78. cmCreate << 0xF745L
  79. << m_dwGUID
  80. << BYTE( 0x11 )
  81. << BYTE( 0 )
  82. << BYTE( 0 )
  83. << BYTE( 0 );
  84. cmCreate << dwFlags1;
  85. cmCreate << WORD(0x0418); // Type of portal
  86. cmCreate << WORD(0x0000); // Unknown
  87. //Flags1 Mask: 0x00019803
  88. {
  89. //Flags1 & 0x00010000 -- DWORD byteCount
  90. DWORD dwUnkCount = 0x0000000C;
  91. BYTE unknownByte[0x0C] = { 0x00,0x00,0x3D,0x00,0x02,0x00,0x00,0x00,
  92. 0x0C, // model appearance: owned = 0x0B; unowned = 0x0A, 0x0C?
  93. 0x00,0x00,0x00};
  94. cmCreate << dwUnkCount;
  95. for ( int i = 0; i < dwUnkCount; ++i ) {
  96. cmCreate << unknownByte[i];
  97. }
  98. DWORD dwUnknownDword = 0x0L;
  99. cmCreate << dwUnknownDword;
  100. //Flags1 & 0x00008000 -- Location
  101. cmCreate.pasteData( (UCHAR*)&m_Location, sizeof(m_Location) ); // Next comes the location
  102. //Flags1 & 0x0000002 -- DWORD ResourceID Animations
  103. DWORD dwAnimC = 0x09000000L + m_wAnimConfig;
  104. cmCreate << dwAnimC;
  105. //Flags1 & 0x0000800 -- DWORD ResourceID Sounds
  106. DWORD dwSoundSet = 0x20000000L + m_wSoundSet;
  107. cmCreate << dwSoundSet;
  108. //Flags1 & 0x00001000 -- DWORD ResourceID
  109. cmCreate << 0x3400002B; // unknown ResourceID
  110. //Flags1 & 0x00000001 -- DWORD ResourceID dwModel = 0x02000001; // the model.
  111. DWORD dwModel = 0x02000000L + m_dwModel;
  112. cmCreate << dwModel;
  113. }
  114. // SeaGreens
  115. WORD wNuminteracts = 0x0004;
  116. WORD wNumbubbles = 0x0000;
  117. WORD wNumJumps = 0x0000;
  118. WORD wUnkFlag6 = 0x0000;
  119. WORD wNumOverrides = 0x0040;
  120. WORD wUnkFlag8 = 0x0000;
  121. WORD wUnkFlag10 = 0x0000;
  122. cmCreate << m_wPositionSequence // movement 0x0001
  123. << wNuminteracts // animations
  124. << wNumbubbles // bubble modes
  125. << wNumJumps // num jumps
  126. << m_wNumPortals
  127. << wUnkFlag6 // anim count
  128. << wNumOverrides // overrides
  129. << wUnkFlag8
  130. << WORD(0x7A51) // m_wNumLogins // 0x0D4B
  131. << wUnkFlag10;
  132. DWORD dwFlags2 = 0x0220003E; // Flags2 -- Defines what data comes next
  133. cmCreate << dwFlags2;
  134. cmCreate << Name( ); // Object's Name
  135. cmCreate << WORD(m_wModel) << WORD(m_wIcon);
  136. DWORD dwObjectFlags1 = 0x00000200; // 0x0200 Containers
  137. DWORD dwObjectFlags2 = 0x00000015; // 0x0010 is not an npc; 0x0004 cannot be picked up; 0x0001 can be opened (false if locked)
  138. cmCreate << dwObjectFlags1 << dwObjectFlags2;
  139. //Flags2 Mask: 0x0220003E
  140. {
  141. // Flags2 & 0x00000002 -- BYTE itemSlots
  142. cmCreate << BYTE(0x1A); // number of item slots
  143. // Flags2 & 0x00000004 -- BYTE packSlots
  144. cmCreate << BYTE(0x01); // number of pack slots (a pack slot is a slot that may hold a pack or a foci)
  145. // Flags2 & 0x00000008 -- DWORD value
  146. cmCreate << 0x000000C8; // object value
  147. // Flags2 & 0x00000010 -- DWORD unknown10
  148. cmCreate << 0x00000030;
  149. // Flags2 & 0x00000020 -- float approachDistance
  150. float flApproach = 1.0f; // 0x3F800000
  151. cmCreate << flApproach; // distance a player will walk to use the object
  152. // Flags2 & 0x00200000 -- WORD burden
  153. cmCreate << WORD(0xBBAF); // total burden of this object
  154. // Flags2 & 0x02000000 -- ObjectID owner
  155. cmCreate << OwnerID; // the owner of this object
  156. }
  157. return cmCreate;
  158. }
  159. /**
  160. * Handles the actions of housing storage chest objects.
  161. *
  162. * This function is called whenever a housing storage chest is used or should perform an action.
  163. */
  164. void cStorage::Action(cClient* who)
  165. {
  166. cMessage cmUseChest;
  167. WORD m_wStance;
  168. if(m_wState == 0) //CLOSED
  169. {
  170. m_dwDoorState = 0x0CL;
  171. m_wStance = 0x3D; // Starting Stance
  172. m_wState = 1;
  173. }
  174. else //OPEN
  175. {
  176. m_dwDoorState = 0x0BL;
  177. m_wStance = 0x3D;
  178. m_wState = 0;
  179. }
  180. //Play Animation
  181. cmUseChest << 0xF74CL // Packet type
  182. << m_dwGUID // Door's GUID
  183. << m_wNumLogins // number of logins
  184. << ++m_wPositionSequence // sequence number
  185. << ++m_wNumAnims // Number Animations this login session
  186. << WORD(0x00) // Activity
  187. << WORD(0x00)
  188. << WORD(0x3D) // Starting Stance
  189. << DWORD(0x00000002) // Supposed to be Animation Mask
  190. << m_dwDoorState; // Door state Closed = 0x0C Open = 0x0B
  191. cWorldManager::SendToAllInFocus( who->m_pcAvatar->m_Location, cmUseChest, 3 );
  192. if(m_wState == 0)
  193. {
  194. //Display the item slots in the chest (0x0196)
  195. cMessage cmSetPackContents;
  196. cmSetPackContents << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x0196L << m_dwGUID;
  197. who->AddPacket(WORLD_SERVER,cmSetPackContents,4);
  198. cMessage cmActionComplete;
  199. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  200. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  201. }
  202. if(m_wState == 1)
  203. {
  204. //Close Container
  205. cMessage cmCloseContainer;
  206. cmCloseContainer << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x0052L << m_dwGUID;
  207. who->AddPacket(WORLD_SERVER,cmCloseContainer,4);
  208. cMessage cmActionComplete;
  209. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  210. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  211. }
  212. }
  213. /**
  214. * Handles the assessment of housing storage chest objects.
  215. *
  216. * This function is called whenever a housing storage chest is assessed by a client.
  217. *
  218. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  219. */
  220. void cStorage::Assess(cClient *pcAssesser)
  221. {
  222. // cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  223. cMessage cmAssess;
  224. DWORD flags = 0x0000000B;
  225. m_strDescription.assign("Use this item to open it and see its content");
  226. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID
  227. << flags
  228. << 0x01L // Success = 0x01; Failure = 0x00
  229. // Flags & 0x00000001
  230. << WORD(0x0002) // Total number of DWORDS
  231. << WORD(0x0010) // Unknown
  232. << 0x13L // Value
  233. << 0xC8L // DWORD value
  234. << 0x05L // Burden
  235. << 0x0001BBAFL // DWORD value
  236. // Flags & 0x00000002
  237. << WORD(0x0001) // Total number of DWORDS
  238. << WORD(0x0008) // Unknown
  239. << 0x02L // Value
  240. << 0x00L // DWORD value
  241. // Flags & 0x00000008
  242. << WORD(0x0002) // Total number of DWORDS
  243. << WORD(0x0008) // Unknown
  244. << 0x10L; // DWORD Full Description
  245. cmAssess << "Owned by Cubem0j0"
  246. << 0x0EL // DWORD Usage Instructions
  247. << this->m_strDescription.c_str();
  248. pcAssesser->AddPacket(WORLD_SERVER,cmAssess,4);
  249. cMessage cmActionComplete;
  250. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  251. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  252. }