mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 11:57:29 +00:00
Refactored setUpdateEveryXTick to updateEvery
Added getMaxCount(), once() and times(int n)
This commit is contained in:
1 parent
f6e0cd8add
commit
a52c676fcb
2 files changed
+36
-9
No files matched your search
@@ -16,9 +16,8 @@ public class Action implements IAction {
|
||||
protected final ScriptedActionManager manager;
|
||||
protected final String name;
|
||||
protected int startAfterTicks;
|
||||
protected int count;
|
||||
protected int duration;
|
||||
protected int maxDuration = -1;
|
||||
protected int count, maxCount = -1;
|
||||
protected int duration, maxDuration = -1;
|
||||
protected int updateEveryXTick = 5;
|
||||
protected Consumer<IAction> task;
|
||||
protected boolean done;
|
||||
@@ -78,7 +77,7 @@ public class Action implements IAction {
|
||||
startAfterTicks--;
|
||||
return;
|
||||
}
|
||||
if (maxDuration > -1 && duration >= maxDuration) {
|
||||
if (maxDuration > -1 && duration >= maxDuration || maxCount == 0) {
|
||||
markDone();
|
||||
return;
|
||||
}
|
||||
@@ -88,6 +87,12 @@ public class Action implements IAction {
|
||||
else
|
||||
executeTask();
|
||||
}
|
||||
|
||||
if (maxCount > -1 && count >= maxCount) {
|
||||
markDone();
|
||||
return;
|
||||
}
|
||||
|
||||
duration++;
|
||||
}
|
||||
|
||||
@@ -105,7 +110,6 @@ public class Action implements IAction {
|
||||
t.printStackTrace();
|
||||
markDone();
|
||||
}
|
||||
duration++;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,6 +143,23 @@ public class Action implements IAction {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCount() {
|
||||
return maxCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAction times(int x) {
|
||||
this.maxCount = Math.max(-1, x);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAction once() {
|
||||
this.maxCount = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDone() {
|
||||
done = true;
|
||||
@@ -181,12 +202,12 @@ public class Action implements IAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUpdateEveryXTick() {
|
||||
public int getUpdateEvery() {
|
||||
return updateEveryXTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAction setUpdateEveryXTick(int x) {
|
||||
public IAction updateEvery(int x) {
|
||||
this.updateEveryXTick = Math.max(1, x);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
private boolean taskExecuted;
|
||||
|
||||
public ConditionalAction(ScriptedActionManager manager, Function<IAction, Boolean> condition, Consumer<IAction> task) {
|
||||
super(manager, "conditional", task);
|
||||
super(manager, task);
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
if (done)
|
||||
return;
|
||||
|
||||
if (maxChecks > -1 && checkCount > maxChecks) {
|
||||
if (maxChecks > -1 && checkCount > maxChecks || maxCount == 0) {
|
||||
markDone();
|
||||
return;
|
||||
}
|
||||
@@ -78,6 +78,12 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
|
||||
checkCount++;
|
||||
}
|
||||
|
||||
if (maxCount > -1 && count >= maxCount) {
|
||||
markDone();
|
||||
return;
|
||||
}
|
||||
|
||||
duration++;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user