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

function init(hero) {
    hero.setName("Stormbreaker");
    hero.setTier(6);
    
    hero.setChestplate("Stormbreaker");

    hero.addPowers("pkg:asgardian_physiology", "pkg:stormbreaker", "pkg:god_thunder_power");
    hero.addAttribute("PUNCH_DAMAGE", 10.0, 0);
    hero.addAttribute("JUMP_HEIGHT", 1.5, 0);    
    hero.addAttribute("SPRINT_SPEED", 0.3, 1);
    hero.addAttribute("FALL_RESISTANCE", 40.0, 0);
    hero.addAttribute("STEP_HEIGHT", 0.5, 0);
    hero.addAttribute("MAX_HEALTH", 1.0, 0);

    hero.addKeyBind("STORMBREAKER", "Stormbreaker", 1);
    hero.addKeyBind("GODPOWER", "God Of Thunder", 2);
    hero.addKeyBind("CHARGED_BEAM", "Charged", 3);
    hero.addKeyBind("TELEPORT", "Bifrost", 4);
    hero.addKeyBind("CHARGE_ENERGY", "Lightning", 5);

    hero.setDefaultScale(1.1);
    hero.setHasProperty(hasProperty);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setModifierEnabled(isModifierEnabled);

    hero.setAttributeProfile(getProfile);
    hero.addAttributeProfile("STORMBREAKER", stormbreakerProfile);
    hero.addAttributeProfile("GODPOWER", godpowerProfile);
    hero.setTickHandler((entity, manager) => {
        utils.flightOnIntangibility(entity, manager);
        landing.tick(entity, manager);
    });
}

function stormbreakerProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("WEAPON_DAMAGE", 4.5, 0);
    profile.addAttribute("PUNCH_DAMAGE", 16.0, 0);
    profile.addAttribute("FALL_RESISTANCE", 85.0, 0);
    profile.addAttribute("JUMP_HEIGHT", 2.0, 0);
}

function godpowerProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("WEAPON_DAMAGE", 4.5, 0);
    profile.addAttribute("PUNCH_DAMAGE", 14.0, 0);
    profile.addAttribute("JUMP_HEIGHT", 2.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0.4, 1);
}

function getProfile(entity) {
    if (entity.getData("pkg:dyn/stormbreaker")) {
        return "STORMBREAKER";
    }
    
    return entity.getData("fiskheroes:dyn/steeled") ? "GODPOWER" : null;
}

function isModifierEnabled(entity, modifier) {
    switch (modifier.name()) {
    case "fiskheroes:lightning_cast":
            return !entity.getData("pkg:dyn/stormbreaker") && entity.getData("fiskheroes:dyn/steeled");
    case "fiskheroes:energy_manipulation":
            return entity.getData("pkg:dyn/stormbreaker");
    case "fiskheroes:teleportation":
            return entity.getData("pkg:dyn/stormbreaker");
        case "fiskheroes:flying":
            return entity.getData("pkg:dyn/stormbreaker");
        case "fiskheroes:flying":
        return entity.isOnGround();   
    default:
        return true;
    }
}

function isKeyBindEnabled(entity, keyBind) {
    switch (keyBind) {
    case "GODPOWER":
        return entity.isSneaking();
    case "TELEPORT":
            return entity.getData("pkg:dyn/stormbreaker");
    case "CHARGED_BEAM":
            return entity.getData("pkg:dyn/stormbreaker");
    case "CHARGE_ENERGY":
            return entity.getData("pkg:dyn/stormbreaker");
    default:
        return true;
    }
}

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