diff --git a/bin/mkjsonapi.py b/bin/mkjsonapi.py index 282f569..eeaad47 100755 --- a/bin/mkjsonapi.py +++ b/bin/mkjsonapi.py @@ -14,7 +14,7 @@ from mhapi import model ENTITIES = """item weapon monster armor skilltree skill decoration - horn_melody""".split() + horn_melody wyporium""".split() def parse_args(argv=None): parser = argparse.ArgumentParser(description= @@ -23,6 +23,7 @@ def parse_args(argv=None): parser.add_argument("-o", "--outpath", help="output base directory, defaults to web/jsonapi/" " in project root") + parser.add_argument("-g", "--game", help="game, one of 4u, gu, gen") parser.add_argument("entities", nargs="*", help=", ".join(ENTITIES)) return parser.parse_args(argv) @@ -68,6 +69,12 @@ def write_all_file(path, all_data): json.dump(all_data, f, cls=model.ModelJSONEncoder, indent=2) +def write_map_file(path, map_data): + map_path = os.path.join(path, "_map.json") + with open(map_path, "w") as f: + json.dump(map_data, f, cls=model.ModelJSONEncoder, indent=2) + + def monster_json(db, path): monsters = db.get_monsters() mkdirs_p(path) @@ -219,10 +226,14 @@ def weapon_json(db, path): def item_json(db, path): - items = db.get_items() + if db.game == "4u": + items = db.get_items(wyporium=True) + else: + items = db.get_items() mkdirs_p(path) write_list_file(path, items) + indexes = {} for item in items: item_path = file_path(path, item) @@ -233,6 +244,21 @@ def item_json(db, path): write_index_file(path, indexes) +def wyporium_json(db, path): + trade_map = {} + for item in db.get_wyporium_trades(): + trade_map[item.id] = dict(id=item.id, + name=item.name) + all_data = item.as_data() + for k in all_data.keys(): + if not k.startswith("wyporium"): + continue + trade_map[item.id][k] = all_data[k] + print trade_map + mkdirs_p(path) + write_map_file(path, trade_map) + + def horn_melody_json(db, path): # only 143 rows, just do index with all data melodies = db.get_horn_melodies() @@ -246,10 +272,10 @@ def horn_melody_json(db, path): def main(): - db = MHDB(include_item_components=True) - args = parse_args() + db = MHDB(game=args.game, include_item_components=True) + if not args.outpath: args.outpath = os.path.join(_pathfix.web_path, "jsonapi") @@ -261,6 +287,9 @@ def main(): else: args.entities = ENTITIES + if db.game != "4u": + args.entities.remove("wyporium") + for entity in args.entities: fn = globals()["%s_json" % entity] fn(db, os.path.join(args.outpath, entity)) diff --git a/mhapi/db.py b/mhapi/db.py index 0483b3b..9d64953 100644 --- a/mhapi/db.py +++ b/mhapi/db.py @@ -157,22 +157,30 @@ class MHDB(object): WHERE type IN (%s) """ % placeholders, tuple(args), model_cls=field_model("name")) - def get_items(self, item_types=None, exclude_types=None): + def get_items(self, item_types=None, exclude_types=None, wyporium=False): """ List of item objects. """ - q = "SELECT * FROM items" + fields = ["items.*"] + where = [] args = [] if item_types: item_types = sorted(item_types) placeholders = ", ".join(["?"] * len(item_types)) - q += "\nWHERE type IN (%s)" % placeholders + where.append("WHERE type IN (%s)" % placeholders) args.extend(item_types) if exclude_types: exclude_types = sorted(exclude_types) placeholders = ", ".join(["?"] * len(exclude_types)) - q += "\nWHERE type NOT IN (%s)" % placeholders + where.append("WHERE type NOT IN (%s)" % placeholders) args.extend(exclude_types) + if wyporium: + where.append("LEFT JOIN wyporium AS w ON w.item_in_id = items._id") + where.append( + "LEFT JOIN items AS wi ON w.item_out_id = wi._id") + fields += ["w.item_out_id AS wyporium_item_id", + "wi.name AS wyporium_item_name"] + q = "SELECT " + ", ".join(fields) + " FROM items " + "\n".join(where) args = tuple(args) return self._query_all("items", q, args, model_cls=model.Item) @@ -205,6 +213,27 @@ class MHDB(object): WHERE item_in_id=? """, (item_id,)) + def get_wyporium_trades(self): + """ + Single wyporium row or None. + """ + if self.game != "4u": + return None + return self._query_all("wyporium", """ + SELECT items.*, + wyporium.item_out_id AS wyporium_item_id, + trade_items.name AS wyporium_item_name, + quests._id AS wyporium_quest_id, + quests.name AS wyporium_quest_name, + quests.hub AS wyporium_quest_hub, + quests.stars AS wyporium_quest_stars, + quests.rank AS wyporium_quest_rank + FROM wyporium + JOIN items ON items._id = wyporium.item_in_id + JOIN items AS trade_items ON trade_items._id = wyporium.item_out_id + JOIN quests ON wyporium.unlock_quest_id == quests._id + """, model_cls=model.Item) + def search_item_name(self, term, item_type=None): """ Search for items containing @term somewhere in the name. Returns diff --git a/mhapi/model.py b/mhapi/model.py index 5cab3f9..451dc84 100644 --- a/mhapi/model.py +++ b/mhapi/model.py @@ -654,6 +654,15 @@ class ItemStars(object): self.db = db self._item_stars = {} # item id -> stars dict self._weapon_stars = {} # weapon id -> stars dict + self._wyporium_trades = {} + + if self.db.game == "4u": + self.init_wyporium_trades() + + def init_wyporium_trades(self): + trades = self.db.get_wyporium_trades() + for item in trades: + self._wyporium_trades[item.id] = item def get_weapon_stars(self, weapon): """ @@ -724,7 +733,10 @@ class ItemStars(object): item = self.db.get_item(row["item_id"]) if "Scrap" in item.name: continue - stars = self.get_item_stars(item.id) + istars = self.get_item_stars(item.id) + for k, v in stars.items(): + if istars[k] > v: + stars[k] = istars[k] break self._item_stars[material_item_id] = stars return stars @@ -737,6 +749,16 @@ class ItemStars(object): stars = dict(Village=None, Guild=None, Permit=None, Arena=None, Event=None) + # for 4u wyporium trade items, use the stars from the unlock quest + trade = self._wyporium_trades.get(item_id) + if trade is not None: + hub = trade.wyporium_quest_hub + if hub == "Caravan": + hub = "Village" + stars[hub] = trade.wyporium_quest_stars + self._item_stars[item_id] = stars + return stars + quests = self.db.get_item_quests(item_id) gathering = self.db.get_item_gathering(item_id) diff --git a/web/mh4u/weaponplanner.html b/web/mh4u/weaponplanner.html index eb0b8a3..ffdbc02 100644 --- a/web/mh4u/weaponplanner.html +++ b/web/mh4u/weaponplanner.html @@ -86,10 +86,23 @@