本文整理汇总了Python中kol.database.ItemDatabase.getOrDiscoverItemFromDescId方法的典型用法代码示例。如果您正苦于以下问题:Python ItemDatabase.getOrDiscoverItemFromDescId方法的具体用法?Python ItemDatabase.getOrDiscoverItemFromDescId怎么用?Python ItemDatabase.getOrDiscoverItemFromDescId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kol.database.ItemDatabase
的用法示例。
在下文中一共展示了ItemDatabase.getOrDiscoverItemFromDescId方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getOrDiscoverItemFromDescId [as 别名]
def parseResponse(self):
cantPulverizePattern = PatternManager.getOrCompilePattern('cantPulverizeItem')
if cantPulverizePattern.search(self.responseText) != None:
item = ItemDatabase.getOrDiscoverItemFromId(self.itemId, self.session)
raise Error.Error("'%s' is not an item that can be pulverized." % item["name"], Error.WRONG_KIND_OF_ITEM)
notEnoughItemsPattern = PatternManager.getOrCompilePattern('notEnoughItems')
if notEnoughItemsPattern.search(self.responseText) != None:
item = ItemDatabase.getOrDiscoverItemFromId(self.itemId, self.session)
if self.quantity == 1:
itemStr = item["name"]
else:
itemStr = item["plural"]
raise Error.Error("You do not have %s (%s)." % (itemStr, self.quantity), Error.ITEM_NOT_FOUND)
items = []
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
for match in singleItemPattern.finditer(self.responseText):
descId = int(match.group(1))
item = ItemDatabase.getOrDiscoverItemFromDescId(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.getOrDiscoverItemFromDescId(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 getOrDiscoverItemFromDescId [as 别名]
def parseResponse(self):
noWokAccess = PatternManager.getOrCompilePattern('noWokAccess')
itemsDontMakeFoodPattern = PatternManager.getOrCompilePattern('dontHaveItemsForWok')
dontHaveSkillPattern = PatternManager.getOrCompilePattern('dontHaveSkillForWok')
dontHaveAdventuresPattern = PatternManager.getOrCompilePattern('dontHaveAdventuresForWok')
# Check for errors.
if noWokAccess.search(self.responseText):
raise Error.Error("Unable to use the Wok of Ages. I can't get to the Wok!", Error.RECIPE_NOT_FOUND)
elif dontHaveSkillPattern.search(self.responseText):
raise Error.Error("Unable to use the Wok of Ages. I am not skilled enough.", Error.SKILL_NOT_FOUND)
elif itemsDontMakeFoodPattern.search(self.responseText):
raise Error.Error("Unable to use the Wok of Ages. Invalid ingredients.", Error.ITEM_NOT_FOUND)
elif dontHaveAdventuresPattern.search(self.responseText):
raise Error.Error("Unable to use the Wok of Agles. I don't have enough adventures.", Error.NOT_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.getOrDiscoverItemFromDescId(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.getOrDiscoverItemFromDescId(descId, self.session)
quantity = int(match.group(2).replace(',', ''))
item["quantity"] = quantity
else:
raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)
self.responseData["wok"] = item
示例3: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getOrDiscoverItemFromDescId [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 Error.Error("Unable to make cocktail. The submitted ingredients do not mix together.", Error.RECIPE_NOT_FOUND)
elif dontHaveSkillPattern.search(self.responseText):
raise Error.Error("Unable to make cocktail. We are not skilled enough.", Error.SKILL_NOT_FOUND)
elif dontHaveItemsPattern.search(self.responseText):
raise Error.Error("Unable to make cocktail. You don't have all of the items you are trying to mix.", Error.ITEM_NOT_FOUND)
elif dontHaveAdventuresPattern.search(self.responseText):
raise Error.Error("Unable to mix drink(s). We don't have enough adventures.", Error.NOT_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.getOrDiscoverItemFromDescId(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.getOrDiscoverItemFromDescId(descId, self.session)
quantity = int(match.group(2).replace(',', ''))
item["quantity"] = quantity
else:
raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)
self.responseData["booze"] = item
示例4: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getOrDiscoverItemFromDescId [as 别名]
def parseResponse(self):
wrongProfessionPattern = PatternManager.getOrCompilePattern('wrongStillProfession')
invalidItemPattern = PatternManager.getOrCompilePattern('invalidStillItem')
ItemNotFoundPattern = PatternManager.getOrCompilePattern('stillItemNotFound')
maxLimitPattern = PatternManager.getOrCompilePattern('stillMaxLimit')
if wrongProfessionPattern.search(self.responseText):
raise Error.Error("You aren't a Disco Bandit or Accordion Thief.", Error.USER_IS_WRONG_PROFESSION)
if invalidItemPattern.search(self.responseText):
raise Error.Error("You can\'t improve that item.", Error.INVALID_ITEM)
if ItemNotFoundPattern.search(self.responseText):
raise Error.Error("Not enough of that item.", Error.ITEM_NOT_FOUND)
if maxLimitPattern.search(self.responseText):
raise Error.Error("Still can\'t be used anymore today.", Error.LIMIT_REACHED)
# 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.getOrDiscoverItemFromDescId(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.getOrDiscoverItemFromDescId(descId, self.session)
quantity = int(match.group(2).replace(',', ''))
item["quantity"] = quantity
else:
print self.responseText
raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)
self.responseData["item"] = item
示例5: parseItemsReceived
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getOrDiscoverItemFromDescId [as 别名]
def parseItemsReceived(text, session):
items = []
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
for match in singleItemPattern.finditer(text):
descId = int(match.group(1))
item = ItemDatabase.getOrDiscoverItemFromDescId(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.getOrDiscoverItemFromDescId(descId, session)
item["quantity"] = quantity
items.append(item)
return items
示例6: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getOrDiscoverItemFromDescId [as 别名]
def parseResponse(self):
items = []
singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
for match in singleItemPattern.finditer(self.responseText):
descId = int(match.group(1))
item = ItemDatabase.getOrDiscoverItemFromDescId(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.getOrDiscoverItemFromDescId(descId, self.session)
item["quantity"] = quantity
items.append(item)
self.responseData["results"] = items
示例7: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getOrDiscoverItemFromDescId [as 别名]
def parseResponse(self):
itemsDontMakeFoodPattern = PatternManager.getOrCompilePattern('itemsDontCook')
dontHaveSkillPattern = PatternManager.getOrCompilePattern('dontHaveSkillToCook')
dontHaveItemsPattern = PatternManager.getOrCompilePattern('dontHaveItemsForCook')
dontHaveAdventuresPattern = PatternManager.getOrCompilePattern('dontHaveAdventuresToCook')
chefExplosionPattern = PatternManager.getOrCompilePattern('chefExplosion')
# Check for errors.
if itemsDontMakeFoodPattern.search(self.responseText):
raise Error.Error("Unable to make food. The submitted ingredients do not cook together.", Error.RECIPE_NOT_FOUND)
elif dontHaveSkillPattern.search(self.responseText):
raise Error.Error("Unable to make food. We are not skilled enough.", Error.SKILL_NOT_FOUND)
elif dontHaveItemsPattern.search(self.responseText):
raise Error.Error("Unable to make food. You don't have all of the items you are trying to cook.", Error.ITEM_NOT_FOUND)
elif dontHaveAdventuresPattern.search(self.responseText):
raise Error.Error("Unable to cook food(s). We don't have enough adventures.", Error.NOT_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.getOrDiscoverItemFromDescId(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.getOrDiscoverItemFromDescId(descId, self.session)
quantity = int(match.group(2).replace(',', ''))
item["quantity"] = quantity
else:
raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)
# Check for an explosion
if chefExplosionPattern.search(self.responseText):
self.responseData["explosion"] = 1
#TODO: Remove the items that came from the explosion
self.responseData["food"] = item
示例8: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getOrDiscoverItemFromDescId [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))
try:
item = ItemDatabase.getOrDiscoverItemFromDescId(descId, self.session)
item["quantity"] = 1
items.append(item)
except Error.Error as e:
if e.code == Error.ITEM_NOT_FOUND and self._allowUnknown:
items.append({'id': None,
'quantity': 1,
'descId': descId})
else:
raise
for match in multiItemPattern.finditer(rawText):
descId = int(match.group(1))
quantity = int(match.group(2).replace(',', ''))
try:
item = ItemDatabase.getOrDiscoverItemFromDescId(descId, self.session)
item["quantity"] = quantity
items.append(item)
except Error.Error as e:
if e.code == Error.ITEM_NOT_FOUND and self._allowUnknown:
items.append({'id': None,
'quantity': quantity,
'descId': descId})
else:
raise
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
#.........这里部分代码省略.........
示例9: parseResponse
# 需要导入模块: from kol.database import ItemDatabase [as 别名]
# 或者: from kol.database.ItemDatabase import getOrDiscoverItemFromDescId [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.getOrDiscoverItemFromDescId(int(hatText.group(1)), self.session)
weaponText = weaponPattern.search(self.responseText)
if weaponText:
self.responseData["weapon"] = ItemDatabase.getOrDiscoverItemFromDescId(int(weaponText.group(1)), self.session)
offhandText = offhandPattern.search(self.responseText)
if offhandText:
self.responseData["offhand"] = ItemDatabase.getOrDiscoverItemFromDescId(int(offhandText.group(1)), self.session)
shirtText = shirtPattern.search(self.responseText)
if shirtText:
self.responseData["shirt"] = ItemDatabase.getOrDiscoverItemFromDescId(int(shirtText.group(1)), self.session)
pantsText = pantsPattern.search(self.responseText)
if pantsText:
self.responseData["pants"] = ItemDatabase.getOrDiscoverItemFromDescId(int(pantsText.group(1)), self.session)
accessories = []
accText = accPattern.search(self.responseText)
if accText:
for match in accPattern.finditer(self.responseText):
item = ItemDatabase.getOrDiscoverItemFromDescId(int(match.group(1)), self.session)
item["slot"] = 0
accessories.append(item)
else:
acc1Text = acc1Pattern.search(self.responseText)
if acc1Text:
item = ItemDatabase.getOrDiscoverItemFromDescId(int(acc1Text.group(1)), self.session)
item["slot"] = 1
accessories.append(item)
acc2Text = acc2Pattern.search(self.responseText)
if acc2Text:
item = ItemDatabase.getOrDiscoverItemFromDescId(int(acc2Text.group(1)), self.session)
item["slot"] = 2
accessories.append(item)
acc3Text = acc3Pattern.search(self.responseText)
if acc3Text:
item = ItemDatabase.getOrDiscoverItemFromDescId(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.getOrDiscoverItemFromDescId(int(famText.group(1)), self.session)