{
  name: "Frozen Heaven",
  rating: 5,
  flags: {},
  onStart(pokemon) {
    this.add("-ability", pokemon, "Frozen Heaven");
    this.field.setWeather("snow", pokemon);
    if (this.field.weatherData) this.field.weatherData.duration = 0;
  },
  onEnd(pokemon) {
    if (!pokemon) return;
    if (this.field.isWeather(["snow"]) && this.field.weatherData?.source === pokemon) this.field.clearWeather();
  },
  onResidualOrder: 1,
  onResidual(pokemon) {
    if (!pokemon || pokemon.fainted) return;
    if (!this.field.isWeather(["snow"])) this.field.setWeather("snow", pokemon);
    if (this.field.weatherData) this.field.weatherData.duration = 0;
    if (this.field.isWeather(["snow"]) && pokemon.hp && pokemon.hp < pokemon.maxhp) this.heal(Math.max(1, Math.floor(pokemon.maxhp / 16)), pokemon, pokemon);
    const foes = pokemon.foes ? pokemon.foes() : pokemon.side?.foe?.active || [];
    for (const foe of foes) {
      if (!foe || foe.fainted) continue;
      this.boost({spe: -1}, foe, pokemon, null, true);
      if ((foe.boosts?.spe || 0) <= -2) foe.addVolatile("icebind", pokemon, null);
    }
  },
  onBasePowerPriority: 20,
  onBasePower(basePower, attacker, defender, move) {
    if (!attacker || !attacker.hasAbility("frozenheaven")) return;
    if (!this.field.isWeather(["snow"])) return;
    if (move?.type === "Ice") return this.chainModify(1.3);
  },
  onModifyMove(move, pokemon) {
    if (!pokemon || !pokemon.hasAbility?.("frozenheaven")) return;
    if (!this.field.isWeather(["snow"])) return;
    if (move.type === "Ice") move.accuracy = true;
    if (move.type === "Water") {
      move.type = "Ice";
      move.accuracy = true;
    }
  },
  onSourceBasePowerPriority: 20,
  onSourceBasePower(basePower, attacker, defender, move) {
    if (!defender || !defender.hasAbility("frozenheaven")) return;
    if (!this.field.isWeather(["snow"])) return;
    if (move?.type === "Fire") return this.chainModify(0.7);
    if (move?.type === "Water") return this.chainModify(0.5);
  },
  onDamagingHit(damage, target, source, move) {
    if (!target || target.fainted || !this.field.isWeather(["snow"])) return;
    if (move?.type === "Ice" || move?.type === "Water") this.heal(Math.max(1, Math.floor(target.maxhp / 8)), target, target);
  },
  onSourceModifyDamagePriority: -5,
  onSourceModifyDamage(damage, source, target, move) {
    if (!target || !target.hasAbility?.("frozenheaven") || !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: Frozen Heaven");
    this.boost({spe: -1}, source, target, null, true);
    return this.chainModify(0.5);
  }
}
