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