def __init__(self, name: str, level: int): self.name = normalize_name(name) self.base_name = self.name self.level = level try: self.base_stats = pokedex[self.name][constants.BASESTATS] except KeyError: logger.info("Could not pokedex entry for {}".format(self.name)) self.name = [k for k in pokedex if self.name.startswith(k)][0] logger.info("Using {} instead".format(self.name)) self.base_stats = pokedex[self.name][constants.BASESTATS] self.stats = calculate_stats(self.base_stats, self.level) self.max_hp = self.stats.pop(constants.HITPOINTS) self.hp = self.max_hp if self.name == 'shedinja': self.max_hp = 1 self.hp = 1 self.ability = None self.types = pokedex[self.name][constants.TYPES] self.item = constants.UNKNOWN_ITEM self.fainted = False self.moves = [] self.status = None self.volatile_statuses = [] self.boosts = defaultdict(lambda: 0) self.can_mega_evo = False self.can_ultra_burst = False self.is_mega = False self.can_have_choice_item = True
def __init__(self, name: str, level: int): self.name = normalize_name(name) self.base_name = self.name self.level = level self.base_stats = pokedex[self.name][constants.BASESTATS] self.stats = calculate_stats(self.base_stats, self.level) self.max_hp = self.stats.pop(constants.HITPOINTS) self.hp = self.max_hp if self.name == 'shedinja': self.max_hp = 1 self.hp = 1 self.ability = normalize_name( pokedex[self.name][constants.MOST_LIKELY_ABILITY]) self.types = pokedex[self.name][constants.TYPES] self.item = 'unknown' self.fainted = False self.moves = [] self.status = None self.volatile_statuses = [] self.boosts = defaultdict(lambda: 0) self.can_mega_evo = False self.can_ultra_burst = True
def set_spread(self, nature, evs): hp_percent = self.hp / self.max_hp self.stats = calculate_stats(self.base_stats, self.level, evs=evs, nature=nature) self.max_hp = self.stats.pop(constants.HITPOINTS) self.hp = self.max_hp * hp_percent
def switch_or_drag(battle, split_msg): if is_opponent(battle, split_msg): side = battle.opponent logger.debug("Opponent has switched - clearing the last used move") else: side = battle.user side.side_conditions[constants.TOXIC_COUNT] = 0 if side.active is not None: # set the pkmn's types back to their original value if the types were changed if constants.TYPECHANGE in side.active.volatile_statuses: original_types = pokedex[side.active.name][constants.TYPES] logger.debug( "{} had it's type changed - changing its types back to {}". format(side.active.name, original_types)) side.active.types = original_types # if the target was transformed, reset its transformed attributes if constants.TRANSFORM in side.active.volatile_statuses: logger.debug( "{} was transformed. Resetting its transformed attributes". format(side.active.name)) side.active.stats = calculate_stats(side.active.base_stats, side.active.level) side.active.ability = None side.active.moves = [] side.active.types = pokedex[side.active.name][constants.TYPES] # reset the boost of the pokemon being replaced side.active.boosts.clear() # reset the volatile statuses of the pokemon being replaced side.active.volatile_statuses.clear() # reset toxic count for this side side.side_conditions[constants.TOXIC_COUNT] = 0 # check if the pokemon exists in the reserves # if it does not, then the newly-created pokemon is used (for formats without team preview) pkmn = Pokemon.from_switch_string(split_msg[3]) pkmn = find_pokemon_in_reserves(pkmn.name, side.reserve) if pkmn is None: pkmn = Pokemon.from_switch_string(split_msg[3]) else: side.reserve.remove(pkmn) side.last_used_move = LastUsedMove(pokemon_name=None, move='switch {}'.format(pkmn.name), turn=battle.turn) # pkmn != active is a special edge-case for Zoroark if side.active is not None and pkmn != side.active: side.reserve.append(side.active) side.active = pkmn if side.active.name in constants.UNKOWN_POKEMON_FORMES: side.active = Pokemon.from_switch_string(split_msg[3])
def set_spread(self, nature, evs): evs = [int(e) for e in evs.split(',')] hp_percent = self.hp / self.max_hp self.stats = calculate_stats(self.base_stats, self.level, evs=evs, nature=nature) self.max_hp = self.stats.pop(constants.HITPOINTS) self.hp = self.max_hp * hp_percent
def __init__(self, name: str, level: int): # Single Number, Should be 1-hot (1136) self.name = normalize_name(name) self.base_name = self.name # Single Number, ignore the level because we assume Lv100 # if it's not level 100, it would be encoded in name (e.g. Rattata) self.level = level try: self.base_stats = pokedex[self.name][constants.BASESTATS] except KeyError: logger.info("Could not pokedex entry for {}".format(self.name)) self.name = [k for k in pokedex if self.name.startswith(k)][0] logger.info("Using {} instead".format(self.name)) self.base_stats = pokedex[self.name][constants.BASESTATS] # 6 numbers self.stats = calculate_stats(self.base_stats, self.level) # can ignore max_hp because it's noisy (hp% is pretty much all we care/know) self.max_hp = self.stats.pop(constants.HITPOINTS) # 1 number as percent self.hp = self.max_hp if self.name == 'shedinja': self.max_hp = 1 self.hp = 1 # TODO: Encode, currently not neccessary self.ability = None # Number between 1-17 self.types = pokedex[self.name][constants.TYPES] # should be ignored in the vector since we have no list of items available # closest item encoding we have is in that boolean below for life orb / choice self.item = constants.UNKNOWN_ITEM # Single number (0,1) self.fainted = False # for now, ignore. maybe one-hot encode moves later? self.moves = [] # one hot encoding for all statuses (0 or 1) # burn, freeze, sleep, paralysis, poison, badly poison (6 total) # badly poison ranges from 0-6, since there are poison stages self.status = None # 5 total volatile statuses # confusion, leech seed, substitute, taunt, partially trapped, transformed self.volatile_statuses = [] # 7 stat boost numbers (-6 to 6 for each stat) self.boosts = defaultdict(lambda: 0) # ignore self.can_mega_evo = False self.can_ultra_burst = False self.can_dynamax = False self.is_mega = False # either choice or life orb, so these are opposing or both 0 self.can_have_choice_item = True self.can_have_life_orb = True