diff options
author | Dipesh Amin <yaypunkrock@gmail.com> | 2011-08-23 21:18:58 +0100 |
---|---|---|
committer | Dipesh Amin <yaypunkrock@gmail.com> | 2011-08-23 21:18:58 +0100 |
commit | eac0a33f4862ebdff5ac8e00fb819dbe34422597 (patch) | |
tree | 2782f110f6bab0924b9c92cf7956477eb9a3cf58 /player.py | |
parent | 1404493735325ce94539fa939567933255412c02 (diff) | |
download | manamarket-eac0a33f4862ebdff5ac8e00fb819dbe34422597.tar.gz manamarket-eac0a33f4862ebdff5ac8e00fb819dbe34422597.tar.bz2 manamarket-eac0a33f4862ebdff5ac8e00fb819dbe34422597.tar.xz manamarket-eac0a33f4862ebdff5ac8e00fb819dbe34422597.zip |
Move inventory check to player.py and remove prettyprintxml()
having looked at the output this produces on the server, it looks terrible.
For some reason it's adding millions of spaces, not sure if the same thing
was happening on my computer.
Diffstat (limited to 'player.py')
-rw-r--r-- | player.py | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -38,5 +38,31 @@ class Player: return item return -10 # Not found - bug somewhere! + def check_inventory(self, user_tree, sale_tree): + # Check the inventory state. + test_node = self.inventory.copy() + for elem in sale_tree.root: + item_found = False + for item in test_node: + if int(elem.get('itemId')) == test_node[item].itemId \ + and int(elem.get('amount')) <= test_node[item].amount: + test_node[item].amount -= int(elem.get('amount')) + if test_node[item].amount == 0: + del test_node[item] + item_found = True + break + + if not item_found: + return "Server and client inventory out of sync." + + total_money = 0 + for user in user_tree.root: + total_money += int(user.get('money')) + + if total_money > self.MONEY: + return "Server and client money out of sync." + + return 0 + if __name__ == '__main__': print "Do not run this file directly. Run main.py" |