var landing = implement("skarredheroes: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("skarredheroes: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("skarredheroes:dyn/boolean") != entity.getData("fiskheroes:heat_vision")) {
            manager.setData(entity, "fiskheroes:heat_vision", entity.getData("skarredheroes:dyn/boolean"));
        }
        if (entity.getData("skarredheroes:dyn/float_interp") == 1) {
            manager.setData(entity, "skarredheroes:dyn/boolean_cooldown", true);
            manager.setData(entity, "skarredheroes:dyn/boolean_animation", false);
            manager.setData(entity, "skarredheroes:dyn/boolean", false);
        }
        if (entity.getData("skarredheroes:dyn/float_interp_animation") == 1 && entity.getData("skarredheroes:dyn/float_interp") == 0 && !entity.getData("skarredheroes:dyn/boolean_cooldown")) {
            entity.playSound("skarredheroes:spit", 0.5, 0.9);
            manager.setData(entity, "skarredheroes:dyn/boolean", 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("skarredheroes:dyn/float_interp_animation") == 0 && !entity.getData("skarredheroes:dyn/boolean_cooldown")) {
        manager.setData(entity, "skarredheroes:dyn/boolean_animation", true);
    }
    return true;
}
