mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 04:09:57 +00:00
Better Lock Movement handling
This commit is contained in:
1 parent
83ccd25b33
commit
7d2bba7b95
24 files changed
+227
-60
No files matched your search
@@ -79,7 +79,7 @@ public class DataAbilities {
|
||||
private transient List<Long> recentHitTimes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Locked rotation values for ACTIVE phase with lockMovement.
|
||||
* Locked rotation values for ACTIVE phase when movement is locked.
|
||||
* Stored when entering ACTIVE phase, applied every tick to prevent rotation changes.
|
||||
*/
|
||||
private transient boolean rotationLocked = false;
|
||||
@@ -146,9 +146,9 @@ public class DataAbilities {
|
||||
// Remove telegraph - it has served its purpose
|
||||
removeTelegraph(currentAbility);
|
||||
|
||||
// Lock rotation if lockMovement is true
|
||||
// Lock rotation if movement is locked during ACTIVE phase
|
||||
// Capture current rotation values to force them every tick
|
||||
if (currentAbility.isLockMovement()) {
|
||||
if (currentAbility.isMovementLockedDuringActive()) {
|
||||
captureLockedRotation();
|
||||
}
|
||||
|
||||
@@ -191,6 +191,32 @@ public class DataAbilities {
|
||||
handleAbilityCompletion(target);
|
||||
break;
|
||||
}
|
||||
|
||||
// Apply movement control if ability is still executing
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
applyMovementControl();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply movement control based on lock movement settings.
|
||||
* Called every tick during ability execution.
|
||||
*/
|
||||
private void applyMovementControl() {
|
||||
if (currentAbility == null) return;
|
||||
|
||||
// Check if movement should be locked for the current phase
|
||||
if (currentAbility.isMovementLockedForCurrentPhase()) {
|
||||
// Clear navigator to prevent AI pathfinding
|
||||
npc.getNavigator().clearPathEntity();
|
||||
|
||||
// Zero motion if ability doesn't have its own movement
|
||||
// This allows abilities like Charge/Slam to control their own motion
|
||||
if (!currentAbility.hasAbilityMovement()) {
|
||||
npc.motionX = 0;
|
||||
npc.motionZ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,29 +236,11 @@ public class DataAbilities {
|
||||
npc.wrappedNPC, currentAbility, target);
|
||||
NpcAPI.EVENT_BUS.post(completeEvent);
|
||||
|
||||
// Clean up and roll cooldown
|
||||
// Release rotation lock before cleanup
|
||||
releaseLockedRotation();
|
||||
|
||||
// Clean up and roll cooldown (this sets currentAbility to null)
|
||||
onAbilityComplete();
|
||||
|
||||
// Clear AI pathfinding if ability is controlling movement
|
||||
// But DON'T zero motion - let the ability set it if needed
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
if (isAbilityControllingMovement()) {
|
||||
// Clear navigator so AI doesn't fight with ability movement
|
||||
npc.getNavigator().clearPathEntity();
|
||||
|
||||
// Only zero motion if lockMovement is true AND ability doesn't have its own movement
|
||||
// This allows stationary abilities to freeze the NPC, while movement abilities can set their own motion
|
||||
if (currentAbility.isLockMovement() && !currentAbility.hasAbilityMovement()) {
|
||||
npc.motionX = 0;
|
||||
npc.motionZ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Unlock rotation when leaving ACTIVE phase
|
||||
if (rotationLocked && currentAbility.getPhase() != AbilityPhase.ACTIVE) {
|
||||
releaseLockedRotation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -787,8 +795,8 @@ public class DataAbilities {
|
||||
* Called by AI tasks to determine if they should try to path.
|
||||
* <p>
|
||||
* Rules:
|
||||
* - WINDUP phase: Block AI if lockMovement is true
|
||||
* - ACTIVE phase: Block AI if lockMovement OR hasAbilityMovement is true
|
||||
* - WINDUP phase: Block AI if movement is locked during windup
|
||||
* - ACTIVE phase: Block AI if movement is locked during active OR hasAbilityMovement is true
|
||||
* - DAZED phase: Always block AI (NPC is stunned)
|
||||
*/
|
||||
public boolean isAbilityControllingMovement() {
|
||||
@@ -800,15 +808,15 @@ public class DataAbilities {
|
||||
|
||||
switch (phase) {
|
||||
case WINDUP:
|
||||
// During windup, only block if lockMovement is set
|
||||
// This allows NPC to keep chasing while winding up if lockMovement=false
|
||||
return currentAbility.isLockMovement();
|
||||
// During windup, only block if movement is locked during windup
|
||||
// This allows NPC to keep chasing while winding up if not locked
|
||||
return currentAbility.isMovementLockedDuringWindup();
|
||||
|
||||
case ACTIVE:
|
||||
// During active phase, block if either:
|
||||
// - lockMovement is true (stationary ability)
|
||||
// - movement is locked during active (stationary ability)
|
||||
// - hasAbilityMovement is true (ability is moving the NPC itself)
|
||||
return currentAbility.isLockMovement() || currentAbility.hasAbilityMovement();
|
||||
return currentAbility.isMovementLockedDuringActive() || currentAbility.hasAbilityMovement();
|
||||
|
||||
case DAZED:
|
||||
// During dazed phase, always block - NPC is stunned from interrupt
|
||||
@@ -821,7 +829,7 @@ public class DataAbilities {
|
||||
|
||||
/**
|
||||
* Check if NPC's look direction should be locked to target.
|
||||
* Only locks during ACTIVE phase when lockMovement is true.
|
||||
* Only locks during ACTIVE phase when movement is locked during active.
|
||||
* This allows the NPC to freely track target during WINDUP and DAZED.
|
||||
*/
|
||||
public boolean shouldLockLookDirection() {
|
||||
@@ -834,7 +842,7 @@ public class DataAbilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
return currentAbility.isLockMovement();
|
||||
return currentAbility.isMovementLockedDuringActive();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -854,7 +862,7 @@ public class DataAbilities {
|
||||
|
||||
/**
|
||||
* Capture current rotation values to lock NPC's look direction.
|
||||
* Called when entering ACTIVE phase with lockMovement enabled.
|
||||
* Called when entering ACTIVE phase with movement locked during active.
|
||||
*/
|
||||
private void captureLockedRotation() {
|
||||
lockedYaw = npc.rotationYaw;
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.Condition;
|
||||
import kamkeel.npcs.controllers.data.ability.LockMovementType;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
@@ -58,7 +59,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
protected String name;
|
||||
protected boolean enabled;
|
||||
protected int weight;
|
||||
protected boolean lockMovement;
|
||||
protected LockMovementType lockMovement;
|
||||
protected boolean interruptible;
|
||||
|
||||
// Timing
|
||||
@@ -111,7 +112,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
this.name = ability.getName() != null ? ability.getName() : "";
|
||||
this.enabled = ability.isEnabled();
|
||||
this.weight = ability.getWeight();
|
||||
this.lockMovement = ability.isLockMovement();
|
||||
this.lockMovement = ability.getLockMovement();
|
||||
this.interruptible = ability.isInterruptible();
|
||||
|
||||
// Timing
|
||||
@@ -251,7 +252,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
addTextField(weightField);
|
||||
|
||||
addLabel(new GuiNpcLabel(5, "ability.lockMove", col2LabelX, y + 5));
|
||||
GuiNpcButton lockMoveBtn = new GuiNpcButton(16, col2FieldX, y, 40, 20, new String[]{"gui.no", "gui.yes"}, lockMovement ? 1 : 0);
|
||||
GuiNpcButton lockMoveBtn = new GuiNpcButton(16, col2FieldX, y, 60, 20, LockMovementType.getDisplayKeys(), lockMovement.ordinal());
|
||||
lockMoveBtn.setHoverText("ability.hover.lockMove");
|
||||
addButton(lockMoveBtn);
|
||||
|
||||
@@ -644,7 +645,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
interruptible = ((GuiNpcButton) guibutton).getValue() == 1;
|
||||
initGui(); // Refresh to show/hide dazed ticks field
|
||||
} else if (id == 16) {
|
||||
lockMovement = ((GuiNpcButton) guibutton).getValue() == 1;
|
||||
lockMovement = LockMovementType.fromOrdinal(((GuiNpcButton) guibutton).getValue());
|
||||
} else if (id == 17) {
|
||||
// Sync windup ticks with animation duration
|
||||
syncWindupWithAnimation();
|
||||
@@ -920,7 +921,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
this.name = ability.getName() != null ? ability.getName() : "";
|
||||
this.enabled = ability.isEnabled();
|
||||
this.weight = ability.getWeight();
|
||||
this.lockMovement = ability.isLockMovement();
|
||||
this.lockMovement = ability.getLockMovement();
|
||||
this.interruptible = ability.isInterruptible();
|
||||
|
||||
this.cooldownTicks = ability.getCooldownTicks();
|
||||
|
||||
Reference in new issue
Block a user