def equip_from_dict(self, unit_dict): for key, value in unit_dict.items(): if key is not 'controller': setattr(self, key, value) if 'weapon' not in unit_dict or unit_dict['weapon'] is None: self.weapon = self.default_weapon else: self.weapon = weapons.weapon_dict[unit_dict['weapon']['name']]( self, obj_dict=unit_dict['weapon']) self.weapons = [] self.statuses = {} if 'abilities' in unit_dict: self.abilities = [ abilities.ability_dict[ability['name']](self, obj_dict=ability) for ability in unit_dict['abilities'] ] if 'inventory' in unit_dict: self.items = engine.Container( base_dict=unit_dict['inventory']).fight_list(self) self.inventory = engine.Container( base_dict=unit_dict['inventory']).inv_list(self) if 'armor' in unit_dict: self.armor = [ armors.armor_dict[armor['name']](self, obj_dict=armor) for armor in unit_dict['armor'] ] if 'statuses' in unit_dict: for status in unit_dict['statuses']: standart_actions.object_dict[status['name']](self, obj_dict=status)
def ending(self): won_teams = [team for team in self.teams if any(unit.alive() for unit in team.units)] if won_teams: self.string_tuple.row(LangTuple('fight', 'winner', {'team_name': won_teams[0].name()})) else: self.string_tuple.row(LangTuple('fight', 'draw')) ending_dict = {'winners': [], 'loser': [], 'loot': engine.Container()} if not won_teams: ending_dict['won_team'] = 'draw' for team in self.teams: if team in won_teams: if team.team_marker is not None: ending_dict['won_team'] = team.team_marker for unit in team.units: if not unit.summoned: ending_dict['winners'].append(unit.to_dict()) else: if team.team_marker is not None: ending_dict['lost_team'] = team.team_marker for unit in team.units: if not unit.summoned: ending_dict['loser'].append(unit.to_dict()) if not unit.alive(): loot = unit.generate_loot() ending_dict['loot'] += loot del dynamic_dicts.fight_dict[str(self.id)] return ending_dict
def laircrate(location): laircrate = engine.Container('Overturned Crate', location) laircrate.describe('You see a crate which has fallen on its side.', 'short') laircrate.describe( 'A wooden crate, lying on its side. The wood looks warped, and the crate\'s lid dangles limply by its hinges.' ) return laircrate
def to_dict(self): unit_dict = { 'controller': None, 'unit_name': self.unit_name, 'name': self.name, 'max_hp': self.max_hp, 'hp': self.hp, 'max_energy': self.max_energy, 'melee_accuracy': self.melee_accuracy, 'range_accuracy': self.range_accuracy, 'speed': self.speed, 'max_recovery': self.max_recovery, 'spell_damage': self.spell_damage, 'evasion': self.evasion, 'damage': self.damage, 'toughness': self.toughness, 'abilities': [ability.to_dict() for ability in self.abilities], 'inventory': engine.Container(base_list=[ *[item.to_dict() for item in self.items], *[item.to_dict() for item in self.inventory] ]).base_dict, 'armor': [armor.to_dict() for armor in self.armor], 'weapon': self.weapon, 'statuses': [ status.to_dict() for status in list(self.statuses.values()) if status.to_dict() is not False ] } if unit_dict['weapon'] is not None: if unit_dict['weapon'].natural: unit_dict['weapon'] = None else: unit_dict['weapon'] = unit_dict['weapon'].to_dict() for key in self.boosted_attributes: unit_dict[key] -= self.boosted_attributes[key] if unit_dict['hp'] < 1: unit_dict['hp'] = 1 if not any(status['name'] == 'wounded' for status in unit_dict['statuses']): unit_dict['statuses'].append(statuses.Wounded().to_dict()) return unit_dict
def __init__(self, dungeon, complexity): self.table_row = 'events_' + self.name self.dungeon = dungeon self.special = '0' self.mobs = None self.mob_team = None self.mob_image = None self.complexity = complexity self.get_mobs() self.entrance_location = None self.continue_func = None self.kwargs = None self.loot = engine.Container()
def generate_loot(self): if self.lost_weapon: self.weapon = self.lost_weapon[0] elif self.weapon_to_member: self.weapon = self.weapon_to_member[0] loot = engine.Container() for item in self.loot: if engine.roll_chance(item[1][1]): loot.put(item[0], value=item[1][0]) if engine.roll_chance( self.loot_chances['weapon']) and not self.weapon.natural: loot.put(self.weapon.name) for piece in self.armor: if engine.roll_chance(self.loot_chances['armor']): loot.put(piece.name) for item in self.items: if engine.roll_chance(self.loot_chances['items']): loot.put(item.name) return loot
def to_dict(self): unit_dict = { 'unit_name': self.unit_name, 'name': self.name, 'max_hp': self.max_hp, 'hp': self.hp, 'max_energy': self.max_energy, 'melee_accuracy': self.melee_accuracy, 'recovery_energy': self.recovery_energy, 'range_accuracy': self.range_accuracy, 'evasion': self.evasion, 'damage': self.damage, 'toughness': self.toughness, 'abilities': [ability.to_dict() for ability in self.abilities], 'inventory': engine.Container(base_list=[ *[item.to_dict() for item in self.items], *[item.to_dict() for item in self.inventory] ]).base_dict, 'armor': [armor.to_dict() for armor in self.armor], 'weapon': self.weapon.to_dict() } for key in self.boosted_attributes: unit_dict[key] -= self.boosted_attributes[key] return unit_dict
def storeroomcrate(name, location): crate = engine.Container(name, location) crate.describe('You see a supply crate.', 'short') crate.describe( 'One of the many wooden crates piled up within the storeroom.') return crate