mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 10:23:06 +00:00
Merge Conflicts + Scripting for Abilities
This commit is contained in:
1 parent
e599ed67f5
commit
83ccd25b33
31 files changed
+408
-63
No files matched your search
@@ -604,6 +604,50 @@ public class DataAbilities {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force start a specific ability, bypassing normal selection and cooldown.
|
||||
* If an ability is currently executing, it will be cancelled.
|
||||
*
|
||||
* @param ability The ability to start
|
||||
* @param target The target entity (can be null for self-targeted abilities)
|
||||
* @return true if the ability was started successfully
|
||||
*/
|
||||
public boolean forceStartAbility(Ability ability, EntityLivingBase target) {
|
||||
if (ability == null || npc.worldObj.isRemote) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Stop any currently executing ability
|
||||
stopCurrentAbility();
|
||||
|
||||
// Reset the ability state
|
||||
ability.reset();
|
||||
|
||||
// Start the ability directly
|
||||
return startAbility(ability, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a preset ability on this NPC.
|
||||
* The NPC does NOT need to have this ability assigned.
|
||||
*
|
||||
* @param presetName The name of the saved ability preset
|
||||
* @param target The target entity (can be null for self-targeted abilities)
|
||||
* @return true if the ability was started successfully
|
||||
*/
|
||||
public boolean executePresetAbility(String presetName, EntityLivingBase target) {
|
||||
if (presetName == null || presetName.isEmpty() || npc.worldObj.isRemote) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Ability preset = AbilityController.Instance.getSavedAbility(presetName);
|
||||
if (preset == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return forceStartAbility(preset, target);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SCRIPT EVENTS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -61,7 +61,7 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig {
|
||||
// Row 4: Sweep Mode + Piercing
|
||||
addLabel(new GuiNpcLabel(106, "ability.sweepMode", labelX, y + 5));
|
||||
String[] sweepModes = {"Swipe", "Spin"};
|
||||
GuiNpcButton sweepModeBtn = new GuiNpcButton(106, fieldX, y, 70, 20, sweepModes, cutter.getSweepMode().ordinal());
|
||||
GuiNpcButton sweepModeBtn = new GuiNpcButton(106, fieldX, y, 70, 20, sweepModes, cutter.getSweepModeEnum().ordinal());
|
||||
sweepModeBtn.setHoverText("ability.hover.sweepMode");
|
||||
addButton(sweepModeBtn);
|
||||
|
||||
@@ -73,7 +73,7 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig {
|
||||
y += 24;
|
||||
|
||||
// Row 5: Spin Duration (only for SPIN mode) + Effects button
|
||||
if (cutter.getSweepMode() == AbilityCutter.SweepMode.SPIN) {
|
||||
if (cutter.getSweepModeEnum() == AbilityCutter.SweepMode.SPIN) {
|
||||
addLabel(new GuiNpcLabel(108, "ability.duration", labelX, y + 5));
|
||||
GuiNpcTextField durationField = createIntField(108, fieldX, y, 50, cutter.getSpinDurationTicks());
|
||||
durationField.setMinMaxDefault(1, 1000, 60);
|
||||
@@ -88,7 +88,7 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig {
|
||||
int value = button.getValue();
|
||||
switch (id) {
|
||||
case 106:
|
||||
cutter.setSweepMode(AbilityCutter.SweepMode.values()[value]);
|
||||
cutter.setSweepModeEnum(AbilityCutter.SweepMode.values()[value]);
|
||||
initGui(); // Refresh to show/hide duration field
|
||||
break;
|
||||
case 107:
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SubGuiAbilityDash extends SubGuiAbilityConfig {
|
||||
// Row 1: Dash Mode
|
||||
addLabel(new GuiNpcLabel(100, "ability.mode", labelX, y + 5));
|
||||
String[] dashModes = {"Aggressive", "Defensive"};
|
||||
GuiNpcButton modeBtn = new GuiNpcButton(100, fieldX, y, 80, 20, dashModes, dash.getDashMode().ordinal());
|
||||
GuiNpcButton modeBtn = new GuiNpcButton(100, fieldX, y, 80, 20, dashModes, dash.getDashModeEnum().ordinal());
|
||||
modeBtn.setHoverText("ability.hover.dashMode");
|
||||
addButton(modeBtn);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SubGuiAbilityDash extends SubGuiAbilityConfig {
|
||||
@Override
|
||||
protected void handleTypeButton(int id, GuiNpcButton button) {
|
||||
if (id == 100) {
|
||||
dash.setDashMode(AbilityDash.DashMode.values()[button.getValue()]);
|
||||
dash.setDashModeEnum(AbilityDash.DashMode.values()[button.getValue()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 1: Anchor Point
|
||||
addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5));
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), disc.getAnchorPoint().getId());
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), disc.getAnchorPointEnum().getId());
|
||||
anchorBtn.setHoverText("ability.hover.anchorPoint");
|
||||
addButton(anchorBtn);
|
||||
|
||||
@@ -227,7 +227,7 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig {
|
||||
initGui();
|
||||
break;
|
||||
case 210:
|
||||
disc.setAnchorPoint(AnchorPoint.fromId(value));
|
||||
disc.setAnchorPointEnum(AnchorPoint.fromId(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 1: Anchor Point
|
||||
addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5));
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), beam.getAnchorPoint().getId());
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), beam.getAnchorPointEnum().getId());
|
||||
anchorBtn.setHoverText("ability.hover.anchorPoint");
|
||||
addButton(anchorBtn);
|
||||
|
||||
@@ -219,7 +219,7 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig {
|
||||
initGui();
|
||||
break;
|
||||
case 210:
|
||||
beam.setAnchorPoint(AnchorPoint.fromId(value));
|
||||
beam.setAnchorPointEnum(AnchorPoint.fromId(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SubGuiAbilityGuard extends SubGuiAbilityConfig {
|
||||
|
||||
addLabel(new GuiNpcLabel(102, "ability.counterType", col2LabelX, y + 5));
|
||||
String[] types = {"Flat", "Percent"};
|
||||
GuiNpcButton counterTypeButton = new GuiNpcButton(102, col2FieldX, y, 60, 20, types, guard.getCounterType().ordinal());
|
||||
GuiNpcButton counterTypeButton = new GuiNpcButton(102, col2FieldX, y, 60, 20, types, guard.getCounterTypeEnum().ordinal());
|
||||
counterTypeButton.setHoverText("ability.hover.counterType");
|
||||
counterTypeButton.setEnabled(guard.isCanCounter());
|
||||
addButton(counterTypeButton);
|
||||
@@ -97,7 +97,7 @@ public class SubGuiAbilityGuard extends SubGuiAbilityConfig {
|
||||
initGui();
|
||||
break;
|
||||
case 102:
|
||||
guard.setCounterType(AbilityGuard.CounterType.values()[button.getValue()]);
|
||||
guard.setCounterTypeEnum(AbilityGuard.CounterType.values()[button.getValue()]);
|
||||
break;
|
||||
case 150:
|
||||
setSubGui(new SubGuiAbilityEffects(guard.getEffects()));
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig {
|
||||
|
||||
addLabel(new GuiNpcLabel(100, "ability.shape", col2LabelX, y + 5));
|
||||
String[] shapes = {"Circle", "Ring", "Cone"};
|
||||
GuiNpcButton shapeBtn = new GuiNpcButton(100, col2FieldX, y, 55, 20, shapes, hazard.getShape().ordinal());
|
||||
GuiNpcButton shapeBtn = new GuiNpcButton(100, col2FieldX, y, 55, 20, shapes, hazard.getShapeEnum().ordinal());
|
||||
shapeBtn.setHoverText("ability.hover.shape");
|
||||
addButton(shapeBtn);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig {
|
||||
// Row 2: Placement
|
||||
addLabel(new GuiNpcLabel(101, "ability.placement", labelX, y + 5));
|
||||
String[] placements = {"Caster", "Target", "FollowCast", "FollowTgt"};
|
||||
GuiNpcButton placementBtn = new GuiNpcButton(101, fieldX, y, 70, 20, placements, hazard.getPlacement().ordinal());
|
||||
GuiNpcButton placementBtn = new GuiNpcButton(101, fieldX, y, 70, 20, placements, hazard.getPlacementEnum().ordinal());
|
||||
placementBtn.setHoverText("ability.hover.placement");
|
||||
addButton(placementBtn);
|
||||
|
||||
@@ -101,10 +101,10 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig {
|
||||
int value = button.getValue();
|
||||
switch (id) {
|
||||
case 100:
|
||||
hazard.setShape(AbilityHazard.HazardShape.values()[value]);
|
||||
hazard.setShapeEnum(AbilityHazard.HazardShape.values()[value]);
|
||||
break;
|
||||
case 101:
|
||||
hazard.setPlacement(AbilityHazard.PlacementMode.values()[value]);
|
||||
hazard.setPlacementEnum(AbilityHazard.PlacementMode.values()[value]);
|
||||
break;
|
||||
case 109:
|
||||
hazard.setAffectsCaster(value == 1);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig {
|
||||
|
||||
// Row 1: Anchor Point
|
||||
addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5));
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), orb.getAnchorPoint().getId());
|
||||
GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), orb.getAnchorPointEnum().getId());
|
||||
anchorBtn.setHoverText("ability.hover.anchorPoint");
|
||||
addButton(anchorBtn);
|
||||
|
||||
@@ -207,7 +207,7 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig {
|
||||
initGui();
|
||||
break;
|
||||
case 210:
|
||||
orb.setAnchorPoint(AnchorPoint.fromId(value));
|
||||
orb.setAnchorPointEnum(AnchorPoint.fromId(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,11 +34,11 @@ public class SubGuiAbilityTeleport extends SubGuiAbilityConfig {
|
||||
// Row 1: Mode
|
||||
addLabel(new GuiNpcLabel(100, "ability.mode", labelX, y + 5));
|
||||
String[] modes = {"Blink", "Behind", "Single"};
|
||||
addButton(new GuiNpcButton(100, fieldX, y, 80, 20, modes, teleport.getMode().ordinal()));
|
||||
addButton(new GuiNpcButton(100, fieldX, y, 80, 20, modes, teleport.getModeEnum().ordinal()));
|
||||
|
||||
y += 24;
|
||||
|
||||
switch (teleport.getMode()) {
|
||||
switch (teleport.getModeEnum()) {
|
||||
case BLINK:
|
||||
// Row 2: Blink Radius + Blink Count
|
||||
addLabel(new GuiNpcLabel(101, "ability.blinkRadius", labelX, y + 5));
|
||||
@@ -109,7 +109,7 @@ public class SubGuiAbilityTeleport extends SubGuiAbilityConfig {
|
||||
int value = button.getValue();
|
||||
switch (id) {
|
||||
case 100:
|
||||
teleport.setMode(AbilityTeleport.TeleportMode.values()[value]);
|
||||
teleport.setModeEnum(AbilityTeleport.TeleportMode.values()[value]);
|
||||
initGui();
|
||||
break;
|
||||
case 105:
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SubGuiAbilityTrap extends SubGuiAbilityConfig {
|
||||
|
||||
addLabel(new GuiNpcLabel(100, "ability.placement", col2LabelX, y + 5));
|
||||
String[] placements = {"Caster", "Target", "Ahead"};
|
||||
GuiNpcButton placementBtn = new GuiNpcButton(100, col2FieldX, y, 55, 20, placements, trap.getPlacement().ordinal());
|
||||
GuiNpcButton placementBtn = new GuiNpcButton(100, col2FieldX, y, 55, 20, placements, trap.getPlacementEnum().ordinal());
|
||||
placementBtn.setHoverText("ability.hover.placement");
|
||||
addButton(placementBtn);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class SubGuiAbilityTrap extends SubGuiAbilityConfig {
|
||||
@Override
|
||||
protected void handleTypeButton(int id, GuiNpcButton button) {
|
||||
if (id == 100) {
|
||||
trap.setPlacement(AbilityTrap.TrapPlacement.values()[button.getValue()]);
|
||||
trap.setPlacementEnum(AbilityTrap.TrapPlacement.values()[button.getValue()]);
|
||||
} else if (id == 150) {
|
||||
setSubGui(new SubGuiAbilityEffects(trap.getEffects()));
|
||||
}
|
||||
|
||||
@@ -1457,4 +1457,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
public IMagicData getMagicData() {
|
||||
return npc.stats.magicData;
|
||||
}
|
||||
|
||||
public noppes.npcs.api.ability.IDataAbilities getAbilityData() {
|
||||
return new noppes.npcs.scripted.wrapper.ScriptDataAbilities(npc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package noppes.npcs.scripted.wrapper;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.DataAbilities;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.ability.IDataAbilities;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
/**
|
||||
* Script wrapper for DataAbilities providing API access to NPC abilities.
|
||||
*/
|
||||
public class ScriptDataAbilities implements IDataAbilities {
|
||||
|
||||
private final DataAbilities data;
|
||||
private final EntityNPCInterface npc;
|
||||
|
||||
public ScriptDataAbilities(EntityNPCInterface npc) {
|
||||
this.npc = npc;
|
||||
this.data = npc.abilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return data.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
data.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility[] getAbilities() {
|
||||
return data.getAbilities().toArray(new IAbility[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAbility(IAbility ability) {
|
||||
if (ability instanceof Ability) {
|
||||
data.addAbility((Ability) ability);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAbility(String abilityId) {
|
||||
data.removeAbility(abilityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getAbility(String abilityId) {
|
||||
return data.getAbility(abilityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAbility(String abilityId) {
|
||||
return data.getAbility(abilityId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAbilities() {
|
||||
data.clearAbilities();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getCurrentAbility() {
|
||||
return data.getCurrentAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExecutingAbility() {
|
||||
return data.isExecutingAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interruptCurrentAbility() {
|
||||
data.interruptCurrentAbility(null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGlobalCooldown() {
|
||||
return (int) data.getRemainingCooldown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGlobalCooldown(int ticks) {
|
||||
// Set the cooldown by manipulating the internal cooldown end time
|
||||
// Not directly exposed, but we can reset and let it tick down
|
||||
data.resetCooldown();
|
||||
// This is a best-effort implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetCooldowns() {
|
||||
data.resetCooldown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forceStartAbility(String abilityId) {
|
||||
return forceStartAbility(abilityId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forceStartAbility(String abilityId, Object target) {
|
||||
// Find the ability
|
||||
Ability ability = data.getAbility(abilityId);
|
||||
if (ability == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Resolve target
|
||||
EntityLivingBase targetEntity = resolveTarget(target);
|
||||
|
||||
// Use the direct force start method
|
||||
return data.forceStartAbility(ability, targetEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executePresetAbility(String presetName) {
|
||||
return executePresetAbility(presetName, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executePresetAbility(String presetName, Object target) {
|
||||
// Resolve target
|
||||
EntityLivingBase targetEntity = resolveTarget(target);
|
||||
|
||||
// Use the direct preset execution method
|
||||
return data.executePresetAbility(presetName, targetEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility createAbility(String typeId) {
|
||||
if (AbilityController.Instance == null) {
|
||||
return null;
|
||||
}
|
||||
return AbilityController.Instance.create(typeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a target object to an EntityLivingBase.
|
||||
*/
|
||||
private EntityLivingBase resolveTarget(Object target) {
|
||||
if (target == null) {
|
||||
// Try to use the NPC's current attack target
|
||||
return npc.getAttackTarget();
|
||||
}
|
||||
|
||||
if (target instanceof EntityLivingBase) {
|
||||
return (EntityLivingBase) target;
|
||||
}
|
||||
|
||||
if (target instanceof noppes.npcs.api.entity.IEntityLivingBase) {
|
||||
Object mcEntity = ((noppes.npcs.api.entity.IEntityLivingBase<?>) target).getMCEntity();
|
||||
if (mcEntity instanceof EntityLivingBase) {
|
||||
return (EntityLivingBase) mcEntity;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user