本文整理汇总了Python中kol.database.ItemDatabase.getItemFromDescId方法的典型用法代码示例。如果您正苦于以下问题:Python ItemDatabase.getItemFromDescId方法的具体用法?Python ItemDatabase.getItemFromDescId怎么用?Python ItemDatabase.getItemFromDescId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kol.database.ItemDatabase
的用法示例。
在下文中一共展示了ItemDatabase.getItemFromDescId方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
cantPulverizePattern = PatternManager.getOrCompilePattern('cantPulverizeItem')
if cantPulverizePattern.search(self.responseText) != None:
item = ItemDatabase.getItemFromId(self.itemId, self.session)
raise UnableToPulverizeItemError("'%s' is not an item that can be pulverized." % item["name"])
notEnoughItemsPattern = PatternManager.getOrCompilePattern('notEnoughItems')
if notEnoughItemsPattern.search(self.responseText) != None:
item = ItemDatabase.getItemFromId(self.itemId, self.session)
if self.quantity == 1:
itemStr = item["name"]
else:
itemStr = item["plural"]
raise NotEnoughItemsError("You do not have %s %s" % (self.quantity % itemStr))
items = []
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
for match in singleItemPattern.finditer(self.responseText):
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = 1
items.append(item)
multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
for match in multiItemPattern.finditer(self.responseText):
descId = int(match.group(1))
quantity = int(match.group(2).replace(',', ''))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = quantity
items.append(item)
self.responseData["results"] = items
示例2: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
dontHaveMeatpastePattern = PatternManager.getOrCompilePattern('noMeatpaste')
itemsDontMeatpastePattern = PatternManager.getOrCompilePattern('itemsDontMeatpaste')
dontHaveItemsPattern = PatternManager.getOrCompilePattern('dontHaveItemsMeatpaste')
# Check for errors.
if dontHaveMeatpastePattern.search(self.responseText):
raise NotEnoughItemsError("Unable to combine items. You don't have any meatpaste.")
elif itemsDontMeatpastePattern.search(self.responseText):
raise InvalidRecipeError("Unable to combine items. The submitted ingredients do not meatpaste together.")
elif dontHaveItemsPattern.search(self.responseText):
raise NotEnoughItemsError("Unable to combine items. You don't have all of the items you are trying to meatpaste.")
# Find the items attached to the message.
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
match = singleItemPattern.search(self.responseText)
if match:
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = 1
else:
multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
match = multiItemPattern.search(self.responseText)
if match:
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
quantity = int(match.group(2).replace(',', ''))
item["quantity"] = quantity
else:
raise RequestError("Unknown error.")
self.responseData["items"] = item
示例3: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
itemsDontMakeCocktailPattern = PatternManager.getOrCompilePattern('itemsDontMakeCocktail')
dontHaveSkillPattern = PatternManager.getOrCompilePattern('dontHaveSkillToMixCocktail')
dontHaveItemsPattern = PatternManager.getOrCompilePattern('dontHaveItemsForThatCocktail')
dontHaveAdventuresPattern = PatternManager.getOrCompilePattern('dontHaveAdventuresToMixCocktail')
# Check for errors.
if itemsDontMakeCocktailPattern.search(self.responseText):
raise InvalidRecipeError("Unable to make cocktail. The submitted ingredients do not mix together.")
elif dontHaveSkillPattern.search(self.responseText):
raise SkillMissingError("Unable to make cocktail. We are not skilled enough.")
elif dontHaveItemsPattern.search(self.responseText):
raise NotEnoughItemsError("Unable to make cocktail. You don't have all of the items you are trying to mix.")
elif dontHaveAdventuresPattern.search(self.responseText):
raise NotEnoughAdventuresLeftError("Unable to mix drink(s). We don't have enough adventures.")
# Find the items attached to the message.
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
match = singleItemPattern.search(self.responseText)
if match:
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = 1
else:
multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
match = multiItemPattern.search(self.responseText)
if match:
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
quantity = int(match.group(2).replace(',', ''))
item["quantity"] = quantity
else:
raise RequestError("Unknown error.")
self.responseData["booze"] = item
示例4: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
noMeatForPastePattern = PatternManager.getOrCompilePattern('noMeatForMeatpasting')
# Check for errors.
if noMeatForPastePattern.search(self.responseText):
raise NotEnoughMeatError("Unable to make the requested item. You don't have enough meat")
# Find the items attached to the message.
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
match = singleItemPattern.search(self.responseText)
if match:
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = 1
else:
multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
match = multiItemPattern.search(self.responseText)
if match:
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
quantity = int(match.group(2).replace(',', ''))
item["quantity"] = quantity
else:
raise RequestError("Unknown error.")
self.responseData["items"] = item
示例5: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
items = []
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
for match in singleItemPattern.finditer(self.responseText):
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = 1
items.append(item)
multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
for match in multiItemPattern.finditer(self.responseText):
descId = int(match.group(1))
quantity = int(match.group(2).replace(',', ''))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = quantity
items.append(item)
self.responseData["results"] = items
示例6: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
items = []
singleItemPattern = PatternManager.getOrCompilePattern('inventorySingleItem')
for match in singleItemPattern.finditer(self.responseText):
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = 1
items.append(item)
multipleItemsPattern = PatternManager.getOrCompilePattern('inventoryMultipleItems')
for match in multipleItemsPattern.finditer(self.responseText):
descId = int(match.group(1))
quantity = int(match.group(3))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = quantity
items.append(item)
self.responseData["items"] = items
示例7: parseItemsReceived
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseItemsReceived(text, session):
items = []
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
for match in singleItemPattern.finditer(text):
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, session)
item["quantity"] = 1
items.append(item)
multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
for match in multiItemPattern.finditer(text):
descId = int(match.group(1))
quantity = int(match.group(2).replace(',', ''))
item = ItemDatabase.getItemFromDescId(descId, session)
item["quantity"] = quantity
items.append(item)
return items
示例8: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
notEnoughMeatPattern = PatternManager.getOrCompilePattern('noMeatForStore')
meatSpentPattern = PatternManager.getOrCompilePattern('meatSpent')
invalidStorePattern = PatternManager.getOrCompilePattern('invalidStore')
notSoldPattern = PatternManager.getOrCompilePattern('notSoldHere')
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
# Check for errors.
if invalidStorePattern.search(self.responseText):
raise NotAStoreError("The store you tried to visit doesn't exist.")
if notSoldPattern.search(self.responseText):
raise NotEnoughItemsError("The store doesn't carry that item.")
if notEnoughMeatPattern.search(self.responseText):
raise NotEnoughMeatError("You do not have enough meat to purchase the item(s).")
response={}
# Find out how much meat was spent
match = meatSpentPattern.search(self.responseText)
if match:
meatSpent = int(match.group(1).replace(',', ''))
response["meatSpent"] = meatSpent
# Find items recieved, if any.
items = []
for match in singleItemPattern.finditer(self.responseText):
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = 1
items.append(item)
for match in multiItemPattern.finditer(self.responseText):
descId = int(match.group(1))
quantity = int(match.group(2).replace(',', ''))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = quantity
items.append(item)
if len(items) > 0:
response["item"] = items
self.responseData = response
示例9: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
menuItemPattern = PatternManager.getOrCompilePattern("menuItem")
cannotGoPattern = PatternManager.getOrCompilePattern("userShouldNotBeHere")
if cannotGoPattern.search(self.responseText):
raise Error.Error("You cannot reach that cafe.", Error.INVALID_LOCATION)
items = []
for match in menuItemPattern.finditer(self.responseText):
descId = match.group(2)
if descId.isdigit():
descId = int(descId)
item = ItemDatabase.getItemFromDescId(descId)
items.append(item)
if len(items) == 0:
raise Error.Error("Retrieved an Empty Menu", Error.REQUEST_GENERIC)
self.responseData["menu"] = items
示例10: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
menuItemPattern = PatternManager.getOrCompilePattern('menuItem')
cannotGoPattern = PatternManager.getOrCompilePattern('userShouldNotBeHere')
if cannotGoPattern.search(self.responseText):
raise UserShouldNotBeHereError("You cannot reach that cafe")
items = []
for match in menuItemPattern.finditer(self.responseText):
descId = match.group(2)
if descId.isdigit():
descId = int(descId)
item = ItemDatabase.getItemFromDescId(descId, session=self.session)
items.append(item)
if len(items) == 0:
raise RequestError("Retrieved an Empty Menu")
self.responseData["menu"] = items
示例11: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
hatPattern = PatternManager.getOrCompilePattern("currentHat")
weaponPattern = PatternManager.getOrCompilePattern("currentWeapon")
offhandPattern = PatternManager.getOrCompilePattern("currentOffhand")
shirtPattern = PatternManager.getOrCompilePattern("currentShirt")
pantsPattern = PatternManager.getOrCompilePattern("currentPants")
accPattern = PatternManager.getOrCompilePattern("currentAcc")
acc1Pattern = PatternManager.getOrCompilePattern("currentAcc1")
acc2Pattern = PatternManager.getOrCompilePattern("currentAcc2")
acc3Pattern = PatternManager.getOrCompilePattern("currentAcc3")
familiarPattern = PatternManager.getOrCompilePattern("currentFam")
hatText = hatPattern.search(self.responseText)
if hatText:
self.responseData["hat"] = ItemDatabase.getItemFromDescId(int(hatText.group(1)), self.session)
weaponText = weaponPattern.search(self.responseText)
if weaponText:
self.responseData["weapon"] = ItemDatabase.getItemFromDescId(int(weaponText.group(1)), self.session)
offhandText = offhandPattern.search(self.responseText)
if offhandText:
self.responseData["offhand"] = ItemDatabase.getItemFromDescId(int(offhandText.group(1)), self.session)
shirtText = shirtPattern.search(self.responseText)
if shirtText:
self.responseData["shirt"] = ItemDatabase.getItemFromDescId(int(shirtText.group(1)), self.session)
pantsText = pantsPattern.search(self.responseText)
if pantsText:
self.responseData["pants"] = ItemDatabase.getItemFromDescId(int(pantsText.group(1)), self.session)
accessories = []
accText = accPattern.search(self.responseText)
if accText:
for match in accPattern.finditer(self.responseText):
item = ItemDatabase.getItemFromDescId(int(match.group(1)), self.session)
item["slot"] = 0
accessories.append(item)
else:
acc1Text = acc1Pattern.search(self.responseText)
if acc1Text:
item = ItemDatabase.getItemFromDescId(int(acc1Text.group(1)), self.session)
item["slot"] = 1
accessories.append(item)
acc2Text = acc2Pattern.search(self.responseText)
if acc2Text:
item = ItemDatabase.getItemFromDescId(int(acc2Text.group(1)), self.session)
item["slot"] = 2
accessories.append(item)
acc3Text = acc3Pattern.search(self.responseText)
if acc3Text:
item = ItemDatabase.getItemFromDescId(int(acc3Text.group(1)), self.session)
item["slot"] = 3
accessories.append(item)
if len(accessories) > 0:
self.responseData["acc"] = accessories
famText = familiarPattern.search(self.responseText)
if famText:
self.responseData["familiar"] = ItemDatabase.getItemFromDescId(int(famText.group(1)), self.session)
示例12: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
"""
Parse each different kind of trade. Each trade offer or offer and response is represented as a dictionary with following keys:
tradeID: The ID of the trade.
tradeType: The type of the trade - OUTGOING, INCOMING, etc.
playerID: The ID of the other player involved in this trade.
playerName: The name of the other player involved in this trade.
incomingitems: An array of items being offered to you in the format of a dictionary with keys itemID, quantity, and itemName.
outgoingitems: An array of items being offered to the other player in the format of a dictionary with keys itemID, quantity, and itemName.
incomingmeat: The amount of meat being offered by the other player.
outgoingmeat: The amount of meat being offered to the other player.
message: The message or note attached to the trade.
"""
outgoingResponsePattern = PatternManager.getOrCompilePattern('tradePendingResponseOutgoing')
incomingResponsePattern = PatternManager.getOrCompilePattern('tradePendingResponseIncoming')
outgoingPattern = PatternManager.getOrCompilePattern('tradePendingOfferOutgoing')
incomingPattern = PatternManager.getOrCompilePattern('tradePendingOfferIncoming')
messagePattern = PatternManager.getOrCompilePattern('tradeMessage')
itemPattern = PatternManager.getOrCompilePattern('tradeItem')
tradeoffers = []
iters = [incomingPattern.finditer(self.responseText), outgoingPattern.finditer(self.responseText), incomingResponsePattern.finditer(self.responseText), outgoingResponsePattern.finditer(self.responseText)]
for matchset in iters:
for trade in matchset:
tradeType = iters.index(matchset) + 1
tradeID = trade.group('tradeid')
playerID = trade.group('playerid')
playerName = trade.group('playername')
try:
incomingitems = trade.group('incomingitems')#To be formatted later
except:
incomingitems = None
try:
outgoingitems = trade.group('outgoingitems')#To be formatted later
except:
outgoingitems = None
try:
incomingmeat = int(trade.group('incomingmeat'))
except:
incomingmeat = None
try:
outgoingmeat = int(trade.group('outgoingmeat'))
except:
outgoingmeat = None
message = trade.group('message')#To be formatted later
iitems = []
if incomingitems != None:
for item in itemPattern.finditer(incomingitems):
iitems.append({
'itemID': item.group(ItemDatabase.getItemFromDescId(item.group('itemdescid'))),
'itemName': item.group(item.group('itemname')),
'quantity': item.group('quantity')
})
oitems = []
if outgoingitems != None:
for item in itemPattern.finditer(outgoingitems):
oitems.append({
'itemID': item.group(ItemDatabase.getItemFromDescId(item.group('itemdescid'))),
'itemName': item.group(item.group('itemname')),
'quantity': item.group('quantity')
})
try:
message = messagePattern.search(message).group('message')
except:
message = None
tradeoffers.append({
'tradeID': tradeID,
'tradeType': tradeType,
'playerID': playerID,
'playerName': playerName,
'incomingitems': iitems,
'outgoingitems': oitems,
'incomingmeat': incomingmeat,
'outgoingmeat': outgoingmeat,
'message': message,
})
self.responseData['trades'] = tradeoffers
示例13: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getItemFromDescId [as 别名]
def parseResponse(self):
"""
Parses through the response and constructs an array of messages.
Each message is represented as a dictionary with the following
keys:
id -- The integer identifier for the message.
userId -- The ID of the user who sent or received this message.
userName -- The name of the user who sent or received this message.
date -- The date the message was sent as a datetime object.
text -- The contents of the message.
items -- An array of items attached to the message.
meat -- The amount of meat sent with the message.
"""
fullMessagePattern = PatternManager.getOrCompilePattern('fullMessage')
whitespacePattern = PatternManager.getOrCompilePattern('whitespace')
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
meatPattern = PatternManager.getOrCompilePattern('gainMeat')
brickPattern = PatternManager.getOrCompilePattern('brickMessage')
coffeePattern = PatternManager.getOrCompilePattern('coffeeMessage')
candyHeartPattern = PatternManager.getOrCompilePattern('candyHeartMessage')
messages = []
for message in fullMessagePattern.finditer(self.responseText):
messageId = int(message.group(1))
userId = int(message.group(2))
userName = message.group(3).strip()
dateStr = message.group(4).strip()
try:
date = datetime.strptime(dateStr, "%A, %B %d, %Y, %I:%M%p")
except ValueError:
date = dateStr
rawText = message.group(5).strip()
index = rawText.find('<center')
if index >= 0:
text = rawText[:index].strip()
else:
text = rawText.strip()
# Get rid of extraneous spaces, tabs, or new lines.
text = text.replace("\r\n", "\n")
text = whitespacePattern.sub(' ', text)
text = text.replace("<br />\n", "\n")
text = text.replace("<br/>\n", "\n")
text = text.replace("<br>\n", "\n")
text = text.replace("\n<br />", "\n")
text = text.replace("\n<br/>", "\n")
text = text.replace("\n<br>", "\n")
text = text.replace("<br />", "\n")
text = text.replace("<br/>", "\n")
text = text.replace("<br>", "\n")
text = text.strip()
# KoL encodes all of the HTML entities in the message. Let's decode them to get the real text.
text = StringUtils.htmlEntityDecode(text)
m = {"id":messageId, "userId":userId, "userName":userName, "date":date, "text":text}
# Find the items attached to the message.
items = []
for match in singleItemPattern.finditer(rawText):
descId = int(match.group(1))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = 1
items.append(item)
for match in multiItemPattern.finditer(rawText):
descId = int(match.group(1))
quantity = int(match.group(2).replace(',', ''))
item = ItemDatabase.getItemFromDescId(descId, self.session)
item["quantity"] = quantity
items.append(item)
m["items"] = items
# Find how much meat was attached to the message.
meat = 0
meatMatch = meatPattern.search(rawText)
if meatMatch:
meat = int(meatMatch.group(1).replace(',', ''))
m["meat"] = meat
# Handle special messages.
if brickPattern.search(rawText):
m["messageType"] = "brick"
elif coffeePattern.search(rawText):
m["messageType"] = "coffeeCup"
elif candyHeartPattern.search(rawText):
m["messageType"] = "candyHeart"
else:
m["messageType"] = "normal"
messages.append(m)
self.responseData["kmails"] = messages