def process_battle_ending(self): battle_1 = Battle1x1Prototype.get_by_account_id(self.hero_1.account_id) battle_2 = Battle1x1Prototype.get_by_account_id(self.hero_2.account_id) participant_1 = AccountPrototype.get_by_id(self.hero_1.account_id) participant_2 = AccountPrototype.get_by_id(self.hero_2.account_id) if self.hero_1.health <= 0: if self.hero_2.health <= 0: Battle1x1ResultPrototype.create(participant_1=participant_1, participant_2=participant_2, result =BATTLE_1X1_RESULT.DRAW) if battle_1.calculate_rating and battle_2.calculate_rating: self.hero_1.statistics.change_pvp_battles_1x1_draws(1) self.hero_2.statistics.change_pvp_battles_1x1_draws(1) else: Battle1x1ResultPrototype.create(participant_1=participant_1, participant_2=participant_2, result =BATTLE_1X1_RESULT.DEFEAT) if battle_1.calculate_rating and battle_2.calculate_rating: self.hero_2.statistics.change_pvp_battles_1x1_victories(1) self.hero_1.statistics.change_pvp_battles_1x1_defeats(1) else: Battle1x1ResultPrototype.create(participant_1=participant_1, participant_2=participant_2, result =BATTLE_1X1_RESULT.VICTORY) if battle_1.calculate_rating and battle_2.calculate_rating: self.hero_1.statistics.change_pvp_battles_1x1_victories(1) self.hero_2.statistics.change_pvp_battles_1x1_defeats(1) battle_1.remove() battle_2.remove() self.hero_1.health = self.hero_1_old_health self.hero_2.health = self.hero_2_old_health self.state = self.STATE.PROCESSED
def test_initiate_battle_with_bot__create_battle(self): self.hero_1.level = 50 heroes_logic.save_hero(self.hero_1) bot_account = self.accounts_factory.create_account(is_bot=True) records_to_remove, records_to_exclude = self.worker._initiate_battle_with_bot(self.battle_1_record()) bot_battle = Battle1x1Prototype.get_by_id(records_to_exclude[1].battle_id) bot_record = QueueRecord(account_id=bot_account.id, battle_id=bot_battle.id, created_at=bot_battle.created_at + datetime.timedelta(seconds=0), hero_level=1) self.assertEqual(records_to_remove, []) self.assertEqual(records_to_exclude, [self.battle_1_record(), bot_record]) self.assertEqual(SupervisorTask.objects.all().count(), 1) battle_player = Battle1x1Prototype.get_by_account_id(self.account_1.id) battle_bot = Battle1x1Prototype.get_by_account_id(bot_account.id) self.assertEqual(battle_player.enemy_id, bot_account.id) self.assertFalse(battle_player.calculate_rating) self.assertEqual(battle_bot.enemy_id, self.account_1.id) self.assertFalse(battle_bot.calculate_rating)
def test_initiate_battle_with_bot__create_battle(self): self.hero_1._model.level = 50 self.hero_1.save() result, bot_account_id, bundle_id = register_user('bot_user', '*****@*****.**', '111111', is_bot=True) records_to_remove, records_to_exclude = self.worker._initiate_battle_with_bot( self.battle_1_record()) bot_battle = Battle1x1Prototype.get_by_id( records_to_exclude[1].battle_id) bot_record = QueueRecord(account_id=bot_account_id, battle_id=bot_battle.id, created_at=bot_battle.created_at + datetime.timedelta(seconds=0), hero_level=1) self.assertEqual(records_to_remove, []) self.assertEqual(records_to_exclude, [self.battle_1_record(), bot_record]) self.assertEqual(SupervisorTask.objects.all().count(), 1) battle_player = Battle1x1Prototype.get_by_account_id(self.account_1.id) battle_bot = Battle1x1Prototype.get_by_account_id(bot_account_id) self.assertEqual(battle_player.enemy_id, bot_account_id) self.assertFalse(battle_player.calculate_rating) self.assertEqual(battle_bot.enemy_id, self.account_1.id) self.assertFalse(battle_bot.calculate_rating)
def test_initiate_battle_with_bot__create_battle(self): self.hero_1._model.level = 50 self.hero_1.save() result, bot_account_id, bundle_id = register_user('bot_user', '*****@*****.**', '111111', is_bot=True) records_to_remove, records_to_exclude = self.worker._initiate_battle_with_bot(self.battle_1_record()) bot_battle = Battle1x1Prototype.get_by_id(records_to_exclude[1].battle_id) bot_record = QueueRecord(account_id=bot_account_id, battle_id=bot_battle.id, created_at=bot_battle.created_at + datetime.timedelta(seconds=0), hero_level=1) self.assertEqual(records_to_remove, []) self.assertEqual(records_to_exclude, [self.battle_1_record(), bot_record]) self.assertEqual(SupervisorTask.objects.all().count(), 1) battle_player = Battle1x1Prototype.get_by_account_id(self.account_1.id) battle_bot = Battle1x1Prototype.get_by_account_id(bot_account_id) self.assertEqual(battle_player.enemy_id, bot_account_id) self.assertFalse(battle_player.calculate_rating) self.assertEqual(battle_bot.enemy_id, self.account_1.id) self.assertFalse(battle_bot.calculate_rating)
def test_initiate_battle_with_bot__create_battle(self): self.hero_1.level = 50 heroes_logic.save_hero(self.hero_1) bot_account = self.accounts_factory.create_account(is_bot=True) records_to_remove, records_to_exclude = self.worker._initiate_battle_with_bot( self.battle_1_record()) bot_battle = Battle1x1Prototype.get_by_id( records_to_exclude[1].battle_id) bot_record = QueueRecord(account_id=bot_account.id, battle_id=bot_battle.id, created_at=bot_battle.created_at + datetime.timedelta(seconds=0), hero_level=1) self.assertEqual(records_to_remove, []) self.assertEqual(records_to_exclude, [self.battle_1_record(), bot_record]) self.assertEqual(SupervisorTask.objects.all().count(), 1) battle_player = Battle1x1Prototype.get_by_account_id(self.account_1.id) battle_bot = Battle1x1Prototype.get_by_account_id(bot_account.id) self.assertEqual(battle_player.enemy_id, bot_account.id) self.assertFalse(battle_player.calculate_rating) self.assertEqual(battle_bot.enemy_id, self.account_1.id) self.assertFalse(battle_bot.calculate_rating)
def form_game_info(account=None, is_own=False, client_turns=None): from the_tale.accounts.prototypes import AccountPrototype from the_tale.game.prototypes import GameState from the_tale.game.pvp.prototypes import Battle1x1Prototype game_time = TimePrototype.get_current_time() data = {'mode': 'pve', 'turn': game_time.ui_info(), 'game_state': GameState.state().value, 'map_version': map_info_storage.version, 'account': None, 'enemy': None } if account: battle = Battle1x1Prototype.get_by_account_id(account.id) data['account'] = _form_game_account_info(game_time, account, in_pvp_queue=False if battle is None else battle.state.is_WAITING, is_own=is_own, client_turns=client_turns) if battle and battle.state.is_PROCESSING: data['mode'] = 'pvp' data['enemy'] = _form_game_account_info(game_time, AccountPrototype.get_by_id(battle.enemy_id), in_pvp_queue=False, is_own=False, client_turns=client_turns) return data
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 = heroes_logic.load_hero(hero_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 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 = heroes_logic.load_hero(hero_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 form_game_info(account=None, is_own=False, client_turns=None): from the_tale.accounts.prototypes import AccountPrototype from the_tale.game.prototypes import GameState from the_tale.game.pvp.prototypes import Battle1x1Prototype game_time = TimePrototype.get_current_time() data = {'mode': 'pve', 'turn': game_time.ui_info(), 'game_state': GameState.state().value, 'map_version': map_info_storage.version, 'account': None, 'enemy': None } if account: battle = Battle1x1Prototype.get_by_account_id(account.id) data['account'] = _form_game_account_info(game_time, account, in_pvp_queue=False if battle is None else battle.state.is_WAITING, is_own=is_own, client_turns=client_turns) if battle and battle.state.is_PROCESSING: data['mode'] = 'pvp' data['enemy'] = _form_game_account_info(game_time, AccountPrototype.get_by_id(battle.enemy_id), in_pvp_queue=False, is_own=False, client_turns=client_turns) return data
def game_page(context): battle = Battle1x1Prototype.get_by_account_id(context.account.id) if battle and battle.state.is_PROCESSING: return dext_views.Redirect(url('game:pvp:')) clan = None if context.account.clan_id is not None: clan = ClanPrototype.get_by_id(context.account.clan_id) cards = sorted(CARD.records, key=lambda r: (r.rarity.value, r.text)) return dext_views.Page('game/game_page.html', content={ 'map_settings': map_settings, 'game_settings': game_settings, 'EQUIPMENT_SLOT': EQUIPMENT_SLOT, 'current_map_version': map_info_storage.version, 'clan': clan, 'CARDS': cards, 'resource': context.resource, 'hero': context.account_hero, 'ABILITY_TYPE': ABILITY_TYPE })
def use(self, task, storage, pvp_balancer, **kwargs): if task.step.is_LOGIC: if not task.hero.can_participate_in_pvp: return task.logic_result( next_step=ComplexChangeTask.STEP.ERROR) task.hero.add_message('angel_ability_arena_pvp_1x1', hero=task.hero, energy=self.TYPE.cost) task.hero.update_habits(HABIT_CHANGE_SOURCE.ARENA_SEND) task.hero.process_removed_artifacts() return task.logic_result( next_step=ComplexChangeTask.STEP.PVP_BALANCER) elif task.step.is_PVP_BALANCER: battle = Battle1x1Prototype.get_by_account_id( task.data['account_id']) if battle is None: pvp_balancer.add_to_arena_queue(task.data['hero_id']) return task.logic_result()
def process_arena_pvp_1x1(self, bundle_id): # pylint: disable=R0914 from the_tale.accounts.prototypes import AccountPrototype from the_tale.game.actions.prototypes import ActionMetaProxyPrototype from the_tale.game.actions import meta_actions from the_tale.game.logic_storage import LogicStorage from the_tale.game.pvp.prototypes import Battle1x1Prototype from the_tale.game.pvp.models import BATTLE_1X1_STATE storage = LogicStorage() account_1_id, account_2_id = list(self.members) account_1 = AccountPrototype.get_by_id(account_1_id) account_2 = AccountPrototype.get_by_id(account_2_id) storage.load_account_data(account_1) storage.load_account_data(account_2) hero_1 = storage.accounts_to_heroes[account_1_id] hero_2 = storage.accounts_to_heroes[account_2_id] old_bundle_1_id = hero_1.actions.current_action.bundle_id old_bundle_2_id = hero_2.actions.current_action.bundle_id meta_action_battle = meta_actions.ArenaPvP1x1.create( storage, hero_1, hero_2) ActionMetaProxyPrototype.create(hero=hero_1, _bundle_id=bundle_id, meta_action=meta_action_battle) ActionMetaProxyPrototype.create(hero=hero_2, _bundle_id=bundle_id, meta_action=meta_action_battle) storage.merge_bundles([old_bundle_1_id, old_bundle_2_id], bundle_id) storage.save_bundle_data(bundle_id) battle_1 = Battle1x1Prototype.get_by_account_id(account_1_id) battle_1.state = BATTLE_1X1_STATE.PROCESSING battle_1.save() battle_2 = Battle1x1Prototype.get_by_account_id(account_2_id) battle_2.state = BATTLE_1X1_STATE.PROCESSING battle_2.save()
def process_battle_ending(self): battle_1 = Battle1x1Prototype.get_by_account_id(self.hero_1.account_id) battle_2 = Battle1x1Prototype.get_by_account_id(self.hero_2.account_id) participant_1 = AccountPrototype.get_by_id(self.hero_1.account_id) participant_2 = AccountPrototype.get_by_id(self.hero_2.account_id) if self.hero_1.health <= 0: if self.hero_2.health <= 0: Battle1x1ResultPrototype.create(participant_1=participant_1, participant_2=participant_2, result=BATTLE_1X1_RESULT.DRAW) if battle_1.calculate_rating and battle_2.calculate_rating: self.hero_1.statistics.change_pvp_battles_1x1_draws(1) self.hero_2.statistics.change_pvp_battles_1x1_draws(1) else: Battle1x1ResultPrototype.create( participant_1=participant_1, participant_2=participant_2, result=BATTLE_1X1_RESULT.DEFEAT) if battle_1.calculate_rating and battle_2.calculate_rating: self.hero_2.statistics.change_pvp_battles_1x1_victories(1) self.hero_1.statistics.change_pvp_battles_1x1_defeats(1) else: Battle1x1ResultPrototype.create(participant_1=participant_1, participant_2=participant_2, result=BATTLE_1X1_RESULT.VICTORY) if battle_1.calculate_rating and battle_2.calculate_rating: self.hero_1.statistics.change_pvp_battles_1x1_victories(1) self.hero_2.statistics.change_pvp_battles_1x1_defeats(1) battle_1.remove() battle_2.remove() self.hero_1.health = self.hero_1_old_health self.hero_2.health = self.hero_2_old_health self.reset_hero_info(self.hero_1) self.reset_hero_info(self.hero_2) self.state = self.STATE.PROCESSED
def process_arena_pvp_1x1(self, bundle_id): # pylint: disable=R0914 from the_tale.accounts.prototypes import AccountPrototype from the_tale.game.actions.prototypes import ActionMetaProxyPrototype from the_tale.game.actions import meta_actions from the_tale.game.logic_storage import LogicStorage from the_tale.game.pvp.prototypes import Battle1x1Prototype from the_tale.game.pvp.models import BATTLE_1X1_STATE storage = LogicStorage() account_1_id, account_2_id = list(self.members) account_1 = AccountPrototype.get_by_id(account_1_id) account_2 = AccountPrototype.get_by_id(account_2_id) storage.load_account_data(account_1) storage.load_account_data(account_2) hero_1 = storage.accounts_to_heroes[account_1_id] hero_2 = storage.accounts_to_heroes[account_2_id] old_bundle_1_id = hero_1.actions.current_action.bundle_id old_bundle_2_id = hero_2.actions.current_action.bundle_id meta_action_battle = meta_actions.ArenaPvP1x1.create(storage, hero_1, hero_2) ActionMetaProxyPrototype.create(hero=hero_1, _bundle_id=bundle_id, meta_action=meta_action_battle) ActionMetaProxyPrototype.create(hero=hero_2, _bundle_id=bundle_id, meta_action=meta_action_battle) storage.merge_bundles([old_bundle_1_id, old_bundle_2_id], bundle_id) storage.save_bundle_data(bundle_id) battle_1 = Battle1x1Prototype.get_by_account_id(account_1_id) battle_1.state = BATTLE_1X1_STATE.PROCESSING battle_1.save() battle_2 = Battle1x1Prototype.get_by_account_id(account_2_id) battle_2.state = BATTLE_1X1_STATE.PROCESSING battle_2.save()
def use_ability(self, ability): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.json_error("pvp.use_ability.no_battle", u"Бой не идёт, вы не можете использовать способность") use_ability_task = UsePvPAbilityTask(battle_id=battle.id, account_id=self.account.id, ability_id=ability.TYPE) task = PostponedTaskPrototype.create(use_ability_task) environment.workers.supervisor.cmd_logic_task(self.account.id, task.id) return self.json_processing(task.status_url)
def use(self, task, storage, **kwargs): # pylint: disable=R0911 battle = Battle1x1Prototype.get_by_account_id(task.hero.account_id) if battle and not battle.state.is_WAITING: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) if not task.hero.can_be_helped(): return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) task.hero.on_help() action = task.hero.actions.current_action choice = action.get_help_choice() if choice is None: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) if action.HABIT_MODE.is_AGGRESSIVE: task.hero.update_habits(HABIT_CHANGE_SOURCE.HELP_AGGRESSIVE) elif action.HABIT_MODE.is_PEACEFUL: task.hero.update_habits(HABIT_CHANGE_SOURCE.HELP_UNAGGRESSIVE) elif action.HABIT_MODE.is_COMPANION: if task.hero.companion: for habit_source in task.hero.companion.modify_attribute( heroes_relations.MODIFIERS.HABITS_SOURCES, set()): task.hero.update_habits( habit_source, multuplier=task.hero.companion_habits_multiplier) else: raise exceptions.UnknownHabitModeError(mode=action.HABIT_MODE) critical = random.uniform(0, 1) < task.hero.might_crit_chance result = self._use(task, choice, action, task.hero, critical) if result[0].is_SUCCESSED: task.hero.statistics.change_help_count(1) if task.hero.actions.current_action.state == task.hero.actions.current_action.STATE.PROCESSED: storage.process_turn__single_hero( hero=task.hero, logger=None, continue_steps_if_needed=True) task.hero.cards.change_help_count(1) self.process_removed_artifacts(task.hero) return result
def leave_arena_queue(self, hero_id): hero = heroes_logic.load_hero(hero_id=hero_id) battle = Battle1x1Prototype.get_by_account_id(hero.account_id) if not battle.state.is_WAITING: return if battle.account_id not in self.arena_queue: self.logger.error("can not leave queue: battle %d in waiting state but no in arena queue" % battle.id) return del self.arena_queue[battle.account_id] battle.remove()
def leave_arena_queue(self, hero_id): hero = heroes_logic.load_hero(hero_id=hero_id) battle = Battle1x1Prototype.get_by_account_id(hero.account_id) if not battle.state.is_WAITING: return if battle.account_id not in self.arena_queue: self.logger.error('can not leave queue: battle %d in waiting state but no in arena queue' % battle.id) return del self.arena_queue[battle.account_id] battle.remove()
def use(self, task, storage, **kwargs): # pylint: disable=R0911 battle = Battle1x1Prototype.get_by_account_id(task.hero.account_id) if battle and not battle.state.is_WAITING: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) if not task.hero.can_be_helped(): return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) task.hero.on_help() action = task.hero.actions.current_action choice = action.get_help_choice() if choice is None: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) if action.HABIT_MODE.is_AGGRESSIVE: task.hero.update_habits(HABIT_CHANGE_SOURCE.HELP_AGGRESSIVE) elif action.HABIT_MODE.is_PEACEFUL: task.hero.update_habits(HABIT_CHANGE_SOURCE.HELP_UNAGGRESSIVE) elif action.HABIT_MODE.is_COMPANION: if task.hero.companion: for habit_source in task.hero.companion.modify_attribute(heroes_relations.MODIFIERS.HABITS_SOURCES, set()): task.hero.update_habits(habit_source, multuplier=task.hero.companion_habits_multiplier) else: raise exceptions.UnknownHabitModeError(mode=action.HABIT_MODE) critical = random.uniform(0, 1) < task.hero.might_crit_chance result = self._use(task, choice, action, task.hero, critical) if result[0].is_SUCCESSED: task.hero.statistics.change_help_count(1) if task.hero.actions.current_action.state == task.hero.actions.current_action.STATE.PROCESSED: storage.process_turn__single_hero(hero=task.hero, logger=None, continue_steps_if_needed=True) task.hero.cards.change_help_count(1) self.process_removed_artifacts(task.hero) return result
def use_ability(self, ability): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.json_error( 'pvp.use_ability.no_battle', u'Бой не идёт, вы не можете использовать способность') use_ability_task = UsePvPAbilityTask(battle_id=battle.id, account_id=self.account.id, ability_id=ability.TYPE) task = PostponedTaskPrototype.create(use_ability_task) environment.workers.supervisor.cmd_logic_task(self.account.id, task.id) return self.json_processing(task.status_url)
def say(self): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.json_error("pvp.say.no_battle", u"Бой не идёт, вы не можете говорить") say_form = SayForm(self.request.POST) if not say_form.is_valid(): return self.json_error("pvp.say.form_errors", say_form.errors) say_task = SayInBattleLogTask(battle_id=battle.id, text=say_form.c.text) task = PostponedTaskPrototype.create(say_task) environment.workers.supervisor.cmd_logic_task(self.account.id, task.id) return self.json_processing(task.status_url)
def use(self, task, storage, pvp_balancer=None, **kwargs): if task.step.is_LOGIC: battle = Battle1x1Prototype.get_by_account_id(task.hero.account_id) if battle is None: return task.logic_result() task.hero.add_message('angel_ability_arena_pvp_1x1_leave_queue', hero=task.hero) task.hero.update_habits(HABIT_CHANGE_SOURCE.ARENA_LEAVE) return task.logic_result(next_step=ComplexChangeTask.STEP.PVP_BALANCER) elif task.step.is_PVP_BALANCER: pvp_balancer.leave_arena_queue(task.data['hero_id']) return task.logic_result()
def use(self, task, storage, pvp_balancer, **kwargs): if task.step.is_LOGIC: if not task.hero.can_participate_in_pvp: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) task.hero.add_message('angel_ability_arena_pvp_1x1', hero=task.hero) task.hero.update_habits(HABIT_CHANGE_SOURCE.ARENA_SEND) return task.logic_result(next_step=ComplexChangeTask.STEP.PVP_BALANCER) elif task.step.is_PVP_BALANCER: battle = Battle1x1Prototype.get_by_account_id(task.data['account_id']) if battle is None: pvp_balancer.add_to_arena_queue(task.data['hero_id']) return task.logic_result()
def say(self): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.json_error('pvp.say.no_battle', u'Бой не идёт, вы не можете говорить') say_form = SayForm(self.request.POST) if not say_form.is_valid(): return self.json_error('pvp.say.form_errors', say_form.errors) say_task = SayInBattleLogTask(battle_id=battle.id, text=say_form.c.text) task = PostponedTaskPrototype.create(say_task) environment.workers.supervisor.cmd_logic_task(self.account.id, task.id) return self.json_processing(task.status_url)
def pvp_page(self): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.redirect(reverse("game:")) own_abilities = sorted(self.own_hero.abilities.all, key=lambda x: x.NAME) enemy_account = AccountPrototype.get_by_id(battle.enemy_id) enemy_hero = HeroPrototype.get_by_account_id(battle.enemy_id) enemy_abilities = sorted(enemy_hero.abilities.all, key=lambda x: x.NAME) say_form = SayForm() clan = None if self.account.clan_id is not None: clan = ClanPrototype.get_by_id(self.account.clan_id) enemy_clan = None if enemy_account.clan_id is not None: enemy_clan = ClanPrototype.get_by_id(enemy_account.clan_id) return self.template( "pvp/pvp_page.html", { "enemy_account": AccountPrototype.get_by_id(battle.enemy_id), "own_hero": self.own_hero, "own_abilities": own_abilities, "enemy_abilities": enemy_abilities, "game_settings": game_settings, "say_form": say_form, "clan": clan, "enemy_clan": enemy_clan, "battle": battle, "EQUIPMENT_SLOT": EQUIPMENT_SLOT, "ABILITIES": (Ice, Blood, Flame), }, )
def pvp_page(self): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.redirect(reverse('game:')) own_abilities = sorted(self.own_hero.abilities.all, key=lambda x: x.NAME) enemy_account = AccountPrototype.get_by_id(battle.enemy_id) enemy_hero = HeroPrototype.get_by_account_id(battle.enemy_id) enemy_abilities = sorted(enemy_hero.abilities.all, key=lambda x: x.NAME) say_form = SayForm() clan = None if self.account.clan_id is not None: clan = ClanPrototype.get_by_id(self.account.clan_id) enemy_clan = None if enemy_account.clan_id is not None: enemy_clan = ClanPrototype.get_by_id(enemy_account.clan_id) return self.template( 'pvp/pvp_page.html', { 'enemy_account': AccountPrototype.get_by_id(battle.enemy_id), 'own_hero': self.own_hero, 'own_abilities': own_abilities, 'enemy_abilities': enemy_abilities, 'game_settings': game_settings, 'say_form': say_form, 'clan': clan, 'enemy_clan': enemy_clan, 'battle': battle, 'EQUIPMENT_SLOT': EQUIPMENT_SLOT, 'ABILITIES': (Ice, Blood, Flame) })
def game_page(context): battle = Battle1x1Prototype.get_by_account_id(context.account.id) if battle and battle.state.is_PROCESSING: return dext_views.Redirect(url('game:pvp:')) clan = None if context.account.clan_id is not None: clan = ClanPrototype.get_by_id(context.account.clan_id) cards = sorted(EFFECTS.values(), key=lambda x: (x.TYPE.rarity.value, x.TYPE.text)) return dext_views.Page('game/game_page.html', content={'map_settings': map_settings, 'game_settings': game_settings, 'EQUIPMENT_SLOT': EQUIPMENT_SLOT, 'current_map_version': map_info_storage.version, 'clan': clan, 'CARDS': cards, 'resource': context.resource, 'hero': context.account_hero} )
def pvp_page(self): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.redirect(reverse('game:')) own_abilities = sorted(self.own_hero.abilities.all, key=lambda x: x.NAME) enemy_account = AccountPrototype.get_by_id(battle.enemy_id) enemy_hero = HeroPrototype.get_by_account_id(battle.enemy_id) enemy_abilities = sorted(enemy_hero.abilities.all, key=lambda x: x.NAME) say_form = SayForm() clan = None if self.account.clan_id is not None: clan = ClanPrototype.get_by_id(self.account.clan_id) enemy_clan = None if enemy_account.clan_id is not None: enemy_clan = ClanPrototype.get_by_id(enemy_account.clan_id) return self.template('pvp/pvp_page.html', {'enemy_account': AccountPrototype.get_by_id(battle.enemy_id), 'own_hero': self.own_hero, 'own_abilities': own_abilities, 'enemy_abilities': enemy_abilities, 'game_settings': game_settings, 'say_form': say_form, 'clan': clan, 'enemy_clan': enemy_clan, 'battle': battle, 'EQUIPMENT_SLOT': EQUIPMENT_SLOT, 'ABILITIES': (Ice, Blood, Flame)} )