{
  name: "Cold Prodigy",
  rating: 4.5,
  flags: {},
  onStart(pokemon) {
    this.add("-ability", pokemon, "Cold Prodigy");
    this.field.setWeather("snow", pokemon);
  },
  onDamagePriority: -100,
  onDamage(damage, target, source, effect) {
    if (!target || target.fainted || !target.hp || typeof damage !== "number") return;
    if (target.bleachCaptainAwakened || target.transformed) return;
    const speciesId = (target.species?.id || "").toLowerCase();
    const speciesName = String(target.species?.name || "");
    const baseSpeciesName = String(target.baseSpecies?.baseSpecies || target.species?.baseSpecies || target.baseSpecies?.name || speciesName || "");
    if (speciesId === "hitsugayamega" || speciesId === "hitsugayabankai" || speciesName === "Hitsugaya-Mega" || speciesName === "Hitsugaya-Bankai" || speciesName.endsWith("-Mega") || speciesName.endsWith("-Bankai")) return;
    if (baseSpeciesName !== "Hitsugaya" && speciesName !== "Hitsugaya" && speciesId !== "hitsugaya") return;
    if (target.hp - damage > target.maxhp * 0.30) return;
    target.bleachCaptainAwakened = true;
    const abilityEffect = this.dex.abilities.get("coldprodigy");
    this.add("-activate", target, "ability: Cold Prodigy");
    if (!target.formeChange("Hitsugaya-Bankai", abilityEffect, true)) {
      target.bleachCaptainAwakened = false;
      return;
    }
    target.canMegaEvo = null;
    const hpBaseStat = target.species.baseStats?.hp ?? target.species.baseStats?.["hp"] ?? 1;
    const hpIV = target.set?.ivs?.hp ?? 31;
    const hpEV = target.set?.evs?.hp ?? 0;
    target.baseMaxhp = Math.floor((Math.floor(2 * hpBaseStat + hpIV + Math.floor(hpEV / 4) + 100) * target.level) / 100 + 10);
    const newMaxHP = target.volatiles?.["dynamax"] ? 2 * target.baseMaxhp : target.baseMaxhp;
    target.maxhp = newMaxHP;
    target.hp = newMaxHP;
    this.add("-heal", target, target.getHealth, "[from] ability: Cold Prodigy");
    return 0;
  },
  onResidualOrder: 29,
  onResidual(pokemon) {
    if (!pokemon || pokemon.fainted || !pokemon.hp) return;
    if (pokemon.bleachCaptainAwakened || pokemon.transformed) return;
    const speciesId = (pokemon.species?.id || "").toLowerCase();
    const speciesName = String(pokemon.species?.name || "");
    const baseSpeciesName = String(pokemon.baseSpecies?.baseSpecies || pokemon.species?.baseSpecies || pokemon.baseSpecies?.name || speciesName || "");
    if (speciesId === "hitsugayamega" || speciesId === "hitsugayabankai" || speciesName === "Hitsugaya-Mega" || speciesName === "Hitsugaya-Bankai" || speciesName.endsWith("-Mega") || speciesName.endsWith("-Bankai")) return;
    if (baseSpeciesName !== "Hitsugaya" && speciesName !== "Hitsugaya" && speciesId !== "hitsugaya") return;
    if (pokemon.hp > pokemon.maxhp * 0.30) return;
    pokemon.bleachCaptainAwakened = true;
    const abilityEffect = this.dex.abilities.get("coldprodigy");
    this.add("-activate", pokemon, "ability: Cold Prodigy");
    if (!pokemon.formeChange("Hitsugaya-Bankai", abilityEffect, true)) {
      pokemon.bleachCaptainAwakened = false;
      return;
    }
    pokemon.canMegaEvo = null;
    const hpBaseStat = pokemon.species.baseStats?.hp ?? pokemon.species.baseStats?.["hp"] ?? 1;
    const hpIV = pokemon.set?.ivs?.hp ?? 31;
    const hpEV = pokemon.set?.evs?.hp ?? 0;
    pokemon.baseMaxhp = Math.floor((Math.floor(2 * hpBaseStat + hpIV + Math.floor(hpEV / 4) + 100) * pokemon.level) / 100 + 10);
    const newMaxHP = pokemon.volatiles?.["dynamax"] ? 2 * pokemon.baseMaxhp : pokemon.baseMaxhp;
    pokemon.maxhp = newMaxHP;
    pokemon.hp = newMaxHP;
    this.add("-heal", pokemon, pokemon.getHealth, "[from] ability: Cold Prodigy");
  },
  onModifyMove(move, pokemon) {
    if (!pokemon || !pokemon.hasAbility?.("coldprodigy")) return;
    if (!this.field.isWeather(["snow"])) return;
    if (move.type === "Ice") {
      move.accuracy = true;
      const secondary = move.secondary;
      if (secondary?.status === "frz" && typeof secondary.chance === "number") {
        move.secondary = {...secondary, chance: Math.min(100, secondary.chance + 15)};
      }
      if (move.secondaries) {
        move.secondaries = move.secondaries.map(sec => sec?.status === "frz" && typeof sec.chance === "number" ? {...sec, chance: Math.min(100, sec.chance + 15)} : sec);
      }
    }
    if (move.type === "Water") {
      move.type = "Ice";
      move.accuracy = true;
    }
  },
  onSourceBasePowerPriority: 20,
  onSourceBasePower(basePower, attacker, defender, move) {
    if (!defender || !defender.hasAbility?.("coldprodigy")) return;
    if (!this.field.isWeather(["snow"])) return;
    if (move?.type === "Water") return this.chainModify(0.5);
  },
  onSourceModifyDamagePriority: -5,
  onSourceModifyDamage(damage, source, target, move) {
    if (!target || !target.hasAbility?.("coldprodigy") || !source || !move) return;
    if (target.hitsugayaIceCloneUsed) return;
    const hitData = target.getMoveHitData?.(move);
    const typeMod = hitData?.typeMod ?? 0;
    if (typeMod <= 0) return;
    target.hitsugayaIceCloneUsed = true;
    this.add("-activate", target, "ability: Cold Prodigy");
    this.boost({spe: -1}, source, target, null, true);
    return this.chainModify(0.5);
  }
}
