{
  name: "Senbonzakura Kageyoshi",
  rating: 5,
  flags: {},
  onStart(pokemon) {
    pokemon.byakuyaKageyoshiGuardUsed = false;
    if (pokemon.byakuyaHakuteikenUsed === undefined) pokemon.byakuyaHakuteikenUsed = false;
    if (pokemon.byakuyaHakuteikenSpent === undefined) pokemon.byakuyaHakuteikenSpent = false;
    this.add("-ability", pokemon, "Senbonzakura Kageyoshi");
  },
  onModifyMove(move, pokemon) {
    if (!pokemon || !move) return;
    if (move.type === "Steel" || move.type === "Fairy" || ["senbonzakura", "senbonzakurakageyoshi", "gokei", "shukeihakuteiken"].includes(move.id)) {
      if (move.flags?.contact) delete move.flags.contact;
      move.flags = {...move.flags, distance: 1, bypasssub: 1};
      move.infiltrates = true;
    }
  },
  onBasePowerPriority: 20,
  onBasePower(basePower, pokemon, target, move) {
    if (!pokemon || !pokemon.hasAbility("senbonzakurakageyoshi") || !move) return;
    if (move.type === "Steel" || move.type === "Fairy") return this.chainModify(1.5);
  },
  onModifyPriority(priority, pokemon, target, move) {
    if (!pokemon || !move || !pokemon.hasAbility("senbonzakurakageyoshi")) return;
    if (!pokemon.volatiles?.senkei) return;
    if (move.type === "Steel" && move.category !== "Status") return priority + 1;
  },
  onSourceModifyDamagePriority: -5,
  onSourceModifyDamage(damage, source, target, move) {
    if (!target || !source || !move || !target.hasAbility("senbonzakurakageyoshi")) return;
    if (move.category === "Status") return;
    if (target.volatiles?.senkei) return;
    if (target.byakuyaHakuteikenSpent) return;
    if (target.byakuyaKageyoshiGuardUsed) return;
    target.byakuyaKageyoshiGuardUsed = true;
    this.add("-activate", target, "ability: Senbonzakura Kageyoshi");
    return this.chainModify(0.75);
  },
  onDamagingHit(damage, target, source, move) {
    if (!target || !source || source === target || !move || !target.hasAbility("senbonzakurakageyoshi")) return;
    if (!this.checkMoveMakesContact(move, source, target)) return;
    this.damage(Math.max(1, Math.floor((source.maxhp || source.baseMaxhp || 1) / 8)), source, target, this.dex.abilities.get("senbonzakurakageyoshi"));
  },
  onResidualOrder: 26,
  onResidual(pokemon) {
    if (!pokemon || pokemon.fainted) return;
    pokemon.byakuyaKageyoshiGuardUsed = false;
  }
}
