function init(hero) {
    hero.setName("The Ninja/Randy Cunningham");
    hero.setTier(6);
    
    hero.setHelmet("item.superhero_armor.piece.mask");
    
    hero.addPowers("tmfp:ninja_powers");
    hero.addAttribute("JUMP_HEIGHT", 3.0, 0);
    hero.addAttribute("PUNCH_DAMAGE", 2.0, 0);
    hero.addAttribute("SPRINT_SPEED", 0.4, 1);
    hero.addAttribute("FALL_RESISTANCE", 15.0, 0);

    hero.addKeyBind("UTILITY_BELT", "Equipments", 1);

    hero.addKeyBind("TELEPORT", "key.teleport", 2);
    hero.addKeyBind("FLAME_MOD", "Ninja Flame Mod", 4);

    hero.addKeyBind("SHIELD", "Ninja Sword", 3);
    hero.addKeyBind("BLADE", "Ninja Chain Sickle", 3);
    hero.addKeyBind("AIM", "key.shoot", 3);

    hero.addKeyBind("WEB_ZIP", "key.webZip", 2);

    hero.addKeyBind("NINJA_TRANSFORM", "Ninja Transform", 5);

    hero.supplyFunction("canAim", canAim);
    hero.setModifierEnabled(isModifierEnabled);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    hero.setTierOverride(getTierOverride);
    hero.addAttributeProfile("INACTIVE", inactiveProfile);
    hero.addAttributeProfile("SHIELD", shieldProfile);
    hero.addAttributeProfile("BLADE", bladeProfile);
    hero.addAttributeProfile("FLAME", flameProfile);
    hero.setAttributeProfile(getProfile);
    hero.setDamageProfile(getProfile);
    hero.addDamageProfile("FLAME_PUNCH", {
        "types": {
            "BLUNT": 1.0,
            "FIRE": 0.4
        },
        "properties": {
            "HEAT_TRANSFER": 40,
            "IGNITE": 2
        }
    });
}

function getDamageProfile(entity) {
    return entity.getHeldItem().isEmpty() && entity.getData("tmfp:dyn/flame_mod") ? "FLAME_PUNCH" : null;
}
function isModifierEnabled(entity, modifier) {
    if (modifier.name() != "fiskheroes:transformation" && modifier.name() != "fiskheroes:cooldown" && (!entity.getData("tmfp:dyn/ninja") && entity.getData("tmfp:dyn/ninja_timer") < 1)) {
        return false;
    }
  
    switch (modifier.name()) {
    case "fiskheroes:web_zip":
        return entity.getData("fiskheroes:blade");
    case "fiskheroes:fireball":
        return entity.getData("tmfp:dyn/flame_mod");
    case "fiskheroes:shield":
        return !entity.getData("tmfp:dyn/flame_mod");
    case "fiskheroes:blade":
        return !entity.getData("tmfp:dyn/flame_mod");
    default:
        return true;
    }
}

function getTierOverride(entity) {
    return entity.getData("tmfp:dyn/ninja") ? 6 : 0;
}

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

function shieldProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 9.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0.2, 1);
}
function bladeProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("PUNCH_DAMAGE", 7.0, 0);
}
function flameProfile(profile) {
    profile.inheritDefaults();
    profile.addAttribute("FALL_RESISTANCE", 8.0, 0);
    profile.addAttribute("JUMP_HEIGHT", 4.0, 0);
    profile.addAttribute("PUNCH_DAMAGE", 4.0, 0);
    profile.addAttribute("SPRINT_SPEED", 0.5, 1);
}


function getProfile(entity) {
    if (!entity.getData("tmfp:dyn/ninja")) {
        return "INACTIVE";
    }
    else if (entity.getData("fiskheroes:shield")) {
        return "SHIELD";
    }
    else if (entity.getData("fiskheroes:blade")) {
        return "BLADE";
    }
    else if (entity.getData("tmfp:dyn/flame_mod")) {
        return "FLAME";
    }
    return null;
}

function isKeyBindEnabled(entity, keyBind) {
    if (keyBind == "NINJA_TRANSFORM") {
        return entity.getData("fiskheroes:mask_open_timer") == 0;
    }
    else if (!entity.getData("tmfp:dyn/ninja")) {
        return false;
    }
    
    switch (keyBind) {
    case "SHIELD":
        return entity.getData("fiskheroes:blade_timer") == 0 && !entity.getData("tmfp:dyn/flame_mod");
    case "BLADE":
        return entity.getData("fiskheroes:shield_timer") > 0 || entity.getData("fiskheroes:blade_timer") > 0 && !entity.getData("tmfp:dyn/flame_mod");
    case "AIM":
        return entity.getData("tmfp:dyn/flame_mod");
    case "TELEPORT":
        return entity.getData("tmfp:dyn/ninja") && !entity.getData("fiskheroes:blade");
    case "WEB_ZIP":
        return entity.getData("fiskheroes:blade");
    case "FLAME_MOD":
        return !entity.getData("fiskheroes:blade") || !entity.getData("fiskheroes:shield");
    case "UTILITY_BELT":
        return entity.getData("tmfp:dyn/ninja");
    default:
        return true;
    }
}
function canAim(entity) {
    return entity.getHeldItem().isEmpty() && entity.getData("tmfp:dyn/flame_mod") && !entity.getData("fiskheroes:jetpacking") && !entity.getData("fiskheroes:shield");
}