mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 07:17:27 +00:00
Improved ParallelActionChain
This commit is contained in:
1 parent
7928c189ad
commit
2bb1df968b
3 files changed
+14
-25
No files matched your search
+1
-1
Submodule src/api updated: f998e8feb4...13d32ae425.
@@ -10,11 +10,12 @@ 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 manager;
|
||||
private int index = 0;
|
||||
protected final ScriptedActionManager manager;
|
||||
protected String defaultName = "sequential#";
|
||||
protected int index = 0;
|
||||
|
||||
public ActionChain(ScriptedActionManager scriptedActionManager) {
|
||||
this.manager = scriptedActionManager;
|
||||
public ActionChain(ScriptedActionManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,14 +23,14 @@ public class ActionChain implements IActionChain {
|
||||
*/
|
||||
@Override
|
||||
public IActionChain after(int delay, String name, Consumer<IAction> task) {
|
||||
index++;
|
||||
manager.schedule(name, delay, task).updateEvery(1).once();
|
||||
index++;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IActionChain after(int delay, Consumer<IAction> task) {
|
||||
return after(delay, "chain#" + index, task);
|
||||
return after(delay, defaultName + index, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,12 +6,12 @@ import noppes.npcs.scripted.ScriptedActionManager;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ParallelActionChain implements IActionChain {
|
||||
private final ScriptedActionManager manager;
|
||||
private int offset = 0, idx = 0;
|
||||
public class ParallelActionChain extends ActionChain implements IActionChain {
|
||||
private int offset;
|
||||
|
||||
public ParallelActionChain(ScriptedActionManager scriptedActionManager) {
|
||||
this.manager = scriptedActionManager;
|
||||
public ParallelActionChain(ScriptedActionManager manager) {
|
||||
super(manager);
|
||||
defaultName = "parallel#";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -20,20 +20,8 @@ public class ParallelActionChain implements IActionChain {
|
||||
@Override
|
||||
public IActionChain after(int delay, String name, Consumer<IAction> task) {
|
||||
offset += delay;
|
||||
idx++;
|
||||
|
||||
manager.scheduleParallel(name, offset, task).updateEvery(1).once();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IActionChain after(int delay, Consumer<IAction> task) {
|
||||
return after(delay, "parallel#" + idx, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IActionChain start() {
|
||||
manager.start();
|
||||
index++;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user