def move(request, coordinate_x, coordinate_y): hero = request.hero herom = HeroM(hero) island = herom.get_island() hero_position = herom.get_position_on_island() islandm = IslandM(island) if not islandm.is_can_make_step(coordinate_x, coordinate_y, hero_position): return HttpResponseRedirect(reverse(settings.URL_REVERSE_404)) if not herom.get_combat(): if not islandm.get_time_left_to_move(hero_position): try: island.islandpart_set.get(coordinate_x=coordinate_x, coordinate_y=coordinate_y, is_move=False) except IslandPart.DoesNotExist: herom.update_position_on_island(coordinate_x, coordinate_y) islandm.update_bots_position(coordinate_x, coordinate_y) CombatM(None, hero).update_bots_in_combats(coordinate_x, coordinate_y) else: # messages.add_message(request, messages.ERROR, 'Take away your demand.') return HttpResponseRedirect(reverse('island'))
def past(request, template_name='combat/past.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 = None if request.method == 'POST': form = PastForm(request.POST) if form.is_valid(): login = form.cleaned_data['login'] date_begin = form.cleaned_data['date_begin'] date_end = form.cleaned_data['date_end'] search_hero = Hero.objects.get(login=login) combats = Combat.objects.filter(is_active=Combat.IS_ACTIVE_PAST, combatwarrior__hero=search_hero, start_date_time__gte=date_begin, start_date_time__lte=date_end) else: form = PastForm() variables = RequestContext(request, { 'form': form, 'combats': combats, 'is_cancel': is_cancel }) return render_to_response(template_name, variables)
def past(request, template_name='combat/past.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 = None if request.method == 'POST': form = PastForm(request.POST) if form.is_valid(): login = form.cleaned_data['login'] date_begin = form.cleaned_data['date_begin'] date_end = form.cleaned_data['date_end'] search_hero = Hero.objects.get(login=login) combats = Combat.objects.filter(is_active=Combat.IS_ACTIVE_PAST, combatwarrior__hero=search_hero, start_date_time__gte=date_begin, start_date_time__lte=date_end) else: form = PastForm() variables = RequestContext(request, {'form': form, 'combats': combats, '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 quit(request): hero = request.hero herom = HeroM(hero) combat = herom.get_combat(Combat.IS_ACTIVE_AFTER_FIGHT) if not combat: return HttpResponseRedirect(reverse(settings.URL_REVERSE_404)) combatm = CombatM(combat, hero) combatwarrior = combat.combatwarrior_set.get(hero=hero) combatwarrior.is_quit = True herom.set_hp() combatwarrior.save() team = combat.combatwarrior_set.get(hero=hero).team is_draw = combatm.is_draw() is_win = combatm.is_win(team, is_draw) if is_draw: hero.number_of_draws += 1 elif is_win: if team == Combat.TEAM_FIRST: all_experience = combat.combatlog_set.filter(hero_one=hero). \ aggregate(Sum('warrior_one_experience'))['warrior_one_experience__sum'] else: all_experience = combat.combatlog_set.filter(hero_two=hero). \ aggregate(Sum('warrior_two_experience'))['warrior_two_experience__sum'] if all_experience == None: all_experience = 0 hero.experience += all_experience hero.number_of_wins += 1 herom.level_up() else: hero.number_of_losses += 1 hero.save() if not combatm.is_anybody_not_quit(): if is_win: combat.win_team = team elif is_draw: combat.win_team = None else: combat.win_team = Combat.TEAM_FIRST if team else Combat.TEAM_SECOND combat.end_date_time = datetime.datetime.now() combat.is_active = Combat.IS_ACTIVE_PAST combat.save() return HttpResponseRedirect(reverse('hero'))
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 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 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 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'))