def group(request, template_name='combat/group.html'): hero = request.hero herom = HeroM(hero) combat = herom.get_combat(Combat.IS_ACTIVE_WAIT) combatm = CombatM(combat, hero) combatm.update_combats(Combat.TYPE_GROUP) if combat and combatm.is_active(): return HttpResponseRedirect(reverse('combat')) is_cancel = False if combat: is_cancel = combatm.is_cancel() if request.method == 'POST' and not combat: form = GroupForm(request.POST) if form.is_valid(): combat = Combat( type=Combat.TYPE_GROUP, time_out=form.cleaned_data['time_out'], injury=form.cleaned_data['injury'], with_things=form.cleaned_data['with_things'], time_wait=form.cleaned_data['time_wait'], location=herom.get_location(), one_team_count=form.cleaned_data['one_team_count'], two_team_count=form.cleaned_data['two_team_count'], one_team_lvl_min=form.cleaned_data['one_team_lvl_min'], one_team_lvl_max=form.cleaned_data['one_team_lvl_max'], two_team_lvl_min=form.cleaned_data['two_team_lvl_min'], two_team_lvl_max=form.cleaned_data['two_team_lvl_max']) combat.save() combat.combatwarrior_set.create(hero=hero) # messages.add_message(request, messages.SUCCESS, 'Your demand create.') return HttpResponseRedirect(reverse('combat_group')) else: form = GroupForm() combats = Combat.objects.filter(type=Combat.TYPE_GROUP, is_active=Combat.IS_ACTIVE_WAIT, location=herom.get_location()) variables = RequestContext( request, { 'form': form, 'combats': combats, 'in_combat': combat, 'is_cancel': is_cancel }) return render_to_response(template_name, variables)
def group(request, template_name='combat/group.html'): hero = request.hero herom = HeroM(hero) combat = herom.get_combat(Combat.IS_ACTIVE_WAIT) combatm = CombatM(combat, hero) combatm.update_combats(Combat.TYPE_GROUP) if combat and combatm.is_active(): return HttpResponseRedirect(reverse('combat')) is_cancel = False if combat: is_cancel = combatm.is_cancel() if request.method == 'POST' and not combat: form = GroupForm(request.POST) if form.is_valid(): combat = Combat(type=Combat.TYPE_GROUP, time_out=form.cleaned_data['time_out'], injury=form.cleaned_data['injury'], with_things=form.cleaned_data['with_things'], time_wait=form.cleaned_data['time_wait'], location=herom.get_location(), one_team_count=form.cleaned_data['one_team_count'], two_team_count=form.cleaned_data['two_team_count'], one_team_lvl_min=form.cleaned_data['one_team_lvl_min'], one_team_lvl_max=form.cleaned_data['one_team_lvl_max'], two_team_lvl_min=form.cleaned_data['two_team_lvl_min'], two_team_lvl_max=form.cleaned_data['two_team_lvl_max']) combat.save() combat.combatwarrior_set.create(hero=hero) # messages.add_message(request, messages.SUCCESS, 'Your demand create.') return HttpResponseRedirect(reverse('combat_group')) else: form = GroupForm() combats = Combat.objects.filter(type=Combat.TYPE_GROUP, is_active=Combat.IS_ACTIVE_WAIT, location=herom.get_location()) variables = RequestContext(request, {'form': form, 'combats': combats, 'in_combat': combat, 'is_cancel': is_cancel}) return render_to_response(template_name, variables)
def duel(request, template_name='combat/duel.html'): hero = request.hero herom = HeroM(hero) combat = herom.get_combat(Combat.IS_ACTIVE_WAIT) is_cancel = is_fight = is_refuse = False if combat: combatm = CombatM(combat, hero) is_cancel = combatm.is_cancel() is_refuse = combatm.is_refuse() is_fight = combatm.is_fight() if request.method == 'POST' and not combat: form = DuelForm(request.POST) if form.is_valid(): combat = Combat(type=Combat.TYPE_DUEL, time_out=form.cleaned_data['time_out'], injury=form.cleaned_data['injury'], with_things=form.cleaned_data['with_things'], location=herom.get_location(), one_team_count=1, two_team_count=1) combat.save() combat.combatwarrior_set.create(hero=hero) # messages.add_message(request, messages.SUCCESS, 'Your demand accept.') return HttpResponseRedirect(reverse('combat_duel')) else: form = DuelForm() combats = Combat.objects.filter(type=Combat.TYPE_DUEL, is_active=Combat.IS_ACTIVE_WAIT, location=herom.get_location()) variables = RequestContext( request, { 'form': form, 'combats': combats, 'in_combat': combat, 'is_cancel': is_cancel, 'is_fight': is_fight, 'is_refuse': is_refuse }) return render_to_response(template_name, variables)
def duel(request, template_name='combat/duel.html'): hero = request.hero herom = HeroM(hero) combat = herom.get_combat(Combat.IS_ACTIVE_WAIT) is_cancel = is_fight = is_refuse = False if combat: combatm = CombatM(combat, hero) is_cancel = combatm.is_cancel() is_refuse = combatm.is_refuse() is_fight = combatm.is_fight() if request.method == 'POST' and not combat: form = DuelForm(request.POST) if form.is_valid(): combat = Combat(type=Combat.TYPE_DUEL, time_out=form.cleaned_data['time_out'], injury=form.cleaned_data['injury'], with_things=form.cleaned_data['with_things'], location=herom.get_location(), one_team_count=1, two_team_count=1) combat.save() combat.combatwarrior_set.create(hero=hero) # messages.add_message(request, messages.SUCCESS, 'Your demand accept.') return HttpResponseRedirect(reverse('combat_duel')) else: form = DuelForm() combats = Combat.objects.filter(type=Combat.TYPE_DUEL, is_active=Combat.IS_ACTIVE_WAIT, location=herom.get_location()) variables = RequestContext(request, {'form': form, 'combats': combats, 'in_combat': combat, 'is_cancel': is_cancel, 'is_fight': is_fight, 'is_refuse': is_refuse}) return render_to_response(template_name, variables)
def current(request, template_name='combat/current.html'): hero = request.hero herom = HeroM(hero) combat = herom.get_combat(Combat.IS_ACTIVE_WAIT) is_cancel = False if combat: is_cancel = CombatM(combat, hero).is_cancel() combats = Combat.objects.filter(is_active=Combat.IS_ACTIVE_FIGHT, location=herom.get_location()) variables = RequestContext(request, {'combats': combats, 'is_cancel': is_cancel}) return render_to_response(template_name, variables)
def current(request, template_name='combat/current.html'): hero = request.hero herom = HeroM(hero) combat = herom.get_combat(Combat.IS_ACTIVE_WAIT) is_cancel = False if combat: is_cancel = CombatM(combat, hero).is_cancel() combats = Combat.objects.filter(is_active=Combat.IS_ACTIVE_FIGHT, location=herom.get_location()) variables = RequestContext(request, { 'combats': combats, 'is_cancel': is_cancel }) return render_to_response(template_name, variables)
def bot_attack(request, bot_id): hero = request.hero herom = HeroM(hero) hero_position = herom.get_position_on_island() try: bot = Bot.objects.get(id=bot_id) except Bot.DoesNotExist: return HttpResponseRedirect(reverse(settings.URL_REVERSE_404)) if bot.current_coordinate_x != hero_position[0] or \ bot.current_coordinate_y != hero_position[1]: # messages.add_message(request, messages.ERROR, 'Bot go away.') return HttpResponseRedirect(reverse('island')) if herom.get_combat(): # messages.add_message(request, messages.ERROR, 'Take away your demand.') return HttpResponseRedirect(reverse('island')) if not bot.in_combat: combat = Combat(type=Combat.TYPE_TERRITORIAL, is_active=Combat.IS_ACTIVE_FIGHT, location=herom.get_location()) combat.save() combat.combatwarrior_set.create(hero=hero, team=Combat.TEAM_FIRST) combat.combatwarrior_set.create(bot=bot, team=Combat.TEAM_SECOND) bot.in_combat = True bot.save() CombatM(combat, hero).write_log_message(combat, True) return HttpResponseRedirect(reverse('combat')) else: # messages.add_message(request, messages.ERROR, 'Bot in combat.') return HttpResponseRedirect(reverse('island'))