def init(self, position=(0, 0), amount=0): GameObject.init(self, ObjectType.illegal_salvage) self.position = position self.material_type = MaterialType.salvage self.turns_till_recycling = 150 self.amount = amount
def init(self, name, value, material_type): GameObject.init(self, ObjectType.material) self.name = name self.value = value self.material_type = material_type self.initialized = True
def init(self, name, station_type=ObjectType.station, position=(0, 0), primary_import=None, primary_consumption_qty=1, primary_max=200, secondary_import=None, secondary_consumption_qty=1, secondary_max=50, production_frequency=5, production_material=None, production_qty=1, production_max=200, sell_price=0, primary_buy_price=0, secondary_buy_price=0, base_sell_price=0, base_primary_buy_price=0, base_secondary_buy_price=0, cargo=None, accessibility_radius=5): GameObject.init(self, station_type) self.id = str(uuid4()) self.name = name self.position = position self.primary_import = primary_import # primary import material self.primary_consumption_qty = primary_consumption_qty # qty to consume in one shot self.primary_max = primary_max self.secondary_import = secondary_import self.secondary_consumption_qty = secondary_consumption_qty self.secondary_max = secondary_max self.production_frequency = production_frequency # how often to consume inputs to create output self.production_material = production_material self.production_qty = production_qty self.production_max = production_max self.sell_price = sell_price self.primary_buy_price = primary_buy_price self.secondary_buy_price = secondary_buy_price self.base_sell_price = base_sell_price self.base_primary_buy_price = base_primary_buy_price self.base_secondary_buy_price = base_secondary_buy_price if cargo is None: self.cargo = {} else: self.cargo = cargo self.accessibility_radius = accessibility_radius
def from_dict(self, d, safe=False): GameObject.from_dict(self, d) if not safe: pass # info hidden from user here self.name = d["name"] self.value = d["value"] self.material_type = d["material_type"]
def to_dict(self, security_level=SecurityLevel.other_player): data = GameObject.to_dict(self) if security_level is SecurityLevel.engine: # fields only accessible to the engine engine = {} data = {**data, **engine} if security_level <= SecurityLevel.player_owned: # fields only accessible to the player owner of this object # Could be used to determine who gets priority of the salvage pass if security_level <= SecurityLevel.other_player: # fields other players can view other_player = { "position": self.position, "material_type": self.material_type, "turns_till_recycling": self.turns_till_recycling, "amount": self.amount } data = {**data, **other_player} return data
def to_dict(self, security_level=SecurityLevel.other_player): data = GameObject.to_dict(self) if security_level is SecurityLevel.engine: # fields only accessible to the engine engine = {"id": self.id} data = {**data, **engine} if security_level <= SecurityLevel.player_owned: # fields only accessible to the player owner of this object # technically a feasible and interesting direction to go but not discussed yet pass if security_level <= SecurityLevel.other_player: # fields other players can view other_player = { "name": self.name, "position": self.position, "material_type": self.material_type, "mining_rate": self.mining_rate, "accessibility_radius": self.accessibility_radius } data = {**data, **other_player} return data
def init(self, field_type, name, material_type, position=(0, 0), mining_rate=1, accessibility_radius=35): GameObject.init(self, field_type) self.name = name self.position = position self.material_type = material_type self.mining_rate = mining_rate self.accessibility_radius = accessibility_radius
def from_dict(self, data, security_level=SecurityLevel.other_player): GameObject.from_dict(self, data) if security_level is SecurityLevel.engine: # properties that will only be populated by the engine, # prevents user tampering with variables self.position = data["position"] self.material_type = data["material_type"] self.turns_till_recycling = data["turns_till_recycling"] self.amount = data["amount"] if security_level <= SecurityLevel.player_owned: pass if security_level <= SecurityLevel.other_player: pass
def from_dict(self, data, security_level=SecurityLevel.other_player): GameObject.from_dict(self, data) if security_level is SecurityLevel.engine: # properties that will only be populated by the engine, # prevents user tampering with variables pass if security_level <= SecurityLevel.player_owned: pass if security_level <= SecurityLevel.other_player: self.name = data["name"] self.position = data["position"] self.material_type = data["material_type"] self.mining_rate = data["mining_rate"] self.accessibility_radius = data["accessibility_radius"]
def from_dict(self, data, security_level=SecurityLevel.other_player): GameObject.from_dict(self, data) if security_level is SecurityLevel.engine: # properties that will only be populated by the engine, # prevents user tampering with variables pass if security_level <= SecurityLevel.player_owned: pass if security_level <= SecurityLevel.other_player: self.id = data["id"] self.name = data["name"] self.position = data["position"] self.primary_import = data["primary_import"] self.primary_consumption_qty = data["primary_consumption_qty"] self.primary_max = data["primary_max"] self.secondary_import = data["secondary_import"] self.secondary_consumption_qty = data["secondary_consumption_qty"] self.secondary_max = data["secondary_max"] self.production_frequency = data["production_frequency"] self.production_material = data["production_material"] self.production_qty = data["production_qty"] self.production_max = data["production_max"] self.cargo = {int(k): v for k, v in data["cargo"].items()} self.accessibility_radius = data["accessibility_radius"] self.sell_price = data["sell_price"] self.primary_buy_price = data["primary_buy_price"] self.secondary_buy_price = data["secondary_buy_price"] self.base_sell_price = data["base_sell_price"] self.base_primary_buy_price = data["base_primary_buy_price"] self.base_secondary_buy_price = data["base_secondary_buy_price"]
def to_dict(self, safe=False): data = GameObject.to_dict(self) if not safe: pass # info hidden from user here data["name"] = self.name data["value"] = self.value data["material_type"] = self.material_type return data
def to_dict(self, security_level=SecurityLevel.other_player): data = GameObject.to_dict(self) if security_level is SecurityLevel.engine: # fields only accessible to the engine engine = {"id": self.id} data = {**data, **engine} if security_level <= SecurityLevel.player_owned: # fields only accessible to the player owner of this object # technically a feasible and interesting direction to go but not discussed yet pass if security_level <= SecurityLevel.other_player: # fields other players can view other_player = { "name": self.name, "position": self.position, "primary_import": self.primary_import, "primary_consumption_qty": self.primary_consumption_qty, "primary_max": self.primary_max, "secondary_import": self.secondary_import, "secondary_consumption_qty": self.secondary_consumption_qty, "secondary_max": self.secondary_max, "production_frequency": self.production_frequency, "production_material": self.production_material, "production_qty": self.production_qty, "production_max": self.production_max, "cargo": self.cargo, "accessibility_radius": self.accessibility_radius, "sell_price": self.sell_price, "primary_buy_price": self.primary_buy_price, "secondary_buy_price": self.secondary_buy_price, "base_sell_price": self.base_sell_price, "base_primary_buy_price": self.base_primary_buy_price, "base_secondary_buy_price": self.base_secondary_buy_price } data = {**data, **other_player} return data
def to_dict(self, security_level=SecurityLevel.other_player): data = GameObject.to_dict(self) if security_level is SecurityLevel.engine: # fields that only the engine (server, visualizer, logs) should # be able to access engine = {"is_npc": self.is_npc, "bounty_list": self.bounty_list} data = {**data, **engine} if security_level <= SecurityLevel.player_owned: # fields that the player who owns the object can view player_owned = { "id": self.id, "team_name": self.team_name, "color": self.color, "respawn_counter": self.respawn_counter, "credits": self.credits, "action": self.action, "action_param_1": self.action_param_1, "action_param_2": self.action_param_2, "action_param_3": self.action_param_3, "move_action": self.move_action, } data = {**data, **player_owned} if security_level <= SecurityLevel.other_player: # fields that other players can view on this object other_player = { "public_id": self.public_id, "max_hull": self.max_hull, "current_hull": self.current_hull, "cargo_space": self.cargo_space, "position": self.position, "inventory": self.inventory, "notoriety": self.notoriety, "legal_standing": self.legal_standing, "bounty": self.bounty, "engine_speed": self.engine_speed, "weapon_damage": self.weapon_damage, "weapon_range": self.weapon_range, "cargo_space": self.cargo_space, "mining_yield": self.mining_yield, "sensor_range": self.sensor_range, "module_0": self.module_0, "module_1": self.module_1, "module_2": self.module_2, "module_3": self.module_3, "module_0_level": self.module_0_level, "module_1_level": self.module_1_level, "module_2_level": self.module_2_level, "module_3_level": self.module_3_level, "bounty_list": self.bounty_list, "passive_repair_counter": self.passive_repair_counter, } data = {**data, **other_player} return data
def from_dict(self, data, security_level=SecurityLevel.other_player): GameObject.from_dict(self, data) if security_level is SecurityLevel.engine: # properties that will only be populated by the engine, # prevents user tampering with variables self.is_npc = data["is_npc"] self.bounty_list = data["bounty_list"] if security_level <= SecurityLevel.player_owned: # properties that the owner of a ship can update # prevents other players from tampering with our ship self.id = data["id"] self.team_name = data["team_name"] self.color = data["color"] self.respawn_counter = data["respawn_counter"] self.credits = data["credits"] self.action = data["action"] self.move_action = data["move_action"] self.action_param_1 = data["action_param_1"] self.action_param_2 = data["action_param_2"] self.action_param_3 = data["action_param_3"] if ((type(self.action_param_1) == int and self.action_param_1 > 2147483647) or (type(self.action_param_2) == int and self.action_param_2 > 2147483647) or (type(self.action_param_3) == int and self.action_param_3 > 2147483647)): print("Action parameters cannot be larter than 2147483647") exit(1) if security_level <= SecurityLevel.other_player: self.public_id = data["public_id"] self.max_hull = data["max_hull"] self.current_hull = data["current_hull"] self.engine_speed = data["engine_speed"] self.weapon_damage = data["weapon_damage"] self.weapon_range = data["weapon_range"] self.cargo_space = data["cargo_space"] self.mining_yield = data["mining_yield"] self.sensor_range = data["sensor_range"] self.module_0 = data["module_0"] self.module_1 = data["module_1"] self.module_2 = data["module_2"] self.module_3 = data["module_3"] self.module_0_level = data["module_0_level"] self.module_1_level = data["module_1_level"] self.module_2_level = data["module_2_level"] self.module_3_level = data["module_3_level"] self.position = data["position"] self.inventory = {int(k): v for k, v in data["inventory"].items()} self.notoriety = data["notoriety"] self.legal_standing = data["legal_standing"] self.bounty = data["bounty"] self.passive_repair_counter = data["passive_repair_counter"]
def init(self, team_name, color=[255, 255, 255], is_npc=False, position=None): GameObject.init(self, ObjectType.ship) # used by engine to track ships self.id = str(uuid4()) # used to match NPC client instances to npc ships self.is_npc = is_npc # allows players to track ships by random id # could be changed to be more readable. self.public_id = str(uuid4()) self.team_name = team_name if self.is_npc: self.color = None else: self.color = color self.max_hull = GameStats.get_ship_stat(ShipStat.hull, ModuleLevel.base) self.current_hull = self.max_hull self.engine_speed = GameStats.get_ship_stat(ShipStat.engine_speed, ModuleLevel.base) self.weapon_damage = GameStats.get_ship_stat(ShipStat.weapon_damage, ModuleLevel.base) self.weapon_range = GameStats.get_ship_stat(ShipStat.weapon_range, ModuleLevel.base) self.cargo_space = GameStats.get_ship_stat(ShipStat.cargo_space, ModuleLevel.base) self.mining_yield = GameStats.get_ship_stat(ShipStat.mining_yield, ModuleLevel.base) self.sensor_range = GameStats.get_ship_stat(ShipStat.sensor_range, ModuleLevel.base) self.module_0 = ModuleType.empty self.module_1 = ModuleType.locked self.module_2 = ModuleType.locked self.module_3 = ModuleType.locked self.module_0_level = ModuleLevel.base self.module_1_level = ModuleLevel.base self.module_2_level = ModuleLevel.base self.module_3_level = ModuleLevel.base self.action = PlayerAction.none self.action_param_1 = None self.action_param_2 = None self.action_param_3 = None self.move_action = None # ideally a dictionary of ItemType enums mapped to a count of the number of that item self.inventory = {} self.position = position self.notoriety = 0 self.legal_standing = LegalStanding.citizen self.bounty = 0 self.bounty_list = [] self.respawn_counter = -1 self.credits = 2000 self.passive_repair_counter = GameStats.passive_repair_counter