diff --git a/Server/src/main/content/minigame/pestcontrol/bots/CombatState.kt b/Server/src/main/content/minigame/pestcontrol/bots/CombatState.kt index eda19e11f..dbfb2ee4a 100644 --- a/Server/src/main/content/minigame/pestcontrol/bots/CombatState.kt +++ b/Server/src/main/content/minigame/pestcontrol/bots/CombatState.kt @@ -97,30 +97,22 @@ class CombatState(val bot: PestControlTestBot) { } } - //Functions - fun randomWalkTo(loc: Location, radius: Int) { + var newloc = loc.transform(RandomFunction.random(radius, -radius), + RandomFunction.random(radius, -radius), 0) if(!bot.walkingQueue.isMoving) { - GlobalScope.launch { - var newloc = loc.transform(RandomFunction.random(radius, -radius), - RandomFunction.random(radius, -radius), 0) - walkToIterator(newloc) - } + walkToIterator(newloc) } } private fun walkToIterator(loc: Location){ var diffX = loc.x - bot.location.x var diffY = loc.y - bot.location.y - while(!bot.location.transform(diffX, diffY, 0).withinDistance(bot.location)) { - diffX /= 2 - diffY /= 2 - } + GameWorld.Pulser.submit(object : MovementPulse(bot, bot.location.transform(diffX, diffY, 0), Pathfinder.SMART) { override fun pulse(): Boolean { return true } }) } - } diff --git a/Server/src/main/content/minigame/pestcontrol/bots/CombatStateIntermediate.kt b/Server/src/main/content/minigame/pestcontrol/bots/CombatStateIntermediate.kt index 303a3d9a9..fbea681bd 100644 --- a/Server/src/main/content/minigame/pestcontrol/bots/CombatStateIntermediate.kt +++ b/Server/src/main/content/minigame/pestcontrol/bots/CombatStateIntermediate.kt @@ -97,30 +97,22 @@ class CombatStateIntermediate(val bot: PestControlTestBot2) { } //Functions - fun randomWalkTo(loc: Location, radius: Int) { + var newloc = loc.transform(RandomFunction.random(radius, -radius), + RandomFunction.random(radius, -radius), 0) if(!bot.walkingQueue.isMoving) { - GlobalScope.launch { - Thread.currentThread().name = "RandomWalkToIteratorBot" - var newloc = loc.transform(RandomFunction.random(radius, -radius), - RandomFunction.random(radius, -radius), 0) - walkToIterator(newloc) - } + walkToIterator(newloc) } } private fun walkToIterator(loc: Location){ var diffX = loc.x - bot.location.x var diffY = loc.y - bot.location.y - while(!bot.location.transform(diffX, diffY, 0).withinDistance(bot.location)) { - diffX /= 2 - diffY /= 2 - } + GameWorld.Pulser.submit(object : MovementPulse(bot, bot.location.transform(diffX, diffY, 0), Pathfinder.SMART) { override fun pulse(): Boolean { return true } }) } - } diff --git a/Server/src/main/core/game/interaction/MovementPulse.java b/Server/src/main/core/game/interaction/MovementPulse.java index 4d4e5f459..fbc345d49 100644 --- a/Server/src/main/core/game/interaction/MovementPulse.java +++ b/Server/src/main/core/game/interaction/MovementPulse.java @@ -7,6 +7,7 @@ import core.game.node.entity.npc.NPC; import core.game.node.entity.npc.NPCBehavior; import core.game.node.entity.player.Player; import core.game.system.task.Pulse; +import core.game.world.GameWorld; import core.game.world.map.Direction; import core.game.world.map.Location; import core.game.world.map.Point; @@ -191,6 +192,12 @@ public abstract class MovementPulse extends Pulse { if (destination instanceof NPC || destination instanceof Player) destinationFlag = DestinationFlag.ENTITY; + + if (mover.currentMovement != null) { + mover.currentMovement.stop(); + mover.getWalkingQueue().reset(); + } + mover.currentMovement = this; } @Override diff --git a/Server/src/main/core/game/node/entity/Entity.java b/Server/src/main/core/game/node/entity/Entity.java index 01f6ba2c7..65197342f 100644 --- a/Server/src/main/core/game/node/entity/Entity.java +++ b/Server/src/main/core/game/node/entity/Entity.java @@ -106,6 +106,8 @@ public abstract class Entity extends Node { public ScriptProcessor scripts = new ScriptProcessor(this); public final int[] clocks = new int[10]; + public MovementPulse currentMovement; + /** * The mapping of event types to event hooks