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 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 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 get_pokemon_from_list(pokemonlist): species = "" level = 0 hpiv = 0 atkiv = 0 defiv = 0 spaiv = 0 spdiv = 0 speiv = 0 hpev = 0 atkev = 0 defev = 0 spaev = 0 spdev = 0 speev = 0 atk1 = "" ppup1 = 0 atk2 = "" ppup2 = 0 atk3 = "" ppup3 = 0 atk4 = "" ppup4 = 0 nature = "" gender = None ability = "" item = None for line in pokemonlist: formattedline = line.strip() if (formattedline[:6] == "[HPIV]"): hpiv = int(formattedline[6:]) if (0 > hpiv > 31): debug.db(dbflag, "HPIV: " + str(hpiv) + " out of range for " + species) return None elif (formattedline[:6] == "[HPEV]"): hpev = int(formattedline[6:]) if (0 > hpev > 255): debug.db(dbflag, "HPEV: " + str(hpev) + " out of range " + species) return None elif (formattedline[:6] == "[ATKEV]"): atkev = int(formattedline[6:]) if (0 > atkev > 255): debug.db(dbflag, "ATKEV: " + str(atkev) + " out of range " + species) return None elif (formattedline[:6] == "[DEFEV]"): defev = int(formattedline[6:]) if (0 > defev > 255): debug.db(dbflag, "DEFEV: " + str(defev) + " out of range " + species) return None elif (formattedline[:6] == "[SPAEV]"): spaev = int(formattedline[6:]) if (0 > spaev > 255): debug.db(dbflag, "SPAEV: " + str(spaev) + " out of range " + species) return None elif (formattedline[:6] == "[SPDEV]"): spdev = int(formattedline[6:]) if (0 > spdev > 255): debug.db(dbflag, "SPDEV: " + str(spdev) + " out of range " + species) return None elif (formattedline[:6] == "[SPEEV]"): speev = int(formattedline[6:]) if (0 > speev > 255): debug.db(dbflag, "SPEEV: " + str(speev) + " out of range " + species) return None elif (formattedline[:6] == "[ATK1]"): atk1 = formattedline[6:] if (not atk1 in learnsets.learnset_list[species]): debug.db(dbflag, atk1 + " is not a valid move for " + species) return None elif (formattedline[:6] == "[ATK2]"): atk2 = formattedline[6:] if (not atk2 in learnsets.learnset_list[species]): debug.db(dbflag, atk2 + " is not a valid move for " + species) return None elif (formattedline[:6] == "[ATK3]"): atk3 = formattedline[6:] if (not atk3 in learnsets.learnset_list[species]): debug.db(dbflag, atk3 + " is not a valid move for " + species) return None elif (formattedline[:6] == "[ATK4]"): atk4 = formattedline[6:] if (not atk4 in learnsets.learnset_list[species]): debug.db(dbflag, atk4 + " is not a valid move for " + species) return None elif (formattedline[:7] == "[ATKIV]"): atkiv = int(formattedline[7:]) if (0 > atkiv > 31): debug.db( dbflag, "ATKIV: " + str(atkiv) + " out of range for " + species) return None elif (formattedline[:7] == "[DEFIV]"): defiv = int(formattedline[7:]) if (0 > defiv > 31): debug.db( dbflag, "DEFIV: " + str(defiv) + " out of range for " + species) return None elif (formattedline[:7] == "[SPAIV]"): spaiv = int(formattedline[7:]) if (0 > spaiv > 31): debug.db( dbflag, "SPAIV: " + str(spaiv) + " out of range for " + species) return None elif (formattedline[:7] == "[SPDIV]"): spdiv = int(formattedline[7:]) if (0 > spdiv > 31): debug.db( dbflag, "SPDIV: " + str(spdiv) + " out of range for " + species) return None elif (formattedline[:7] == "[SPEIV]"): speiv = int(formattedline[7:]) if (0 > speiv > 31): debug.db( dbflag, "SPEIV: " + str(speiv) + " out of range for " + species) return None elif (formattedline[:7] == "[LEVEL]"): level = int(formattedline[7:]) if (1 > level > 100): debug.db( dbflag, "LEVEL " + str(level) + " is out of range for " + species) return None elif (formattedline[:7] == "[PPUP1]"): ppup1 = int(formattedline[7:]) if (0 > ppup1 > 3): debug.db( dbflag, "PPUP1 " + str(ppup1) + " is out of range for move1 for " + species) return None elif (formattedline[:7] == "[PPUP2]"): ppup2 = int(formattedline[7:]) if (0 > ppup2 > 3): debug.db( dbflag, "PPUP2 " + str(ppup2) + " is out of range for move2 for " + species) return None elif (formattedline[:7] == "[PPUP3]"): ppup3 = int(formattedline[7:]) if (0 > ppup3 > 3): debug.db( dbflag, "PPUP3 " + str(ppup3) + " is out of range for move3 for " + species) return None elif (formattedline[:7] == "[PPUP4]"): ppup4 = int(formattedline[7:]) if (0 > ppup4 > 3): debug.db( dbflag, "PPUP4 " + str(ppup4) + " is out of range for move4 for " + species) return None elif (formattedline[:8] == "[GENDER]"): if (formattedline[8:] == "NONE"): gender = None else: gender = formattedline[8:] elif (formattedline[:9] == "[SPECIES]"): species = formattedline[9:] if (hpev + atkev + defev + spaev + spdev + speev > 510): debug.db(dbflag, "EV total out of range for " + species) return None return Pokemon(species, level, gender, [hpiv, atkiv, defiv, spaiv, spdiv, speiv], [hpev, atkev, defev, spaev, spdev, speev], [(atk1, ppup1), (atk2, ppup2), (atk3, ppup3), (atk4, ppup4)])
def main(game): k = game.k # edge.owner is -1 if nobody claimed, else id of owner # game.me is our id comp = [-1] * k comp_nodes = [None] * k i = 0 for j in range(k): if comp[j] >= 0: continue comp[j] = i comp_nodes[i] = [j] to_visit = [j] while len(to_visit) > 0: n1 = to_visit.pop() for n2, e in game.nodes[n1].edges.items(): if e.owner == game.me and comp[n2] < 0: to_visit.append(n2) comp[n2] = i comp_nodes[i].append(n2) i += 1 comp_mines = [[] for i in range(k)] # c: mines of c for m in game.mines: comp_mines[comp[m]].append(m) db("The comps are:") db(comp) db(comp_mines) max_val = 0 max_e = -1 for e in game.edges: if e.owner != -1: continue comp1 = comp[e.source] comp2 = comp[e.target] if comp1 == comp2: continue val = 0 for m in comp_mines[comp1]: for n in comp_nodes[comp2]: val += game.dists[m][n] ** 2 for m in comp_mines[comp2]: for n in comp_nodes[comp1]: val += game.dists[m][n] ** 2 if val > max_val: max_val = val max_e = e if max_val == 0: for e in game.edges: if e.owner == -1: return e db ("max added value is: " + str(max_val)) db ("with edge: "+ str(max_e.source) + ' ' + str(max_e.target)) return max_e
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)