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

function init(hero) {
    hero.setName("Supergirl");
    hero.setVersion("item.superhero_armor.version.dceu");
    hero.setTier(9);
    
    hero.setChestplate("item.superhero_armor.piece.chestpiece");
    hero.setLeggings("item.superhero_armor.piece.pants");
    hero.setBoots("item.superhero_armor.piece.boots");
    
    hero.addPowers("skarlet:kryptonian_physiology");
    hero.addAttribute("PUNCH_DAMAGE", 10.0, 0);
    hero.addAttribute("WEAPON_DAMAGE", 1.5, 0);
    hero.addAttribute("SPRINT_SPEED", 0.7, 1);
    hero.addAttribute("BASE_SPEED_LEVELS", 3.0, 0);
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);
    
    hero.addKeyBind("SUPER_SPEED", "key.superSpeed", 1);
    hero.addKeyBindFunc("PROJECTILE", projectile, "Super Spit", 5);
    hero.addKeyBind("SLOW_MOTION", "key.slowMotionHold", 3);
    hero.addKeyBind("CHARGED_BEAM", "Heat Vision", 2);
    
    hero.setHasProperty(hasProperty);
    hero.setModifierEnabled(isModifierEnabled);
    hero.setKeyBindEnabled(isKeyBindEnabled);
    
    hero.setTickHandler((entity, manager) => {
        landing.tick(entity, manager);
        super_boost.tick(entity, manager);

        if (entity.getData("skarlet:dyn/throw") != entity.getData("fiskheroes:heat_vision")) {
            manager.setData(entity, "fiskheroes:heat_vision", entity.getData("skarlet:dyn/throw"));
        }
        if (entity.getData("skarlet:dyn/throw_timer") == 1) {
            manager.setData(entity, "skarlet:dyn/throw_cooldown", true);
            manager.setData(entity, "skarlet:dyn/throw_animation", false);
            manager.setData(entity, "skarlet:dyn/throw", false);
        }
        if (entity.getData("skarlet:dyn/throw_animation_timer") == 1 && entity.getData("skarlet:dyn/throw_timer") == 0 && !entity.getData("skarlet:dyn/throw_cooldown")) {
            entity.playSound("skarlet:spit", 0.5, 0.9);
            manager.setData(entity, "skarlet:dyn/throw", true);
        }
    });
}

function isModifierEnabled(entity, modifier) {
    switch (modifier.name()) {
    case "fiskheroes:super_speed":
        return !entity.getData("fiskheroes:flying");
    default:
        return super_boost.isModifierEnabled(entity, modifier);
    }
}

function isKeyBindEnabled(entity, keyBind) {
	switch (keyBind) {
		case "PROJECTILE":
			return entity.getData("fiskheroes:flight_boost_timer") < 1;
		case "CHARGED_BEAM":
			return !entity.getData("fiskheroes:dyn/flight_super_boost") > 0;
		case "SUPER_SPEED":
			return !entity.getData("fiskheroes:flying");
		default:
			return super_boost.isKeyBindEnabled(entity, keyBind);
	}
}

function hasProperty(entity, property) {
    return property == "BREATHE_SPACE";
}

function projectile(entity, manager) {
    if (entity.getData("skarlet:dyn/throw_animation_timer") == 0 && !entity.getData("skarlet:dyn/throw_cooldown")) {
        manager.setData(entity, "skarlet:dyn/throw_animation", true);
    }
    return true;
}
