{
  name: "Hidden Malice",
  rating: 5,
  flags: {},
  onStart(pokemon) {
    pokemon.ginHiddenMaliceFirstMove = true;
    this.add("-ability", pokemon, "Hidden Malice");
  },
  onModifyPriority(priority, pokemon, target, move) {
    if (!pokemon || !move || move.category === "Status") return;
    if (!pokemon.ginHiddenMaliceFirstMove) return;
    this.add("-activate", pokemon, "ability: Hidden Malice");
    return priority + 1;
  },
  onAfterMoveSecondarySelf(source, target, move) {
    if (source && move && move.category !== "Status") source.ginHiddenMaliceFirstMove = false;
    if (!source || !target || !move || move.category === "Status") return;
    if (source.fainted || target.fainted) return;
    if (move.type !== "Steel") return;
    if (!move.flags?.contact && !move.flags?.slicing) return;
    target.ginSuspiciousWoundSource = source;
    target.addVolatile("suspiciouswound", source, move);
  },
  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 === "ginmega" || speciesId === "ginbankai" || speciesName === "Gin-Mega" || speciesName === "Gin-Bankai" || speciesName.endsWith("-Mega") || speciesName.endsWith("-Bankai")) return;
    if (baseSpeciesName !== "Gin" && speciesName !== "Gin" && speciesId !== "gin") return;
    if (target.hp - damage > target.maxhp * 0.30) return;
    return this.effect.awaken.call(this, target);
  },
  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 === "ginmega" || speciesId === "ginbankai" || speciesName === "Gin-Mega" || speciesName === "Gin-Bankai" || speciesName.endsWith("-Mega") || speciesName.endsWith("-Bankai")) return;
    if (baseSpeciesName !== "Gin" && speciesName !== "Gin" && speciesId !== "gin") return;
    if (pokemon.hp > pokemon.maxhp * 0.30) return;
    this.effect.awaken.call(this, pokemon);
  },
  awaken(pokemon) {
    pokemon.bleachCaptainAwakened = true;
    const abilityEffect = this.dex.abilities.get("hiddenmalice");
    this.add("-activate", pokemon, "ability: Hidden Malice");
    if (!pokemon.formeChange("Gin-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: Hidden Malice");
    for (const side of this.sides || []) {
      const mons = [...(side.active || []), ...(side.pokemon || [])];
      for (const mon of mons) {
        if (!mon || mon.fainted || mon === pokemon) continue;
        if (mon.ginSuspiciousWoundSource !== pokemon) continue;
        if (!mon.status) mon.setStatus("psn", pokemon, abilityEffect, true);
        mon.ginSuspiciousWoundSource = null;
        if (mon.volatiles?.suspiciouswound) mon.removeVolatile("suspiciouswound");
      }
    }
    return 0;
  },
  onSwitchOut(pokemon) {
    pokemon.ginHiddenMaliceFirstMove = true;
  }
}
