Skip to content

Commit

Permalink
Fix ship crafting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuyukai committed Jan 20, 2016
1 parent 0d751e7 commit dbe2c6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
9 changes: 6 additions & 3 deletions db/admiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def get_usable(self, name):
return None

def add_kanmusu(self, kanmusu, fleet_number=None, position=None):
kanmusu.number = len(self.kanmusu) + 1
kanmusu.number = len(self.kanmusu)
if fleet_number:
self.fleets[fleet_number - 1].kanmusu.append(kanmusu)
kanmusu.fleet_position = position if position else 1
Expand Down Expand Up @@ -211,7 +211,8 @@ def default_resources(self):
if self.resources is None:
self.resources = Resources(fuel=0, ammo=0, steel=0, baux=0)

def update(self, fuel: int, ammo: int, steel: int, baux: int, ship: Kanmusu, build: bool = True):
def update(self, ship: Kanmusu, fuel: int=None, ammo: int=None, steel: int=None, baux: int=None,
build: bool=True):
"""
Update a dock.
:param ship: The ship to use.
Expand All @@ -235,11 +236,13 @@ def update(self, fuel: int, ammo: int, steel: int, baux: int, ship: Kanmusu, bui
ntime = util.millisecond_timestamp(datetime.datetime.now() + datetime.timedelta(minutes=22))
self.complete = ntime
else:
self.complete = 0
self.complete = None
self.kanmusu = ship
return self




class Fleet(db.Model):
__tablename__ = 'fleet'

Expand Down
17 changes: 9 additions & 8 deletions helpers/DockHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,28 @@ def get_ship_from_recipe(fuel: int=30, ammo: int=30, steel: int=30, baux: int=30
def get_and_remove_ship_kdock(dockid: int):
admiral = g.admiral
try:
dock = admiral.docks_craft.all()[dockid]
dock = admiral.docks_craft[dockid]
except IndexError:
abort(404)
return None

dock.resources.fuel, dock.resources.ammo, \
dock.resources.steel, dock.resources.baux = 0, 0, 0, 0
if dock.kanmusu is None:
# ....
abort(400)
return

dock.kanmusu.active = True

db.session.add(dock.ship)
api_data = {
"api_ship_id": dock.ship.ship.id,
"api_ship_id": dock.kanmusu.ship.api_id,
"api_kdock": MemberHelper.dock_data([dock], False),
"api_id": dock.kanmusu.number,
"api_slotitem": [], # TODO: Equipment!
"api_ship": MemberHelper.kanmusu(kanmusu=dock.kanmusu)
}
# Update dock data.
dock.kanmusu = None
dock.complete = None
db.session.add(dock.kanmusu)
dock.update(None)
db.session.add(dock)
db.session.commit()
return api_data
Expand Down Expand Up @@ -89,7 +90,7 @@ def craft_ship(fuel: int, ammo: int, steel: int, baux: int, dockid: int):
abort(400)
return

dock = dock.update(fuel, ammo, steel, baux, nship, True)
dock = dock.update(nship, fuel, ammo, steel, baux, True)

admiral.resources.sub(fuel, ammo, steel, baux)

Expand Down

0 comments on commit dbe2c6e

Please sign in to comment.