From e77d91b0dbdc21eeb04b4e802403eebd34a0d876 Mon Sep 17 00:00:00 2001 From: Bryce Allen Date: Sat, 28 Mar 2015 18:12:59 -0500 Subject: [PATCH] handle wyporium items by listing trade item data --- mhapi/db.py | 9 ++++++++- mhapi/rewards.py | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/mhapi/db.py b/mhapi/db.py index 478b5f4..3704db2 100644 --- a/mhapi/db.py +++ b/mhapi/db.py @@ -8,7 +8,7 @@ import sqlite3 class Quest(object): - def __init__(self, quest_row, quest_rewards): + def __init__(self, quest_row, quest_rewards=None): self._row = quest_row self.rewards = quest_rewards @@ -87,6 +87,13 @@ class MHDB(object): """, name) return v[0] if v else None + def get_wyporium_trade(self, item_id): + v = self._get_memoized("wyporium", """ + SELECT * FROM wyporium + WHERE item_in_id=? + """, item_id) + return v[0] if v else None + def search_item_name(self, term, item_type): """ Search for items containing @term somewhere in the name. Returns diff --git a/mhapi/rewards.py b/mhapi/rewards.py index 9f8666a..e50bae2 100644 --- a/mhapi/rewards.py +++ b/mhapi/rewards.py @@ -7,6 +7,7 @@ from __future__ import print_function from collections import OrderedDict from mhapi import stats +from mhapi.db import Quest SKILL_CARVING = "carving" SKILL_CAP = "cap" @@ -497,6 +498,19 @@ class ItemRewards(object): self.item_row = item_row self.item_id = item_row["_id"] + wyp_row = db.get_wyporium_trade(self.item_id) + if wyp_row is not None: + self.trade_unlock_quest = Quest( + db.get_quest(wyp_row["unlock_quest_id"])) + self.trade_item_row = self.item_row + self.trade_item_id = self.item_id + self.item_id = wyp_row["item_out_id"] + self.item_row = db.get_item(wyp_row["item_out_id"]) + else: + self.trade_item_row = None + self.trade_item_id = None + self.trade_unlock_quest = None + self.rank_skill_sets = OrderedDict() for rank in "G HR LR".split(): self.rank_skill_sets[rank] = OrderedDict([ @@ -664,9 +678,16 @@ class ItemRewards(object): def print_all(self, out): if self.is_empty(): - # TODO: this happens for Wymporium tradeable monster parts. out.write("ERROR: data for this item is not yet available\n") return + + if self.trade_unlock_quest: + item_name = self.item_row["name"] + out.write("*** Wyporium trade for '%s'\n" % item_name) + out.write(" Unlocked by quest '%s'\n" + % unicode(self.trade_unlock_quest).split("\n")[0]) + out.write("\n") + self.print_recommended_hunts(out) self.print_monsters(out) self.print_quests(out)