From b8fc118369375341f119cb99510ffb22600f89ad Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Mon, 28 Apr 2025 07:19:59 +0300 Subject: [PATCH] Added before and after chains to IAction --- .../npcs/scripted/ScriptedActionManager.java | 104 +++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptedActionManager.java b/src/main/java/noppes/npcs/scripted/ScriptedActionManager.java index bc0c0a96d..37a552d8b 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptedActionManager.java +++ b/src/main/java/noppes/npcs/scripted/ScriptedActionManager.java @@ -161,7 +161,7 @@ public class ScriptedActionManager implements IActionManager { protected int startAfterTicks; protected int count = 0; protected int duration = 0; - protected final int maxDuration; + protected int maxDuration = -1; protected int updateEveryXTick = 5; protected final Consumer task; private boolean done = false; @@ -173,6 +173,26 @@ public class ScriptedActionManager implements IActionManager { this.task = task; } + public ActionBase(String name, int startAfterTicks, Consumer task) { + this.name = name; + this.startAfterTicks = startAfterTicks; + this.task = task; + } + + public ActionBase(String name, Consumer task) { + this.name = name; + this.task = task; + } + + public ActionBase(int startAfterTicks, Consumer task) { + this(task); + this.startAfterTicks = startAfterTicks; + } + + public ActionBase(Consumer task) { + this.name = task.toString(); + this.task = task; + } /** * Called once per global tick; respects delay, interval, duration & done‐flag. */ @@ -221,6 +241,7 @@ public class ScriptedActionManager implements IActionManager { return done; } + private final java.util.Map dataStore = new java.util.HashMap<>(); @Override public Object getData(String key) { return dataStore.get(key); @@ -267,6 +288,9 @@ public class ScriptedActionManager implements IActionManager { : null; } + ///////////////////////////////////////////////// + ///////////////////////////////////////////////// + //After chains @Override public IAction after(IAction after) { int idx = getIndex(this); @@ -274,8 +298,40 @@ public class ScriptedActionManager implements IActionManager { return after; } + @Override + public IAction after(String name, int maxDuration, int delay, Consumer t) { + IAction act = new Action(name, maxDuration, delay, t); + return after(act); + } + @Override + public IAction after(String name, int delay, Consumer t) { + IAction act = new Action(name, delay, t); + return after(act); + } + @Override + public IAction after(int delay, Consumer t) { + IAction act = new Action(delay, t); + return after(act); + } + + @Override + public IAction after(String name, Consumer t) { + IAction act = new Action(name, t); + return after(act); + } + + @Override + public IAction after(Consumer t) { + IAction act = new Action(t); + return after(act); + + } + + ///////////////////////////////////////////////// + ///////////////////////////////////////////////// + //Before chains @Override public IAction before(IAction before) { int idx = getIndex(this); @@ -283,7 +339,35 @@ public class ScriptedActionManager implements IActionManager { return before; } - private final java.util.Map dataStore = new java.util.HashMap<>(); + @Override + public IAction before(String name, int maxDuration, int delay, Consumer t) { + IAction act = new Action(name, maxDuration, delay, t); + return before(act); + } + + @Override + public IAction before(String name, int delay, Consumer t) { + IAction act = new Action(name, delay, t); + return before(act); + } + + @Override + public IAction before(int delay, Consumer t) { + IAction act = new Action(delay, t); + return before(act); + } + + @Override + public IAction before(String name, Consumer t) { + IAction act = new Action(name, t); + return before(act); + } + + @Override + public IAction before(Consumer t) { + IAction act = new Action(t); + return before(act); + } } private class Action extends ActionBase { @@ -291,6 +375,22 @@ public class ScriptedActionManager implements IActionManager { super(name, maxDuration, startAfterTicks, task); } + public Action(String name, int startAfterTicks, Consumer task) { + super(name, startAfterTicks, task); + } + + public Action(String name, Consumer task) { + super(name, task); + } + + public Action(int startAfterTicks, Consumer task) { + super(startAfterTicks, task); + } + + public Action(Consumer task) { + super(task); + } + @Override public int getCheckCount() { return 0; } @Override public int getMaxChecks() { return 0; }