mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 21:54:08 +00:00
Adjusted ActionChains
This commit is contained in:
1 parent
a52c676fcb
commit
47dc56c25e
2 files changed
+19
-20
No files matched your search
@@ -10,11 +10,11 @@ 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 final ScriptedActionManager manager;
|
||||
private int offset = 0, index = 0;
|
||||
|
||||
public ActionChain(ScriptedActionManager scriptedActionManager) {
|
||||
this.scriptedActionManager = scriptedActionManager;
|
||||
this.manager = scriptedActionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,14 +23,8 @@ public class ActionChain implements IActionChain {
|
||||
@Override
|
||||
public IActionChain after(int delay, String name, Consumer<IAction> task) {
|
||||
offset += delay;
|
||||
Consumer<IAction> wrapper = act -> {
|
||||
task.accept(act);
|
||||
act.markDone();
|
||||
};
|
||||
IAction a = scriptedActionManager.create(name, offset, wrapper);
|
||||
index++;
|
||||
a.setUpdateEveryXTick(1);
|
||||
scriptedActionManager.schedule(a);
|
||||
manager.schedule(name, offset, task).updateEvery(1).once();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -38,4 +32,10 @@ public class ActionChain implements IActionChain {
|
||||
public IActionChain after(int delay, Consumer<IAction> task) {
|
||||
return after(delay, "chain#" + index, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IActionChain start() {
|
||||
manager.start();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,11 @@ import noppes.npcs.scripted.ScriptedActionManager;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ParallelActionChain implements IActionChain {
|
||||
private final ScriptedActionManager scriptedActionManager;
|
||||
private final ScriptedActionManager manager;
|
||||
private int offset = 0, idx = 0;
|
||||
|
||||
public ParallelActionChain(ScriptedActionManager scriptedActionManager) {
|
||||
this.scriptedActionManager = scriptedActionManager;
|
||||
this.manager = scriptedActionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -20,16 +20,9 @@ public class ParallelActionChain implements IActionChain {
|
||||
@Override
|
||||
public IActionChain after(int delay, String name, Consumer<IAction> task) {
|
||||
offset += delay;
|
||||
Consumer<IAction> wrapper = act -> {
|
||||
task.accept(act);
|
||||
act.markDone();
|
||||
};
|
||||
IAction a = scriptedActionManager.create(name,
|
||||
offset,
|
||||
wrapper);
|
||||
idx++;
|
||||
a.setUpdateEveryXTick(1);
|
||||
scriptedActionManager.scheduleParallel(a);
|
||||
|
||||
manager.scheduleParallel(name, offset, task).updateEvery(1).once();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -37,4 +30,10 @@ public class ParallelActionChain implements IActionChain {
|
||||
public IActionChain after(int delay, Consumer<IAction> task) {
|
||||
return after(delay, "parallel#" + idx, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IActionChain start() {
|
||||
manager.start();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user