Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************
- * inventory.h
- * Eskun, 29 May 2009
- **************************************/
- /*
- < INCLUDES HERE >
- */
- class Inventory
- {
- private:
- int equippedBoxID; // The ID of the box you equipped
- /*
- Inventory Linked
- List here
- */
- public:
- Inventory();
- ~Inventory();
- int returnInventoryOrbs( ItemDatabase &itemdb, int ItemID );
- int checkUsedInventoryOrbs();
- bool verifyMaxOrbs( ItemDatabase &itemdb );
- bool addItem( ItemDatabase &itemdb, Player &player, int itemID );
- bool destroyItem( Player &player, int inventorySlot );
- };
- /**************************************
- * inventory.cpp
- * Eskun, 29 May 2009
- **************************************/
- #include \"inventory.h\"
- Inventory::Inventory()
- {
- }
- Inventory::~Inventory()
- {
- /*
- Warning, PHP code below, I'll convert it the moment
- I grasp C++/MySQL usage.
- Anyway, this function, when destroyed, will simply
- close the connection to the database.
- */
- mysql_close( $mysql_connection );
- }
- int Inventory::returnInventoryOrbs( int ItemID )
- {
- return item.returnMaxOrbs( itemID );
- }
- int Inventory::checkUsedInventoryOrbs()
- {
- /*
- Ok listen up, I forgot about how Linked Lists works
- so the below code is concept only, I'll re-touch it
- when I looked at Linked Lists again ;p
- So, inb4 OMG-NUB-GO-LEARN-LINKED-LISTS!
- */
- // This will hold the orbs we're holding
- int usedOrbs = 0;
- // Set 'this' to the start of the list
- this = first;
- // If we're not having an empty inventory
- if( first->next != last )
- {
- // Go through the list (Player's inventory) and sum up the Orbs Usage (weight ;/)
- while( this != last )
- {
- this = this->next;
- usedOrbs += this.itemRequiredOrbs;
- }
- }
- return usedOrbs;
- }
- bool Inventory::verifyMaxOrbs( ItemDatabase &itemdb )
- {
- /*
- Warning, PHP code below, I'll convert it the moment
- I grasp C++/MySQL usage.
- Also, this function should be done everytime onZone();
- (When people zone into another area/quest, when loading
- the data of the other zone/area, it should display the
- graphics saying *Loading...*, and in meanwhile it should
- also perform hack checks, this function being one of them.)
- When this function returns false, just for safety measures
- we can make it run again (remember queries take less than a
- millisecond to return data, if not doing 10,000 queries at
- once), and if after a 3rd check it still returns a non-matching
- data, then banhammer/suspensionslap or something.
- */
- $result = mysql_query( "select EquipmentBoxes from ItemDatabase where id=%d", itemdb.getItemID() ); // Should speak for itself
- $array = mysql_fetch_array( $result ); // <- Fetch the array containing the all the information about the Box
- $boxMaxOrbs = $array["maxorbs"]; // <- Fetch the value of the row which holds the max orb-count(weight)
- // If the client data doesn't match with the server-side stored data, banhammer/suspensionslap
- if( equippedBoxID != $boxMaxOrbs )
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- bool Inventory::addItem( ItemDatabase &itemdb, Player &player, int itemID )
- {
- // Locally insert the item into the inventory for easier loading
- /*
- Execute SQL Query to save the item in the database as well,
- however no checking occurs here so we can keep the query to
- a minimum, remember, 1 query is better that 2 queries.
- Plus as I earlier mentioned, inventory checks will occur
- when a player zones to another zone/area/quest.
- */
- switch( itemdb.getItemType( itemID ) )
- {
- case ITEM_USABLE:
- {
- mysql_query( "insert into inventory (playerid, itemid, itemtype) values (%d, %d, %d)", player.getPlayerID(), itemdb.getItemID(), itemdb.getItemType() );
- }
- default:
- {
- // 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'
- mysql_query( "insert into inventory (playerid, itemid, itemtype) values (%d, %d, %d)", player.getPlayerID(), ITEM_MONOMATE_ID, ITEM_MONOMATE_TYPE );
- }
- }
- }
- bool Inventory::destroyItem( Player &player, int inventorySlot );
- {
- // Locally remove the item from the inventory
- /*
- Same as above, submit it to the game's server/database but
- don't verify as that'd require a 2nd query, verifying happens
- when zoning already.
- */
- mysql_query( "delete from inventory where playerid=%d and equipmentbox=%d and equipmentslot=%d", player.getPlayerID(), equippedBoxId, inventorySlot );
- }
Add Comment
Please, Sign In to add comment