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 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 update_feature(self): from hero.manipulation import HeroM herom = HeroM(self) herom.update_feature() herom.level_up()
def update_feature(self): from hero.manipulation import HeroM herom = HeroM(self) herom.update_feature() herom.level_up()