def place_info_persons_data(place): data = [] for person in place.persons: building = storage.buildings_storage.get_by_person_id(person.id) connections = [(connection_type.value, person_id) for connection_type, person_id in persons_storage.social_connections.get_person_connections(person)] connections.sort() person_data = {'id': person.id, 'name': person.name, 'gender': person.gender.value, 'race': person.race.value, 'type': person.type.value, 'unfreeze_in': person.time_before_unfreeze.total_seconds(), 'mastery': {'value': person.mastery, 'name': person.mastery_verbose}, 'power': { 'percents': person.power / place.total_persons_power if place.total_persons_power > 0 else 0, 'positive_bonus': person.power_positive, 'negative_bonus': person.power_negative }, 'building': building.id if building else None, 'connections': connections, 'keepers': {'friends': [hero.account_id for hero in HeroPreferences.get_friends_of(person, all=place.depends_from_all_heroes)], 'enemies': [hero.account_id for hero in HeroPreferences.get_enemies_of(person, all=place.depends_from_all_heroes)]} } data.append(person_data) return data
def test_get_citizens_number(self): hero_1 = self.hero hero_1.preferences.set(relations.PREFERENCE_TYPE.PLACE, self.place) hero_1.premium_state_end_at = datetime.datetime.now( ) + datetime.timedelta(seconds=60) logic.save_hero(hero_1) account_2 = self.accounts_factory.create_account() hero_2 = logic.load_hero(account_id=account_2.id) hero_2.preferences.set(relations.PREFERENCE_TYPE.PLACE, self.place) logic.save_hero(hero_2) account_3 = self.accounts_factory.create_account() hero_3 = logic.load_hero(account_id=account_3.id) hero_3.preferences.set(relations.PREFERENCE_TYPE.PLACE, self.place) hero_3.premium_state_end_at = datetime.datetime.now( ) + datetime.timedelta(seconds=60) logic.save_hero(hero_3) account_4 = self.accounts_factory.create_account(is_fast=True) hero_4 = logic.load_hero(account_id=account_4.id) hero_4.preferences.set(relations.PREFERENCE_TYPE.PLACE, self.place) logic.save_hero(hero_4) account_5 = self.accounts_factory.create_account() hero_5 = logic.load_hero(account_id=account_5.id) hero_5.preferences.set(relations.PREFERENCE_TYPE.PLACE, self.place) hero_5.ban_state_end_at = datetime.datetime.now() + datetime.timedelta( seconds=60) logic.save_hero(hero_5) account_6 = self.accounts_factory.create_account() hero_6 = logic.load_hero(account_id=account_6.id) hero_6.preferences.set(relations.PREFERENCE_TYPE.PLACE, self.place_2) hero_6.premium_state_end_at = datetime.datetime.now( ) + datetime.timedelta(seconds=60) logic.save_hero(hero_6) account_7 = self.accounts_factory.create_account() hero_7 = logic.load_hero(account_id=account_7.id) hero_7.preferences.set(relations.PREFERENCE_TYPE.PLACE, self.place) hero_7.active_state_end_at = datetime.datetime.now( ) - datetime.timedelta(seconds=60) logic.save_hero(hero_7) self.assertEqual( set([ h.id for h in HeroPreferences.get_citizens_of(self.place, all=False) ]), set([hero_1.id, hero_3.id])) self.assertEqual( set([ h.id for h in HeroPreferences.get_citizens_of(self.place, all=True) ]), set([hero_1.id, hero_2.id, hero_3.id]))
def test_get_enemies_number(self): hero_1 = self.hero account_2 = self.accounts_factory.create_account() hero_2 = logic.load_hero(account_id=account_2.id) account_3 = self.accounts_factory.create_account() hero_3 = logic.load_hero(account_id=account_3.id) person_1 = self.place_1.persons[0] person_2 = self.place_1.persons[-1] hero_1.preferences.set(relations.PREFERENCE_TYPE.ENEMY, person_1) hero_1.premium_state_end_at = datetime.datetime.now( ) + datetime.timedelta(seconds=60) logic.save_hero(hero_1) hero_2.preferences.set(relations.PREFERENCE_TYPE.ENEMY, person_1) logic.save_hero(hero_2) hero_3.preferences.set(relations.PREFERENCE_TYPE.ENEMY, person_1) hero_3.premium_state_end_at = datetime.datetime.now( ) + datetime.timedelta(seconds=60) logic.save_hero(hero_3) account_4 = self.accounts_factory.create_account(is_fast=True) hero_4 = logic.load_hero(account_id=account_4.id) hero_4.preferences.set(relations.PREFERENCE_TYPE.ENEMY, person_1) logic.save_hero(hero_4) account_5 = self.accounts_factory.create_account() hero_5 = logic.load_hero(account_id=account_5.id) hero_5.preferences.set(relations.PREFERENCE_TYPE.ENEMY, person_1) hero_5.ban_state_end_at = datetime.datetime.now() + datetime.timedelta( seconds=60) logic.save_hero(hero_5) account_6 = self.accounts_factory.create_account() hero_6 = logic.load_hero(account_id=account_6.id) hero_6.preferences.set(relations.PREFERENCE_TYPE.ENEMY, person_1) hero_6.active_state_end_at = datetime.datetime.now( ) - datetime.timedelta(seconds=60) logic.save_hero(hero_6) self.assertEqual( set([ h.id for h in HeroPreferences.get_enemies_of(person_1, all=False) ]), set([hero_1.id, hero_3.id])) self.assertEqual( set([ h.id for h in HeroPreferences.get_enemies_of(person_1, all=True) ]), set([hero_1.id, hero_2.id, hero_3.id]))
def test_count_habit_values(self): hero_1 = self.hero hero_1.preferences.set(relations.PREFERENCE_TYPE.ENEMY, self.enemy) hero_1.premium_state_end_at = datetime.datetime.now( ) + datetime.timedelta(seconds=60) hero_1.habit_honor.change(-1) hero_1.habit_peacefulness.change(1) logic.save_hero(hero_1) account_2 = self.accounts_factory.create_account() hero_2 = logic.load_hero(account_id=account_2.id) hero_2.preferences.set(relations.PREFERENCE_TYPE.ENEMY, self.enemy) hero_2.premium_state_end_at = datetime.datetime.now( ) + datetime.timedelta(seconds=60) hero_2.habit_honor.change(2) hero_2.habit_peacefulness.change(-2) logic.save_hero(hero_2) account_3 = self.accounts_factory.create_account() hero_3 = logic.load_hero(account_id=account_3.id) hero_3.preferences.set(relations.PREFERENCE_TYPE.ENEMY, self.enemy_2) hero_3.premium_state_end_at = datetime.datetime.now( ) + datetime.timedelta(seconds=30) hero_3.habit_honor.change(-4) hero_3.habit_peacefulness.change(4) logic.save_hero(hero_3) account_4 = self.accounts_factory.create_account() hero_4 = logic.load_hero(account_id=account_4.id) hero_4.preferences.set(relations.PREFERENCE_TYPE.ENEMY, self.enemy) hero_4.premium_state_end_at = datetime.datetime.now( ) + datetime.timedelta(seconds=30) hero_4.habit_honor.change(8) hero_4.habit_peacefulness.change(-8) logic.save_hero(hero_4) self.assertEqual( HeroPreferences.count_habit_values(self.place_1, all=False), ((10, -1), (1, -10))) self.assertEqual( HeroPreferences.count_habit_values(self.place_2, all=False), ((0, -4), (4, 0))) self.assertEqual( HeroPreferences.count_habit_values(self.place_1, all=True), ((10, -1), (1, -10))) self.assertEqual( HeroPreferences.count_habit_values(self.place_2, all=True), ((0, -4), (4, 0)))
def place_info_persons_data(place): data = [] for person in place.persons: building = storage.buildings_storage.get_by_person_id(person.id) connections = [ (connection_type.value, person_id) for connection_type, person_id in persons_storage.social_connections.get_person_connections(person) ] connections.sort() person_data = { 'id': person.id, 'name': person.name, 'gender': person.gender.value, 'race': person.race.value, 'type': person.type.value, 'unfreeze_in': person.time_before_unfreeze.total_seconds(), 'mastery': { 'value': person.mastery, 'name': person.mastery_verbose }, 'power': { 'percents': person.power / place.total_persons_power if place.total_persons_power > 0 else 0, 'positive_bonus': person.power_positive, 'negative_bonus': person.power_negative }, 'building': building.id if building else None, 'connections': connections, 'keepers': { 'friends': [ hero.account_id for hero in HeroPreferences.get_friends_of( person, all=place.depends_from_all_heroes) ], 'enemies': [ hero.account_id for hero in HeroPreferences.get_enemies_of( person, all=place.depends_from_all_heroes) ] } } data.append(person_data) return data
def place_info(place): data = {'id': place.id, 'name': place.name, 'frontier': place.is_frontier, 'new_for': time.mktime(place.new_for.timetuple()), 'position': {'x': place.x, 'y': place.y}, 'updated_at': time.mktime(place.updated_at.timetuple()), 'power': { 'positive_bonus': place.power_positive, 'negative_bonus': place.power_negative }, 'description': place.description_html, 'persons': place_info_persons_data(place), 'keepers': {'friends': [hero.account_id for hero in HeroPreferences.get_citizens_of(place, all=place.depends_from_all_heroes)] , 'enemies': []}, 'parameters': place_info_parameters(place), 'demographics': place_info_demographics(place), 'bills': place_info_bills(place), 'specializations': place_info_specializations(place), 'habits': place_info_habits(place), 'chronicle': place_info_cronicle(place), 'accounts': None, 'clans': None } data['accounts'] = place_info_accounts(data) data['clans'] = place_info_clans(data) return data
def update_heroes_habits(self): from the_tale.game.heroes.preferences import HeroPreferences habits_values = HeroPreferences.count_habit_values(self, all=self.depends_from_all_heroes) self.habit_honor_positive = habits_values[0][0] self.habit_honor_negative = habits_values[0][1] self.habit_peacefulness_positive = habits_values[1][0] self.habit_peacefulness_negative = habits_values[1][1]
def place_info(place): data = { 'id': place.id, 'name': place.name, 'frontier': place.is_frontier, 'new_for': time.mktime(place.new_for.timetuple()), 'position': { 'x': place.x, 'y': place.y }, 'updated_at': time.mktime(place.updated_at.timetuple()), 'power': { 'positive_bonus': place.power_positive, 'negative_bonus': place.power_negative }, 'description': place.description_html, 'persons': place_info_persons_data(place), 'keepers': { 'friends': [ hero.account_id for hero in HeroPreferences.get_citizens_of( place, all=place.depends_from_all_heroes) ], 'enemies': [] }, 'parameters': place_info_parameters(place), 'demographics': place_info_demographics(place), 'bills': place_info_bills(place), 'specializations': place_info_specializations(place), 'habits': place_info_habits(place), 'chronicle': place_info_cronicle(place), 'accounts': None, 'clans': None } data['accounts'] = place_info_accounts(data) data['clans'] = place_info_clans(data) return data
def update_heroes_number(self): from the_tale.game.heroes.preferences import HeroPreferences self._model.heroes_number = HeroPreferences.count_citizens_of( self, all=self.depends_from_all_heroes)
def test_preferences_serialization(self): self.hero.preferences.set(relations.PREFERENCE_TYPE.MOB, mobs_storage.mobs.all()[0]) data = self.hero.preferences.serialize() self.assertEqual(data, HeroPreferences.deserialize(data).serialize())
def test_preferences_serialization(self): self.hero.preferences.set(relations.PREFERENCE_TYPE.COMPANION_EMPATHY, self.empath) data = self.hero.preferences.serialize() self.assertEqual(data, HeroPreferences.deserialize(data).serialize())
def test_preferences_serialization(self): self.hero.preferences.set( relations.PREFERENCE_TYPE.COMPANION_DEDICATION, self.egoism) data = self.hero.preferences.serialize() self.assertEqual(data, HeroPreferences.deserialize(data).serialize())
def test_preferences_serialization(self): self.hero.preferences.set(relations.PREFERENCE_TYPE.ARCHETYPE, self.mage) data = self.hero.preferences.serialize() self.assertEqual(data, HeroPreferences.deserialize(data).serialize())
def test_preferences_serialization(self): self.hero.preferences.set(relations.PREFERENCE_TYPE.RISK_LEVEL, self.risk_1) data = self.hero.preferences.serialize() self.assertEqual(data, HeroPreferences.deserialize(data).serialize())
def update_enemies_number(self): from the_tale.game.heroes.preferences import HeroPreferences self._model.enemies_number = HeroPreferences.count_enemies_of( self, all=self.place.is_frontier)
def update_heroes_number(self): from the_tale.game.heroes.preferences import HeroPreferences self._model.heroes_number = HeroPreferences.count_citizens_of(self, all=self.depends_from_all_heroes)
def test_preferences_serialization(self): data = self.hero.preferences.serialize() self.assertEqual(data, HeroPreferences.deserialize(data).serialize())
def test_preferences_serialization(self): self.hero.preferences.set(relations.PREFERENCE_TYPE.ENEMY, persons_storage.persons[self.enemy_id]) data = self.hero.preferences.serialize() self.assertEqual(data, HeroPreferences.deserialize(data).serialize())
def test_preferences_serialization(self): self.hero.preferences.set(relations.PREFERENCE_TYPE.FAVORITE_ITEM, self.slot_1) data = self.hero.preferences.serialize() self.assertEqual(data, HeroPreferences.deserialize(data).serialize())
def update_enemies_number(self): from the_tale.game.heroes.preferences import HeroPreferences self._model.enemies_number = HeroPreferences.count_enemies_of(self, all=self.place.is_frontier)