add quest level filter to weapon list for mhgen
This commit is contained in:
@@ -174,6 +174,8 @@ def weapon_json(db, path):
|
||||
mkdirs_p(path)
|
||||
write_list_file(path, weapons)
|
||||
|
||||
item_stars = model.ItemStars(db)
|
||||
|
||||
all_data = []
|
||||
melodies = {}
|
||||
indexes = {}
|
||||
@@ -193,6 +195,12 @@ def weapon_json(db, path):
|
||||
]
|
||||
data["horn_melodies"] = melodies[w.horn_notes]
|
||||
|
||||
stars = item_stars.get_weapon_stars(w)
|
||||
data["village_stars"] = stars["Village"]
|
||||
data["guild_stars"] = stars["Guild"]
|
||||
data["permit_stars"] = stars["Permit"]
|
||||
data["arena_stars"] = stars["Arena"]
|
||||
|
||||
all_data.append(data)
|
||||
|
||||
with open(weapon_path, "w") as f:
|
||||
|
||||
@@ -1,99 +1,42 @@
|
||||
#!/usr/bin/env python2
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
import _pathfix
|
||||
|
||||
from mhapi.db import MHDB, MHDBX
|
||||
from mhapi.model import get_costs
|
||||
|
||||
|
||||
def find_cost_level(db, c):
|
||||
monsters = { "HR": set(), "LR": set() }
|
||||
materials = { "HR": set(), "LR": set() }
|
||||
stars = dict(Village=None, Guild=None, Permit=None, Arena=None)
|
||||
for item in c["components"].keys():
|
||||
if item.startswith("HR ") or item.startswith("LR "):
|
||||
if not item.endswith(" Materials"):
|
||||
print "Error: bad item format '%s'" % item
|
||||
rank = item[:2]
|
||||
item = item[len("HR "):-len(" Materials")]
|
||||
monster = db.get_monster_by_name(item)
|
||||
if monster:
|
||||
monsters[rank].add(monster)
|
||||
#print "Monster", rank, monster.name, monster.id
|
||||
else:
|
||||
materials[rank].add(item)
|
||||
#print "Material", rank, item
|
||||
else:
|
||||
data = db.get_item_by_name(item)
|
||||
current_stars = find_item_level(db, data.id)
|
||||
# keep track of most 'expensive' item
|
||||
for k, v in current_stars.iteritems():
|
||||
if v is None:
|
||||
continue
|
||||
if stars[k] is None or v > stars[k]:
|
||||
stars[k] = v
|
||||
return stars
|
||||
|
||||
|
||||
def find_item_level(db, item_id):
|
||||
stars = dict(Village=None, Guild=None, Permit=None, Arena=None)
|
||||
|
||||
quests = db.get_item_quests(item_id)
|
||||
|
||||
gathering = db.get_item_gathering(item_id)
|
||||
gather_locations = set()
|
||||
for gather in gathering:
|
||||
gather_locations.add((gather["location_id"], gather["rank"]))
|
||||
for location_id, rank in list(gather_locations):
|
||||
gather_quests = db.get_location_quests(location_id, rank)
|
||||
quests.extend(gather_quests)
|
||||
|
||||
monsters = db.get_item_monsters(item_id)
|
||||
monster_ranks = set()
|
||||
for monster in monsters:
|
||||
monster_ranks.add((monster["monster_id"], monster["rank"]))
|
||||
for monster_id, rank in list(monster_ranks):
|
||||
monster_quests = db.get_monster_quests(monster_id, rank)
|
||||
quests.extend(monster_quests)
|
||||
|
||||
# find least expensive quest for getting the item
|
||||
for quest in quests:
|
||||
if quest.stars == 0:
|
||||
# ignore training quests
|
||||
if "Training" not in quest.name:
|
||||
print "Error: non training quest has 0 stars", \
|
||||
quest.id, quest.name
|
||||
continue
|
||||
if quest.hub in stars:
|
||||
current = stars[quest.hub]
|
||||
if current is None or quest.stars < current:
|
||||
stars[quest.hub] = quest.stars
|
||||
else:
|
||||
print "Error: unknown hub", quest.hub
|
||||
|
||||
return stars
|
||||
from mhapi.model import ItemStars
|
||||
|
||||
|
||||
def main():
|
||||
weapon_name = sys.argv[1]
|
||||
db = MHDB(game="gen", include_item_components=True)
|
||||
weapon = db.get_weapon_by_name(weapon_name)
|
||||
if weapon is None:
|
||||
print "Weapon '%s' not found" % weapon_name
|
||||
item_stars = ItemStars(db)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-i", "--item")
|
||||
parser.add_argument("-w", "--weapon")
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.item:
|
||||
item = db.get_item_by_name(args.item)
|
||||
if item is None:
|
||||
print "Item '%s' not found" % args.item
|
||||
sys.exit(1)
|
||||
if item.type == "Materials":
|
||||
stars = item_stars.get_material_stars(item.id)
|
||||
else:
|
||||
stars = item_stars.get_item_stars(item.id)
|
||||
elif args.weapon:
|
||||
weapon = db.get_weapon_by_name(args.weapon)
|
||||
if weapon is None:
|
||||
print "Weapon '%s' not found" % args.weapon
|
||||
sys.exit(1)
|
||||
stars = item_stars.get_weapon_stars(weapon)
|
||||
else:
|
||||
print "Specify -w or -i"
|
||||
sys.exit(1)
|
||||
|
||||
costs = get_costs(db, weapon)
|
||||
stars = dict(Village=None, Guild=None, Permit=None, Arena=None)
|
||||
# find least 'expensive' path
|
||||
for c in costs:
|
||||
current_stars = find_cost_level(db, c)
|
||||
for k, v in current_stars.iteritems():
|
||||
if v is None:
|
||||
continue
|
||||
if stars[k] is None or v < stars[k]:
|
||||
stars[k] = v
|
||||
for k, v in stars.iteritems():
|
||||
print k, v
|
||||
|
||||
|
||||
Reference in New Issue
Block a user