new web index, refactor, data fixes

This commit is contained in:
Bryce Allen
2015-05-20 11:05:32 -05:00
parent 9bad89b0af
commit f6fa342ac4
12 changed files with 341 additions and 151 deletions

View File

@@ -284,11 +284,15 @@ class MHDB(object):
WHERE monster_id=?
""", (monster_id,), collection_cls=model.MonsterDamage)
def get_weapons(self):
return self._query_all("weapons", """
def get_weapons(self, get_components=False):
results = self._query_all("weapons", """
SELECT * FROM weapons
LEFT JOIN items ON weapons._id = items._id
""", model_cls=model.Weapon)
if results and get_components:
for r in results:
self._add_components(r)
return results
def _add_components(self, item_data):
ccomps = self.get_item_components(item_data.id, "Create")

View File

@@ -507,3 +507,59 @@ def _break_find(part, parts, breaks):
if matches:
return matches[0]
return None
def get_costs(db, weapon):
"""
Get a list of alternative ways of making a weapon, as a list of dicts
containing item counts. The dicts also contain special keys _zenny
for the total zenny needed, and _path for a list of weapons that
make up the upgrade path.
"""
costs = []
if weapon.parent_id:
if not weapon.upgrade_cost:
# db has errors where upgrade cost is listed as create
# cost and components are listed under create. Assume
# parent_id is correct, and they are upgrade only.
if not weapon.upgrade_components and weapon.create_components:
weapon.upgrade_components = weapon.create_components
weapon.create_components = []
weapon.upgrade_cost = weapon.creation_cost
weapon.creation_cost = 0
try:
upgrade_cost = int(weapon.upgrade_cost)
except ValueError:
upgrade_cost = 0
print "WARN: bad upgrade cost for '%s' (%s): '%s'" \
% (weapon.name, weapon.id, weapon.upgrade_cost)
except UnicodeError:
upgrade_cost = 0
cost_display = urllib.quote(weapon.upgrade_cost)
print "WARN: bad upgrade cost for '%s' (%s): '%s'" \
% (weapon.name, weapon.id, cost_display)
parent_weapon = db.get_weapon(weapon.parent_id, True)
costs = get_costs(db, parent_weapon)
for cost in costs:
cost["zenny"] += upgrade_cost
cost["path"] += [weapon]
for item in weapon.upgrade_components:
if item.type == "Weapon":
continue
if item.name not in cost["components"]:
cost["components"][item.name] = 0
cost["components"][item.name] += item.quantity
if weapon.create_components:
try:
zenny = int(weapon.creation_cost)
except ValueError:
print "WARN: bad creation cost for '%s': '%s'" \
% (weapon.name, weapon.creation_cost)
zenny = weapon.upgrade_cost or 0
create_cost = dict(zenny=zenny,
path=[weapon],
components={})
for item in weapon.create_components:
create_cost["components"][item.name] = item.quantity
costs = [create_cost] + costs
return costs