def test_save_all(self): self.hero_1.health = 1 self.hero_2.health = 1 self.hero_1.actions.updated = True self.storage.save_all() self.assertEqual(self.hero_1.health, HeroPrototype.get_by_id(self.hero_1.id).health) self.assertEqual(self.hero_2.health, HeroPrototype.get_by_id(self.hero_2.id).health) self.assertFalse(self.hero_1.actions.updated)
def add_to_arena_queue(self, hero_id): hero = HeroPrototype.get_by_id(hero_id) if hero.account_id in self.arena_queue: return None battle = Battle1x1Prototype.create( AccountPrototype.get_by_id(hero.account_id)) if not battle.state.is_WAITING: raise PvPBalancerException( 'account %d already has battle not in waiting state' % hero.account_id) record = QueueRecord(account_id=battle.account_id, created_at=battle.created_at, battle_id=battle.id, hero_level=hero.level) if record.account_id in self.arena_queue: raise PvPBalancerException( 'account %d already added in balancer queue' % record.account_id) self.arena_queue[record.account_id] = record return battle
def accept_battle(cls, pvp_balancer, battle_id, hero_id): accepted_battle = Battle1x1Prototype.get_by_id(battle_id) if accepted_battle is None: return ACCEPT_BATTLE_RESULT.BATTLE_NOT_FOUND if not accepted_battle.state.is_WAITING: return ACCEPT_BATTLE_RESULT.WRONG_ACCEPTED_BATTLE_STATE if not accepted_battle.account_id in pvp_balancer.arena_queue: return ACCEPT_BATTLE_RESULT.NOT_IN_QUEUE initiator_id = HeroPrototype.get_by_id(hero_id).account_id initiator_battle = Battle1x1Prototype.get_by_account_id(initiator_id) if initiator_battle is not None and not initiator_battle.state.is_WAITING: return ACCEPT_BATTLE_RESULT.WRONG_INITIATOR_BATTLE_STATE if initiator_id not in pvp_balancer.arena_queue: pvp_balancer.add_to_arena_queue(hero_id) pvp_balancer.force_battle(accepted_battle.account_id, initiator_id) return ACCEPT_BATTLE_RESULT.PROCESSED
def _test_save(self): for hero_id in self.heroes: self._save_hero_data(hero_id) test_storage = LogicStorage() for hero_id in self.heroes: test_storage._add_hero(HeroPrototype.get_by_id(hero_id)) return self == test_storage
def test_use(self): self.hero.add_experience(self.hero.experience_to_next_level / 2) self.assertTrue(self.hero.experience > 0) self.assertEqual(self.hero.level, 1) with self.check_not_changed(lambda: self.hero.experience): with self.check_delta(lambda: self.hero.level, 1): result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero)) self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) saved_hero = HeroPrototype.get_by_id(self.hero.id) self.assertEqual(saved_hero.abilities.destiny_points, self.abilities.destiny_points)
def test_dispatch_command_for_unregistered_account(self): self.worker.process_initialize() result, account_3_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111') account_3 = AccountPrototype.get_by_id(account_3_id) hero_3 = HeroPrototype.get_by_id(account_3_id) with mock.patch('the_tale.game.workers.logic.Worker.cmd_logic_task') as logic_task_counter: with mock.patch.object(self.worker.logger, 'warn') as logger_warn_counter: self.worker.process_update_hero_with_account_data(account_3_id, is_fast=account_3.is_fast, premium_end_at=account_3.premium_end_at, active_end_at=account_3.active_end_at, ban_end_at=account_3.ban_game_end_at, might=666, actual_bills=7) self.assertEqual(logic_task_counter.call_count, 0) self.assertEqual(logger_warn_counter.call_count, 1) self.assertFalse(account_3_id in self.worker.accounts_owners) self.assertTrue(account_3_id in self.worker.accounts_queues)
def add_to_arena_queue(self, hero_id): hero = HeroPrototype.get_by_id(hero_id) if hero.account_id in self.arena_queue: return None battle = Battle1x1Prototype.create(AccountPrototype.get_by_id(hero.account_id)) if not battle.state.is_WAITING: raise PvPBalancerException('account %d already has battle not in waiting state' % hero.account_id) record = QueueRecord(account_id=battle.account_id, created_at=battle.created_at, battle_id=battle.id, hero_level=hero.level) if record.account_id in self.arena_queue: raise PvPBalancerException('account %d already added in balancer queue' % record.account_id) self.arena_queue[record.account_id] = record return battle