import {EquipmentSlot,world} from "@minecraft/server";
import { getScore } from "../../utils/score";



export function equipmentWork(player){
    
    const equipment = player.getComponent('equippable');
    const head = equipment.getEquipment(EquipmentSlot.Head);
    const chest = equipment.getEquipment(EquipmentSlot.Chest);
    const legs = equipment.getEquipment(EquipmentSlot.Legs);
    const feet = equipment.getEquipment(EquipmentSlot.Feet);
    crabChestplate(player,chest)
    furChestplate(player,chest)
    furBoots(player,feet)
    PenguinLeggings(player,legs)
    furHelmet(player,head)
    furLeggings(player,legs)
}
function crabChestplate(player,armor){
    if(armor?.typeId == 'edx:crab_chestplate' && player.isInWater)
    {
      player.addEffect("haste", 60,{ amplifier: 1 ,showParticles: false});
    }
}
function furBoots(player,armor){
    if(armor?.typeId == 'edx:fur_boots') {player.addTag('fur_boots')}
    else {player.removeTag('fur_boots')}
}
function PenguinLeggings(player,armor){
    if(armor?.typeId == 'edx:penguin_leggings') {player.addTag('penguin_leggings')}
    else {player.removeTag('penguin_leggings')}
}
function furHelmet(player,armor){
    if(armor?.typeId == 'edx:fur_helmet') {player.addTag('fur_helmet')}
    else {player.removeTag('fur_helmet')}
}
function furChestplate(player,armor)
{
    if (armor?.typeId == 'edx:fur_chestplate' && player.hasTag("frozen")) {
        let health = player.getComponent("health")
        health.setCurrentValue(health.currentValue+0.20)
    }
}
function furLeggings(player,armor)
{
    if (armor?.typeId == 'edx:fur_leggings' && player.hasTag("frozen")) {
        player.removeEffect("slowness");
    }
}



export function bouncingBootsGround(entity)
{
    const boots = entity.getComponent("equippable").getEquipment("Feet")?.typeId == "edx:bouncing_boots"
    var distance = getScore(entity,'Height') - entity.location.y
    if(distance>50)
       distance = 50
    if(boots && distance>1)
    {
      const strength = -(0.6 ** (distance)) + 0.08*distance + 1
      entity.applyKnockback({x:0,z:0},strength*0.60);
    }
}

export function bouncingBootsAir(entity)
{
    entity.runCommand(`scoreboard players set @s Height ${Math.round(entity.location.y)}`)
}