function init(hero) {
    hero.setName("Blue Beetle");
    hero.setVersion("item.superhero_armor.version.dceu");
    hero.setTier(8);
    
    hero.setChestplate("Scarab");

    hero.addPowers("jmctheroes:blue_beetle_scarab_dceu");
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    hero.addAttribute("JUMP_HEIGHT", 3.0, 0);
    hero.addAttribute("PUNCH_DAMAGE", 9.0, 0);
    hero.addAttribute("SPRINT_SPEED", 0.40, 1);
    hero.addAttribute("STEP_HEIGHT", 0.5, 0);
    hero.addAttribute("IMPACT_DAMAGE", 0.75, 1);

    hero.addKeyBind("CHARGED_BEAM", "Energy Beam", 1);
    hero.addKeyBind("SHIELD", "Reach Shield", 2);
    hero.addKeyBind("BLADE", "Reach Blade", 2);
    hero.addKeyBind("HOVER", "Hover", 4);
    hero.addKeyBind("BEETLE", "Toggle Scarab", 5);

    hero.setHasProperty(hasProperty);
    hero.setAttributeProfile(getProfile);
    hero.setTierOverride(getTierOverride);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setModifierEnabled(isModifierEnabled);
    hero.addAttributeProfile("INACTIVE", inactiveProfile);
    hero.addSoundEvent("MASK_OPEN", "fiskheroes:mk50_mask_open");
    hero.addSoundEvent("MASK_CLOSE", "fiskheroes:mk50_mask_close");
}

function bladeProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("FALL_RESISTANCE", 1.0, 1);
    profile.addAttribute("JUMP_HEIGHT", 3.0, 0);
    profile.addAttribute("PUNCH_DAMAGE", 9.1, 0);
    profile.addAttribute("SPRINT_SPEED", 0.40, 1);
    profile.addAttribute("STEP_HEIGHT", 0.5, 0);
    profile.addAttribute("IMPACT_DAMAGE", 0.8, 1);
}

function shieldProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("FALL_RESISTANCE", 1.0, 1);
    profile.addAttribute("JUMP_HEIGHT", 3.0, 0);
    profile.addAttribute("PUNCH_DAMAGE", 9.7, 0);
    profile.addAttribute("SPRINT_SPEED", 0.40, 1);
    profile.addAttribute("STEP_HEIGHT", 0.5, 0);
    profile.addAttribute("IMPACT_DAMAGE", 0.95, 1);
}

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

function getProfile(entity) {
    if (!entity.getData("jmctheroes:dyn/beetle")) {
        return "INACTIVE";
    }
    else if (entity.getData("fiskheroes:blade")) {
        return "BLADE";
    }
    else if (entity.getData("fiskheroes:shield")) {
        return "SHIELD";
    }
}

function isModifierEnabled(entity, modifier) {
    if (modifier.name() != "fiskheroes:transformation" && modifier.name() != "fiskheroes:cooldown" && (!entity.getData("jmctheroes:dyn/beetle"))) {
        return false;
    }
  
    switch (modifier.name()) {
    case "fiskheroes:blade":
        return entity.getData("fiskheroes:beam_charge") == 0 && !(entity.getData("fiskheroes:shield") && entity.getData("fiskheroes:blade"));
    case "fiskheroes:shield":
        return entity.getData("fiskheroes:beam_charge") == 0 && !(entity.getData("fiskheroes:shield") && entity.getData("fiskheroes:blade"));
    case "fiskheroes:charged_beam":
        return entity.getHeldItem().isEmpty() && entity.getData("jmctheroes:dyn/beetle");
    case "fiskheroes:propelled_flight":
        return entity.getData("jmctheroes:dyn/beetle");
    case "fiskheroes:hover":
        return entity.getData("jmctheroes:dyn/beetle");
    case "fiskheroes:water_breathing":
        return !entity.getData("fiskheroes:mask_open") && entity.getData("jmctheroes:dyn/beetle");
    default:
        return true;
    }
}

function isKeyBindEnabled(entity, keyBind) {
    if (keyBind == "BEETLE") {
        return entity.getData("fiskheroes:mask_open_timer") == 0;
    }
    else if (!entity.getData("jmctheroes:dyn/beetle")) {
        return false;
    }
    
    switch (keyBind) {
    case "SHIELD":
        return entity.getData("fiskheroes:blade_timer") == 0 || entity.isBookPlayer();
    case "BLADE":
        return entity.getData("fiskheroes:shield_timer") > 0 || entity.getData("fiskheroes:blade_timer") > 0 || entity.isBookPlayer();
    case "CHARGED_BEAM":
        return entity.getHeldItem().isEmpty() && entity.getData("jmctheroes:dyn/beetle");
    case "HOVER":
        return entity.getData("jmctheroes:dyn/beetle");
    default:
        return true;
    }
}

function getTierOverride(entity) {
    return entity.getData("jmctheroes:dyn/beetle") ? 8 : 0;
}

function hasProperty(entity, property) {
    switch (property) {
    case "MASK_TOGGLE":
        return entity.getData("jmctheroes:dyn/beetle_timer") == 1;
    case "BREATHE_SPACE":
        return !entity.getData("fiskheroes:mask_open") && entity.getData("jmctheroes:dyn/beetle");
    case "BREATHE_UNDERWATER":
        return !entity.getData("fiskheroes:mask_open") && entity.getData("jmctheroes:dyn/beetle");
    default:
        return false;
    }
}
