mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 09:37:29 +00:00
Add Movement Speed, Knockback Res and Health % Boost Modifiers to Items
This commit is contained in:
1 parent
3dc08696f7
commit
7f5ba9a1c4
3 files changed
+78
-14
No files matched your search
@@ -12,6 +12,7 @@ import kamkeel.npcs.controllers.data.attribute.requirement.types.QuestCompletedR
|
||||
*/
|
||||
public class CustomAttributes {
|
||||
public static final String HEALTH_KEY = "health";
|
||||
public static final String HEALTH_BOOST_KEY = "health_boost";
|
||||
public static final String MAIN_ATTACK_KEY = "main_attack";
|
||||
public static final String MAIN_ATTACK_BOOST_KEY = "main_attack_boost";
|
||||
public static final String NEUTRAL_KEY = "neutral";
|
||||
@@ -22,24 +23,28 @@ public class CustomAttributes {
|
||||
public static final String MAGIC_BOOST_KEY = "magic_boost";
|
||||
public static final String MAGIC_DEFENSE_KEY = "magic_defense";
|
||||
public static final String MAGIC_RESISTANCE_KEY = "magic_resistance";
|
||||
public static final String MOVEMENT_SPEED_KEY = "movement_speed";
|
||||
public static final String KNOCKBACK_RES_KEY = "knockback_res";
|
||||
|
||||
|
||||
public static AttributeDefinition HEALTH;
|
||||
public static AttributeDefinition HEALTH_BOOST;
|
||||
public static AttributeDefinition MAIN_ATTACK;
|
||||
public static AttributeDefinition MAIN_BOOST;
|
||||
public static AttributeDefinition NEUTRAL_ATTACK;
|
||||
public static AttributeDefinition NEUTRAL_BOOST;
|
||||
|
||||
public static AttributeDefinition HEALTH;
|
||||
public static AttributeDefinition CRITICAL_CHANCE;
|
||||
public static AttributeDefinition CRITICAL_DAMAGE;
|
||||
|
||||
public static AttributeDefinition MAGIC_DAMAGE;
|
||||
public static AttributeDefinition MAGIC_BOOST;
|
||||
public static AttributeDefinition MAGIC_DEFENSE;
|
||||
public static AttributeDefinition MAGIC_RESISTANCE;
|
||||
public static AttributeDefinition MOVEMENT_SPEED;
|
||||
public static AttributeDefinition KNOCKBACK_RES;
|
||||
|
||||
public CustomAttributes() {
|
||||
HEALTH = AttributeController.registerAttribute(HEALTH_KEY, "Health", 'c', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.BASE);
|
||||
HEALTH_BOOST = AttributeController.registerAttribute(HEALTH_BOOST_KEY, "Health Boost", 'c', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
HEALTH_BOOST.setTranslationKey("attribute.name.generic.maxHealth");
|
||||
|
||||
MAIN_ATTACK = AttributeController.registerAttribute(MAIN_ATTACK_KEY, "Main Attack Damage", '4', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.BASE);
|
||||
MAIN_BOOST = AttributeController.registerAttribute(MAIN_ATTACK_BOOST_KEY, "Main Attack Damage", '4', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
@@ -56,6 +61,11 @@ public class CustomAttributes {
|
||||
MAGIC_DEFENSE = AttributeController.registerAttribute(MAGIC_DEFENSE_KEY, "Magic Defense", 'b', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.BASE);
|
||||
MAGIC_RESISTANCE = AttributeController.registerAttribute(MAGIC_RESISTANCE_KEY, "Magic Resistance", 'b', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
|
||||
MOVEMENT_SPEED = AttributeController.registerAttribute(MOVEMENT_SPEED_KEY, "Movement Speed", 'a', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
MOVEMENT_SPEED.setTranslationKey("attribute.name.generic.movementSpeed");
|
||||
|
||||
KNOCKBACK_RES = AttributeController.registerAttribute(KNOCKBACK_RES_KEY, "Knockback Resistance", 'b', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
KNOCKBACK_RES.setTranslationKey("attribute.name.generic.knockbackResistance");
|
||||
|
||||
// TODO: Attributes
|
||||
// Durability Attribute
|
||||
|
||||
+58
-8
@@ -23,12 +23,18 @@ import java.util.UUID;
|
||||
public class PlayerAttributeTracker {
|
||||
|
||||
public static UUID healthUUID = UUID.fromString("48a0ad75-2cf8-4838-ad2f-9a0aadc57dfe");
|
||||
|
||||
public static UUID healthBoostUUID = UUID.fromString("93cfba41-294a-4e6b-a98b-bee76a9f813b");
|
||||
public static UUID movementSpeedUUID = UUID.fromString("e7e0dd10-8ed5-42fb-8167-e71f8de4ea0c");
|
||||
public static UUID knockbackResUUID = UUID.fromString("b2f261e8-34f0-4140-9828-b56c1f6e0ff2");
|
||||
|
||||
private final UUID playerId;
|
||||
private PlayerAttributeMap playerAttributes = new PlayerAttributeMap();
|
||||
|
||||
public float extraHealth = 0;
|
||||
public float extraHealthBoost = 0;
|
||||
public float movementSpeed = 0;
|
||||
public float knockbackRes = 0;
|
||||
|
||||
public float gearOutput = 0.0f;
|
||||
|
||||
public final Map<Integer, Float> magicDamage = new HashMap<>();
|
||||
@@ -117,9 +123,16 @@ public class PlayerAttributeTracker {
|
||||
}
|
||||
equipmentTracker = currentEquip;
|
||||
gearOutput = AttributeAttackUtil.calculateGearOutput(this);
|
||||
extraHealth = getAttributeValue(CustomAttributes.HEALTH);
|
||||
|
||||
extraHealth = getAttributeValue(CustomAttributes.HEALTH);
|
||||
extraHealthBoost = getAttributeValue(CustomAttributes.HEALTH_BOOST);
|
||||
movementSpeed = getAttributeValue(CustomAttributes.MOVEMENT_SPEED);
|
||||
knockbackRes = getAttributeValue(CustomAttributes.KNOCKBACK_RES);
|
||||
|
||||
// Update vanilla attributes with our aggregated values.
|
||||
updatePlayerMaxHealth(player);
|
||||
updatePlayerMovementSpeed(player);
|
||||
updatePlayerKnockbackRes(player);
|
||||
|
||||
// Post Recalculation Event to Listeners
|
||||
AttributeRecalcEvent.post(player, this);
|
||||
@@ -134,24 +147,61 @@ public class PlayerAttributeTracker {
|
||||
*/
|
||||
public void updatePlayerMaxHealth(EntityPlayer player) {
|
||||
float bonusHealth = extraHealth;
|
||||
float healthBoostPercent = extraHealthBoost / 100;
|
||||
IAttributeInstance maxHealthAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth);
|
||||
try {
|
||||
AttributeModifier old = maxHealthAttr.getModifier(healthUUID);
|
||||
if (old != null) {
|
||||
maxHealthAttr.removeModifier(old);
|
||||
AttributeModifier oldFlat = maxHealthAttr.getModifier(healthUUID);
|
||||
if (oldFlat != null) {
|
||||
maxHealthAttr.removeModifier(oldFlat);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
AttributeModifier oldBoost = maxHealthAttr.getModifier(healthBoostUUID);
|
||||
if (oldBoost != null) {
|
||||
maxHealthAttr.removeModifier(oldBoost);
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
// Apply the flat bonus (operation 0)
|
||||
if (bonusHealth != 0) {
|
||||
maxHealthAttr.applyModifier(new AttributeModifier(healthUUID, "RPGCoreHealthBonus", bonusHealth, 0));
|
||||
}
|
||||
// Ensure the player's current health does not exceed the new maximum.
|
||||
// Apply the percent boost (operation 1 multiplies the base health, here assumed to be 20)
|
||||
if (healthBoostPercent != 0) {
|
||||
maxHealthAttr.applyModifier(new AttributeModifier(healthBoostUUID, "RPGCoreHealthBoost", healthBoostPercent, 1));
|
||||
}
|
||||
// Ensure current health is within the new maximum.
|
||||
float currentHealth = player.getHealth();
|
||||
if (currentHealth > maxHealthAttr.getAttributeValue()) {
|
||||
player.setHealth((float) maxHealthAttr.getAttributeValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayerMovementSpeed(EntityPlayer player) {
|
||||
float extraSpeed = movementSpeed / 100;
|
||||
IAttributeInstance speedAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.movementSpeed);
|
||||
try {
|
||||
AttributeModifier old = speedAttr.getModifier(movementSpeedUUID);
|
||||
if (old != null) {
|
||||
speedAttr.removeModifier(old);
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
if (extraSpeed != 0) {
|
||||
speedAttr.applyModifier(new AttributeModifier(movementSpeedUUID, "RPGCoreMovementSpeed", extraSpeed, 1));
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayerKnockbackRes(EntityPlayer player) {
|
||||
float extraRes = knockbackRes / 100;
|
||||
IAttributeInstance knockResAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.knockbackResistance);
|
||||
try {
|
||||
AttributeModifier old = knockResAttr.getModifier(knockbackResUUID);
|
||||
if (old != null) {
|
||||
knockResAttr.removeModifier(old);
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
if (extraRes != 0) {
|
||||
knockResAttr.applyModifier(new AttributeModifier(knockbackResUUID, "RPGCoreKnockbackRes", extraRes, 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player's equipment has changed and recalculates attributes if needed.
|
||||
*/
|
||||
|
||||
@@ -281,10 +281,14 @@ public class AttributeItemUtil {
|
||||
baseOrder.put("Health", 1);
|
||||
baseOrder.put("Main Attack Damage", 2);
|
||||
baseOrder.put("Neutral Damage", 3);
|
||||
|
||||
// For Modifier: Main Attack Damage then Neutral Damage.
|
||||
Map<String, Integer> modOrder = new HashMap<>();
|
||||
modOrder.put("Main Attack Damage", 1);
|
||||
modOrder.put("Neutral Damage", 2);
|
||||
modOrder.put("Health Boost", 1);
|
||||
modOrder.put("Main Attack Damage", 2);
|
||||
modOrder.put("Neutral Damage", 3);
|
||||
modOrder.put("Movement Speed", 4);
|
||||
modOrder.put("Knockback Resistance", 5);
|
||||
|
||||
// Build sections using our custom sorting.
|
||||
newTooltips.addAll(buildSection(baseList, baseOrder));
|
||||
|
||||
Reference in new issue
Block a user