From acb99b5c48f53ea568cc6745b3347277d82e343d Mon Sep 17 00:00:00 2001 From: Vidal Date: Sat, 21 Feb 2026 01:21:33 -0300 Subject: [PATCH] Added percent option to ConditionHPThreshold and added EQUAL comparison type --- .../conditions/ConditionHPThreshold.java | 52 +++++++++++++------ .../assets/customnpcs/lang/en_US.lang | 2 + 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionHPThreshold.java b/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionHPThreshold.java index 803fc978c..5eed753fa 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionHPThreshold.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionHPThreshold.java @@ -8,19 +8,26 @@ import java.util.List; public class ConditionHPThreshold extends AbilityCondition{ private float threshold = 0.5f; // 50% + private boolean percent = true; private ThresholdType thresholdType = ThresholdType.ABOVE; public enum ThresholdType { ABOVE { @Override public boolean test(float value, float threshold) { - return value >= threshold; + return value > threshold; } }, BELOW { @Override public boolean test(float value, float threshold) { - return value <= threshold; + return value < threshold; + } + }, + EQUAL { + @Override + public boolean test(float value, float threshold) { + return value == threshold; } }; @@ -41,6 +48,8 @@ public class ConditionHPThreshold extends AbilityCondition{ return "condition.hp_above"; case BELOW: return "condition.hp_below"; + case EQUAL: + return "condition.hp_equal"; default: return name(); } @@ -54,8 +63,8 @@ public class ConditionHPThreshold extends AbilityCondition{ @Override public boolean check(EntityLivingBase caster, EntityLivingBase target) { - float casterHP = caster.getHealth() / caster.getMaxHealth(); - float targetHP = target.getHealth() / target.getMaxHealth(); + float casterHP = isPercent() ? caster.getHealth() / caster.getMaxHealth() : caster.getHealth(); + float targetHP = isPercent() ? target.getHealth() / target.getMaxHealth() : target.getHealth(); return compare(casterHP, targetHP); @@ -75,6 +84,24 @@ public class ConditionHPThreshold extends AbilityCondition{ } } + @Override + public void getConditionDefinitions(List defs) { + defs.add(FieldDef.floatField("condition.threshold", this::getThreshold, this::setThreshold).min(0)); + defs.add(FieldDef.boolField("condition.percent", this::isPercent, this::setIsPercent)); + defs.add(FieldDef.enumField("condition.threshold_type", ThresholdType.class, + this::getThresholdType, this::setThresholdType)); + } + + @Override + public void writeTypeNBT(NBTTagCompound nbt) { + nbt.setFloat("threshold", threshold); + } + + @Override + public void readTypeNBT(NBTTagCompound nbt) { + threshold = nbt.getFloat("threshold"); + } + public float getThreshold() { return threshold; } @@ -91,20 +118,11 @@ public class ConditionHPThreshold extends AbilityCondition{ this.thresholdType = thresholdType; } - @Override - public void getConditionDefinitions(List defs) { - defs.add(FieldDef.floatField("condition.threshold", this::getThreshold, this::setThreshold).min(0)); - defs.add(FieldDef.enumField("condition.threshold_type", ThresholdType.class, - this::getThresholdType, this::setThresholdType)); + public boolean isPercent() { + return percent; } - @Override - public void writeTypeNBT(NBTTagCompound nbt) { - nbt.setFloat("threshold", threshold); - } - - @Override - public void readTypeNBT(NBTTagCompound nbt) { - threshold = nbt.getFloat("threshold"); + public void setIsPercent(boolean percent) { + this.percent = percent; } } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index d32b62471..b3e09b08f 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -2088,7 +2088,9 @@ condition.filter.both=Both condition.hp_threshold=HP Threshold condition.hp_above=HP Above condition.hp_below=HP Below +condition.hp_equal=HP Equal condition.threshold=Threshold +condition.percent=Use Percent condition.threshold_type=Threshold Type # Condition Hit Count