{
  name: "Unrestrained Reiatsu",
  rating: 5,
  flags: {},
  foeDebuffKey(target) {
    return target.uuid || `${target.side?.id || ""}:${target.position}:${target.species?.id || target.name || ""}`;
  },
  applyFoeDebuff(source, target) {
    if (!source || source.fainted || !target || target.fainted) return;
    source.kenpachiUnrestrainedDebuffed = source.kenpachiUnrestrainedDebuffed || {};
    const key = this.effect.foeDebuffKey(target);
    if (source.kenpachiUnrestrainedDebuffed[key] === this.turn) return;
    source.kenpachiUnrestrainedDebuffed[key] = this.turn;
    this.boost({ spe: -1 }, target, source, this.dex.abilities.get("unrestrainedreiatsu"));
  },
  onStart(pokemon) {
    pokemon.kenpachiHitTurn = -1;
    this.add("-ability", pokemon, "Unrestrained Reiatsu");
    for (const target of pokemon.foes()) this.effect.applyFoeDebuff.call(this, pokemon, target);
  },
  onFoeSwitchIn(target) {
    const source = this.effectState && this.effectState.target;
    this.effect.applyFoeDebuff.call(this, source, target);
  },
  onBoost(boost, target, source, effect) {
    if (boost.atk && boost.atk < 0) delete boost.atk;
  },
  onFlinch(pokemon) {
    return false;
  },
  onModifyMove(move, pokemon) {
    if (!pokemon || !move) return;
    if (move.id === "wildswing") move.type = "Dark";
  },
  onBasePowerPriority: 20,
  onBasePower(basePower, pokemon, target, move) {
    if (!pokemon || !pokemon.hasAbility("unrestrainedreiatsu") || !move || move.category === "Status") return;
    if (move.type === "Dark" || move.type === "Fighting" || ["wildswing", "kendostrike"].includes(move.id)) return this.chainModify(1.3);
  },
  onDamagingHit(damage, target, source, move) {
    if (!target || !source || !move || !damage || !target.hasAbility("unrestrainedreiatsu")) return;
    if (target.kenpachiHitTurn === this.turn) return;
    target.kenpachiHitTurn = this.turn;
    this.boost({ atk: 1 }, target, target, this.dex.abilities.get("unrestrainedreiatsu"));
    const maxhp = target.maxhp || target.baseMaxhp || 1;
    if (damage >= maxhp / 5) this.boost({ spe: 1 }, target, target, this.dex.abilities.get("unrestrainedreiatsu"));
  }
}
