def init_battle(self): if self.battlefield.turns > 0: if __debug__: log.e('Trying to initialize battle already in progress:\n\n%r', self.battlefield) return sides = self.battlefield.sides if __debug__: log.i('Starting battle: %s %s', sides[0], sides[1]) leads = sorted([side.active_pokemon for side in sides], key=lambda p: (-p.calculate_stat('spe'), random.random())) for lead in leads: self.switch_in(lead) for lead in leads: self.post_switch_in(lead) self.run_update()
def heal(self, pokemon, hp, cause=None, source=None, foe=None): if pokemon.is_fainted(): if __debug__: log.e('Tried to heal fainted pokemon: %s, cause=%s, source=%s, foe=%s', pokemon, cause, source, foe) return assert isinstance(hp, int) assert hp >= 0 if foe is not None and foe.activate_effect('on_foe_heal', pokemon, hp, cause, self, failfast=True) is FAIL: return FAIL if __debug__: prev_hp = pokemon.hp pokemon.hp = min(hp + pokemon.hp, pokemon.max_hp) if __debug__: log.i('%s healed %d damage; hp=%d', pokemon, pokemon.hp - prev_hp, pokemon.hp)
def process_message(self, msg): if msg.startswith(">") or len(msg) < 2: return msg = msg.split("|") msg_type = msg[0] if msg_type == "": msg.remove("") msg_type = msg[0] if msg_type in self.IGNORE_MSGS: return if msg_type in self.BATTLE_MSGS or msg_type.startswith("-"): return self.battleclient.handle(msg_type, msg) if msg_type in self.BOT_MSGS: return getattr(self, "handle_%s" % msg_type)(msg) log.e("Unhandled msg:\n%s", msg)