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

cHooks.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 cHooks.cpp
  19. * Implements functionality for housing hooks.
  20. *
  21. * This class is referenced whenever a housing hook 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 hooks.
  33. *
  34. * Called whenever a housing hook object should be initialized.
  35. */
  36. cHooks::cHooks( 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_dwHouseID = dwHouseID;
  45. }
  46. /**********
  47. * methods
  48. *********/
  49. /**
  50. * Handles the message sent for the creation of housing hooks in the world.
  51. *
  52. * This function is called whenever a housing hook should be created for a client.
  53. *
  54. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  55. */
  56. cMessage cHooks::CreatePacket()
  57. {
  58. cMessage cmCreate;
  59. char szCommand[200];
  60. RETCODE retcode;
  61. char OwnerIDBuff[9];
  62. DWORD OwnerID = 0x0L;
  63. sprintf( szCommand, "SELECT OwnerID FROM houses_covenants WHERE HouseID = %d;",m_dwHouseID);
  64. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  65. retcode = SQLExecute( cDatabase::m_hStmt );
  66. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_CHAR, OwnerIDBuff, sizeof( OwnerIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  67. // Return SQL_SUCCESS if there is a house that corresponds to the hook's HouseID
  68. if (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) {
  69. sscanf(OwnerIDBuff,"%08x",&OwnerID);
  70. }
  71. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  72. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  73. float flpScale; // Scale used in Packet being Sent
  74. float flmScale = 0; // Model Data Scale
  75. DWORD dwFlags1 = 0x00009081; // Flags1
  76. /*
  77. dwModel
  78. 0x0A8D Floor Hook
  79. 0x0A8E Wall Hook
  80. 0x0A8C Ceiling Hook
  81. 0x0A8D Yard Hook
  82. 0x0A8D Roof Hook
  83. wModelID
  84. 0x2DB1 Floor Hook
  85. 0x25D6 Wall Hook
  86. 0x2DB2 Ceiling Hook
  87. 0x3187 Yard Hook
  88. 0x3186 Roof Hook
  89. wIconID
  90. 0x20C0
  91. */
  92. WORD tBurden = 0;
  93. if (IsUsed == 1)
  94. {
  95. // cItemModels *h_model = cItemModels::FindModel(m_hook_item->GetItemModelID());
  96. // h_model->m_wBurden //Burden (WORD, no padding)
  97. // tBurden += h_model->m_wBurden;
  98. }
  99. /*
  100. //Loop through inventory and find all items.
  101. for (int i = 0; i < this->m_hook_lstInventory.size(); i++)
  102. {
  103. //Find each item by it's GUID
  104. cObject *v_item = this->FindInventory(this->v_guids[i]);
  105. //Associate model with item
  106. cItemModels *v_model = cItemModels::FindModel(v_item->GetItemModelID());
  107. // v_item->GetGUID() //Item GUID
  108. // v_model->m_dwFlags2 //10254018
  109. // v_model->m_strName.c_str() //Item Name
  110. // v_model->m_wModel //Model
  111. // v_model->m_wIcon //Icon
  112. // v_model->m_wBurden //Burden (WORD, no padding)
  113. // v_model->m_wHooks; //Hook Type (WORD, no padding)
  114. }
  115. */
  116. cmCreate << 0xF745L
  117. << m_dwGUID
  118. << BYTE( 0x11 )
  119. << BYTE( 0 )
  120. << BYTE( 0 )
  121. << BYTE( 0 );
  122. cmCreate << dwFlags1;
  123. cmCreate << WORD(0x0014); // Type of portal
  124. cmCreate << WORD(0x0000); // Unknown
  125. //Flags1 Mask: 0x00009081
  126. {
  127. //Flags1 & 0x00008000 -- Location
  128. cmCreate.pasteData( (UCHAR*)&m_Location, sizeof(m_Location) ); //Next comes the location
  129. //Flags1 & 0x00001000 -- DWORD ResourceID
  130. cmCreate << 0x3400002B; // unknown ResourceID
  131. //Flags1 & 0x00000001 -- DWORD dwModel = 0x02000001; // the model.
  132. DWORD dwModel = 0x02000000L + m_dwModel;
  133. cmCreate << dwModel;
  134. //Flags1 & 0x00000080 -- unknown_green
  135. if (flmScale > 0)
  136. {
  137. flpScale = flmScale;// FLOAT flpScale
  138. }
  139. else
  140. {
  141. flpScale = 0.5;
  142. }
  143. cmCreate << flpScale;
  144. }
  145. // SeaGreens
  146. WORD wUnkFlag2 = 0x0000;
  147. WORD wUnkFlag3 = 0x0002;
  148. WORD wUnkFlag4 = 0x0000;
  149. WORD wUnkFlag6 = 0x0000;
  150. WORD wUnkFlag7 = 0x0000;
  151. WORD wUnkFlag8 = 0x0000;
  152. WORD wUnkFlag10 = 0x0000;
  153. cmCreate << m_wPositionSequence // movement 0x0001
  154. << wUnkFlag2 // animations
  155. << wUnkFlag3 // bubble modes
  156. << wUnkFlag4 // num jumps
  157. << m_wNumPortals
  158. << wUnkFlag6 // anim count
  159. << wUnkFlag7 // overrides
  160. << wUnkFlag8
  161. << WORD(0x7A51) // m_wNumLogins // 0x0D4B
  162. << wUnkFlag10;
  163. DWORD dwFlags2 = 0x3220003A; // Flags2 -- Defines what data comes next
  164. cmCreate << dwFlags2;
  165. cmCreate << Name( ); // Object's Name
  166. cmCreate << WORD(m_wModel) << WORD(m_wIcon);
  167. DWORD dwObjectFlags1 = 0x00000200; // 0x0200 Containers
  168. DWORD dwObjectFlags2 = 0x00000015; // 0x0010 is not an npc; 0x0004 cannot be picked up; 0x0001 can be opened (false if locked)
  169. cmCreate << dwObjectFlags1 << dwObjectFlags2;
  170. // Flags2 & 0x00000002 -- BYTE itemSlots
  171. cmCreate << BYTE(0x01); // number of item slots
  172. // Flags2 & 0x00000008 -- BYTE value
  173. cmCreate << BYTE(0x0A); // object value
  174. // Flags2 & 0x00000010 -- DWORD unknown10
  175. cmCreate << 0x30000000L;
  176. // Unknown
  177. cmCreate << BYTE( 0 )
  178. << BYTE( 0 )
  179. << BYTE( 0 );
  180. // Flags2 & 0x00000020 -- float approachDistance
  181. float flApproach = 10.0f; // 0x41200000
  182. cmCreate << flApproach; // distance a player will walk to use the object
  183. // Flags2 & 0x00200000 -- WORD burden
  184. tBurden += WORD(0x0005);
  185. cmCreate << tBurden; // total burden of this object
  186. // Flags2 & 0x02000000 -- ObjectID owner
  187. cmCreate << OwnerID; // the owner of this object
  188. // Flags2 & 0x20000000 -- hookType Unknown
  189. cmCreate << WORD(0xFFFF); // always -1
  190. // Flags2 & 0x10000000 -- hookable On
  191. /*
  192. 0x0001 floor hook
  193. 0x0002 wall hook
  194. 0x0004 ceiling hook
  195. 0x0008 yard hook
  196. 0x0010 roof hook
  197. */
  198. cmCreate << WORD(0xFFFF); // the types of hooks this object may be placed on (-1 for hooks)
  199. return cmCreate;
  200. }
  201. /**
  202. * Handles the actions of housing hook objects.
  203. *
  204. * This function is called whenever a housing hook is used or should perform an action.
  205. */
  206. void cHooks::Action(cClient* who)
  207. {
  208. cMessage cmUseHook;
  209. WORD m_wStance;
  210. if(m_wState == 0) //CLOSED
  211. {
  212. m_dwDoorState = 0x0CL;
  213. m_wStance = 0x3D; // Starting Stance
  214. m_wState = 1;
  215. }
  216. else //OPEN
  217. {
  218. m_dwDoorState = 0x0BL;
  219. m_wStance = 0x3D;
  220. m_wState = 0;
  221. }
  222. cmUseHook << 0xF74CL // Packet type
  223. << who->m_pcAvatar->GetGUID() // Character'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(0x08)
  229. << WORD(0x3D) // Starting Stance
  230. << m_dwGUID; // Hook's GUID
  231. cmUseHook << 0x4342BD54 // DWORD unknown_value
  232. << 0x19C5EE0F // bitfield?
  233. << 0x3F800000 // unknown -- unknown DWORD
  234. << 0x00000000; // float heading -- Appears to be the heading to which the object is turning
  235. cWorldManager::SendToAllInFocus( who->m_pcAvatar->m_Location, cmUseHook, 3 );
  236. if(m_wState == 0)
  237. {
  238. //Display the item slot in the hook (0x0196)
  239. cMessage cmSetPackContents;
  240. cmSetPackContents << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x0196L << m_dwGUID;
  241. who->AddPacket(WORLD_SERVER,cmSetPackContents,4);
  242. cMessage cmActionComplete;
  243. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  244. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  245. }
  246. if(m_wState == 1)
  247. {
  248. //Close Container
  249. cMessage cmCloseContainer;
  250. cmCloseContainer << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x0052L << m_dwGUID;
  251. who->AddPacket(WORLD_SERVER,cmCloseContainer,4);
  252. cMessage cmActionComplete;
  253. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  254. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  255. }
  256. }
  257. /**
  258. * Handles the assessment of housing hook objects.
  259. *
  260. * This function is called whenever a housing hook is assessed by a client.
  261. *
  262. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  263. */
  264. void cHooks::Assess(cClient *pcAssesser)
  265. {
  266. // cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  267. cMessage cmAssess;
  268. DWORD flags = 0x0000000B;
  269. m_strDescription.assign("Use this item to open it and see its content");
  270. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID
  271. << flags
  272. << 0x01L; // Success = 0x01; Failure = 0x00
  273. // Flags & 0x00000001
  274. WORD dwUnkCount = 0x0002;
  275. cmAssess << dwUnkCount // Total number of DWORDS
  276. << WORD(0x0010) // Unknown
  277. << 0x13L // Value
  278. << 0x0AL // DWORD value
  279. << 0x05L // Burden
  280. << 0x05L // DWORD value
  281. // Flags & 0x00000002
  282. << WORD(0x0001) // Total number of DWORDS
  283. << WORD(0x0008) // Unknown
  284. << 0x02L // Value
  285. << 0x00L // DWORD value
  286. // Flags & 0x00000008
  287. << WORD(0x0002) // Total number of DWORDS
  288. << WORD(0x0008) // Unknown
  289. << 0x10L; // DWORD Full Description
  290. cmAssess << "This hook is owned by Cubem0j0"
  291. << 0x0EL // DWORD Usage Instructions
  292. << this->m_strDescription.c_str();
  293. pcAssesser->AddPacket(WORLD_SERVER,cmAssess,4);
  294. cMessage cmActionComplete;
  295. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  296. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  297. }