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

function init(hero) {
    hero.setName("Severus Snape");
    hero.setTier(5);

    hero.setChestplate("Wand");

    hero.addPowers("pkg:wizard_physiology");
    hero.addAttribute("PUNCH_DAMAGE", 5.0, 0);
    hero.addAttribute("JUMP_HEIGHT", 1.5, 0);
    hero.addAttribute("SPRINT_SPEED", 0.3, 1);
    hero.addAttribute("FALL_RESISTANCE", 3.0, 0);
    hero.addAttribute("STEP_HEIGHT", 0.5, 0);

    hero.addKeyBind("WAND", "Wand", 1);
    hero.addKeyBind("TELEKINESIS", "Levicorpus", 2);
    hero.addKeyBind("CHARGED_BEAM", "Avada KEDAVRA!!", 3);
    hero.addKeyBind("TELEPORT", "Appa", 4);
    hero.addKeyBind("CHARGE_ENERGY", "Expelliarmus", 5);
    hero.addKeyBind("SHADOWFORM", "Death Eaters", 5);
    ;
    hero.setHasProperty(hasProperty);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setModifierEnabled(isModifierEnabled);

    hero.setAttributeProfile(getProfile);
    hero.addAttributeProfile("Wand", wandProfile);

    hero.setAttributeProfile(entity => entity.hasStatusEffect("fiskheroes:eternium") ? "ETERNIUM" : null);
    hero.addAttributeProfile("ETERNIUM", profile => {
        profile.inheritDefaults();
        profile.addAttribute("PUNCH_DAMAGE", 6.5, 0);
        profile.addAttribute("SPRINT_SPEED", 0.2, 1);
        profile.addAttribute("FALL_RESISTANCE", 5.0, 1);
    });
}

function wandProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("WEAPON_DAMAGE", 4.5, 0);
    profile.addAttribute("PUNCH_DAMAGE", 6.0, 0);
    profile.addAttribute("FALL_RESISTANCE", 5.0, 0);
    profile.addAttribute("JUMP_HEIGHT", 1.5, 0);
}

function getProfile(entity) {
    if (entity.getData("pkg:dyn/wand")) {
        return "WAND";
    }

    return entity.getData("fiskheroes:dyn/steeled") ? "SHADOWFORM" : null;
}

function isModifierEnabled(entity, modifier) {
    if (modifier.name() != "fiskheroes:transformation" && modifier.name() != "fiskheroes:cooldown" && (!entity.getData("pkg:dyn/wand") || modifier.name() == entity.getData("pkg:dyn/wand_timer") < 1)) {
        return false;
        if (modifier.name() != "fiskheroes:eternium_weakness" && entity.hasStatusEffect("fiskheroes:eternium")) {
            return false;
        }
    }
    switch (modifier.name()) {
        case "fiskheroes:energy_manipulation":
            return entity.getData("pkg:dyn/wand");
        case "fiskheroes:teleportation":
            return entity.getData("pkg:dyn/wand");
        case "fiskheroes:telekinesis":
            return entity.getData("pkg:dyn/wand");
        case "fiskheroes:flight":
            return entity.getData("fiskheroes:shadowform"); 
        default:
            return true;
    }
}

function getTierOverride(entity) {
    return entity.hasStatusEffect("fiskheroes:eternium") ? 6 : 9;
}

function isKeyBindEnabled(entity, keyBind) {
    if (entity.hasStatusEffect("fiskheroes:eternium")) {
        return false;
    }
    switch (keyBind) {
        case "TELEPORT":
            return entity.getData("pkg:dyn/wand");
        case "CHARGED_BEAM":
            return entity.getData("pkg:dyn/wand");
        case "CHARGE_ENERGY":
            return entity.getData("pkg:dyn/wand");
        case "SHADOWFORM":
            return entity.isSneaking()
        case "TELEKINESIS":
            return entity.getData("pkg:dyn/wand");
        default:
            return true;
    }
}

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