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

function init(hero) {
    hero.setName("Eugene Choi");
    hero.setTier(9);

    hero.setChestplate("Chestplate");

    hero.addPowers("pkg:shazam_physiology");
    hero.addAttribute("FALL_RESISTANCE", 1, 1);
    hero.addAttribute("PUNCH_DAMAGE", 20.0, 0);
    hero.addAttribute("SPRINT_SPEED", 0.5, 1);
    hero.addAttribute("STEP_HEIGHT", 0.5, 0);
    hero.addAttribute("IMPACT_DAMAGE", 0.5, 1);
    hero.addAttribute("BASE_SPEED_LEVELS", 5.0, 0);

    hero.setDefaultScale(defaultScale);

    hero.addKeyBind("ENERGY_PROJECTION", "Lightning Bolt", 1);
    hero.addKeyBind("CHARGED_BEAM", "Thunder Blast", 2);
    hero.addKeyBind("CHARGED_PUNCH", "Lightning Punch", 3);
    hero.addKeyBind("SUPER_SPEED", "key.superSpeed", 4);
    hero.addKeyBind("SHAZAM", "SHAZAM!", 5);
    hero.addKeyBind("TELEPORT", "Go to the Moon(You need to look to the moon)", 4);

    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);
    });

    hero.setDamageProfile(entity => !entity.getHeldItem().isWeapon() ? "PUNCH" : null);
    hero.addDamageProfile("PUNCH", {
        "types": {
            "BLUNT": 1.0,
            "MAGIC": 0.7
        }
    });


    hero.setModifierEnabled(isModifierEnabled);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.addAttributeProfile("PUNCH", punchProfile);
    hero.addAttributeProfile("BLUNT", bluntProfile);
    hero.addAttributeProfile("NOTSHAZAM", notshazamProfile);
    hero.setAttributeProfile(getAttributeProfile);
    hero.setTickHandler((entity, manager) => {
        utils.flightOnIntangibility(entity, manager);
        landing.tick(entity, manager);
    });
}

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

function isModifierEnabled(entity, modifier) {
    if (modifier.name() != "fiskheroes:transformation" && modifier.name() != "fiskheroes:cooldown" && (!entity.getData("pkg:dyn/shazam") || modifier.name() == "fiskheroes:controlled_flight" && entity.getData("pkg:dyn/shazam_timer") < 1)) {
        return false;
        if (modifier.name() != "fiskheroes:eternium_weakness" && entity.hasStatusEffect("fiskheroes:eternium")) {
            return false;
        }
    }
    return modifier.name() != "fiskheroes:super_speed" || !entity.getData("fiskheroes:flying");
    switch (modifier.name()) {
        case "fiskheroes:icicles":
            return entity.getData("fiskheroes:cryo_charge") == 1;
        default:
            return true;
    }
}

function isKeyBindEnabled(entity, keyBind) {
    if (keyBind == "SHAZAM") {
        return true;
    }
    else if (!entity.getData("pkg:dyn/shazam")) {
        return false;
    }

    if (entity.hasStatusEffect("fiskheroes:eternium")) {
        return false;
    }
    return keyBind != "SUPER_SPEED" || !entity.getData("fiskheroes:flying");

    switch (keyBind) {
        case "MECHA":
            return !entity.getData("fiskheroes:dyn/steeled");
        default:
            return true;
    }
    switch (keyBind) {
        case "SUPER_SPEED":
            return !entity.isSneaking();
        case "TELEPORT":
            return entity.isSneaking();
        default:
            return true;
    }
}
function defaultScale(entity) {
    if (!entity.getData("pkg:dyn/shazam")) {
        return 0.6;
    }
    return 1.2;
}
function punchProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 25, 0);
    profile.addAttribute("KNOCKBACK", 30.0, 0);
}

function bluntProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 20, 0);
}

function getAttributeProfile(entity) {
    if (!entity.getData("pkg:dyn/shazam")) {
        return "NOTSHAZAM";
    }
    return entity.getData("fiskheroes:punchmode") ? "PUNCH" : "BLUNT";
}
function getTierOverride(entity) {
    return entity.getData("pkg:dyn/shazam") ? 9 : 0;
}

function notshazamProfile(profile) {
    profile.revokeAugments();
}

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