mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-23 22:59:41 +00:00
Cleanup Damage Handling Logic for CNPC+ and DBC Addon for better readability / context. Added Magic Data Support to Abilities
This commit is contained in:
1 parent
c3096b320e
commit
d9f100d245
12 files changed
+604
-13
No files matched your search
@@ -22,6 +22,7 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
import kamkeel.npcs.util.FileNameHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -37,6 +38,7 @@ import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.NpcDamageSource;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.api.INbt;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
|
||||
@@ -49,11 +51,18 @@ import noppes.npcs.controllers.data.AbilityScript;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicData;
|
||||
import noppes.npcs.controllers.data.MagicEntry;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityMagic;
|
||||
import noppes.npcs.scripted.event.AbilityEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Ability implements IAbility, IAbilityAction {
|
||||
|
||||
@@ -117,6 +126,9 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
// Custom data for external mods
|
||||
protected NBTTagCompound customData = new NBTTagCompound();
|
||||
|
||||
// Magic data — defines magic types and damage splits for this ability
|
||||
protected MagicData magicData = new MagicData();
|
||||
|
||||
// User type restriction
|
||||
protected UserType allowedBy = UserType.BOTH;
|
||||
|
||||
@@ -281,6 +293,15 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this ability type uses magic data.
|
||||
* By default, any ability that deals damage also has magic.
|
||||
* Override in subclasses like Barrier that need magic but don't deal direct damage.
|
||||
*/
|
||||
public boolean hasMagic() {
|
||||
return hasDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to provide variant templates for this ability type.
|
||||
* When a user creates this ability type, they will be shown a selection dialog
|
||||
@@ -472,13 +493,22 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
this, caster, hitEntity, damage, knockback, knockbackUp,
|
||||
knockbackDirX, knockbackDirZ, 1.0f);
|
||||
if (!handled) {
|
||||
float finalDamage = damage;
|
||||
|
||||
// Apply magic pipeline for player and NPC casters
|
||||
MagicData resolved = resolveMagicData(caster);
|
||||
if (resolved != null && !resolved.isEmpty()) {
|
||||
finalDamage = AttributeAttackUtil.calculateAbilityDamage(
|
||||
caster, hitEntity, damage, resolved);
|
||||
}
|
||||
|
||||
// Default damage path
|
||||
if (caster instanceof EntityNPCInterface) {
|
||||
hitEntity.attackEntityFrom(new NpcDamageSource("mob", (EntityNPCInterface) caster), damage);
|
||||
hitEntity.attackEntityFrom(new NpcDamageSource("mob", (EntityNPCInterface) caster), finalDamage);
|
||||
} else if (caster instanceof EntityPlayer) {
|
||||
hitEntity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) caster), damage);
|
||||
hitEntity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) caster), finalDamage);
|
||||
} else {
|
||||
hitEntity.attackEntityFrom(DamageSource.causeMobDamage(caster), damage);
|
||||
hitEntity.attackEntityFrom(DamageSource.causeMobDamage(caster), finalDamage);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -737,6 +767,41 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Magic section ────────────────────────────────────────────
|
||||
if (hasMagic()) {
|
||||
defs.add(FieldDef.section("ability.section.magic").tab("General"));
|
||||
|
||||
defs.add(FieldDef.labelField("ability.magic.note", () -> {
|
||||
if (magicData.isEmpty()) {
|
||||
return StatCollector.translateToLocal("ability.magic.usesCaster");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry<Integer, MagicEntry> entry : magicData.getMagics().entrySet()) {
|
||||
Magic magic = MagicController.getInstance().getMagic(entry.getKey());
|
||||
if (magic != null) {
|
||||
if (sb.length() > 0) sb.append(", ");
|
||||
sb.append(magic.getDisplayName()).append(": ")
|
||||
.append(Math.round(entry.getValue().split * 100)).append("%");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}).tab("General"));
|
||||
|
||||
defs.add(FieldDef.subGuiField("ability.magic.editor",
|
||||
() -> new SubGuiAbilityMagic(magicData.copy()),
|
||||
gui -> {
|
||||
MagicData result = ((SubGuiAbilityMagic) gui).magicData;
|
||||
magicData.getMagics().clear();
|
||||
for (Map.Entry<Integer, MagicEntry> e : result.getMagics().entrySet()) {
|
||||
magicData.getMagics().put(e.getKey(), e.getValue());
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> magicData.isEmpty()
|
||||
? StatCollector.translateToLocal("ability.magic.usesCaster")
|
||||
: magicData.getMagics().size() + " Magic(s)")
|
||||
.tab("General"));
|
||||
}
|
||||
|
||||
// ── Target tab ───────────────────────────────────────────────
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.intField("ability.minRange", () -> (int) getMinRange(), v -> setMinRange(v)).range(0, 100),
|
||||
@@ -1410,6 +1475,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
nbt.setString("telegraphType", telegraphType.name());
|
||||
nbt.setFloat("telegraphHeightOffset", telegraphHeightOffset);
|
||||
nbt.setTag("customData", (NBTTagCompound) customData.copy());
|
||||
magicData.writeToNBT(nbt);
|
||||
nbt.setInteger("allowedBy", allowedBy.ordinal());
|
||||
nbt.setBoolean("ignoreCooldown", ignoreCooldown);
|
||||
nbt.setBoolean("perAbilityCooldown", perAbilityCooldown);
|
||||
@@ -1508,6 +1574,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
}
|
||||
telegraphHeightOffset = nbt.getFloat("telegraphHeightOffset");
|
||||
customData = (NBTTagCompound) nbt.getCompoundTag("customData").copy();
|
||||
magicData.readToNBT(nbt);
|
||||
allowedBy = UserType.fromOrdinal(nbt.getInteger("allowedBy"));
|
||||
ignoreCooldown = nbt.getBoolean("ignoreCooldown");
|
||||
perAbilityCooldown = nbt.getBoolean("perAbilityCooldown");
|
||||
@@ -2205,6 +2272,35 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
return customData;
|
||||
}
|
||||
|
||||
public MagicData getMagicData() {
|
||||
return magicData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve magic data for this ability + caster combination.
|
||||
* If the ability has its own magic data, use that (override).
|
||||
* Otherwise, fall back to the caster's magic data (player or NPC).
|
||||
*
|
||||
* @return Resolved MagicData, or null if neither has magic
|
||||
*/
|
||||
public MagicData resolveMagicData(EntityLivingBase caster) {
|
||||
if (!this.magicData.isEmpty()) {
|
||||
return this.magicData;
|
||||
}
|
||||
if (caster instanceof EntityPlayer) {
|
||||
PlayerData data = PlayerData.get((EntityPlayer) caster);
|
||||
if (data != null && data.magicData != null && !data.magicData.isEmpty()) {
|
||||
return data.magicData;
|
||||
}
|
||||
} else if (caster instanceof EntityNPCInterface) {
|
||||
EntityNPCInterface npc = (EntityNPCInterface) caster;
|
||||
if (npc.stats != null && npc.stats.magicData != null && !npc.stats.magicData.isEmpty()) {
|
||||
return npc.stats.magicData;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<AbilityCondition> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user