Пример #1
0
	def refreshInventory(self):
		self.items = {}
		for i in range(1,4):
			r = InventoryRequest(self.session, which=i)
			data = r.doRequest()
			for item in data["items"]:
				self.items[item["id"]] = item["quantity"]
Пример #2
0
 def refreshInventory(self):
     self.items = {}
     for i in range(1, 4):
         r = InventoryRequest(self.session, which=i)
         data = r.doRequest()
         for item in data["items"]:
             self.items[item["id"]] = item["quantity"]
Пример #3
0
def discoverMissingItems(session):
    global __isLoaded
    if not __isLoaded:
        loadItemsFromFile()
    newInformation = False
    from kol.request.InventoryRequest import InventoryRequest
    from kol.request.ItemInformationRequest import ItemInformationRequest
    invRequest = InventoryRequest(session)
    invRequest.ignoreItemDatabase = True
    invData = invRequest.doRequest()
    for item in invData["items"]:
        if item["id"] not in __itemsById:
            try:
                itemRequest = ItemInformationRequest(session, item["id"])
                itemData = itemRequest.doRequest()
                item = itemData["item"]
                addItem(item)
                Report.trace("itemdatabase", "Discovered new item: %s" % item["name"])
                context = { "item" : item }
                FilterManager.executeFiltersForEvent("discoveredNewItem", context, session=session, item=item)
                newInformation = True
            except:
                pass
    if newInformation or not __isLoaded:
        saveItemsToFile()
        __isLoaded = True
Пример #4
0
def discoverMissingItems(session):
    global __isLoaded
    if not __isLoaded:
        loadItemsFromFile()
    newInformation = False
    from kol.request.InventoryRequest import InventoryRequest
    from kol.request.ItemInformationRequest import ItemInformationRequest
    invRequest = InventoryRequest(session)
    invRequest.ignoreItemDatabase = True
    invData = invRequest.doRequest()
    for item in invData["items"]:
        if item["id"] not in __itemsById:
            try:
                itemRequest = ItemInformationRequest(session, item["id"])
                itemData = itemRequest.doRequest()
                item = itemData["item"]
                addItem(item)
                Report.trace("itemdatabase",
                             "Discovered new item: %s" % item["name"])
                context = {"item": item}
                FilterManager.executeFiltersForEvent("discoveredNewItem",
                                                     context,
                                                     session=session,
                                                     item=item)
                newInformation = True
            except:
                pass
    if newInformation or not __isLoaded:
        saveItemsToFile()
        __isLoaded = True
Пример #5
0
    def openAllGiftPackages(self):
        giftPackages = {}

        # Get a list of all gift packages in our inventory.
        r = InventoryRequest(self.session, which=3)
        responseData = r.doRequest()
        items = responseData["items"]
        for item in items:
            if "type" in item and item["type"] == "gift package":
                giftPackages[item["id"]] = item["quantity"]

        # Open all of the gift packages.
        for itemId, quantity in giftPackages.iteritems():
            for i in range(quantity):
                r = UseItemRequest(self.session, itemId)
                r.doRequest()
Пример #6
0
	def openAllGiftPackages(self):
		giftPackages = {}
		
		# Get a list of all gift packages in our inventory.
		r = InventoryRequest(self.session, which=3)
		responseData = r.doRequest()
		items = responseData["items"]
		for item in items:
			if "type" in item and item["type"] == "gift package":
				giftPackages[item["id"]] = item["quantity"]
		
		# Open all of the gift packages.
		for itemId,quantity in giftPackages.iteritems():
			for i in range(quantity):
				r = UseItemRequest(self.session, itemId)
				r.doRequest()
Пример #7
0
 def refreshInventory(self):
     self.items = {}
     r = InventoryRequest(self.session)
     data = r.doRequest()
     for item in data["items"]:
         self.items[item["id"]] = item["quantity"]
Пример #8
0
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
Пример #9
0
 def refreshInventory(self):
     self.items = {}
     r = InventoryRequest(self.session)
     data = r.doRequest()
     for item in data["items"]:
         self.items[item["id"]] = item["quantity"]
Пример #10
0
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