import { system } from "@minecraft/server";

export default function goodLeggingsAbility(player, duration, tier) {
  const absorptionLevel = tier; // Scale absorption level with player tier
  player.runCommandAsync(`effect "${player.name}" absorption infinite ${absorptionLevel} true`);
  player.sendMessage(
    `§aDamage taken! Absorption activated for ${duration / 1000} seconds. 60s cooldown to activate again.`
  );

  // Play sound
  player.playSound("float_ad.leggings_ability_good_tier1");

  let remainingTime = duration / 1000;
  const intervalId = system.runInterval(() => {
    if (remainingTime > 0) {
      remainingTime--;
    } else {
      system.clearRun(intervalId);
      player.runCommandAsync(`effect "${player.name}" clear absorption`);
    }
  }, 20); // 20 ticks = 1 second
}
