def get_damage(self, attacker, defender, move): if (move.category == moves.STATUS): return 0 attack = None defence = None if (move.category == moves.PHYSICAL): attack = attacker.attack * self.get_stat_modifier(attacker.atk_stage) defence = defender.defence * self.get_stat_modifier(defender.def_stage) elif (move.category == moves.SPECIAL): attack = attacker.spattack * self.get_stat_modifier(attacker.spa_stage) defence = defender.spdefence * self.get_stat_modifier(defender.spd_stage) else: debug.db(dbflag, "UNEXPECTED MOVE CATEGORY " + str(move.category)) sys.exit() stab = attacker.get_stab(move.element) type_effectiveness = typechart.get_effectiveness(move.element, defender.template.elements) if (type_effectiveness == 0): log.message("It has no effect") return 0 elif (type_effectiveness < 1): log.message("It isn't very effective") elif (type_effectiveness > 1): log.message("It's super effective") critical = 1 if (fakerandom.fakerandom() < self.get_crit_modifier(attacker.crit_stage + move.critRatio)): critical = 2 log.message("It's a critical hit") randomamount = (1 - (fakerandom.fakerandom() * 0.15)) return int((((2 * (attacker.level + 10)) / 250.0) * (float(attack) / float(defence)) * move.base_power + 2) * stab * type_effectiveness * critical * randomamount)
def PARonBeforeMove(pokemon, target = None, move = None): if (fakerandom.fakerandom() < 0.25): log.message(pokemon.template.species + " was paralyzed and couldn't move") # return (False, PAR) return False # return (True,) return True
def PARonBeforeMove(pokemon, target=None, move=None): if (fakerandom.fakerandom() < 0.25): log.message(pokemon.template.species + " was paralyzed and couldn't move") # return (False, PAR) return False # return (True,) return True
def CONFUSIONonBeforeMove(pokemon, target = None, move = None): pokemon.confusion_count -= 1 if (pokemon.confusion_count <= 0 and pokemon.remove_volatile(CONFUSION)): log.message(pokemon.template.species + " snapped out of confusion") # return (True,) return True if (fakerandom.fakerandom() < 0.5): # return (True,) return True log.message(pokemon.template.species + " hurt itself in confusion") pokemon.damage(battle.get_damage(pokemon, pokemon, moves.hitself)) # need to make sure there's a typless move for confusion to simulate hitting itself # return (False, CONFUSION) return False
def CONFUSIONonBeforeMove(pokemon, target=None, move=None): pokemon.confusion_count -= 1 if (pokemon.confusion_count <= 0 and pokemon.remove_volatile(CONFUSION)): log.message(pokemon.template.species + " snapped out of confusion") # return (True,) return True if (fakerandom.fakerandom() < 0.5): # return (True,) return True log.message(pokemon.template.species + " hurt itself in confusion") pokemon.damage(pokemon.max_hp / 10) # take 10% of HP # return (False, CONFUSION) return False
def get_damage(self, attacker, defender, move): if (move.category == moves.STATUS): return 0 attack = None defence = None if (move.category == moves.PHYSICAL): attack = attacker.attack * self.get_stat_modifier( attacker.atk_stage) defence = defender.defence * self.get_stat_modifier( defender.def_stage) if attacker.fainted_self: defence = defence / 2 elif (move.category == moves.SPECIAL): attack = attacker.spattack * self.get_stat_modifier( attacker.spa_stage) defence = defender.spdefence * self.get_stat_modifier( defender.spd_stage) else: debug.db(dbflag, "UNEXPECTED MOVE CATEGORY " + str(move.category)) sys.exit() stab = attacker.get_stab(move.element) type_effectiveness = typechart.get_effectiveness( move.element, defender.types) if (type_effectiveness == 0): log.message("It has no effect") return 0 elif (type_effectiveness < 1): log.message("It isn't very effective") elif (type_effectiveness > 1): log.message("It's super effective") critical = 1 if (fakerandom.fakerandom() < self.get_crit_modifier(attacker.crit_stage + move.critRatio)): critical = 2 log.message("It's a critical hit") randomamount = (1 - (fakerandom.fakerandom() * 0.15)) return int((((2 * (attacker.level + 10)) / 250.0) * (float(attack) / float(defence)) * move.base_power + 2) * stab * type_effectiveness * critical * randomamount)
def FRZonBeforeMove(pokemon, target, move): if (move.flags["DEFROST"]): log.message(pokemon.template.species + " thawed out") pokemon.cure_status() # return (True, ) return True if (fakerandom.fakerandom() < 0.2): log.message(pokemon.template.species + " thawed out") pokemon.cure_status() # return (True,) return True log.message(pokemon.template.species + " is frozen solid") # return (False, FRZ) return False
def CONFUSIONonBeforeMove(pokemon, target=None, move=None): pokemon.confusion_count -= 1 if (pokemon.confusion_count <= 0 and pokemon.remove_volatile(CONFUSION)): log.message(pokemon.template.species + " snapped out of confusion") # return (True,) return True if (fakerandom.fakerandom() < 0.5): # return (True,) return True log.message(pokemon.template.species + " hurt itself in confusion") pokemon.damage( battle.get_damage(pokemon, pokemon, moves.hitself) ) # need to make sure there's a typless move for confusion to simulate hitting itself # return (False, CONFUSION) return False
def make_random_team(num): teamsize = 6 team = [] pokemon_chosen = [] # Weird edge case moves that we didn't have time to implement skipped_moves = [ 'BIDE', 'COUNTER', 'DISABLE', 'DOUBLEEDGE', 'DRAGONRAGE', 'DREAMEATER', 'FOCUSENERGY', 'HAZE', 'HIGHJUMPKICK', 'HYPERBEAM', 'JUMPKICK', 'LIGHTSCREEN', 'MIMIC', 'MINIMIZE', 'MIRRORMOVE', 'MIST', 'PSYWAVE', 'RAGE', 'REFLECT', 'SEISMICTOSS', 'SONICBOOM', 'STRUGGLE', 'SUPERSONIC', 'TELEPORT', 'TRANSFORM', 'SKULLBASH', 'NIGHTSHADE', 'SUBSTITUTE', 'WHIRLWIND', 'ROAR', 'METRONOME', 'SELFDESTRUCT', 'EXPLOSION' ] # Until we have 6 pokemon while len(team) < teamsize: # choose a random pokemon from the pokedex (0-indexed) pokedex_num = fakerandom.fakerandint(0, 150) while pokedex_num in pokemon_chosen: pokedex_num = fakerandom.fakerandint(0, 150) species = pokedex.pokedex_list.keys()[pokedex_num] pokemon_chosen.append(pokedex_num) # skip ditto because we didnt implement transform if species == 'DITTO': continue # set constants that we dont want to randomize level = 100 ivs = [31, 31, 31, 31, 31, 31] evs = [0, 0, 0, 0, 0, 0, 0] # pick 4 attacks attacks = [] attacks_chosen = [] learnset = learnsets.learnset_list[pokedex.pokedex_list.keys() [pokedex_num]] while len(attacks) < 4: attack_num = fakerandom.fakerandint(0, len(learnset) - 1) while (attack_num in attacks_chosen and len(attacks_chosen) < len(learnset)): attack_num = fakerandom.fakerandint(0, len(learnset) - 1) attacks_chosen.append(attack_num) attack = learnset[attack_num] #skip attacks we didnt implement if attack in skipped_moves: continue attacks.append((attack, 3)) # pick gender based on pokemon's gender ratios gender = None ratios = pokedex.pokedex_list[species].gender_ratios counter = 0 gender_num = fakerandom.fakerandom() if gender_num >= counter and gender_num < counter + ratios[0]: gender = 'MALE' counter += ratios[0] if gender_num >= counter and gender_num < counter + ratios[1]: gender = 'FEMALE' team.append( pokemon.Pokemon(species, level, gender, num, ivs, evs, attacks)) return Team(team)
def battle(self): self.team1.pokemon[0].is_active = True self.team2.pokemon[0].is_active = True self.active1 = self.team1.pokemon[0] self.active2 = self.team2.pokemon[0] self.player1.set_active(self.active1) self.player2.set_active(self.active2) self.turncount += 1 while (self.get_winner() == None): player1action = None player2action = None while (True): player1action = self.player1.get_action(self) if (player1action.action == player.SWITCH and "PARTIALLYTRAPPED" in self.active1.volatiles and status.battle_status["PARTIALLYTRAPPED"]. onTrySwitchAction() == False): continue else: break while (True): player2action = self.player2.get_action(self) if (player2action.action == player.SWITCH and "PARTIALLYTRAPPED" in self.active2.volatiles and status.battle_status["PARTIALLYTRAPPED"]. onTrySwitchAction() == False): continue else: break # both players switch (order doesn't matter) if (player1action.action == player.SWITCH and player2action.action == player.SWITCH): self.switch(player1action.user, player1action.target) self.switch(player2action.user, player2action.target) elif (player1action.action == player.SWITCH or player2action.action == player.SWITCH): # just player 1 switches - takes priority over all moves implemented so far if (player1action.action == player.SWITCH and player1action.user.fainted == False): if (player2action.user.fainted == False): # player2action.target.onBeforeSwitchOut(self.active2, self.active1) self.switch(player1action.user, player1action.target) if (player2action.action == player.ATTACK and player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # just player 2 switches - takes priority over all moves implemented so far if (player2action.action == player.SWITCH and player2action.user.fainted == False): if (player1action.user.fainted == False): # player1action.target.onBeforeSwitchOut(self.active1, self.active2) self.switch(player2action.user, player2action.target) if (player1action.action == player.ATTACK and player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) elif (player1action.action == player.ATTACK and player2action.action == player.ATTACK): if (player1action.target.priority == player2action.target.priority): # pokemon 1 is faster # check to see if status affects speed if (self.active1.status.onModifySpe( self.active1.speed, self.active1) > self.active2.status.onModifySpe( self.active2.speed, self.active2)): # pokemon 1 is alive, use move first if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # pokemon 2 is alive, use move second if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 2 is faster # check to see if status affects speed elif (self.active1.status.onModifySpe( self.active1.speed, self.active1) < self.active2.status.onModifySpe( self.active2.speed, self.active2)): # pokemon 2 is alive, use move first if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 1 is alive, use move second if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # speeds are equal, random order else: if (fakerandom.fakerandom() < 0.5): # pokemon 1 is alive, use move first if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # pokemon 2 is alive, use move second if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) else: # pokemon 2 is alive, use move first if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 1 is alive, use move second if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) elif (player1action.target.priority > player2action.target.priority): # pokemon 1 is alive, use move first if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # pokemon 2 is alive, use move second if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) else: # pokemon 2 is alive, use move first if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 1 is alive, use move second if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) if (self.get_winner() != None): break player1switchin = None player2switchin = None if (player1action.user.fainted == True): player1switchin = self.player1.get_fainted_switch(self) if (player2action.user.fainted == True): player2switchin = self.player2.get_fainted_switch(self) if (player1switchin != None): self.switch(player1action.user, player1switchin) if (player2switchin != None): self.switch(player2action.user, player2switchin) else: debug.db( dbflag, "UNEXPECTED COMBINATION OF ACTIONS: " + str(player1action.action) + " and " + str(player2action.action)) if (self.active1.status.onResidualOrder <= self.active2.status.onResidualOrder): self.active1.status.onResidual(self.active1) self.active2.status.onResidual(self.active2) else: self.active2.status.onResidual(self.active2) self.active1.status.onResidual(self.active1) return self.get_winner()
def move(self, user, opponent, move): statuslist = [] # try: statuslist = sorted([user.status] + user.volatiles, key=lambda x: x.onBeforeMovePriority) # except: # pass target = None if (move.target == moves.SELF): target = user elif (move.target == moves.FOE): target = opponent else: debug.db(dbflag, "UNEXPECTED MOVE TARGET: " + str(move.target)) sys.exit() for st in statuslist: onBeforeMove = st.onBeforeMove(user, target, move) # if (onBeforeMove != None and onBeforeMove[0] == False): if (onBeforeMove != None and onBeforeMove == False): # log.message(user.template.species + " couldn't use " + move.name + " due to " + str(onBeforeMove[1])) debug.db(dbflag, "Move failed onBeforeMove") return log.message(user.template.species + " used " + move.name) move.pp -= 1 onTry = move.onTry(user, target, move) # if (onTry != None and onTry[0] == False): if (onTry != None and onTry == False): # log.message(user.template.species + onTry[1]) debug.db(dbflag, "Move failed onTry") return onTryHit = move.onTryHit(user) if (onTryHit != None and onTryHit == False): # log.message(move.name + " failed because " + user.template.species + onTryHit[1]) debug.db(dbflag, "Move failed onTryHit") return accuracy = move.onMoveAccuracy() damage = 0 if (accuracy == None): accuracy = 1 accuracy = accuracy * move.accuracy * self.get_accuracy_modifier( user.acc_stage) / self.get_accuracy_modifier(target.eva_stage) if (accuracy < 0): damage = self.get_damage(user, target, move) target.damage(damage) elif (fakerandom.fakerandom() * 100 < accuracy): damage = self.get_damage(user, target, move) target.damage(damage) else: log.message("But it missed") debug.db(dbflag, "Move missed/failed") return move.onStart(target) move.onHit(target) if (move.drain != 0): user.heal(int(move.drain * damage)) for boost in move.boosts: if (fakerandom.fakerandom() * 100 <= boost.chance): boost_target = None if (boost.target == moves.SELF): boost_target = user else: boost_target = target if (boost.stat == pokemon.ATK): if (boost_target.increment_atk(boost.amount) == False): # debug.db(dbflag, "ATK can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s attack can't go any higher") else: log.message(target.template.species + "'s attack can't go any lower") elif (boost.stat == pokemon.DEF): if (boost_target.increment_def(boost.amount) == False): # debug.db(dbflag, "DEF can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s defence can't go any higher") else: log.message(target.template.species + "'s defence can't go any lower") elif (boost.stat == pokemon.SPA): if (boost_target.increment_spa(boost.amount) == False): # debug.db(dbflag, "SPA can't go any higher/lower") if (boost.amount > 0): log.message( target.template.species + "'s special attack can't go any higher") else: log.message(target.template.species + "'s special attack can't go any lower") elif (boost.stat == pokemon.SPD): if (boost_target.increment_spd(boost.amount) == False): # debug.db(dbflag, "SPD can't go any higher/lower") if (boost.amount > 0): log.message( target.template.species + "'s special defence can't go any higher") else: log.message( target.template.species + "'s special defence can't go any lower") elif (boost.stat == pokemon.SPE): if (boost_target.increment_spe(boost.amount) == False): # debug.db(dbflag, "SPE can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s speed can't go any higher") else: log.message(target.template.species + "'s speed can't go any lower") elif (boost.stat == pokemon.ACC): if (boost_target.increment_acc(boost.amount) == False): # debug.db(dbflag, "ACC can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s accuracy can't go any higher") else: log.message(target.template.species + "'s accuracy can't go any lower") elif (boost.stat == pokemon.EVA): if (boost_target.increment_eva(boost.amount) == False): # debug.db(dbflag, "EVA can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s evasiveness can't go any higher") else: log.message(target.template.species + "'s evasiveness can't go any lower") if (target.fainted == True): log.message(target.template.species + " fainted") return user.status.onHit(target, user, move) for second in move.secondary: if (fakerandom.fakerandom() * 100 <= second.chance): second_target = None if (second.target == moves.SELF): second_target = user else: second_target = target status.battle_status[second.stat].onStart(second_target)
def battle(self): self.team1.pokemon[0].is_active = True self.team2.pokemon[0].is_active = True self.active1 = self.team1.pokemon[0] self.active2 = self.team2.pokemon[0] self.player1.set_active(self.active1) self.player2.set_active(self.active2) self.turncount += 1 while (self.get_winner() == None): player1action = None player2action = None while (True): player1action = self.player1.get_action(self) if (player1action.action == player.SWITCH and "PARTIALLYTRAPPED" in self.active1.volatiles and status.battle_status["PARTIALLYTRAPPED"].onTrySwitchAction() == False): continue else: break while (True): player2action = self.player2.get_action(self) if (player2action.action == player.SWITCH and "PARTIALLYTRAPPED" in self.active2.volatiles and status.battle_status["PARTIALLYTRAPPED"].onTrySwitchAction() == False): continue else: break # both players switch (order doesn't matter) if (player1action.action == player.SWITCH and player2action.action == player.SWITCH): self.switch(player1action.user, player1action.target) self.switch(player2action.user, player2action.target) elif (player1action.action == player.SWITCH or player2action.action == player.SWITCH): # just player 1 switches - takes priority over all moves implemented so far if (player1action.action == player.SWITCH and player1action.user.fainted == False): if (player2action.user.fainted == False): # player2action.target.onBeforeSwitchOut(self.active2, self.active1) self.switch(player1action.user, player1action.target) if (player2action.action == player.ATTACK and player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # just player 2 switches - takes priority over all moves implemented so far if (player2action.action == player.SWITCH and player2action.user.fainted == False): if (player1action.user.fainted == False): # player1action.target.onBeforeSwitchOut(self.active1, self.active2) self.switch(player2action.user, player2action.target) if (player1action.action == player.ATTACK and player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) elif (player1action.action == player.ATTACK and player2action.action == player.ATTACK): if (player1action.target.priority == player2action.target.priority): # pokemon 1 is faster # check to see if status affects speed if (self.active1.status.onModifySpe(self.active1.speed, self.active1) > self.active2.status.onModifySpe(self.active2.speed, self.active2)): # pokemon 1 is alive, use move first if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # pokemon 2 is alive, use move second if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 2 is faster # check to see if status affects speed elif (self.active1.status.onModifySpe(self.active1.speed, self.active1) < self.active2.status.onModifySpe(self.active2.speed, self.active2)): # pokemon 2 is alive, use move first if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 1 is alive, use move second if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # speeds are equal, random order else: if (fakerandom.fakerandom() < 0.5): # pokemon 1 is alive, use move first if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # pokemon 2 is alive, use move second if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) else: # pokemon 2 is alive, use move first if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 1 is alive, use move second if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) elif (player1action.target.priority > player2action.target.priority): # pokemon 1 is alive, use move first if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # pokemon 2 is alive, use move second if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) else: # pokemon 2 is alive, use move first if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 1 is alive, use move second if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) if (self.get_winner() != None): break player1switchin = None player2switchin = None if (player1action.user.fainted == True): player1switchin = self.player1.get_fainted_switch(self) if (player2action.user.fainted == True): player2switchin = self.player2.get_fainted_switch(self) if (player1switchin != None): self.switch(player1action.user, player1switchin) if (player2switchin != None): self.switch(player2action.user, player2switchin) else: debug.db(dbflag, "UNEXPECTED COMBINATION OF ACTIONS: " + str(player1action.action) + " and " + str(player2action.action)) if (self.active1.status.onResidualOrder <= self.active2.status.onResidualOrder): self.active1.status.onResidual(self.active1) self.active2.status.onResidual(self.active2) else: self.active2.status.onResidual(self.active2) self.active1.status.onResidual(self.active1) return self.get_winner()
def move(self, user, opponent, move): statuslist = [] # try: statuslist = sorted([user.status] + user.volatiles, key=lambda x: x.onBeforeMovePriority) # except: # pass target = None if (move.target == moves.SELF): target = user elif (move.target == moves.FOE): target = opponent else: debug.db(dbflag, "UNEXPECTED MOVE TARGET: " + str(move.target)) sys.exit() for st in statuslist: onBeforeMove = st.onBeforeMove(user, target, move) # if (onBeforeMove != None and onBeforeMove[0] == False): if (onBeforeMove != None and onBeforeMove == False): # log.message(user.template.species + " couldn't use " + move.name + " due to " + str(onBeforeMove[1])) debug.db(dbflag, "Move failed onBeforeMove") return log.message(user.template.species + " used " + move.name) move.pp -= 1 onTry = move.onTry(user, target, move) # if (onTry != None and onTry[0] == False): if (onTry != None and onTry == False): # log.message(user.template.species + onTry[1]) debug.db(dbflag, "Move failed onTry") return onTryHit = move.onTryHit(user) if (onTryHit != None and onTryHit == False): # log.message(move.name + " failed because " + user.template.species + onTryHit[1]) debug.db(dbflag, "Move failed onTryHit") return accuracy = move.onMoveAccuracy() damage = 0 if (accuracy == None): accuracy = 1 accuracy = accuracy * move.accuracy * self.get_accuracy_modifier(user.acc_stage) / self.get_accuracy_modifier(target.eva_stage) if (accuracy < 0): damage = self.get_damage(user, target, move) target.damage(damage) elif (fakerandom.fakerandom() * 100 < accuracy): damage = self.get_damage(user, target, move) target.damage(damage) else: log.message("But it missed") debug.db(dbflag, "Move missed/failed") return move.onStart(target) move.onHit(target) if (move.drain != 0): user.heal(int(move.drain * damage)) for boost in move.boosts: if (fakerandom.fakerandom() * 100 <= boost.chance): boost_target = None if (boost.target == moves.SELF): boost_target = user else: boost_target = target if (boost.stat == pokemon.ATK): if (boost_target.increment_atk(boost.amount) == False): # debug.db(dbflag, "ATK can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s attack can't go any higher") else: log.message(target.template.species + "'s attack can't go any lower") elif (boost.stat == pokemon.DEF): if (boost_target.increment_def(boost.amount) == False): # debug.db(dbflag, "DEF can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s defence can't go any higher") else: log.message(target.template.species + "'s defence can't go any lower") elif (boost.stat == pokemon.SPA): if (boost_target.increment_spa(boost.amount) == False): # debug.db(dbflag, "SPA can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s special attack can't go any higher") else: log.message(target.template.species + "'s special attack can't go any lower") elif (boost.stat == pokemon.SPD): if (boost_target.increment_spd(boost.amount) == False): # debug.db(dbflag, "SPD can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s special defence can't go any higher") else: log.message(target.template.species + "'s special defence can't go any lower") elif (boost.stat == pokemon.SPE): if (boost_target.increment_spe(boost.amount) == False): # debug.db(dbflag, "SPE can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s speed can't go any higher") else: log.message(target.template.species + "'s speed can't go any lower") elif (boost.stat == pokemon.ACC): if (boost_target.increment_acc(boost.amount) == False): # debug.db(dbflag, "ACC can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s accuracy can't go any higher") else: log.message(target.template.species + "'s accuracy can't go any lower") elif (boost.stat == pokemon.EVA): if (boost_target.increment_eva(boost.amount) == False): # debug.db(dbflag, "EVA can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s evasiveness can't go any higher") else: log.message(target.template.species + "'s evasiveness can't go any lower") if (target.fainted == True): log.message(target.template.species + " fainted") return user.status.onHit(target, user, move) for second in move.secondary: if (fakerandom.fakerandom() * 100 <= second.chance): second_target = None if (second.target == moves.SELF): second_target = user else: second_target = target status.battle_status[second.stat].onStart(second_target)
def play_turn(self, player1action, player2action, show_logs=True): if show_logs: log.message = log.do_print else: log.message = log.dont_print self.turncount += 1 # both players switch (order doesn't matter) if (player1action.action == player.SWITCH and player2action.action == player.SWITCH): self.switch(player1action.user, player1action.target) self.switch(player2action.user, player2action.target) elif (player1action.action == player.SWITCH or player2action.action == player.SWITCH): # just player 1 switches - takes priority over all moves implemented so far if (player1action.action == player.SWITCH and player1action.user.fainted == False): if (player2action.user.fainted == False): # player2action.target.onBeforeSwitchOut(self.active2, self.active1) self.switch(player1action.user, player1action.target) if (player2action.action == player.ATTACK and player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # just player 2 switches - takes priority over all moves implemented so far if (player2action.action == player.SWITCH and player2action.user.fainted == False): if (player1action.user.fainted == False): # player1action.target.onBeforeSwitchOut(self.active1, self.active2) self.switch(player2action.user, player2action.target) if (player1action.action == player.ATTACK and player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) elif (player1action.action == player.ATTACK and player2action.action == player.ATTACK): if (player1action.target.priority == player2action.target.priority ): # pokemon 1 is faster # check to see if status affects speed if (self.active1.status.onModifySpe(self.active1.speed, self.active1) > self.active2.status.onModifySpe( self.active2.speed, self.active2)): # pokemon 1 is alive, use move first if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # pokemon 2 is alive, use move second if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 2 is faster # check to see if status affects speed elif (self.active1.status.onModifySpe(self.active1.speed, self.active1) < self.active2.status.onModifySpe( self.active2.speed, self.active2)): # pokemon 2 is alive, use move first if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 1 is alive, use move second if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # speeds are equal, random order else: if (fakerandom.fakerandom() < 0.5): # pokemon 1 is alive, use move first if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # pokemon 2 is alive, use move second if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) else: # pokemon 2 is alive, use move first if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 1 is alive, use move second if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) elif (player1action.target.priority > player2action.target.priority): # pokemon 1 is alive, use move first if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) # pokemon 2 is alive, use move second if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) else: # pokemon 2 is alive, use move first if (player2action.user.fainted == False): self.move(player2action.user, self.active1, player2action.target) # pokemon 1 is alive, use move second if (player1action.user.fainted == False): self.move(player1action.user, self.active2, player1action.target) if (self.get_winner() != None): return else: debug.db( dbflag, "UNEXPECTED COMBINATION OF ACTIONS: " + str(player1action.action) + " and " + str(player2action.action)) if self.active1.status is not None and self.active2.status is not None: if (self.active1.status.onResidualOrder <= self.active2.status.onResidualOrder): self.active1.status.onResidual(self.active1) self.active2.status.onResidual(self.active2) else: self.active2.status.onResidual(self.active2) self.active1.status.onResidual(self.active1) log.message = log.do_print if show_logs: self.json_out() return self.get_winner()
def move(self, user, opponent, move): statuslist = [] # try: statuslist = sorted([user.status] + user.volatiles, key=lambda x: x.onBeforeMovePriority) # except: # pass target = None if (move.target == moves.SELF): target = user elif (move.target == moves.FOE): target = opponent else: debug.db(dbflag, "UNEXPECTED MOVE TARGET: " + str(move.target)) sys.exit() for st in statuslist: onBeforeMove = st.onBeforeMove(user, target, move) # if (onBeforeMove != None and onBeforeMove[0] == False): # Call onBeforeMove flag function first if it exists if (onBeforeMove != None and onBeforeMove == False): # log.message(user.template.species + " couldn't use " + move.name + " due to " + str(onBeforeMove[1])) debug.db(dbflag, "Move failed onBeforeMove") return log.message(user.template.species + " used " + move.name) move.pp -= 1 # Call move onTry function if it exists onTry = move.onTry(user, target, move) # if (onTry != None and onTry[0] == False): if (onTry != None and onTry == False): # log.message(user.template.species + onTry[1]) debug.db(dbflag, "Move failed onTry") return # Call move onTryHit function if it exists onTryHit = move.onTryHit(user) if (onTryHit != None and onTryHit == False): # log.message(move.name + " failed because " + user.template.species + onTryHit[1]) debug.db(dbflag, "Move failed onTryHit") return # if the target is invulnerable, we don't hit if target.invulnerable_source is not None: log.message("But it missed") return # Check is move has any special accuracy characteristics accuracy = move.onMoveAccuracy() damage = 0 if (accuracy == None): accuracy = 1 accuracy = accuracy * move.accuracy * self.get_accuracy_modifier( user.acc_stage) / self.get_accuracy_modifier(target.eva_stage) # Multihit move calculation if move.num_hits == 1: if (accuracy < 0): damage = self.get_damage(user, target, move) target.damage(damage) elif (fakerandom.fakerandom() * 100 < accuracy): damage = self.get_damage(user, target, move) target.damage(damage) else: log.message("But it missed") debug.db(dbflag, "Move missed/failed") return if user.fainted_self: if (target.fainted == True): log.message(target.template.species + " fainted") user.damage(sys.maxint) log.message(user.template.species + " fainted") return else: hit_count = 0 for i in range(0, move.num_hits): damage = 0 if (accuracy < 0): damage = self.get_damage(user, target, move) target.damage(damage) hit_count += 1 elif (fakerandom.fakerandom() * 100 < accuracy): damage = self.get_damage(user, target, move) target.damage(damage) hit_count += 1 log.message("It hit " + str(hit_count) + " times!") # Call move on start method if it exists move.onStart(target) # Call move onHit method if it exists move.onHit(target) # Drain health from user if applicable if (move.drain != 0): user.heal(int(move.drain * damage)) # Apply status boosts for boost in move.boosts: if (fakerandom.fakerandom() * 100 <= boost.chance): boost_target = None if (boost.target == moves.SELF): boost_target = user else: boost_target = target if (boost.stat == pokemon.ATK): if (boost_target.increment_atk(boost.amount) == False): # debug.db(dbflag, "ATK can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s attack can't go any higher") else: log.message(target.template.species + "'s attack can't go any lower") elif (boost.stat == pokemon.DEF): if (boost_target.increment_def(boost.amount) == False): # debug.db(dbflag, "DEF can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s defence can't go any higher") else: log.message(target.template.species + "'s defence can't go any lower") elif (boost.stat == pokemon.SPA): if (boost_target.increment_spa(boost.amount) == False): # debug.db(dbflag, "SPA can't go any higher/lower") if (boost.amount > 0): log.message( target.template.species + "'s special attack can't go any higher") else: log.message(target.template.species + "'s special attack can't go any lower") elif (boost.stat == pokemon.SPD): if (boost_target.increment_spd(boost.amount) == False): # debug.db(dbflag, "SPD can't go any higher/lower") if (boost.amount > 0): log.message( target.template.species + "'s special defence can't go any higher") else: log.message( target.template.species + "'s special defence can't go any lower") elif (boost.stat == pokemon.SPE): if (boost_target.increment_spe(boost.amount) == False): # debug.db(dbflag, "SPE can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s speed can't go any higher") else: log.message(target.template.species + "'s speed can't go any lower") elif (boost.stat == pokemon.ACC): if (boost_target.increment_acc(boost.amount) == False): # debug.db(dbflag, "ACC can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s accuracy can't go any higher") else: log.message(target.template.species + "'s accuracy can't go any lower") elif (boost.stat == pokemon.EVA): if (boost_target.increment_eva(boost.amount) == False): # debug.db(dbflag, "EVA can't go any higher/lower") if (boost.amount > 0): log.message(target.template.species + "'s evasiveness can't go any higher") else: log.message(target.template.species + "'s evasiveness can't go any lower") # Check for death of pokemon if (target.fainted == True): log.message(target.template.species + " fainted") return # Apply status user.status.onHit(target, user, move) # Apply secondary status effects for second in move.secondary: if (fakerandom.fakerandom() * 100 <= second.chance): second_target = None if (second.target == moves.SELF): second_target = user else: second_target = target status.battle_status[second.stat].onStart(second_target)