def buyFromMall(session, itemId, quantity=1, maxPrice=0, logFunc=None): if logFunc is None: logFunc = _empty s = tryRequest(StatusRequest(session)) canBuy = ((int(s.get('hardcore', "1")) == 0 and int(s.get('roninleft', "1")) == 0) or int(s.get('casual', "0")) == 1 or int(s.get('freedralph', "0")) == 1) if not canBuy: raise kol.Error.Error("Can't buy from mall in Ronin/Hardcore", kol.Error.USER_IN_HARDCORE_RONIN) with InventoryLock.lock: item = getItemFromId(itemId) itemName = item.get('name', str(itemId)) numTries = 0 numBought = 0 numResults = 10 logFunc("Trying to buy {}x {} from mall...".format(quantity, itemName)) while numTries < 10: r1 = MallItemSearchRequest(session, itemName, maxPrice=maxPrice, numResults=numResults) d1 = tryRequest(r1, numTries=1) itemList = [ item for item in d1['results'] if item.get('id', -1) == itemId ] listFull = (len(itemList) == numResults) availableList = [ item for item in itemList if not item.get('hitLimit', False) ] if not itemList: return numBought if not availableList and listFull: numResults *= 2 while availableList and numBought < quantity: item = availableList[0] limitedMode = False qty = min(quantity, item['quantity']) if 'limit' in item: qty = 1 limitedMode = True price = item['price'] storeId = item['storeId'] logFunc("Buying {}x {} @ {} meat from store {}".format( qty, itemName, price, storeId)) r2 = MallItemPurchaseRequest(session, storeId, itemId, price, qty) try: d2 = tryRequest(r2, numTries=1) numBought += d2['items'][0]['quantity'] logFunc("Spent {} meat and got {}x {}.".format( d2['meatSpent'], d2['items'][0]['quantity'], itemName)) if not limitedMode: availableList.pop(0) except kol.Error.Error as e: if e.code == kol.Error.ITEM_NOT_FOUND: logFunc("Could not buy item. Refreshing...") # refresh search availableList = [] continue else: logFunc("Error buying from this store. Moving on...") availableList.pop(0) continue numTries += 1 if numBought >= quantity: break return numBought
def makeItRain(): for term in searchTerms: m = MallItemSearchRequest(s, pad(term)) res = m.doRequest()["results"][0] curResult = [res["price"], res["quantity"], res["id"]] result[term] = curResult print "Booze: {0}, price: {1}, quantity: {2}".format( res["name"], res["price"], res["quantity"]) curRecipe = recipe[term] total = 0 recipeData = [] for ingredient in curRecipe: m = MallItemSearchRequest(s, pad(ingredient)) searchData = m.doRequest() recipeData.append(searchData["results"][0]) price = searchData["results"][0]["price"] total += price if res["price"] > total: print "{0} should be crafted for profit. {0} has a total ingredient cost of {1}, but is selling for {2}".format( term, total, res["price"]) if "limit" in recipeData[0] or "limit" in recipeData[1]: if "limit" in recipeData[0] and "limit" not in recipeData[1]: if min(recipeData[0]["quantity"], recipeData[1]["quantity"]) > recipeData[0]["limit"]: print "minimum is greater than limit, must limit how much we buy for {0}".format( term) quantityOfEach = min(int(meatLimit / total), recipeData[0]["limit"]) buyItem( recipeData[0]["storeId"], ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem( recipeData[1]["storeId"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "Minimum less than limit for {0}".format(term) quantityOfEach = min( int(meatLimit / total), min(recipeData[0]["quantity"], recipeData[1]["quantity"])) buyItem( recipeData[0]["storeId"], ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem( recipeData[1]["storeId"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) elif "limit" in recipeData[1] and "limit" not in recipeData[0]: if min(recipeData[0]["quantity"], recipeData[1]["quantity"]) > recipeData[1]["limit"]: print "minimum is greater than limit, must limit how much we buy for {0}".format( term) quantityOfEach = min(int(meatLimit / total), recipeData[1]["limit"]) buyItem( recipeData[0]["storeId"], ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem( recipeData[1]["storeId"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "Minimum less than limit for {0}".format(term) quantityOfEach = min( int(meatLimit / total), min(recipeData[0]["quantity"], recipeData[1]["quantity"])) buyItem( recipeData[0]["storeId"], ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem( recipeData[1]["storeId"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) elif "limit" in recipeData[1] and "limit" in recipeData[0]: if min(recipeData[0]["quantity"], recipeData[1]["quantity"]) > min( recipeData[1]["limit"], recipeData[0]["limit"]): print "minimum is greater than limit, must limit how much we buy for {0}".format( term) quantityOfEach = min( int(meatLimit / total), min(recipeData[1]["limit"], recipeData[0]["limit"])) buyItem( recipeData[0]["storeId"], ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem( recipeData[1]["storeId"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "Minimum less than limit for {0}".format(term) quantityOfEach = min( int(meatLimit / total), min(recipeData[0]["quantity"], recipeData[1]["quantity"])) buyItem( recipeData[0]["storeId"], ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem( recipeData[1]["storeId"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "Ingredients not limited for {0}".format(term) quantityOfEach = min( int(meatLimit / total), min(recipeData[0]["quantity"], recipeData[1]["quantity"])) buyItem( recipeData[0]["storeId"], ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem( recipeData[1]["storeId"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem( craftItem( ItemDatabase.getItemFromName( recipeData[0]["name"])["id"], ItemDatabase.getItemFromName( recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "{0} should NOT be crafted for profit. {0} has a total ingredient cost of {1}, but is selling for {2}".format( term, total, res["price"])
def mainloop(): global s global chatMgr while True: event = droid.eventWait().result if event["name"] == "key" and event["data"]["key"] == "4": return id = event["name"] if id == "makeToast": droid.makeToast(event["data"]) elif id == "charData": droid.dialogCreateSpinnerProgress("Loading", "Loading...") droid.dialogShow() c = CharpaneRequest(s) response = None try: response = c.doRequest() except Error as e: alertNotLoggedIn(True) message = "" title = "Character Data" for key in response.keys(): if key != "effects": message += "%s: %s\n" % (key, response[key]) else: message += "-------\nEFFECTS:\n" for effect in response["effects"]: message += " - " + effect["name"] + ": " + str( effect["turns"]) + "\n" droid.dialogDismiss() droid.dialogCreateAlert(title, message) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() # objectPost("charDataInfo", response) elif id == "inventory": droid.dialogCreateSpinnerProgress("Loading", "Loading...") droid.dialogShow() i = InventoryRequest(s) response = None try: response = i.doRequest() except Error as e: alertNotLoggedIn(True) title = "Inventory" message = "" for key in response["items"]: message += "%s: %s\n" % (key["name"], key["quantity"]) droid.dialogDismiss() droid.dialogCreateAlert(title, message) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() # objectPost("inventoryInfo", response) elif id == "findInventory": droid.dialogCreateInput( "Item to find:", "Enter the name (or partial name) of the item to find") droid.dialogSetPositiveButtonText("OK") droid.dialogSetNegativeButtonText("Cancel") droid.dialogShow() response = droid.dialogGetResponse().result if response.has_key("which") and response[ "which"] == "positive" and response.has_key( "value") and response["value"] != "": droid.dialogCreateSpinnerProgress("Searching...", "Finding items...") droid.dialogShow() i = InventoryRequest(s) inventory = None try: inventory = i.doRequest() except Error as e: alertNotLoggedIn(True) title = "Search results" message = "" for item in inventory["items"]: if item.has_key("name") and response["value"].lower( ) in item["name"].lower(): message += "%s: %s\n" % (item["name"], item["quantity"]) if message == "": message = "No item matching %s was found" % response[ "value"] droid.dialogDismiss() droid.dialogCreateAlert(title, message) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() elif id == "getNewChat": try: objectPost("getNewChatResult", chatMgr.getNewChatMessages()) except Error as e: alertNotLoggedIn(True) elif id == "sendChat": try: data = json.loads(event["data"]) chatMgr.sendChatMessage("/" + data["channel"] + " " + data["message"]) droid.eventPost("sendChatResult", "success") except Error as e: droid.eventPost("sendChatResult", "fail") elif id == "getChannels": try: pass except Error as e: alertNotLoggedIn(True) elif id == "searchMall": try: m = MallItemSearchRequest(s, event["data"], numResults=10) droid.dialogCreateSpinnerProgress( "Searching...", "Searching for \"%s\"" % event["data"]) droid.dialogShow() objectPost("searchMallResult", m.doRequest()) droid.dialogDismiss() except Error as e: alertNotLoggedIn(True) elif id == "buyMall": droid.dialogCreateInput("Purchase mall item", "Enter quantity to purchase", "0", "number") droid.dialogSetPositiveButtonText("OK") droid.dialogSetNegativeButtonText("Cancel") droid.dialogShow() resp = droid.dialogGetResponse().result evtdata = None try: evtdata = json.loads(event["data"]) droid.log("evtdata loaded from string") droid.log("evtdata = %s" % event["data"]) buy = MallItemPurchaseRequest(s, evtdata["storeId"], evtdata["id"], evtdata["price"], resp["value"]) droid.log("MIPR created") droid.dialogCreateSpinnerProgress("Buying...", "Buying item(s)...") droid.dialogShow() buyResponse = buy.doRequest() droid.dialogDismiss() droid.dialogCreateAlert( "Results", "Brought %s for %d" % (resp["value"], buyResponse["meatSpent"])) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() except Error as e: droid.dialogCreateAlert("Results", e.msg) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() except: droid.dialogCreateAlert("WTF", "WTF?") droid.dialogSetPositiveButtonText("OK") droid.dialogShow() elif id == "exit": s.logout() sys.exit() return
def makeItRain(): for term in searchTerms: m = MallItemSearchRequest(s, pad(term)) res = m.doRequest()["results"][0] curResult = [res["price"], res["quantity"], res["id"]] result[term] = curResult print "Booze: {0}, price: {1}, quantity: {2}".format(res["name"], res["price"], res["quantity"]) curRecipe = recipe[term] total = 0 recipeData = [] for ingredient in curRecipe: m = MallItemSearchRequest(s, pad(ingredient)) searchData = m.doRequest() recipeData.append(searchData["results"][0]) price = searchData["results"][0]["price"] total += price if res["price"] > total: print "{0} should be crafted for profit. {0} has a total ingredient cost of {1}, but is selling for {2}".format(term, total, res["price"]) if "limit" in recipeData[0] or "limit" in recipeData[1]: if "limit" in recipeData[0] and "limit" not in recipeData[1]: if min(recipeData[0]["quantity"], recipeData[1]["quantity"]) > recipeData[0]["limit"]: print "minimum is greater than limit, must limit how much we buy for {0}".format(term) quantityOfEach = min(int(meatLimit / total), recipeData[0]["limit"]) buyItem(recipeData[0]["storeId"], ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem(recipeData[1]["storeId"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "Minimum less than limit for {0}".format(term) quantityOfEach = min(int(meatLimit / total), min(recipeData[0]["quantity"], recipeData[1]["quantity"])) buyItem(recipeData[0]["storeId"], ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem(recipeData[1]["storeId"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) elif "limit" in recipeData[1] and "limit" not in recipeData[0]: if min(recipeData[0]["quantity"], recipeData[1]["quantity"]) > recipeData[1]["limit"]: print "minimum is greater than limit, must limit how much we buy for {0}".format(term) quantityOfEach = min(int(meatLimit / total), recipeData[1]["limit"]) buyItem(recipeData[0]["storeId"], ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem(recipeData[1]["storeId"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "Minimum less than limit for {0}".format(term) quantityOfEach = min(int(meatLimit / total), min(recipeData[0]["quantity"], recipeData[1]["quantity"])) buyItem(recipeData[0]["storeId"], ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem(recipeData[1]["storeId"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) elif "limit" in recipeData[1] and "limit" in recipeData[0]: if min(recipeData[0]["quantity"], recipeData[1]["quantity"]) > min(recipeData[1]["limit"], recipeData[0]["limit"]): print "minimum is greater than limit, must limit how much we buy for {0}".format(term) quantityOfEach = min(int(meatLimit / total), min(recipeData[1]["limit"], recipeData[0]["limit"])) buyItem(recipeData[0]["storeId"], ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem(recipeData[1]["storeId"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "Minimum less than limit for {0}".format(term) quantityOfEach = min(int(meatLimit / total), min(recipeData[0]["quantity"], recipeData[1]["quantity"])) buyItem(recipeData[0]["storeId"], ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem(recipeData[1]["storeId"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "Ingredients not limited for {0}".format(term) quantityOfEach = min(int(meatLimit / total), min(recipeData[0]["quantity"], recipeData[1]["quantity"])) buyItem(recipeData[0]["storeId"], ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], quantityOfEach, recipeData[0]["price"]) buyItem(recipeData[1]["storeId"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach, recipeData[1]["price"]) if res["storeId"] == myStoreId: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), res["price"], quantityOfEach) else: sellItem(craftItem(ItemDatabase.getItemFromName(recipeData[0]["name"])["id"], ItemDatabase.getItemFromName(recipeData[1]["name"])["id"], quantityOfEach), (res["price"] - underCut), quantityOfEach) else: print "{0} should NOT be crafted for profit. {0} has a total ingredient cost of {1}, but is selling for {2}".format(term, total, res["price"])
def mainloop(): global s global chatMgr while True: event = droid.eventWait().result id = event["name"] if id == "key" and event["data"]["key"] == "4": return if id == "login": try: title = "Logging in..." message = 'KoL for Android is logging you in...' droid.dialogCreateSpinnerProgress(title, message) droid.dialogShow() try: loginData = json.loads(event["data"]) s.login(loginData["user"], loginData["pass"]) if s.isConnected: droid.eventPost("loginResult", "success") chatMgr = ChatManager(s) droid.dialogDismiss() return except Error as e: droid.dialogDismiss() droid.eventPost("login", "fail") droid.makeToast(e.msg) except: droid.eventPost("login", "fail") finally: if s.isConnected: droid.dialogDismiss() else: alertNotLoggedIn(False) except: droid.dialogDismiss() alertNotLoggedIn(False) elif id == "requestLoginInfo": objectPost("loginInfo", {"user": droid.prefGetValue("user"), "pass": droid.prefGetValue("pass")}) elif id == "makeToast": droid.makeToast(event["data"]) elif id == "charData": droid.dialogCreateSpinnerProgress("Loading", "Loading...") droid.dialogShow() c = CharpaneRequest(s) response = None try: response = c.doRequest() except Error as e: alertNotLoggedIn(True) message = "" title = "Character Data" for key in response.keys(): if key != "effects": message += "%s: %s\n" % (key, response[key]) else: message += "-------\nEFFECTS:\n" for effect in response["effects"]: message += " - " + effect["name"] + ": " + str(effect["turns"]) + "\n" droid.dialogDismiss() droid.dialogCreateAlert(title, message) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() # objectPost("charDataInfo", response) elif id == "inventory": droid.dialogCreateSpinnerProgress("Loading", "Loading...") droid.dialogShow() i = InventoryRequest(s) response = None try: response = i.doRequest() except Error as e: alertNotLoggedIn(True) title = "Inventory" message = "" for key in response["items"]: message += "%s: %s\n" % (key["name"], key["quantity"]) droid.dialogDismiss() droid.dialogCreateAlert(title, message) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() # objectPost("inventoryInfo", response) elif id == "findInventory": droid.dialogCreateInput("Item to find:", "Enter the name (or partial name) of the item to find") droid.dialogSetPositiveButtonText("OK") droid.dialogSetNegativeButtonText("Cancel") droid.dialogShow() response = droid.dialogGetResponse().result if response.has_key("which") and response["which"] == "positive" and response.has_key("value") and response["value"] != "": droid.dialogCreateSpinnerProgress("Searching...", "Finding items...") droid.dialogShow() i = InventoryRequest(s) inventory = None try: inventory = i.doRequest() except Error as e: alertNotLoggedIn(True) title = "Search results" message = "" for item in inventory["items"]: if item.has_key("name") and response["value"].lower() in item["name"].lower(): message += "%s: %s\n" % (item["name"], item["quantity"]) if message == "": message = "No item matching %s was found" % response["value"] droid.dialogDismiss() droid.dialogCreateAlert(title, message) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() elif id == "getNewChat": try: objectPost("getNewChatResult", chatMgr.getNewChatMessages()) except Error as e: alertNotLoggedIn(True) elif id == "sendChat": try: data = json.loads(event["data"]) chatMgr.sendChatMessage("/" + data["channel"] + " " + data["message"]) droid.eventPost("sendChatResult", "success") except Error as e: droid.eventPost("sendChatResult", "fail") elif id == "getChannels": try: pass except Error as e: alertNotLoggedIn(True) elif id == "searchMall": try: m = MallItemSearchRequest(s, event["data"], numResults=10) droid.dialogCreateSpinnerProgress("Searching...", "Searching for \"%s\"" % event["data"]) droid.dialogShow() objectPost("searchMallResult", m.doRequest()) droid.dialogDismiss() except Error as e: alertNotLoggedIn(True) elif id == "buyMall": droid.dialogCreateInput("Purchase mall item", "Enter quantity to purchase", "0", "number") droid.dialogSetPositiveButtonText("OK") droid.dialogSetNegativeButtonText("Cancel") droid.dialogShow() resp = droid.dialogGetResponse().result evtdata = None try: evtdata = json.loads(event["data"]) droid.log("evtdata loaded from string") droid.log("evtdata = %s" % event["data"]) buy = MallItemPurchaseRequest(s, evtdata["storeId"], evtdata["id"], evtdata["price"], resp["value"]) droid.log("MIPR created") droid.dialogCreateSpinnerProgress("Buying...", "Buying item(s)...") droid.dialogShow() buyResponse = buy.doRequest() droid.dialogDismiss() droid.dialogCreateAlert("Results", "Brought %s for %d" % (resp["value"], buyResponse["meatSpent"])) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() except Error as e: droid.dialogCreateAlert("Results", e.msg) droid.dialogSetPositiveButtonText("OK") droid.dialogShow() except: droid.dialogCreateAlert("WTF", "WTF?") droid.dialogSetPositiveButtonText("OK") droid.dialogShow() elif id == "exit": s.logout() sys.exit() return