mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-12 10:21:39 +01:00
Switched to Cooldown object in attacking goals
This commit is contained in:
parent
3f184aad41
commit
e295ffea51
@ -20,8 +20,7 @@ import java.util.function.Function;
|
||||
*/
|
||||
public class CombinedAttackGoal extends GoalSelector {
|
||||
|
||||
private final UpdateOption pathUpdateOptions = new UpdateOption(5, TimeUnit.TICK);
|
||||
private long lastPathUpdate;
|
||||
private final Cooldown cooldown = new Cooldown(new UpdateOption(5, TimeUnit.TICK));
|
||||
|
||||
private final int meleeRangeSquared;
|
||||
private final int meleeDelay;
|
||||
@ -94,8 +93,8 @@ public class CombinedAttackGoal extends GoalSelector {
|
||||
Check.argCondition(desirableRange > rangedRange, "Desirable range can not exceed ranged range!");
|
||||
}
|
||||
|
||||
public UpdateOption getPathUpdateOptions() {
|
||||
return this.pathUpdateOptions;
|
||||
public Cooldown getCooldown() {
|
||||
return this.cooldown;
|
||||
}
|
||||
|
||||
public void setProjectileGenerator(Function<Entity, EntityProjectile> projectileGenerator) {
|
||||
@ -167,8 +166,8 @@ public class CombinedAttackGoal extends GoalSelector {
|
||||
// Otherwise going to the target.
|
||||
Position targetPosition = target.getPosition();
|
||||
if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) {
|
||||
if (!Cooldown.hasCooldown(time, this.lastPathUpdate, getPathUpdateOptions())) {
|
||||
this.lastPathUpdate = time;
|
||||
if (this.cooldown.isReady(time)) {
|
||||
this.cooldown.refreshLastUpdate(time);
|
||||
navigator.setPathTo(targetPosition);
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class MeleeAttackGoal extends GoalSelector {
|
||||
|
||||
private final UpdateOption pathUpdateOptions = new UpdateOption(5, TimeUnit.TICK);
|
||||
private long lastPathUpdate;
|
||||
private final Cooldown cooldown = new Cooldown(new UpdateOption(5, TimeUnit.TICK));
|
||||
|
||||
private long lastHit;
|
||||
private final int delay;
|
||||
@ -41,8 +40,8 @@ public class MeleeAttackGoal extends GoalSelector {
|
||||
this.timeUnit = timeUnit;
|
||||
}
|
||||
|
||||
public UpdateOption getPathUpdateOptions() {
|
||||
return this.pathUpdateOptions;
|
||||
public Cooldown getCooldown() {
|
||||
return this.cooldown;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,8 +84,8 @@ public class MeleeAttackGoal extends GoalSelector {
|
||||
final Position pathPosition = navigator.getPathPosition();
|
||||
final Position targetPosition = target.getPosition();
|
||||
if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) {
|
||||
if (!Cooldown.hasCooldown(time, this.lastPathUpdate, getPathUpdateOptions())) {
|
||||
this.lastPathUpdate = time;
|
||||
if (this.cooldown.isReady(time)) {
|
||||
this.cooldown.refreshLastUpdate(time);
|
||||
navigator.setPathTo(targetPosition);
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,7 @@ import java.util.function.Function;
|
||||
|
||||
public class RangedAttackGoal extends GoalSelector {
|
||||
|
||||
private final UpdateOption pathUpdateOptions = new UpdateOption(5, TimeUnit.TICK);
|
||||
private long lastPathUpdate;
|
||||
private final Cooldown cooldown = new Cooldown(new UpdateOption(5, TimeUnit.TICK));
|
||||
|
||||
private long lastShot;
|
||||
private final int delay;
|
||||
@ -56,8 +55,8 @@ public class RangedAttackGoal extends GoalSelector {
|
||||
Check.argCondition(desirableRange > attackRange, "Desirable range can not exceed attack range!");
|
||||
}
|
||||
|
||||
public UpdateOption getPathUpdateOptions() {
|
||||
return this.pathUpdateOptions;
|
||||
public Cooldown getCooldown() {
|
||||
return this.cooldown;
|
||||
}
|
||||
|
||||
public void setProjectileGenerator(Function<Entity, EntityProjectile> projectileGenerator) {
|
||||
@ -119,8 +118,8 @@ public class RangedAttackGoal extends GoalSelector {
|
||||
}
|
||||
Position targetPosition = target.getPosition();
|
||||
if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) {
|
||||
if (!Cooldown.hasCooldown(time, this.lastPathUpdate, getPathUpdateOptions())) {
|
||||
this.lastPathUpdate = time;
|
||||
if (this.cooldown.isReady(time)) {
|
||||
this.cooldown.refreshLastUpdate(time);
|
||||
navigator.setPathTo(targetPosition);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,10 @@ public final class Cooldown {
|
||||
this.lastUpdate = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public UpdateOption getUpdateOption() {
|
||||
return this.updateOption;
|
||||
}
|
||||
|
||||
public void refreshLastUpdate(long lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user