Heavy Action Refactoring

This commit is contained in:
Kam committed 2025-04-28 03:25:01 -04:00
1 parent d3cae9e9cb
commit ae4b4c8702
6 files changed
+464 -460

No files matched your search

@@ -0,0 +1,35 @@
package noppes.npcs.controllers.data.action;
import noppes.npcs.api.handler.data.IAction;
import noppes.npcs.api.handler.data.IActionChain;
import noppes.npcs.scripted.ScriptedActionManager;
import java.util.function.Consumer;
/**
* helper to build a back‐to‐back chain of one‐shot actions
*/
public class ActionChain implements IActionChain {
private final ScriptedActionManager scriptedActionManager;
private int offset = 0, index = 0;
public ActionChain(ScriptedActionManager scriptedActionManager) {
this.scriptedActionManager = scriptedActionManager;
}
/**
* schedule the next task ‘delay’ ticks after the previous one
*/
@Override
public IActionChain after(int delay, Consumer<IAction> task) {
offset += delay;
Consumer<IAction> wrapper = act -> {
task.accept(act);
act.markDone();
};
IAction a = scriptedActionManager.create("chain#" + (index++), Integer.MAX_VALUE, offset, wrapper);
a.setUpdateEveryXTick(1);
scriptedActionManager.scheduleAction(a);
return this;
}
}