import { system, world, EquipmentSlot, EntityEquippableComponent, Player } from "@minecraft/server";
//Anything in a folder in the scripts does not copy over to the dist_ builds file, do it manually!

export const getObjective = (id) => world.scoreboard.getObjective(id) ?? world.scoreboard.addObjective(id, id);

export function getEquipment(player) {
  const tick = system.currentTick;
  if (player._equip?.tick === tick) return player._equip.comp;
  const comp = player.getComponent(EntityEquippableComponent.componentId);
  player._equip = { tick, comp };
  return comp;
}

export const classTests = [
  ["_hoe", "_dagger", "_kama", "_nunchaku", "_sai"], //7 swift
  ["_pickaxe", "_cleaver"], //12 light
  ["_axe", "_shovel", "trident", "_khopesh"], //20 medium
  ["_spade", "shield"], //25 heavy
  ["_battleaxe"], //30 extreme
  ["_gladius", "_katana"], //7 swift
  ["_sword", "_broadsword", "_cutlass", "_scimitar"], //12 light
  ["_claymore", "_longsword", "_mace"], //20 medium
  ["_machete", "_scythe"], //25 heavy
  ["_greatsword", "_morningstar"], //30 extreme
  //special weapons
  ["_lance"], ["_rapier"], ["_hammer"],
];

export const cooldownMap = {
  0: 5, 1: 7, 2: 12,
  3: 20, 4: 25, 5: 30,
  6: 7, 7: 12, 8: 20,
  9: 25, 10: 30,
  //special weapons
  11: 12, 12: 7, 13: 25, /*14: 20, 15: 30,*/
};

export const commandMap = {
  6: 'htc_sweep_light',
  7: 'htc_sweep_light',
  8: 'htc_sweep_medium',
  9: 'htc_sweep_heavy',
  10: 'htc_sweep_extreme',
  //11: 'htc_stab_large',
  13: 'htc_shockwave',
};

export const standardMap = [6, 7, 8, 9, 10];

export const displayMap = {
  1: '', 2: '', 3: '', 4: '', 5: '',
  6: '', 7: '', 8: '', 9: '', 10: '',
  11: '', 12: '', 13: '', 14: '', 15: '',
  16: '', 17: '', 18: '', 19: '', 20: '',
  21: '', 22: '', 23: '', 24: '', 25: '',
  26: '', 27: '', 28: '', 29: '',
};


let playersCache;
export function getPlayers() {
  const tick = system.currentTick;
  if (playersCache?.tick === tick) return playersCache.players;
  const players = world.getPlayers();
  playersCache = { tick, players };
  return players;
}