def attacktheboss(): data = request.json api_key = data["key"] valid = db.confirm_key(api_key) if (valid) : useremail = data["email"] user_inventory = json.loads(db.get_userinventory(useremail, api_key)) user = json.loads(db.get_user(useremail)) itemname = "" if(user_inventory["pulverizinglaser"]['value'] == "True") : itemname = "pulverizing laser" elif(user_inventory["meltinglaser"]['value'] == "True") : itemname = "melting laser" elif(user_inventory["damaginglaser"]['value'] == "True") : itemname = "damaging laser" totaldamage = 0 if(itemname != "") : iteminfo = json.loads(db.get_item(itemname)) totaldamage = int(user["curdmg"] + iteminfo["dmginc"]) else : totaldamage = int(user["curdmg"]) currentboss["currenthealth"] -= totaldamage db.give_money(useremail, 10000, api_key) return jsonify({"health" : currentboss["health"], "currenthealth" : currentboss["currenthealth"], "name": currentboss["name"], "balance" : 10000}), 200 else : return jsonify({"message" : "no key provided"}), 400
def getbosshealth(): data = request.json api_key = data["key"] valid = db.confirm_key(api_key) if (valid) : bn = data['boss_name'] bosshealth = json.loads(db.get_boss_health(bn)) return jsonify({"currentbosshealth" : bosshealth }), 201 else : return jsonify({"message" : "no key provided"}), 400
def getplayerinventory(): data = request.json api_key = data["key"] email = data["email"] valid = db.confirm_key(api_key) a = json.loads(db.get_userinventory(email,api_key)) if (valid) : return a, 201 else : return jsonify({"message" : "no key provided"}), 400
def getplayerbalance(): data = request.json api_key = data["key"] valid = db.confirm_key(api_key) if (valid) : email = data["email"] user = json.loads(db.get_user(email)) return jsonify({"currentplayerbalance" : user["curbalance"] }), 201 else : return jsonify({"message" : "no key provided"}), 400
def buyitem(): data = request.json api_key = data["key"] valid = db.confirm_key(api_key) if (valid) : data = request.json email = data['email'] itemname = data['itemname'] db.buy_item(email, itemname, api_key) return json.dumps(userinventory), 201 else : return jsonify({"message" : "no key provided"}), 400
def updateplayerbalance(): data = request.json email = data["email"] amount = data["amount"] api_key = data["key"] valid = db.confirm_key(api_key) if (valid) : db.give_money(email,amount, api_key) user = json.loads(db.get_user(email)) return jsonify({"currentplayerbalance" : user["curbalance"] }), 201 else : return jsonify({"message" : "no key provided"}), 400
def updatebosshealth(): data = request.json api_key = data["key"] bn = data["bossname"] valid = db.confirm_key(api_key) if (valid) : bosshealth = json.loads(db.get_boss_health(bn)) newbosshealth = bosshealth+ data["currentbosshealthmodifier"] bosshealth = newbosshealth db.set_boss_health(bn,bosshealth) return jsonify({"currentbosshealth" : newbosshealth }), 201 else : return jsonify({"message" : "no key provided"}), 400
def consume(): data = request.json api_key = data["key"] valid = db.confirm_key(api_key) if (valid) : consumable_name = data['itemname'] email = data['email'] db.consume(email, consumable_name, api_key) if(consumable_name == "bomb"): currentboss["currenthealth"] -= 10000 return jsonify({"name" : currentboss["name"], "health" : currentboss["health"], "currenthealth" : currentboss["currenthealth"]}), 201 else : return jsonify({"message" : "no key provided"}), 400
def getimages(): data = request.json api_key = data["key"] valid = db.confirm_key(api_key) if (valid) : email = data['email'] item_name = data['itemname'] bosstype = data["bosstype"] if bosstype == "pumpkin": return jsonify({"type":"pumpkin","numberofFrames":10,"path":"pumpkin"}), 201 elif bosstype == "skull": return jsonify({"type":"skull","numberofFrames":9,"path":"skull"}), 201 elif bosstype == "candymonster": return jsonify({"type":"candy","numberofFrames":10,"path":"candy"}), 201 else : return jsonify({"message" : "no key provided"}), 400
def getplayerdamage(): data = request.json api_key = data["key"] valid = db.confirm_key(api_key) if (valid) : email = data["email"] user = json.loads(db.get_user(email)) resp = Response( jsonify({"currentplayerdamage" : user["curdmg"] }), 201) resp.headers['Access-Control-Allow-Origin'] = '*' return resp else : resp = Response(jsonify({"message" : "no key provided"}), 400) resp.headers['Access-Control-Allow-Origin'] = '*' return resp
def getcooldown(): data = request.json api_key = data["key"] valid = db.confirm_key(api_key) if(valid) : email = data["email"] user = json.loads(db.get_user(email)) uid = user['id'] a = json.loads(db.get_userinventory(uid)) if(a.liquidnitrogen) : b = json.loads(db.get_item("liquid nitrogen")) return b['cooldowntime'] elif(a.watercooling) : b = json.loads(db.get_item("water cooling")) return b['cooldowntime'] elif(a.icepack) : b = json.loads(db.get_item("ice pack")) return b['cooldowntime']