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

function init(hero) {
    hero.setName("Photon/Monica Rambeau");
    hero.setTier(7);

    hero.setChestplate("Torso");
    hero.setLeggings("Pants");
    hero.setBoots("Boots");

    hero.addPowers("wv:altered_physiology");
    hero.addAttribute("PUNCH_DAMAGE", 4.0, 0);
    hero.addAttribute("WEAPON_DAMAGE", 2, 0);
    hero.addAttribute("SPRINT_SPEED", 0.5, 1);
    hero.addAttribute("FALL_RESISTANCE", 1, 1);

    hero.addKeyBind("AIM", "Aim", 1);
    hero.addKeyBind("ENERGY_PROJECTION", "Energy Beam", 2);
    hero.addKeyBind("SHIELD", "Charge Energy", 3);
    hero.addKeyBind("INTANGIBILITY", "key.intangibility", 4);
    hero.addKeyBind("TRANSFORMATION", "Energy Form", 5)

    hero.supplyFunction("canAim", canAim)
    hero.setModifierEnabled(isModifierEnabled);
    hero.addAttributeProfile("SHIELD", shieldProfile);
    hero.setAttributeProfile(getAttributeProfile);

    hero.setTickHandler((entity, manager) => {
        utils.flightOnIntangibility(entity, manager);
        landing.tick(entity, manager);
        manager.incrementData(entity, "wv:dyn/holoanimation", 20, 20, entity.is("DISPLAY") && !entity.as("DISPLAY").isStatic() && entity.as("DISPLAY").getDisplayType() === "HOLOGRAM");
        var time = 20;
        if (entity.getData("wv:dyn/worn_suit") < 10) {
            manager.setData(entity, "wv:dyn/worn_suit", entity.getData("wv:dyn/worn_suit") + 0.1);
        }
        if (entity.getData("fiskheroes:shield_blocking_timer") < time && entity.getData("wv:dyn/worn_suit") > time / 5 && !entity.getData("wv:dyn/power")) {
            manager.setData(entity, "wv:dyn/power", true);
        } else if (entity.getData("fiskheroes:shield_blocking_timer") > time && entity.getData("wv:dyn/power")) {
            manager.setData(entity, "wv:dyn/power", false);
        } else if (entity.getData("wv:dyn/transformation")) {
            manager.setData(entity, "wv:dyn/power_charge", time + 1000)
        } else if (!entity.getData("wv:dyn/transformation")) {
            manager.setData(entity, "fiskheroes:energy_projection", false)
        } else if (!entity.getData("wv:dyn/transformation")) {
            manager.setData(entity, "fiskheroes:aiming", false)
        } else if (!entity.getData("wv:dyn/transformation")) {
            manager.setData(entity, "fiskheroes:intangible", false)
        } else if (!entity.getData("wv:dyn/transformation")) {
            manager.setData(entity, "fiskheroes:controlled_flight", false)
        }
    });
    hero.setHasProperty((entity, property) => property == "BREATHE_SPACE");

    hero.setKeyBindEnabled((entity, keyBind) => {
        switch (keyBind) {
            case "AIM":
                return entity.getData("wv:dyn/transformation") && !entity.getData("fiskheroes:energy_projection");
            case "INTANGIBILITY":
                return entity.getData("wv:dyn/transformation") && !entity.getData("fiskheroes:energy_projection");
            case "ENERGY_PROJECTION":
                return entity.getData("wv:dyn/transformation") && !entity.getData("fiskheroes:aiming");
            case "TRANSFORMATION":
                return (entity.getData("wv:dyn/power_charge") > 0.95);
                case "SHIELD":
                    return !entity.getData("wv:dyn/transformation")
            default:
                return true;

        }
    })
}

function getTierOverride(entity) {
    return entity.getData("wv:dyn/transformation") ? 7 : 5;
}

function isModifierEnabled(entity, modifier) {
    switch (modifier.name()) {
        case "fiskheroes:controlled_flight":
            return entity.getData("wv:dyn/transformation");
        default:
            return true;
    }
}

function shieldProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("BASE_SPEED", -10, 1);
    profile.addAttribute("JUMP_HEIGHT", -2.0, 1);
}

function getAttributeProfile(entity) {
    return entity.getData("fiskheroes:shield_blocking") ? "SHIELD" : null;
}


function canAim(entity) {
    return entity.getHeldItem().isEmpty();
}
