{
  name: "Golden Poison Womb",
  rating: 5,
  flags: {},
  onStart(pokemon) {
    pokemon.goldenPoisonWombActive = true;
    pokemon.goldenPoisonWombFormulaTurn = -1;
    pokemon.goldenPoisonWombLockedPoison = pokemon.goldenPoisonWombLockedPoison || {};
    this.add("-activate", pokemon, "ability: Golden Poison Womb");
  },
  onBasePowerPriority: 20,
  onBasePower(basePower, attacker, defender, move) {
    if (!attacker || !attacker.hasAbility("goldenpoisonwomb")) return;
    if (move?.type !== "Poison") return;
    return this.chainModify(1.5);
  },
  onResidualOrder: 5,
  onResidual(pokemon) {
    if (!pokemon || !pokemon.hasAbility("goldenpoisonwomb") || pokemon.fainted) return;
    const formulas = ["nerve", "corrosive", "blood", "anesthetic", "adaptation"];
    const formula = formulas[this.random(formulas.length)];
    pokemon.goldenPoisonWombActive = true;
    pokemon.goldenPoisonWombFormula = formula;
    pokemon.goldenPoisonWombFormulaTurn = this.turn;
    pokemon.goldenPoisonWombLockedPoison = pokemon.goldenPoisonWombLockedPoison || {};
    const abilityEffect = this.dex.abilities.get("goldenpoisonwomb");
    this.add("-activate", pokemon, "ability: Golden Poison Womb");
    this.add("-start", pokemon, "goldenpoisonwomb" + formula);
    for (const target of pokemon.foes()) {
      if (!target || target.fainted) continue;
      const poisonImmuneType = target.hasType("Poison") || target.hasType("Steel");
      const poisonBypass = formula === "adaptation";
      if (!target.status && (!poisonImmuneType || poisonBypass)) {
        const poisoned = target.setStatus("tox", pokemon, abilityEffect, poisonBypass);
        if (poisoned) pokemon.goldenPoisonWombLockedPoison[target.uuid] = "tox";
      } else if (target.status === "psn" || target.status === "tox") {
        pokemon.goldenPoisonWombLockedPoison[target.uuid] = "tox";
      }
      const poisonedNow = target.status === "psn" || target.status === "tox";
      if (!poisonImmuneType || poisonBypass) {
        const divisor = formula === "blood" ? 4 : 8;
        this.damage(Math.max(1, Math.floor((target.baseMaxhp || target.maxhp) / divisor)), target, pokemon, abilityEffect);
      }
      if (!poisonedNow) continue;
      if (formula === "nerve") {
        this.boost({ spe: -1 }, target, pokemon, null, true);
        if (this.randomChance(45, 100)) target.addVolatile("ashisogijizonerve", pokemon, abilityEffect);
      } else if (formula === "corrosive") {
        this.boost({ def: -1, spd: -1 }, target, pokemon, null, true);
      } else if (formula === "blood") {
        if (this.randomChance(1, 2)) {
          this.boost({ spe: -1 }, target, pokemon, null, true);
        } else {
          this.boost({ spd: -1 }, target, pokemon, null, true);
        }
      } else if (formula === "anesthetic") {
        this.boost({ accuracy: -1 }, target, pokemon, null, true);
        if (this.randomChance(1, 2)) {
          this.boost({ spe: -1 }, target, pokemon, null, true);
        } else {
          this.boost({ spd: -1 }, target, pokemon, null, true);
        }
      } else if (formula === "adaptation") {
        this.boost({ spd: -1 }, target, pokemon, null, true);
      }
    }
  },
  onEnd(pokemon) {
    delete pokemon.goldenPoisonWombActive;
    delete pokemon.goldenPoisonWombFormula;
    delete pokemon.goldenPoisonWombFormulaTurn;
    delete pokemon.goldenPoisonWombLockedPoison;
  }
}
