def setUp(self): super(BuildingRepairTest, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() self.account_1 = self.accounts_factory.create_account() self.account_2 = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(self.account_1) self.storage.load_account_data(self.account_2) self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id] self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id] self.ability_1 = self.PROCESSOR() self.ability_2 = self.PROCESSOR() environment.deinitialize() environment.initialize() self.highlevel = environment.workers.highlevel self.highlevel.process_initialize(0, 'highlevel') self.building = places_logic.create_building(self.place_1.persons[0], utg_name=names.generator().get_test_name('building-name')) self.building.integrity = 0.5 places_logic.save_building(self.building)
def use(self, task, storage, highlevel=None, **kwargs): # pylint: disable=R0911,W0613 building_id = task.data.get('building_id') if building_id is None: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) if task.step.is_LOGIC: if building_id not in places_storage.buildings: return task.logic_result( next_step=ComplexChangeTask.STEP.ERROR) if not places_storage.buildings[building_id].need_repair: return task.logic_result( next_step=ComplexChangeTask.STEP.ERROR) if not task.hero.can_repair_building: return task.logic_result( next_step=ComplexChangeTask.STEP.ERROR) critical = random.uniform(0, 1) < task.hero.might_crit_chance task.data['critical'] = critical task.hero.cards.change_help_count(1) if critical: task.hero.add_message('angel_ability_building_repair_crit', hero=task.hero) else: task.hero.add_message('angel_ability_building_repair', hero=task.hero) task.hero.process_removed_artifacts() return task.logic_result( next_step=ComplexChangeTask.STEP.HIGHLEVEL) elif task.step.is_HIGHLEVEL: if building_id not in places_storage.buildings: return task.logic_result( next_step=ComplexChangeTask.STEP.ERROR) building = places_storage.buildings[building_id] building.repair() if task.data.get('critical'): # repair second time building.repair() places_logic.save_building(building) places_storage.buildings.update_version() return task.logic_result(next_step=ComplexChangeTask.STEP.SUCCESS)
def use(self, task, storage, highlevel=None, **kwargs): # pylint: disable=R0911,W0613 building_id = task.data.get('value') if building_id not in places_storage.buildings: return task.logic_result( next_step=postponed_tasks.UseCardTask.STEP.ERROR, message='Строение не найдено.') if task.step.is_LOGIC: return task.logic_result( next_step=postponed_tasks.UseCardTask.STEP.HIGHLEVEL) elif task.step.is_HIGHLEVEL: building = places_storage.buildings[building_id] building.repair(self.modificator) places_logic.save_building(building) return task.logic_result()
def apply(self, bill=None): if self.has_meaning(): self.building.set_utg_name(self.new_building_name_forms) places_logic.save_building(self.building)
def test_use_for_repaired_building(self): self.building = places_logic.create_building(self.place_1.persons[0], utg_name=names.generator().get_test_name('building-name')) self.building.integrity = 1.0 places_logic.save_building(self.building) self.assertEqual(self.ability_1.use(**self.use_attributes(hero=self.hero_1, storage=self.storage)), (ComplexChangeTask.RESULT.FAILED, ComplexChangeTask.STEP.ERROR, ()))