def setUp(self): super(QuestsTestBase, self).setUp() self.p1, self.p2, self.p3 = create_test_map() # add more persons, to lower conflicts places_logic.add_person_to_place(self.p1) places_logic.add_person_to_place(self.p1) places_logic.add_person_to_place(self.p2) places_logic.add_person_to_place(self.p2) places_logic.add_person_to_place(self.p3) places_logic.add_person_to_place(self.p3) persons_logic.sync_social_connections() result, account_id, bundle_id = register_user('test_user') self.storage = LogicStorage() self.storage.load_account_data(AccountPrototype.get_by_id(account_id)) self.hero = self.storage.accounts_to_heroes[account_id] self.action_idl = self.hero.actions.current_action self.hero.money += 1 self.hero.preferences.set_mob(mobs_storage.all()[0]) self.hero.preferences.set_place(self.p1) self.hero.preferences.set_friend(self.p1.persons[0]) self.hero.preferences.set_enemy(self.p2.persons[0]) self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE) self.hero.position.set_place(self.p3) heroes_logic.save_hero(self.hero) self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY) places_logic.save_place(self.p2) self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH persons_logic.save_person(self.p1.persons[0])
def setUp(self): super(QuestsTestBase, self).setUp() self.p1, self.p2, self.p3 = create_test_map() # add more persons, to lower conflicts self.p1.add_person() self.p1.add_person() self.p2.add_person() self.p2.add_person() self.p3.add_person() self.p3.add_person() persons_logic.sync_social_connections() result, account_id, bundle_id = register_user('test_user') self.storage = LogicStorage() self.storage.load_account_data(AccountPrototype.get_by_id(account_id)) self.hero = self.storage.accounts_to_heroes[account_id] self.action_idl = self.hero.actions.current_action self.hero._model.money += 1 self.hero.preferences.set_mob(mobs_storage.all()[0]) self.hero.preferences.set_place(self.p1) self.hero.preferences.set_friend(self.p1.persons[0]) self.hero.preferences.set_enemy(self.p2.persons[0]) self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE) self.hero.position.set_place(self.p3) self.hero.save() self.p2.modifier = HolyCity(self.p2) self.p2.save() self.p1.persons[0]._model.type = PERSON_TYPE.BLACKSMITH self.p1.persons[0].save()
def run(self, *args, **kwargs): # to sync map size and do other unpredictable operations run_django_command(['map_update_map']) self.INITIAL_PERSON_POWER = persons_storage.get_medium_power_for_person( ) with transaction.atomic(): p35 = places_storage[35] p35._model.is_frontier = False p35.save() p8x13 = self._create_place( x=8, y=13, roads_to=[p35], name_forms=noun( forms=(u'Сольвейг', u'Сольвейга', u'Сольвейгу', u'Сольвейг', u'Сольвейгом', u'Сольвейге', u'Сольвейги', u'Сольвейгов', u'Сольвейгам', u'Сольвейги', u'Сольвейгами', u'Сольвейгах'), properties=(u'мр,но'))) p39 = places_storage[39] p39._model.is_frontier = False p39.save() p52x26 = self._create_place( x=52, y=26, roads_to=[p39, places_storage[40]], name_forms=noun(forms=(u'Аматир', u'Аматира', u'Аматиру', u'Аматир', u'Аматиром', u'Аматире', u'Аматиры', u'Аматиров', u'Аматирам', u'Аматиры', u'Аматирами', u'Аматирах'), properties=(u'мр,но'))) p36 = places_storage[36] p36._model.is_frontier = False p36.save() p22x8 = self._create_place( x=22, y=8, roads_to=[p36], name_forms=noun(forms=(u'Залесье', u'Залесья', u'Залесью', u'Залесье', u'Залесьем', u'Залесье', u'Залесьи', u'Залесьев', u'Залесьям', u'Залесьи', u'Залесьями', u'Залесьях'), properties=(u'ср,но'))) update_waymarks() persons_logic.sync_social_connections() # update map with new places run_django_command(['map_update_map'])
def sync_data(self, sheduled=True): self.logger.info('sync data') all_persons = persons_storage.persons_storage.filter(state=PERSON_STATE.IN_GAME) self.sync_persons_powers(persons=[person for person in all_persons if person.place.is_frontier]) self.sync_persons_powers(persons=[person for person in all_persons if not person.place.is_frontier]) for person in all_persons: person.update_friends_number() person.update_enemies_number() self.persons_power = {} self.sync_places_powers(places=[place for place in places_storage.all() if place.is_frontier]) self.sync_places_powers(places=[place for place in places_storage.all() if not place.is_frontier]) self.places_power = {} # update size if sheduled: self.sync_sizes([place for place in places_storage.all() if place.is_frontier], hours=c.MAP_SYNC_TIME_HOURS, max_size=places_settings.MAX_FRONTIER_SIZE) self.sync_sizes([place for place in places_storage.all() if not place.is_frontier], hours=c.MAP_SYNC_TIME_HOURS, max_size=places_settings.MAX_SIZE) for place in places_storage.all(): place.sync_stability() place.sync_modifier() place.sync_habits() place.sync_parameters() # must be last operation to display and use real data place.update_heroes_number() place.update_heroes_habits() place.mark_as_updated() places_storage.save_all() persons_storage.persons_storage.remove_out_game_persons() persons_storage.persons_storage.save_all() persons_logic.sync_social_connections() if sheduled: for building in buildings_storage.all(): building.amortize(c.MAP_SYNC_TIME) buildings_storage.save_all() self.logger.info('sync data completed')
def setUp(self): super(RequestsTestsBase, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() persons_logic.sync_social_connections() result, account_id, bundle_id = register_user("test_user", "*****@*****.**", "111111") self.account = AccountPrototype.get_by_id(account_id) self.client = client.Client() self.request_login("*****@*****.**")
def setUp(self): super(RequestsTestsBase, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() persons_logic.sync_social_connections() result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.account = AccountPrototype.get_by_id(account_id) self.client = client.Client() self.request_login('*****@*****.**')
def run(self, *args, **kwargs): # to sync map size and do other unpredictable operations run_django_command(['map_update_map']) self.INITIAL_PERSON_POWER = persons_storage.get_medium_power_for_person() with transaction.atomic(): p35 = places_storage[35] p35._model.is_frontier = False p35.save() p8x13 = self._create_place(x=8, y=13, roads_to=[p35], name_forms=noun(forms=(u'Сольвейг', u'Сольвейга', u'Сольвейгу', u'Сольвейг', u'Сольвейгом', u'Сольвейге', u'Сольвейги', u'Сольвейгов', u'Сольвейгам', u'Сольвейги', u'Сольвейгами', u'Сольвейгах'), properties=(u'мр,но'))) p39 = places_storage[39] p39._model.is_frontier = False p39.save() p52x26 = self._create_place(x=52, y=26, roads_to=[p39, places_storage[40]], name_forms=noun(forms=(u'Аматир', u'Аматира', u'Аматиру', u'Аматир', u'Аматиром', u'Аматире', u'Аматиры', u'Аматиров', u'Аматирам', u'Аматиры', u'Аматирами', u'Аматирах'), properties=(u'мр,но'))) p36 = places_storage[36] p36._model.is_frontier = False p36.save() p22x8 = self._create_place(x=22, y=8, roads_to=[p36], name_forms=noun(forms=(u'Залесье', u'Залесья', u'Залесью', u'Залесье', u'Залесьем', u'Залесье', u'Залесьи', u'Залесьев', u'Залесьям', u'Залесьи', u'Залесьями', u'Залесьях'), properties=(u'ср,но'))) update_waymarks() persons_logic.sync_social_connections() # update map with new places run_django_command(['map_update_map'])
def test_social_connections(self): persons_logic.sync_social_connections() self.hero.position.set_place(self.place_1) logic.fill_places( self.knowledge_base, self.get_hero_info(), waymarks_storage.look_for_road(self.place_1, self.place_2).length) logic.setup_persons(self.knowledge_base, self.get_hero_info()) logic.setup_social_connections(self.knowledge_base) expected_connections = [] for person in persons_storage.persons.all(): if person.place_id == self.place_3.id: continue for connection_type, connected_person_id in persons_storage.social_connections.get_person_connections( person): connected_person = persons_storage.persons[connected_person_id] if connected_person.place_id == self.place_3.id: continue expected_connections.append( logic.fact_social_connection( connection_type, uids.person(person.id), uids.person(connected_person.id))) self.check_facts(places=[ logic.fact_place(self.place_1), logic.fact_place(self.place_2) ], persons=[ logic.fact_person(person) for person in persons_storage.persons.all() if person.place_id != self.place_3.id ], locations=[ logic.fact_located_in(person) for person in persons_storage.persons.all() if person.place_id != self.place_3.id ], social_connections=expected_connections)
def test_social_connections(self): persons_logic.sync_social_connections() self.hero.position.set_place(self.place_1) logic.fill_places(self.knowledge_base, self.get_hero_info(), waymarks_storage.look_for_road(self.place_1, self.place_2).length) logic.setup_persons(self.knowledge_base, self.get_hero_info()) logic.setup_social_connections(self.knowledge_base) expected_connections = [] for person in persons_storage.persons.all(): if person.place_id == self.place_3.id: continue for connection_type, connected_person_id in persons_storage.social_connections.get_person_connections(person): connected_person = persons_storage.persons[connected_person_id] if connected_person.place_id == self.place_3.id: continue expected_connections.append(logic.fact_social_connection(connection_type, uids.person(person.id), uids.person(connected_person.id))) self.check_facts(places=[logic.fact_place(self.place_1), logic.fact_place(self.place_2)], persons=[logic.fact_person(person) for person in persons_storage.persons.all() if person.place_id != self.place_3.id], locations=[logic.fact_located_in(person) for person in persons_storage.persons.all() if person.place_id != self.place_3.id], social_connections=expected_connections)
def sync_data(self, sheduled=True): self.logger.info('sync data') call_after_transaction = [] with transaction.atomic(): self.logger.info('sync data transaction started') if sheduled: for person in persons_storage.persons.all(): person.politic_power.sync_power() for place in places_storage.places.all(): place.politic_power.sync_power() for power_info in self.persons_politic_power: person = persons_storage.persons[power_info.person_id] place_power = person.politic_power.change_power(person=person, hero_id=power_info.hero_id, has_in_preferences=power_info.has_person_in_preferences, power=power_info.power_delta) self.places_politic_power.append(power_info.clone(place_id=person.place.id, power_delta=place_power)) for power_info in self.places_politic_power: place = places_storage.places[power_info.place_id] place.politic_power.change_power(place=place, hero_id=power_info.hero_id, has_in_preferences=power_info.has_place_in_preferences, power=power_info.power_delta) self.persons_politic_power[:] = [] self.places_politic_power[:] = [] if sheduled: # обрабатывает работы только во время запланированного обновления # поскольку при остановке игры нельзя будет обработать команды для героев # (те уже будут сохраняться в базу, рабочие логики будут недоступны) for person in persons_storage.persons.all(): call_after_transaction.extend(person.update_job()) for place in places_storage.places.all(): call_after_transaction.extend(place.update_job()) # update size self.sync_sizes([place for place in places_storage.places.all() if place.is_frontier], hours=c.MAP_SYNC_TIME_HOURS, max_economic=c.PLACE_MAX_FRONTIER_ECONOMIC) self.sync_sizes([place for place in places_storage.places.all() if not place.is_frontier], hours=c.MAP_SYNC_TIME_HOURS, max_economic=c.PLACE_MAX_ECONOMIC) for place in places_storage.places.all(): place.effects_update_step() place.sync_race() place.sync_habits() place.update_heroes_habits() place.refresh_attributes() # must be last operation to display and use real data place.mark_as_updated() places_storage.places.save_all() persons_storage.persons.save_all() persons_logic.sync_social_connections() if sheduled: for building in places_storage.buildings.all(): building.amortize(c.MAP_SYNC_TIME) places_storage.buildings.save_all() self.logger.info('sync data transaction completed') self.logger.info(u'after transaction operations number: {number}'.format(number=len(call_after_transaction))) for operation in call_after_transaction: operation() self.logger.info('sync data completed')
def handle(self, *args, **options): print print 'UPDATE MAP' print run_django_command(['map_update_map']) print print 'UPDATE LINGUISTICS' linguistics_logic.sync_static_restrictions() linguistics_logic.update_templates_errors() linguistics_logic.update_words_usage_info() print print 'SYNC MARKET' run_django_command(['market_sync_goods']) print print 'SYNC SOCIAL CONNECTIONS' persons_logic.sync_social_connections() print print 'SYNC ACTUAL BILLS' bills_logic.update_actual_bills_for_all_accounts() print print 'REMOVE OLD SDN INFO' if portal_settings.SETTINGS_CDN_INFO_KEY in settings: del settings[portal_settings.SETTINGS_CDN_INFO_KEY] if portal_settings.SETTINGS_PREV_CDN_SYNC_TIME_KEY in settings: del settings[portal_settings.SETTINGS_PREV_CDN_SYNC_TIME_KEY] print print 'SYNC GROUPS AND PERMISSIONS' print sync_group('content group', ['cms.add_page', 'cms.change_page', 'cms.delete_page', 'news.add_news', 'news.change_news', 'news.delete_news']) sync_group(forum_settings.MODERATOR_GROUP_NAME, ['forum.moderate_thread', 'forum.moderate_post']) sync_group('bills moderators group', ['bills.moderate_bill']) sync_group('developers group', ['mobs.moderate_mobrecord', 'artifacts.moderate_artifactrecord', 'linguistics.moderate_word', 'linguistics.moderate_template', 'linguistics.edit_template']) sync_group('folclor moderation group', ['blogs.moderate_post']) sync_group('mobs & artifacts create group', ['mobs.create_mobrecord', 'artifacts.create_artifactrecord']) sync_group('accounts moderators group', ['accounts.moderate_account']) sync_group('collections editors group', ['collections.edit_collection', 'collections.edit_kit', 'collections.edit_item']) sync_group('collections moderators group', ['collections.moderate_collection', 'collections.moderate_kit', 'collections.moderate_item']) sync_group('achievements editors group', ['achievements.edit_achievement']) sync_group(linguistics_settings.MODERATOR_GROUP_NAME, ['linguistics.moderate_word', 'linguistics.moderate_template', 'linguistics.edit_template']) sync_group(linguistics_settings.EDITOR_GROUP_NAME, ['linguistics.moderate_word', 'linguistics.edit_template'])
def sync_data(self, sheduled=True): self.logger.info('sync data') call_after_transaction = [] with transaction.atomic(): self.logger.info('sync data transaction started') if sheduled: for person in persons_storage.persons.all(): person.politic_power.sync_power() for place in places_storage.places.all(): place.politic_power.sync_power() for power_info in self.persons_politic_power: person = persons_storage.persons[power_info.person_id] place_power = person.politic_power.change_power( person=person, hero_id=power_info.hero_id, has_in_preferences=power_info.has_person_in_preferences, power=power_info.power_delta) self.places_politic_power.append( power_info.clone(place_id=person.place.id, power_delta=place_power)) for power_info in self.places_politic_power: place = places_storage.places[power_info.place_id] place.politic_power.change_power( place=place, hero_id=power_info.hero_id, has_in_preferences=power_info.has_place_in_preferences, power=power_info.power_delta) self.persons_politic_power[:] = [] self.places_politic_power[:] = [] if sheduled: # обрабатывает работы только во время запланированного обновления # поскольку при остановке игры нельзя будет обработать команды для героев # (те уже будут сохраняться в базу, рабочие логики будут недоступны) for person in persons_storage.persons.all(): call_after_transaction.extend(person.update_job()) for place in places_storage.places.all(): call_after_transaction.extend(place.update_job()) # update size self.sync_sizes([ place for place in places_storage.places.all() if place.is_frontier ], hours=c.MAP_SYNC_TIME_HOURS, max_economic=c.PLACE_MAX_FRONTIER_ECONOMIC) self.sync_sizes([ place for place in places_storage.places.all() if not place.is_frontier ], hours=c.MAP_SYNC_TIME_HOURS, max_economic=c.PLACE_MAX_ECONOMIC) for place in places_storage.places.all(): place.effects_update_step() place.sync_race() place.sync_habits() place.update_heroes_habits() place.refresh_attributes( ) # must be last operation to display and use real data place.mark_as_updated() places_storage.places.save_all() persons_storage.persons.save_all() persons_logic.sync_social_connections() if sheduled: for building in places_storage.buildings.all(): building.amortize(c.MAP_SYNC_TIME) places_storage.buildings.save_all() self.logger.info('sync data transaction completed') self.logger.info( u'after transaction operations number: {number}'.format( number=len(call_after_transaction))) for operation in call_after_transaction: operation() self.logger.info('sync data completed')
def sync_data(self, sheduled=True): self.logger.info('sync data') all_persons = persons_storage.persons_storage.filter( state=PERSON_STATE.IN_GAME) self.sync_persons_powers(persons=[ person for person in all_persons if person.place.is_frontier ]) self.sync_persons_powers(persons=[ person for person in all_persons if not person.place.is_frontier ]) for person in all_persons: person.update_friends_number() person.update_enemies_number() self.persons_power = {} self.sync_places_powers(places=[ place for place in places_storage.all() if place.is_frontier ]) self.sync_places_powers(places=[ place for place in places_storage.all() if not place.is_frontier ]) self.places_power = {} # update size if sheduled: self.sync_sizes( [place for place in places_storage.all() if place.is_frontier], hours=c.MAP_SYNC_TIME_HOURS, max_size=places_settings.MAX_FRONTIER_SIZE) self.sync_sizes([ place for place in places_storage.all() if not place.is_frontier ], hours=c.MAP_SYNC_TIME_HOURS, max_size=places_settings.MAX_SIZE) for place in places_storage.all(): place.sync_stability() place.sync_modifier() place.sync_habits() place.sync_parameters( ) # must be last operation to display and use real data place.update_heroes_number() place.update_heroes_habits() place.mark_as_updated() places_storage.save_all() persons_storage.persons_storage.remove_out_game_persons() persons_storage.persons_storage.save_all() persons_logic.sync_social_connections() if sheduled: for building in buildings_storage.all(): building.amortize(c.MAP_SYNC_TIME) buildings_storage.save_all() self.logger.info('sync data completed')