function init(hero) {
    hero.setName("Moon Knight");
    hero.setTier(5);
    
    hero.setChestplate("Konshu");
    hero.addEquipment("fiskheroes:black_canarys_tonfas");
    hero.addEquipment("fiskheroes:bo_staff");
    hero.addEquipment("fiskheroes:grappling_gun");
    
    hero.addPowers("cwheropack:lunar_physiology");
    hero.addAttribute("PUNCH_DAMAGE", 6.5, 0);
    hero.addAttribute("JUMP_HEIGHT", 1.0, 0);
    hero.addAttribute("SPRINT_SPEED", 0.30, 1);
    hero.addAttribute("FALL_RESISTANCE", 4.5, 0);
    
    hero.addKeyBind("UTILITY_BELT", "key.utilityBelt", 1);
    hero.addKeyBind("BLADE", "Moon Knife", 2);
    hero.addKeyBind("SHIELD", "Moon Sticks", 2);
    hero.addKeyBind("TRANSFORM", "Lunar Transformation", 5);
    hero.addKeyBind("TELEPORT", "Space/Earth", 3)
    
    hero.setDefaultScale(1.02);

    hero.addAttributeProfile("AVATAR", steelProfile);
    hero.setAttributeProfile(getAttributeProfile);
    hero.setModifierEnabled(isModifierEnabled);
    hero.setTierOverride(getTierOverride);
    hero.setHasPermission(hasPermission);

    hero.addAttributeProfile("SHIELD", shieldProfile);
    hero.addAttributeProfile("BLADE", bladeProfile);
    hero.setHasProperty(hasProperty);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.addAttributeProfile("INACTIVE", inactiveProfile);
    hero.setAttributeProfile(getProfile);
    hero.setDamageProfile(getProfile);

}

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

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

function steelProfile(profile) {
    profile.addAttribute("PUNCH_DAMAGE", 6.72, 0);
    profile.addAttribute("JUMP_HEIGHT", 2.5, 0);
    profile.addAttribute("FALL_RESISTANCE", 5.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0.30, 1);
}

function bladeProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 8.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0.39, 1);
    profile.addAttribute("IMPACT_DAMAGE", 1.35, 1);
}

function shieldProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 7.50, 0);
    profile.addAttribute("SPRINT_SPEED", 0.35, 1);
    profile.addAttribute("IMPACT_DAMAGE", 1.0, 1);
}

function getProfile(entity) {
    if (entity.getData("fiskheroes:blade")) {
        return "BLADE";
    }
    else if (entity.getData("fiskheroes:shield")) {
        return "SHIELD";
    }
}

function isKeyBindEnabled(entity, keyBind) {
    if (keyBind == "TRANSFORM") {
        return entity.getData("fiskheroes:mask_open_timer") == 0;
    }
    else if (!entity.getData("cwheropack:dyn/avatar")) {
        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 "TELEPORT":
        return entity.posY() > 75;
    case "UTILITY_BELT":
        return !entity.isSneaking() && !entity.getData("fiskheroes:blade");
    default:
        return true;
    }
}


function hasPermission(entity, permission) {
    return permission == "USE_GRAPPLING_GUN";
}


function getAttributeProfile(entity) {
    return entity.getData("cwheropack:dyn/avatar") ? "AVATAR" : null;
}

function isModifierEnabled(entity, modifier) {
    if (modifier.name() != "fiskheroes:transformation" && modifier.name() != "fiskheroes:cooldown" && (!entity.getData("cwheropack:dyn/avatar") || modifier.name() == "fiskheroes:propelled_flight" && entity.getData("cwheropack:dyn/avatar_timer") < 1)) {
        return false;
    }
  
    switch (modifier.name()) {
    case "fiskheroes:water_breathing":
        return !entity.getData("fiskheroes:mask_open") && entity.getData("cwheropack:dyn/avatar");
    case "fiskheroes:teleportation":
        return entity.posY() > 75;
    default:
        return true;
    }
}
function hasProperty(entity, property) {
    switch (property) {
    case "MASK_TOGGLE":
        return entity.getData("cwheropack:dyn/avatar_timer") == 1;
    case "BREATHE_SPACE":
        return !entity.getData("fiskheroes:mask_open") && entity.getData("cwheropack:dyn/avatar");
    default:
        return false;
    }
}

