Commit 19d1c4a3 authored by Tony's avatar Tony
Browse files

Update mixitem

parent dd1c6f64
......@@ -56,16 +56,14 @@ elif user_input == '3':
username = input("Username: ")
password = input("Password: ")
message = '{"method": "login", "username": "'+ username +'", "password": "'+ password +'"}'
#response from server
user_token = '55335e89fc0a81d87f582ed8'
#Inventory#
elif user_input == '4':
message = '{"method": "inventory", "token": "55335e89fc0a81d87f582ed8"}'
message = '{"method": "inventory", "token": "553525ee2c4aa802e47749c6"}'
#MixItem#
elif user_input == '5':
message = '{"method": "mixitem", "token": "55335e89fc0a81d87f582ed8", "item1": 0, "item2": 1}'
message = '{"method": "mixitem", "token": "553525ee2c4aa802e47749c6", "item1": 0, "item2": 1}'
elif user_input == '6':
message = '{\"method\": \"map\", \"token\": \"1\"}'
elif user_input == '7':
......
......@@ -29,6 +29,18 @@ user = db.user
map = db.map
tradebox = db.tradebox
#Defining All Items in Inventory
honey = 0
herbs = 1
clay = 2
mineral = 3
potion = 4
incense = 5
gems = 6
lifeElixir = 7
manaCrystal = 8
philosopherStone = 9
#Function for handling tracker connection.
#def trackerThread(conn):
#while True:
......@@ -100,8 +112,40 @@ def clientThread(conn):
reply = {"status": "ok", "inventory": userQuery['inventory']}
#MixItem
#elif (decoded['method'] == 'mixitem'):
elif (decoded['method'] == 'mixitem'):
userQuery = user.find_one({"_id": ObjectId(decoded['token'])})
if (userQuery == None): #Invalid Request, token mismatch
reply = {"status": "error"}
else: #valid request
if (userQuery['inventory'][decoded['item1']] >= 3 and userQuery['inventory'][decoded['item2']] >= 3): #number of item sufficient
if ((decoded['item1'] == honey and decoded['item2'] == herbs) or (decoded['item2'] == honey and decoded['item1'] == herbs)): #into potion
user.update({"_id":userQuery['_id']},{"$inc":{"inventory."+str(decoded['item1']):-3 , "inventory."+str(decoded['item2']):-3 , "inventory.4" : 1}})
mixItem = potion
elif ((decoded['item1'] == clay and decoded['item2'] == herbs) or (decoded['item2'] == clay and decoded['item1'] == herbs)): #into incense
user.update({"_id":userQuery['_id']},{"$inc":{"inventory."+str(decoded['item1']):-3 , "inventory."+str(decoded['item2']):-3 , "inventory.5" : 1}})
mixItem = incense
elif ((decoded['item1'] == clay and decoded['item2'] == mineral) or (decoded['item2'] == clay and decoded['item1'] == mineral)): #into gems
user.update({"_id":userQuery['_id']},{"$inc":{"inventory."+str(decoded['item1']):-3 , "inventory."+str(decoded['item2']):-3 , "inventory.6" : 1}})
mixItem = gems
elif ((decoded['item1'] == potion and decoded['item2'] == incense) or (decoded['item2'] == potion and decoded['item1'] == incense)): #into lifeElixir
user.update({"_id":userQuery['_id']},{"$inc":{"inventory."+str(decoded['item1']):-3 , "inventory."+str(decoded['item2']):-3 , "inventory.7" : 1}})
mixItem = lifeElixir
elif ((decoded['item1'] == gems and decoded['item2'] == incense) or (decoded['item2'] == gems and decoded['item1'] == incense)): #into manaCrystal
user.update({"_id":userQuery['_id']},{"$inc":{"inventory."+str(decoded['item1']):-3 , "inventory."+str(decoded['item2']):-3 , "inventory.8" : 1}})
mixItem = manaCrystal
elif ((decoded['item1'] == lifeElixir and decoded['item2'] == manaCrystal) or (decoded['item2'] == lifeElixir and decoded['item1'] == manaCrystal)): #into philosopherStone
user.update({"_id":userQuery['_id']},{"$inc":{"inventory."+str(decoded['item1']):-3 , "inventory."+str(decoded['item2']):-3 , "inventory.9" : 1}})
mixItem = philosopherStone
else:
mixItem = ''
if (mixItem):
reply = {"status":"ok", "item": int(mixItem)}
else:
reply = {"status":"fail", "description": "Item Combination is not valid"}
else:
reply = {"status": "fail", "description": "You have not enough items to combine"}
elif (decoded['method'] == 'map'):
userQuery = user.find_one({"_id": ObjectId(decoded['token'])})
if (userQuery == None): #Invalid Request, token mismatch
......@@ -111,7 +155,7 @@ def clientThread(conn):
if(mapQuery == None):
reply = {"status": "error"}
else:
reply = {"status": "ok", "name": mapQuery["name"], "width": mapQuery["width"], "heigth": mapQuery["height"]}
reply = {"status": "ok", "name": mapQuery["name"], "width": mapQuery["width"], "height": mapQuery["height"]}
print(reply)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment