def test_get_available_mobs_list(self): mobs_in_forest = [ mob.uuid for mob in mobs_storage.get_available_mobs_list( 1, TERRAIN.PLANE_SAND) ] self.assertEqual( frozenset(mobs_in_forest), frozenset([ self.mob_1.uuid, self.mob_2.uuid, self.mob_3.uuid, self.bandit.uuid ])) mobs_in_forest = [ mob.uuid for mob in mobs_storage.get_available_mobs_list( 1, TERRAIN.PLANE_GRASS) ] self.assertEqual( frozenset(mobs_in_forest), frozenset([self.mob_1.uuid, self.mob_2.uuid, self.mob_3.uuid])) mobs_in_forest = [ mob.uuid for mob in mobs_storage.get_available_mobs_list( 0, TERRAIN.PLANE_SAND) ] self.assertEqual(frozenset(mobs_in_forest), frozenset())
def test_get_available_mobs_list__mercenary__false(self): mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(1, TERRAIN.PLANE_SAND, mercenary=False)] self.assertEqual(frozenset(mobs_in_forest), frozenset([self.mob_2.uuid])) mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(1, TERRAIN.PLANE_GRASS, mercenary=False)] self.assertEqual(frozenset(mobs_in_forest), frozenset([self.mob_2.uuid])) mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(0, TERRAIN.PLANE_SAND, mercenary=False)] self.assertEqual(frozenset(mobs_in_forest), frozenset())
def test_get_available_mobs_list(self): mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(1, TERRAIN.PLANE_SAND)] self.assertEqual(frozenset(mobs_in_forest), frozenset([self.mob_1.uuid, self.mob_2.uuid, self.mob_3.uuid, self.bandit.uuid])) mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(1, TERRAIN.PLANE_GRASS)] self.assertEqual(frozenset(mobs_in_forest), frozenset([self.mob_1.uuid, self.mob_2.uuid, self.mob_3.uuid])) mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(0, TERRAIN.PLANE_SAND)] self.assertEqual(frozenset(mobs_in_forest), frozenset())
def test_get_available_mobs_list__mercenary__false(self): mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(1, map_relations.TERRAIN.PLANE_SAND, mercenary=False)] self.assertEqual(frozenset(mobs_in_forest), frozenset([self.mob_2.uuid])) mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(1, map_relations.TERRAIN.PLANE_GRASS, mercenary=False)] self.assertEqual(frozenset(mobs_in_forest), frozenset([self.mob_2.uuid])) mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(0, map_relations.TERRAIN.PLANE_SAND, mercenary=False)] self.assertEqual(frozenset(mobs_in_forest), frozenset())
def mobs_and_artifacts(self): # pylint: disable=R0914 from the_tale.game.mobs.storage import mobs_storage from the_tale.game.artifacts.storage import artifacts_storage from the_tale.game.map.relations import TERRAIN from the_tale.game.heroes import relations as heroes_relations mobs_without_loot = [] mobs_without_artifacts = [] mobs_without_loot_on_first_level = [] mobs_without_artifacts_on_first_level = [] for mob in mobs_storage.get_available_mobs_list(level=999999): if not mob.loot: mobs_without_loot.append(mob) elif not any(loot.level == mob.level for loot in mob.loot): mobs_without_loot_on_first_level.append(mob) if not mob.artifacts: mobs_without_artifacts.append(mob) elif not any(artifact.level == mob.level for artifact in mob.artifacts): mobs_without_artifacts_on_first_level.append(mob) territory_levels_checks = [1, 2, 3, 5, 7, 10, 15, 20, 30, 50, 75, 100] mobs_by_territory = {terrain.name: [0] * len(territory_levels_checks) for terrain in TERRAIN.records} for mob in mobs_storage.get_available_mobs_list(level=999999): for terrain in mob.terrains: for i, level in enumerate(territory_levels_checks): if level >= mob.level: mobs_by_territory[terrain.name][i] += 1 del mobs_by_territory["WATER_SHOAL"] del mobs_by_territory["WATER_DEEP"] mobs_by_territory = sorted(list(mobs_by_territory.items()), key=lambda x: x[1][-1]) artifacts_without_mobs = [] for artifact in itertools.chain(artifacts_storage.artifacts, artifacts_storage.loot): if artifact.uuid not in heroes_relations.EQUIPMENT_SLOT.index_default and artifact.mob is None: artifacts_without_mobs.append(artifact) return self.template( "developers_info/mobs_and_artifacts.html", { "page_type": "mobs_and_artifacts", "mobs_without_loot": mobs_without_loot, "mobs_without_artifacts": mobs_without_artifacts, "mobs_without_loot_on_first_level": mobs_without_loot_on_first_level, "mobs_without_artifacts_on_first_level": mobs_without_artifacts_on_first_level, "mobs_by_territory": mobs_by_territory, "territory_levels_checks": territory_levels_checks, "artifacts_without_mobs": artifacts_without_mobs, }, )
def test_get_available_mobs_list__mercenary__true(self): mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(1, map_relations.TERRAIN.PLANE_SAND, mercenary=True)] self.assertEqual(frozenset(mobs_in_forest), frozenset([self.mob_1.uuid, self.mob_3.uuid, self.bandit.uuid])) mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(1, map_relations.TERRAIN.PLANE_GRASS, mercenary=True)] self.assertEqual(frozenset(mobs_in_forest), frozenset([self.mob_1.uuid, self.mob_3.uuid])) mobs_in_forest = [mob.uuid for mob in mobs_storage.get_available_mobs_list(0, map_relations.TERRAIN.PLANE_SAND, mercenary=True)] self.assertEqual(frozenset(mobs_in_forest), frozenset())
def deserialize(cls, data): # we do not save abilities and after load, mob can has differen abilities levels # if mob record is desabled or deleted, get another random record from the_tale.game.mobs.storage import mobs_storage record = mobs_storage.get_by_uuid(data['id']) level = data['level'] if record is None or record.state.is_DISABLED: record = random.choice(mobs_storage.get_available_mobs_list(level)) abilities = cls._produce_abilities(record, level) return cls(record_id=record.id, level=level, health=data['health'], is_boss=data.get('is_boss', False), abilities=abilities, action_type=actions_relations.ACTION_TYPE( data['action_type']) if 'action_type' in data else actions_relations.ACTION_TYPE.BATTLE_PVE_1X1, terrain=map_relations.TERRAIN(data['terrain']) if 'terrain' in data else map_relations.TERRAIN.PLANE_GRASS)
def press_kit(self): from the_tale.game.mobs.storage import mobs_storage return self.template( 'guide/press_kit.html', { 'section': 'press-kit', 'mob': random.choice(mobs_storage.get_available_mobs_list(level=666)) })
def landing(self, type="normal"): from the_tale.game.map.storage import map_info_storage from the_tale.game.mobs.storage import mobs_storage mobs = [mob for mob in mobs_storage.get_available_mobs_list(level=666) if len(mob.description) < portal_settings.LANDING_MOB_DESCRIPTION_MAX_LENGTH] return self.template('portal/landing.html', {'current_map_version': map_info_storage.version, 'landing_type': type, 'mob': random.choice(mobs)})
def test_prefered_mob_loot_multiplier(self): from the_tale.game.mobs.storage import mobs_storage self.hero.level = relations.PREFERENCE_TYPE.MOB.level_required logic.save_hero(self.hero) self.mob = mobs_storage.get_available_mobs_list(level=self.hero.level)[0].create_mob(self.hero) self.assertEqual(self.hero.preferences.mob, None) with self.check_increased(lambda: self.hero.loot_probability(self.mob)): with self.check_increased(lambda: self.hero.artifacts_probability(self.mob)): self.hero.preferences.set_mob(self.mob.record)
def test_prefered_mob_loot_multiplier(self): from the_tale.game.mobs.storage import mobs_storage self.hero._model.level = relations.PREFERENCE_TYPE.MOB.level_required self.hero._model.save() self.mob = mobs_storage.get_available_mobs_list( level=self.hero.level)[0].create_mob(self.hero) self.assertEqual(self.hero.preferences.mob, None) with self.check_increased( lambda: self.hero.loot_probability(self.mob)): with self.check_increased( lambda: self.hero.artifacts_probability(self.mob)): self.hero.preferences.set_mob(self.mob.record)
def landing(self, type="normal"): from the_tale.game.map.storage import map_info_storage from the_tale.game.mobs.storage import mobs_storage mobs = [ mob for mob in mobs_storage.get_available_mobs_list(level=666) if len(mob.description) < portal_settings.LANDING_MOB_DESCRIPTION_MAX_LENGTH ] return self.template( 'portal/landing.html', { 'current_map_version': map_info_storage.version, 'landing_type': type, 'mob': random.choice(mobs) })
def deserialize(cls, data): # we do not save abilities and after load, mob can has differen abilities levels # if mob record is desabled or deleted, get another random record from the_tale.game.mobs.storage import mobs_storage record = mobs_storage.get_by_uuid(data['id']) level = data['level'] if record is None or record.state.is_DISABLED: record = random.choice(mobs_storage.get_available_mobs_list(level)) abilities = cls._produce_abilities(record, level) return cls(record_id=record.id, level=level, health=data['health'], is_boss=data.get('is_boss', False), abilities=abilities)
def deserialize(cls, data): # we do not save abilities and after load, mob can has differen abilities levels # if mob record is desabled or deleted, get another random record from the_tale.game.mobs.storage import mobs_storage record = mobs_storage.get_by_uuid(data['id']) level = data['level'] if record is None or record.state.is_DISABLED: record = random.choice(mobs_storage.get_available_mobs_list(level)) abilities = cls._produce_abilities(record, level) return cls(record_id=record.id, level=level, health=data['health'], is_boss=data.get('is_boss', False), abilities=abilities, action_type=actions_relations.ACTION_TYPE(data['action_type']) if 'action_type' in data else actions_relations.ACTION_TYPE.BATTLE_PVE_1X1, terrain=map_relations.TERRAIN(data['terrain']) if 'terrain' in data else map_relations.TERRAIN.PLANE_GRASS)
def press_kit(self): from the_tale.game.mobs.storage import mobs_storage return self.template('guide/press_kit.html', {'section': 'press-kit', 'mob': random.choice(mobs_storage.get_available_mobs_list(level=666))})
def choose_preferences_dialog(self, type): # pylint: disable=W0622 mobs = None places = None friends = None enemies = None equipment_slots = None favorite_items = None all_places = places_storage.places.all() all_places.sort(key=lambda x: x.name) if type.is_ENERGY_REGENERATION_TYPE: pass if type.is_MOB: all_mobs = mobs_storage.get_available_mobs_list( level=self.hero.level) all_mobs = sorted(all_mobs, key=lambda x: x.name) mobs = split_list(all_mobs) elif type.is_PLACE: places = split_list(all_places) elif type.is_FRIEND: friends = sorted( [person for person in persons_storage.persons.all()], key=lambda person: person.name) elif type.is_ENEMY: enemies = sorted( [person for person in persons_storage.persons.all()], key=lambda person: person.name) elif type.is_EQUIPMENT_SLOT: equipment_slots = split_list(list( relations.EQUIPMENT_SLOT.records)) elif type.is_RISK_LEVEL: pass elif type.is_ARCHETYPE: pass elif type.is_COMPANION_DEDICATION: pass elif type.is_COMPANION_EMPATHY: pass elif type.is_FAVORITE_ITEM: favorite_items = { slot: self.hero.equipment.get(slot) for slot in relations.EQUIPMENT_SLOT.records if self.hero.equipment.get(slot) is not None } return self.template( 'heroes/choose_preferences.html', { 'type': type, 'mobs': mobs, 'places': places, 'all_places': places_storage.places.get_choices(), 'places_powers': { place.id: place.total_politic_power_fraction for place in all_places }, 'friends': friends, 'enemies': enemies, 'equipment_slots': equipment_slots, 'favorite_items': favorite_items, 'PREFERENCES_CHANGE_DELAY': datetime.timedelta(seconds=c.PREFERENCES_CHANGE_DELAY), 'EQUIPMENT_SLOT': relations.EQUIPMENT_SLOT, 'RISK_LEVEL': relations.RISK_LEVEL, 'COMPANION_DEDICATION': relations.COMPANION_DEDICATION, 'COMPANION_EMPATHY': relations.COMPANION_EMPATHY, 'ENERGY_REGENERATION': relations.ENERGY_REGENERATION, 'ARCHETYPE': game_relations.ARCHETYPE })
def mobs_and_artifacts(self): # pylint: disable=R0914 from the_tale.game.mobs.storage import mobs_storage from the_tale.game.artifacts.storage import artifacts_storage from the_tale.game.map.relations import TERRAIN from the_tale.game.logic import DEFAULT_HERO_EQUIPMENT mobs_without_loot = [] mobs_without_artifacts = [] mobs_without_loot_on_first_level = [] mobs_without_artifacts_on_first_level = [] for mob in mobs_storage.get_available_mobs_list(level=999999): if not mob.loot: mobs_without_loot.append(mob) elif not any(loot.level == mob.level for loot in mob.loot): mobs_without_loot_on_first_level.append(mob) if not mob.artifacts: mobs_without_artifacts.append(mob) elif not any(artifact.level == mob.level for artifact in mob.artifacts): mobs_without_artifacts_on_first_level.append(mob) territory_levels_checks = [1, 2, 3, 5, 7, 10, 15, 20, 30, 50, 75, 100] mobs_by_territory = { terrain.name: [0] * len(territory_levels_checks) for terrain in TERRAIN.records } for mob in mobs_storage.get_available_mobs_list(level=999999): for terrain in mob.terrains: for i, level in enumerate(territory_levels_checks): if level >= mob.level: mobs_by_territory[terrain.name][i] += 1 del mobs_by_territory['WATER_SHOAL'] del mobs_by_territory['WATER_DEEP'] mobs_by_territory = sorted(mobs_by_territory.items(), key=lambda x: x[1][-1]) artifacts_without_mobs = [] for artifact in itertools.chain(artifacts_storage.artifacts, artifacts_storage.loot): if artifact.uuid not in DEFAULT_HERO_EQUIPMENT._ALL and artifact.mob is None: artifacts_without_mobs.append(artifact) return self.template( 'developers_info/mobs_and_artifacts.html', { 'page_type': 'mobs_and_artifacts', 'mobs_without_loot': mobs_without_loot, 'mobs_without_artifacts': mobs_without_artifacts, 'mobs_without_loot_on_first_level': mobs_without_loot_on_first_level, 'mobs_without_artifacts_on_first_level': mobs_without_artifacts_on_first_level, 'mobs_by_territory': mobs_by_territory, 'territory_levels_checks': territory_levels_checks, 'artifacts_without_mobs': artifacts_without_mobs })
def choose_preferences_dialog(self, type): # pylint: disable=W0622 mobs = None places = None friends = None enemies = None equipment_slots = None favorite_items = None all_places = places_storage.places.all() all_places.sort(key=lambda x: x.name) if type.is_ENERGY_REGENERATION_TYPE: pass if type.is_MOB: all_mobs = mobs_storage.get_available_mobs_list(level=self.hero.level) all_mobs = sorted(all_mobs, key=lambda x: x.name) mobs = split_list(all_mobs) elif type.is_PLACE: places = split_list(all_places) elif type.is_FRIEND: friends = sorted([person for person in persons_storage.persons.all()], key=lambda person: person.name) elif type.is_ENEMY: enemies = sorted([person for person in persons_storage.persons.all()], key=lambda person: person.name) elif type.is_EQUIPMENT_SLOT: equipment_slots = split_list(list(relations.EQUIPMENT_SLOT.records)) elif type.is_RISK_LEVEL: pass elif type.is_ARCHETYPE: pass elif type.is_COMPANION_DEDICATION: pass elif type.is_COMPANION_EMPATHY: pass elif type.is_FAVORITE_ITEM: favorite_items = {slot: self.hero.equipment.get(slot) for slot in relations.EQUIPMENT_SLOT.records if self.hero.equipment.get(slot) is not None} return self.template('heroes/choose_preferences.html', {'type': type, 'mobs': mobs, 'places': places, 'all_places': places_storage.places.get_choices(), 'places_powers': {place.id: place.total_politic_power_fraction for place in all_places}, 'friends': friends, 'enemies': enemies, 'equipment_slots': equipment_slots, 'favorite_items': favorite_items, 'PREFERENCES_CHANGE_DELAY': datetime.timedelta(seconds=c.PREFERENCES_CHANGE_DELAY), 'EQUIPMENT_SLOT': relations.EQUIPMENT_SLOT, 'RISK_LEVEL': relations.RISK_LEVEL, 'COMPANION_DEDICATION': relations.COMPANION_DEDICATION, 'COMPANION_EMPATHY': relations.COMPANION_EMPATHY, 'ENERGY_REGENERATION': relations.ENERGY_REGENERATION, 'ARCHETYPE': game_relations.ARCHETYPE} )