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

function init(hero) {
    hero.setName("Doorman/DeMarr Davis");
    hero.setTier(3);
    

    hero.setChestplate("Sweatshirt");

    
    hero.addPowers("tgheroes:dark_dimention_magic");
    hero.addAttribute("PUNCH_DAMAGE", 3.0, 0);
    hero.addAttribute("SPRINT_SPEED", 0.15, 1);
    hero.addAttribute("JUMP_HEIGHT", 1.0, 0);
    hero.addAttribute("FALL_RESISTANCE", 0.4, 1);

    hero.addKeyBind("INTANGIBILITY", "Intangibility", 1);
	hero.addKeyBind("TELEPORT", "Teleport", 2);
    hero.addKeyBind("NANITE_TRANSFORM", "Transform", 3);	

    hero.setModifierEnabled(isModifierEnabled);
    hero.setKeyBindEnabled(isKeyBindEnabled);

    hero.setTickHandler((entity, manager) => {
        utils.flightOnIntangibility(entity, manager);
    });
}

function isModifierEnabled(entity, modifier) {
    if (modifier.name() != "fiskheroes:transformation" && modifier.name() != "fiskheroes:cooldown" && (!entity.getData("tgheroes:dyn/doorman_suit") || modifier.name() == "fiskheroes:controlled_flight" && entity.getData("tgheroes:dyn/doorman_timer") < 1)) {
        return false;
    }
    switch (modifier.name()) {
        default:
            return true;
    }
}

function isKeyBindEnabled(entity, keyBind) {
    if (keyBind == "NANITE_TRANSFORM") {
        return entity.getData("fiskheroes:mask_open_timer") == 0;
    }
    else if (!entity.getData("tgheroes:dyn/doorman_suit")) {
        return false;
    }
    else if (entity.isSprinting() && entity.getData("fiskheroes:flying")) {
        return false;
    }
    
    switch (keyBind) {
        case "SHIELD":
            return entity.isSneaking() || entity.isBookPlayer();
        case "BLADE":
            return entity.isSneaking() || entity.isBookPlayer();
        default:
            return true;
    }
}