2025-04-28 03:25:01 -04:00
|
|
|
|
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();
|
|
|
|
|
|
};
|
2025-04-28 10:41:36 +03:00
|
|
|
|
IAction a = scriptedActionManager.create("chain#" + (index++), offset, wrapper);
|
2025-04-28 03:25:01 -04:00
|
|
|
|
a.setUpdateEveryXTick(1);
|
|
|
|
|
|
scriptedActionManager.scheduleAction(a);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|