var utils = implement("fiskheroes:external/utils");

function init(hero) {
    hero.setName("Kang the Conqueror");
    hero.setTier(10);
    

    hero.setHelmet("Helmet");
    hero.setChestplate("Chestpiece");
    hero.setLeggings("Pants");
    hero.setBoots("Boots");
    
    hero.addPowers("tgheroes:kang_suit");
    hero.addAttribute("PUNCH_DAMAGE", 16.0, 0);
    hero.addAttribute("SPRINT_SPEED", 0.3, 1);
    hero.addAttribute("JUMP_HEIGHT", 2.5, 0);
    hero.addAttribute("FALL_RESISTANCE", 1.0, 1);


	hero.addKeyBind("CHARGED_BEAM", "Energy Beam", 1);
    hero.addKeyBind("SHIELD", "Forcefield", 2);
    hero.addKeyBind("GLIDER", "Glider", 3);	
	hero.addKeyBind("TELEPORT", "Teleport", 4);
    hero.addKeyBind("TELEKINESIS", "Telekinesis", 5);

    hero.setModifierEnabled(isModifierEnabled);

    hero.setHasProperty(hasProperty);

	hero.setDamageProfile(entity => entity.getHeldItem().isEmpty() ? "PUNCH" : null);
	hero.addDamageProfile("PUNCH", {
	"types": {
	"BLUNT": 3.0
        },
	});
	
    hero.setTickHandler((entity, manager) => {
        if (entity.getData("tgheroes:dyn/kang_glider") && !entity.isOnGround() && entity.motionY() < -0.5 ) {
        manager.setData(entity, "fiskheroes:flying", true);
    }
    });
}

function isModifierEnabled(entity, modifier) {
  switch (modifier.name()) {
    case "fiskheroes:controlled_flight":
        return entity.getData("tgheroes:dyn/kang_glider"); 
	case "fiskheroes:water_breathing":
		return !entity.getData("fiskheroes:mask_open");
    default:
        return true;
    }
}

function hasProperty(entity, property) {
    return property == "MASK_TOGGLE" || property == "BREATHE_SPACE" && !entity.getData("fiskheroes:mask_open");
}
