def swap(self, swap_event, star_system, storing_ship_name): if self.db is None: return if swap_event.get("event", None) != "ShipyardSwap": return if "SellShipID" in swap_event: self.__sold(swap_event["SellShipID"]) else: storing_ship_id = swap_event.get("StoreShipID", None) ship_type = swap_event.get("StoreOldShip", None).lower() localised = EDVehicleFactory.canonicalize(ship_type) market_id = swap_event.get("MarketID", None) self.db.execute( '''INSERT INTO ships(id, type, localised, name, star_system, ship_market_id, value, hot) VALUES(?,?,?,?,?,?,?,?)''', (storing_ship_id, ship_type, localised, storing_ship_name, star_system, market_id, 0, 0)) self.db.execute('DELETE from transits WHERE ship_id=?', (storing_ship_id, )) piloting_ship_id = swap_event.get("ShipID", None) self.db.execute( 'UPDATE ships SET ship_market_id="", star_system="", piloted=1, eta=0 WHERE id=?', (piloting_ship_id, )) self.db.execute('DELETE from transits WHERE ship_id=?', (piloting_ship_id, )) self.db.commit()
def npc(self, name, rank=None, ship_internal_name=None): hopefully_unique_name = "{}{}{}".format(name, rank, EDVehicleFactory.canonicalize(ship_internal_name) if ship_internal_name else "") if hopefully_unique_name in self.npcs: return self.npcs[hopefully_unique_name][u"pilot"] if name in self.npc_names_to_npcs: return self.npcs[next(iter(self.npc_names_to_npcs[name]))][u"pilot"] return None
def npc_out(self, name, ship_internal_name=None, rank=None): now = EDTime.py_epoch_now() try: if ship_internal_name: hopefully_unique_name = "{}{}{}".format(name, rank, EDVehicleFactory.canonicalize(ship_internal_name)) del self.npcs[hopefully_unique_name] self.npc_names_to_npcs[name].remove(hopefully_unique_name) else: for hopefully_unique_name in self.npc_names_to_npcs[name]: del self.npcs[hopefully_unique_name] del self.npc_names_to_npcs[name] self.timestamp = now self._touched = True except KeyError: pass
def buy(self, buy_event, star_system, storing_ship_name): if self.db is None: return if buy_event.get("event", None) != "ShipyardBuy": return market_id = buy_event.get("MarketID", None) if buy_event.get("StoreShipID", None): storing_ship_id = buy_event["StoreShipID"] ship_type = buy_event["StoreOldShip"].lower() localised = EDVehicleFactory.canonicalize(ship_type) self.db.execute( '''INSERT INTO ships(id, type, localised, name, star_system, ship_market_id, value, hot) VALUES(?,?,?,?,?,?,?,?)''', (storing_ship_id, ship_type, localised, storing_ship_name, star_system, market_id, 0, 0)) self.db.execute('DELETE from transits WHERE ship_id=?', (storing_ship_id, )) self.db.commit() elif buy_event.get("SellShipID", None): self.__sold(buy_event["SellShipID"])