public static void use(Entity entity, String name) { Ability abilityComponent = EntityUtil.getComponent(entity, Ability.class); if (abilityComponent == null) { return; } AbilityInfo ability = abilityComponent.getAbility(name); if (ability == null) { return; } ability.getAbility().cast(entity); ability.setLastCast(TimeUtil.getGameTime()); }
public static boolean isAvailable(Entity entity, String name) { Ability abilityComponent = EntityUtil.getComponent(entity, Ability.class); if (abilityComponent == null) { return false; } AbilityInfo ability = abilityComponent.getAbility(name); if (ability == null) { return false; } long lastCast = ability.getLastCast(); return lastCast == -1 || (TimeUtil.getGameTime() - lastCast > ability.getCooldown()); }