var utils = implement("fiskheroes:external/utils");
var landing = implement("fiskheroes:external/superhero_landing");

function init(hero) {
    hero.setName("Puss In Boots");
    hero.addKeyBindFunc("TENTACLES", StartClimb, "Climb", 3);
    hero.setTier(1);

    hero.setHelmet("item.superhero_armor.piece.head");
    hero.setChestplate("item.superhero_armor.piece.torso");
    hero.setLeggings("item.superhero_armor.piece.legs");
    hero.setBoots("item.superhero_armor.piece.boots");

    hero.addPowers("pkg:puss_in_boots");
    hero.addAttribute("PUNCH_DAMAGE", 1.0, 0);
    hero.addAttribute("WEAPON_DAMAGE", 1.5, 0);
    hero.addAttribute("SPRINT_SPEED", 0.15, 1);
    hero.addAttribute("JUMP_HEIGHT", 1.0, 0);
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);

    hero.addKeyBind("BLADE", "Sword", 1);

    hero.addAttributeProfile("BLADE", swordProfile);
    hero.setAttributeProfile(getProfile);
    hero.setDamageProfile(getProfile);
    hero.addDamageProfile("BLADE", { "types": { "BLUNT": 1.0 } });	

    hero.addSoundEvent("MASK_OPEN", "pkg:puss_in_boots_1");

    hero.addSoundEvent("WEAPON_EQUIP", "pkg:sword_on");
    hero.addSoundEvent("WEAPON_UNEQUIP", "pkg:sword_off");

    hero.setDefaultScale(0.4);
    hero.setHasProperty(hasProperty);
    hero.setTickHandler((entity, manager) => {
        utils.flightOnIntangibility(entity, manager);
        landing.tick(entity, manager);

        var value = entity.getData("pkg:dyn/climb");
        if (entity.getData('fiskheroes:tentacle_lift')) {
            if (entity.motionY() > 0.05 || entity.isSneaking() && entity.world().getBlock(entity.pos().add(0, -1, 0)) == 'minecraft:air') {
                manager.setData(entity, "pkg:dyn/climb", value + 0.1);
            }
        } else if (!entity.getData('fiskheroes:tentacle_lift') && value != 0) {
            manager.setData(entity, "pkg:dyn/climb", 0);
            manager.setData(entity, "pkg:dyn/climb_bool", false);
        }
        if (entity.getData("fiskheroes:tentacles") == null && entity.getData('fiskheroes:tentacle_lift')) {
            manager.setData(entity, "fiskheroes:tentacle_lift", false);
        } else if (entity.getData("fiskheroes:tentacles") != null && !entity.getData('fiskheroes:tentacle_lift')) {
            manager.setData(entity, "fiskheroes:tentacle_lift", true);
        }
    });
}

function hasProperty(entity, property) {
    return property == "MASK_TOGGLE";
}

function isModifierEnabled(entity, modifier) {
    var syaw = entity.getData("pkg:dyn/startedyaw");
    var yaw = entity.rotYaw();
    var pitch = entity.rotPitch();
    var Jump = entity.getData("pkg:dyn/jump");
    var YDif = Math.round(entity.posY()) - entity.posY();
    switch (modifier.name()) {
    } "fiskheroes:tentacles"
            if (entity.world().getBlock(entity.pos().add(0, YDif, 0.5)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(0, YDif, -0.5)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(0.5, YDif, 0)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(-0.5, YDif, 0)) == 'minecraft:air' ||

                Jump == true && entity.world().getBlock(entity.pos().add(0, YDif + 0, 1.5)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(0, YDif + 0, -2.0)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(2.0, YDif + 0, 0)) == 'minecraft:air'
                && entity.world().getBlock(entity.pos().add(-2.0, YDif + 0, 0)) == 'minecraft:air'

                || entity.isInWater() || pitch > 30 || yaw < syaw - 30 || yaw > syaw + 30 || !entity.getData("fiskheroes:speeding")) {
                return false
            };

    }

function getProfile(entity) {
    return entity.getData("fiskheroes:blade") ? "BLADE" : null;
}

function StartClimb(entity, manager) {
    manager.setData(entity, "pkg:dyn/startedclimb", true);
    manager.setData(entity, "pkg:dyn/startedyaw", entity.rotYaw());
    var syaw = entity.getData("pkg:dyn/startedyaw");
    return true;
}

function swordProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 17.5, 0);
}