Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. /**************************************
  2. * inventory.h
  3. * Eskun, 29 May 2009
  4. **************************************/
  5.  
  6. /*
  7. < INCLUDES HERE >
  8. */
  9.  
  10. class Inventory
  11. {
  12. private:
  13. int equippedBoxID; // The ID of the box you equipped
  14. /*
  15. Inventory Linked
  16. List here
  17. */
  18.  
  19. public:
  20. Inventory();
  21. ~Inventory();
  22. int returnInventoryOrbs( ItemDatabase &itemdb, int ItemID );
  23. int checkUsedInventoryOrbs();
  24. bool verifyMaxOrbs( ItemDatabase &itemdb );
  25. bool addItem( ItemDatabase &itemdb, Player &player, int itemID );
  26. bool destroyItem( Player &player, int inventorySlot );
  27. };
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. /**************************************
  37. * inventory.cpp
  38. * Eskun, 29 May 2009
  39. **************************************/
  40.  
  41. #include \"inventory.h\"
  42.  
  43. Inventory::Inventory()
  44. {
  45.  
  46. }
  47.  
  48. Inventory::~Inventory()
  49. {
  50. /*
  51. Warning, PHP code below, I'll convert it the moment
  52. I grasp C++/MySQL usage.
  53.  
  54. Anyway, this function, when destroyed, will simply
  55. close the connection to the database.
  56. */
  57.  
  58. mysql_close( $mysql_connection );
  59. }
  60.  
  61. int Inventory::returnInventoryOrbs( int ItemID )
  62. {
  63. return item.returnMaxOrbs( itemID );
  64. }
  65.  
  66. int Inventory::checkUsedInventoryOrbs()
  67. {
  68. /*
  69. Ok listen up, I forgot about how Linked Lists works
  70. so the below code is concept only, I'll re-touch it
  71. when I looked at Linked Lists again ;p
  72.  
  73. So, inb4 OMG-NUB-GO-LEARN-LINKED-LISTS!
  74. */
  75.  
  76. // This will hold the orbs we're holding
  77. int usedOrbs = 0;
  78.  
  79. // Set 'this' to the start of the list
  80. this = first;
  81.  
  82. // If we're not having an empty inventory
  83. if( first->next != last )
  84. {
  85. // Go through the list (Player's inventory) and sum up the Orbs Usage (weight ;/)
  86. while( this != last )
  87. {
  88. this = this->next;
  89. usedOrbs += this.itemRequiredOrbs;
  90. }
  91. }
  92.  
  93. return usedOrbs;
  94. }
  95.  
  96. bool Inventory::verifyMaxOrbs( ItemDatabase &itemdb )
  97. {
  98. /*
  99. Warning, PHP code below, I'll convert it the moment
  100. I grasp C++/MySQL usage.
  101.  
  102. Also, this function should be done everytime onZone();
  103. (When people zone into another area/quest, when loading
  104. the data of the other zone/area, it should display the
  105. graphics saying *Loading...*, and in meanwhile it should
  106. also perform hack checks, this function being one of them.)
  107.  
  108. When this function returns false, just for safety measures
  109. we can make it run again (remember queries take less than a
  110. millisecond to return data, if not doing 10,000 queries at
  111. once), and if after a 3rd check it still returns a non-matching
  112. data, then banhammer/suspensionslap or something.
  113. */
  114.  
  115. $result = mysql_query( "select EquipmentBoxes from ItemDatabase where id=%d", itemdb.getItemID() ); // Should speak for itself
  116. $array = mysql_fetch_array( $result ); // <- Fetch the array containing the all the information about the Box
  117. $boxMaxOrbs = $array["maxorbs"]; // <- Fetch the value of the row which holds the max orb-count(weight)
  118.  
  119. // If the client data doesn't match with the server-side stored data, banhammer/suspensionslap
  120. if( equippedBoxID != $boxMaxOrbs )
  121. {
  122. return false;
  123. }
  124. else
  125. {
  126. return true;
  127. }
  128.  
  129. }
  130.  
  131. bool Inventory::addItem( ItemDatabase &itemdb, Player &player, int itemID )
  132. {
  133. // Locally insert the item into the inventory for easier loading
  134.  
  135. /*
  136. Execute SQL Query to save the item in the database as well,
  137. however no checking occurs here so we can keep the query to
  138. a minimum, remember, 1 query is better that 2 queries.
  139.  
  140. Plus as I earlier mentioned, inventory checks will occur
  141. when a player zones to another zone/area/quest.
  142. */
  143. switch( itemdb.getItemType( itemID ) )
  144. {
  145. case ITEM_USABLE:
  146. {
  147. mysql_query( "insert into inventory (playerid, itemid, itemtype) values (%d, %d, %d)", player.getPlayerID(), itemdb.getItemID(), itemdb.getItemType() );
  148. }
  149. default:
  150. {
  151. // Nullify the item dropped, and log it in the Server's DEBUG log, send an apology ingame_mail to the user and give him/her a monomate, because the code should never have to resort to 'default'
  152. mysql_query( "insert into inventory (playerid, itemid, itemtype) values (%d, %d, %d)", player.getPlayerID(), ITEM_MONOMATE_ID, ITEM_MONOMATE_TYPE );
  153. }
  154. }
  155.  
  156. }
  157.  
  158. bool Inventory::destroyItem( Player &player, int inventorySlot );
  159. {
  160. // Locally remove the item from the inventory
  161.  
  162. /*
  163. Same as above, submit it to the game's server/database but
  164. don't verify as that'd require a 2nd query, verifying happens
  165. when zoning already.
  166. */
  167.  
  168. mysql_query( "delete from inventory where playerid=%d and equipmentbox=%d and equipmentslot=%d", player.getPlayerID(), equippedBoxId, inventorySlot );
  169. }
Add Comment
Please, Sign In to add comment