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

const speedAmplifiers = [0, 1, 2]; // Speed amplifiers for each tier
const durations = [5000, 7000, 9000]; // Durations for each tier in milliseconds
const cooldowns = new Map(); // Cooldown map

export default function goodBootsAbility(
  player,
  playerTier,
  bootsTier,
  customSpeedAmplifier = null,
  customDuration = null
) {
  const now = Date.now();
  const lastUsed = cooldowns.get(player.id) || 0;

  if (now - lastUsed < 30000) {
    return; // 30 seconds cooldown
  }

  if (playerTier < bootsTier) {
    return; // Player tier is too low for the boots
  }

  const speedAmplifier = customSpeedAmplifier !== null ? customSpeedAmplifier : speedAmplifiers[bootsTier - 1] || 0;
  const duration = customDuration !== null ? customDuration : durations[bootsTier - 1] || 5000;

  player.runCommandAsync(`effect "${player.name}" speed ${duration / 1000} ${speedAmplifier} true`);
  player.playSound("float_ad.boots_ability_good");
  player.runCommandAsync(`particle float_ad:good_step ~ ~ ~`);

  cooldowns.set(player.id, now);
}
