mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 02:37:27 +00:00
Add a chain builder to action manager
This commit is contained in:
1 parent
1e249f317d
commit
a6665b1de8
2 files changed
+26
-1
No files matched your search
@@ -2,6 +2,7 @@ package noppes.npcs.scripted;
|
||||
|
||||
import noppes.npcs.api.handler.IActionManager;
|
||||
import noppes.npcs.api.handler.data.IAction;
|
||||
import noppes.npcs.api.handler.data.IActionChain;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
@@ -126,6 +127,30 @@ public class ScriptedActionManager implements IActionManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IActionChain chain() {
|
||||
return new ActionChain(this);
|
||||
}
|
||||
|
||||
/** helper to build a back‐to‐back chain of one‐shot actions */
|
||||
public static class ActionChain implements IActionChain {
|
||||
private final IActionManager mgr;
|
||||
private int offset = 0, index = 0;
|
||||
|
||||
private ActionChain(IActionManager mgr) {
|
||||
this.mgr = mgr;
|
||||
}
|
||||
|
||||
/** schedule the next task ‘delay’ ticks after the previous one */
|
||||
@Override
|
||||
public IActionChain after(int delay, Consumer<IAction> task) {
|
||||
offset += delay;
|
||||
IAction a = mgr.create("chain#" + (index++), 1, offset, task);
|
||||
mgr.scheduleAction(a);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
// ──── base class for all custom actions ──────────────────────────────────
|
||||
|
||||
private abstract class ActionBase implements IAction {
|
||||
|
||||
Reference in new issue
Block a user