Changed some logic on conditions for automatically checking all filters

This commit is contained in:
Vidal committed 2026-02-21 03:24:27 -03:00
1 parent 99de894d3f
commit 8648e019a9
3 files changed
+19 -43

No files matched your search

@@ -21,14 +21,20 @@ public abstract class AbilityCondition {
protected UserType userType = UserType.BOTH;
protected ConditionFilter conditionFilter = ConditionFilter.CASTER;
/**
* Check if this condition is met.
*
* @param caster The entity that would use the ability (NPC or Player)
* @param target The current target (may be null for self-targeting abilities or players)
* @return true if the condition is satisfied
*/
public abstract boolean check(EntityLivingBase caster, EntityLivingBase target);
public boolean check(EntityLivingBase caster, EntityLivingBase target) {
switch (getFilter()) {
case CASTER:
return checkEntity(caster);
case TARGET:
return target != null && checkEntity(target);
case BOTH:
return checkEntity(caster) && (target != null && checkEntity(target));
default:
return checkEntity(caster);
}
}
protected abstract boolean checkEntity(EntityLivingBase entity);
public boolean requiresTarget() {
return false;
@@ -6,7 +6,7 @@ import noppes.npcs.client.gui.builder.FieldDef;
import java.util.List;
public class ConditionHPThreshold extends AbilityCondition{
public class ConditionHPThreshold extends AbilityCondition {
private float threshold = 0.5f; // 50%
private boolean percent = true;
private ThresholdType thresholdType = ThresholdType.ABOVE;
@@ -62,26 +62,9 @@ public class ConditionHPThreshold extends AbilityCondition{
}
@Override
public boolean check(EntityLivingBase caster, EntityLivingBase target) {
float casterHP = isPercent() ? caster.getHealth() / caster.getMaxHealth() : caster.getHealth();
float targetHP = isPercent() ? target.getHealth() / target.getMaxHealth() : target.getHealth();
return compare(casterHP, targetHP);
}
public boolean compare(float casterHp, float targetHp) {
boolean casterCheck = thresholdType.test(casterHp, threshold);
boolean targetCheck = thresholdType.test(targetHp, threshold);
switch (getFilter()) {
case BOTH:
return casterCheck && targetCheck;
case CASTER:
return casterCheck;
default:
return targetCheck;
}
protected boolean checkEntity(EntityLivingBase entity) {
float entityHP = isPercent() ? entity.getHealth() / entity.getMaxHealth() : entity.getHealth();
return thresholdType.test(entityHP, getThreshold());
}
@Override
@@ -46,20 +46,7 @@ public class ConditionItem extends AbilityCondition {
}
@Override
public boolean check(EntityLivingBase caster, EntityLivingBase target) {
switch (getFilter()) {
case CASTER:
return checkEntity(caster);
case TARGET:
return target != null && checkEntity(target);
case BOTH:
return checkEntity(caster) && (target != null && checkEntity(target));
default:
return checkEntity(caster);
}
}
private boolean checkEntity(EntityLivingBase entity) {
protected boolean checkEntity(EntityLivingBase entity) {
switch (usageType) {
case HOLDING:
return checkHolding(entity);