def pweaknesses(self, pokemon): weaknesses = [type_.capitalize() if effectiveness(type_, pokedex[pokemon]) == 2 else self.bu(type_.capitalize()) for type_ in Type.values if effectiveness(type_, pokedex[pokemon]) > 1] resistances = [type_.capitalize() if effectiveness(type_, pokedex[pokemon]) == 0.5 else self.bu(type_.capitalize()) for type_ in Type.values if 0 < effectiveness(type_, pokedex[pokemon]) < 1] immunities = [type_.capitalize() for type_ in Type.values if effectiveness(type_, pokedex[pokemon]) == 0] return '\n'.join(['Weaknesses: ' + ', '.join(weaknesses), 'Resistances: ' + ', '.join(resistances), 'Immunities: ' + ', '.join(immunities)])
def is_immune_to(self, thing): """ `thing` may be a move Type, Status, Weather, POWDER, or Volatile """ for on_get_immunity in self.effect_handlers['on_get_immunity']: immune = on_get_immunity(thing) if immune is not None: return immune if thing in Type.values: return effectiveness(thing, self) == 0 if thing in self.STATUS_IMMUNITIES: return any(type in self.STATUS_IMMUNITIES[thing] for type in self.types) if thing is Weather.SANDSTORM: return any(type in (Type.GROUND, Type.ROCK, Type.STEEL) for type in self.types) if thing is POWDER: return Type.GRASS in self.types if thing is Weather.HAIL: return Type.ICE in self.types return False
def is_immune_to_move(self, user, move): """Return True if self is immune to move""" for on_get_immunity in self.effect_handlers['on_get_immunity']: immune = on_get_immunity(move.type) # check type immunity first, then move if immune is None: immune = on_get_immunity(move) # for bulletproof, overcoat, etc. if immune is not None: return immune if Type.GRASS in self.types and (move.is_powder or move == movedex['leechseed']): return True if move.category is MoveCategory.STATUS and move != movedex['thunderwave']: return False if user.ability is abilitydex['scrappy'] and move.type in (Type.FIGHTING, Type.NORMAL): return False return effectiveness(move.type, self) == 0
def calculate_evs_ivs(self): """ Order of stats: hp, atk, def, spa, spd, spe """ evs = [85, 85, 85, 85, 85, 85] # Use correct IVs for hiddenpower for move in self.moves: if move.is_hiddenpower: has_hiddenpower = True ivs = list(HPivs[move.type]) break else: has_hiddenpower = False ivs = [31, 31, 31, 31, 31, 31] HP, ATK, SPE = 0, 1, 5 # Adjust HP stat for substitute/bellydrum/stealthrock if self.item is itemdex['sitrusberry'] and movedex['substitute'] in self.moves: while self._calc_hp(evs[HP], ivs[HP]) % 4 > 0: evs[HP] -= 4 elif self.item is itemdex['sitrusberry'] and movedex['bellydrum'] in self.moves: if self._calc_hp(evs[HP], ivs[HP]) % 2 > 0: evs[HP] -= 4 else: # stealth rock weakness forme = self if self.item is not None and self.item.is_mega_stone: forme = pokedex[self.item.forme] elif self.name == 'castform': if self.item == itemdex['heatrock']: forme = pokedex['castformsunny'] elif self.item == itemdex['damprock']: forme = pokedex['castformrainy'] eff = effectiveness(Type.ROCK, forme) mod = None if eff == 2: mod = 4 elif eff == 4: mod = 2 if mod is not None: while self._calc_hp(evs[HP], ivs[HP]) % mod == 0: evs[HP] -= 4 # Minimize confusion damage for non-physical pokemon if (not any(move not in (movedex['seismictoss'], movedex['counter'], movedex['metalburst']) and move.category == MoveCategory.PHYSICAL for move in self.moves) and movedex['copycat'] not in self.moves and movedex['transform'] not in self.moves and len(self.moves) == 4 # for remote pokemon with unknown moves. ): evs[ATK] = 0 if has_hiddenpower: ivs[ATK] -= 30 else: ivs[ATK] = 0 # Reduce speed for gyroball/trickroom if movedex['gyroball'] in self.moves or movedex['trickroom'] in self.moves: evs[SPE] = 0 ivs[SPE] = 0 assert all(0 <= ev <= 85 for ev in evs), evs assert all(0 <= iv <= 31 for iv in ivs), ivs return evs, ivs
def on_switch_in(self, pokemon, battle): if __debug__: log.i("%s was damaged by StealthRock", pokemon) battle.damage(pokemon, pokemon.max_hp / (8.0 / effectiveness(Type.ROCK, pokemon)), Cause.HAZARD, self)
def test_type_multiplier(self): assert effectiveness(Type.GRASS, self.ferrothorn) == 0.25 assert effectiveness(Type.FIRE, self.ferrothorn) == 4 assert effectiveness(Type.ICE, self.ferrothorn) == 1 assert effectiveness(Type.FIGHTING, self.ferrothorn) == 2 assert effectiveness(Type.STEEL, self.ferrothorn) == 0.5 assert effectiveness(Type.NOTYPE, self.ferrothorn) == 1 assert effectiveness(Type.WATER, self.arcanine) == 2 assert effectiveness(Type.NORMAL, self.arcanine) == 1 assert effectiveness(Type.FAIRY, self.arcanine) == 0.5 assert effectiveness(Type.NOTYPE, self.arcanine) == 1 assert effectiveness(Type.POISON, self.typeless) == 1 assert effectiveness(Type.NOTYPE, self.typeless) == 1