def update_dock(dock: db.Dock, fuel: int=None, ammo: int=None, steel: int=None, baux: int=None, ship: db.AdmiralShip=None, build=True): """ Updates a dock with the correct values. Can be called just like ```update_dock(dock)``` to reset the dock. :param dock: The dock object to work on. :param fuel: The amount of fuel in the recipe. :param ammo: The amount of ammo in the recipe. :param steel: The amount of steel in the recipe. :param baux: The amount of Bauxite in the recipe. :param ship: The ship object to add to the dock. :return: """ dock.fuel = fuel dock.ammo = ammo dock.steel = steel dock.baux = baux if ship is not None: dock.cmats = 1 try: if build: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta(minutes=ship.ship.buildtime)) else: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta(minutes=ShipHelper.get_repair_time(ship))) except TypeError: ntime = util.millisecond_timestamp(datetime.datetime.now() + datetime.timedelta(minutes=22)) dock.complete = ntime else: dock.cmats = 0 dock.complete = 0 dock.ship = ship return dock
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. :param build: Are we building? :return: Ourselves, after we've updated. Make sure to commit this new state. """ self.resources.fuel = fuel self.resources.ammo = ammo self.resources.steel = steel self.resources.baux = baux if ship is not None: try: if build: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta(minutes=ship.ship.buildtime)) else: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta(minutes=ship.ship.repairtime)) except TypeError: ntime = util.millisecond_timestamp(datetime.datetime.now() + datetime.timedelta(minutes=22)) self.complete = ntime else: self.complete = None self.kanmusu = ship return self
def update_dock(dock: db.Dock, fuel: int, ammo: int, steel: int, baux: int, ship: db.AdmiralShip): dock.fuel = fuel dock.ammo = ammo dock.steel = steel dock.baux = baux dock.cmats = 1 dock.ship = ship try: ntime = util.millisecond_timestamp(datetime.datetime.now() + datetime.timedelta(minutes=ship.ship.buildtime)) except TypeError: ntime = util.millisecond_timestamp(datetime.datetime.now() + datetime.timedelta(minutes=22)) dock.complete = ntime return dock
def update_dock(dock: Dock, fuel: int = None, ammo: int = None, steel: int = None, baux: int = None, ship: AdmiralShip = None, build=True): """ Updates a dock with the correct values. Can be called just like ```update_dock(dock)``` to reset the dock. :param dock: The dock object to work on. :param fuel: The amount of fuel in the recipe. :param ammo: The amount of ammo in the recipe. :param steel: The amount of steel in the recipe. :param baux: The amount of Bauxite in the recipe. :param ship: The ship object to add to the dock. :return: """ dock.fuel = fuel dock.ammo = ammo dock.steel = steel dock.baux = baux if ship is not None: dock.cmats = 1 try: if build: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta(minutes=ship.ship.buildtime)) else: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta( minutes=ShipHelper.get_repair_time(ship))) except TypeError: ntime = util.millisecond_timestamp(datetime.datetime.now() + datetime.timedelta(minutes=22)) dock.complete = ntime else: dock.cmats = 0 dock.complete = 0 dock.ship = ship return dock
def update_dock(dock: Dock, fuel: int=None, ammo: int=None, steel: int=None, baux: int=None, ship: Kanmusu=None, build=True): dock.resources.fuel = fuel dock.resources.ammo = ammo dock.resources.steel = steel dock.resources.baux = baux if ship is not None: try: if build: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta(minutes=ship.ship.buildtime)) else: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta(minutes=ship.ship.repairtime)) except TypeError: ntime = util.millisecond_timestamp(datetime.datetime.now() + datetime.timedelta(minutes=22)) dock.complete = ntime else: dock.complete = 0 dock.kanmusu = ship return dock
def expedition(fleet, cancelled=False): """Generate expedition data""" if fleet.expedition: # Cancelled means the cancel request has just come through. # We then perform an expedition_cancelled check to respond to a /port re-request after cancellation. if cancelled: state = 3 elif fleet.expedition_cancelled or fleet.expedition_completed <= time.time(): state = 2 else: state = 1 return [state, fleet.expedition.id, util.millisecond_timestamp(fleet.expedition_completed), 0] else: return [0, 0, 0, 0]
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. :param build: Are we building? :return: Ourselves, after we've updated. Make sure to commit this new state. """ self.resources.fuel = fuel self.resources.ammo = ammo self.resources.steel = steel self.resources.baux = baux if ship is not None: try: if build: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta(minutes=ship.ship.buildtime)) else: ntime = util.millisecond_timestamp( datetime.datetime.now() + datetime.timedelta(minutes=ship.ship.repairtime)) except TypeError: ntime = util.millisecond_timestamp(datetime.datetime.now() + datetime.timedelta( minutes=22)) self.complete = ntime else: self.complete = None self.kanmusu = ship return self
def start_mission(): # This is mostly an internal method. # This sets up the fleet for an expedition, sending them out. # First, get the required data from the request. fleet_id = int(request.values.get("api_deck_id")) - 1 expedition_id = int(request.values.get("api_mission_id")) # There's an extra value, api_mission. # No idea what it does. # Also, api_serial_cid # This is presumably an anti-bot method by DMM. # We don't have these, because we don't have the game source code (and never will) # So we ignore this # Get the expedition requested by the ID. expedition = Expedition.query.filter( Expedition.id == expedition_id).first_or_404() # Get the fleet requested by the ID. try: fleet = g.admiral.fleets[fleet_id] except IndexError: abort(404) return # Set the fleet up. if fleet.expedition is not None: # Nice try. abort(400) return # Set the expedition && time. fleet.expedition = expedition fleet.expedition_completed = time.time() + expedition.time_taken db.session.add(fleet) db.session.commit() # Internal state updated, now to reflect this state on the rest of the app. return svdata({ "api_complatetime": util.millisecond_timestamp(datetime.datetime.now() + datetime.timedelta( seconds=expedition.time_taken)), "api_complatetime_str": datetime.datetime.fromtimestamp(fleet.expedition_completed / 1000).strftime('%Y-%m-%d %H:%M:%S') })
def expedition(fleet, cancelled=False): """Generate expedition data""" if fleet.expedition: # Cancelled means the cancel request has just come through. # We then perform an expedition_cancelled check to respond to a /port re-request after cancellation. if cancelled: state = 3 elif fleet.expedition_cancelled or fleet.expedition_completed <= time.time( ): state = 2 else: state = 1 return [ state, fleet.expedition.id, util.millisecond_timestamp(fleet.expedition_completed), 0 ] else: return [0, 0, 0, 0]