mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-10-24 11:43:06 +02:00
120 lines
3.6 KiB
Java
120 lines
3.6 KiB
Java
package com.eu.habbo.threading.runnables;
|
|
|
|
import com.eu.habbo.Emulator;
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
|
import com.eu.habbo.habbohotel.rooms.RoomTile;
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
|
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
|
|
|
|
import java.util.List;
|
|
|
|
public class RoomUnitWalkToRoomUnit implements Runnable
|
|
{
|
|
private final int minDistance;
|
|
private RoomUnit walker;
|
|
private RoomUnit target;
|
|
private Room room;
|
|
private List<Runnable> targetReached;
|
|
private List<Runnable> failedReached;
|
|
|
|
private RoomTile goalTile = null;
|
|
|
|
public RoomUnitWalkToRoomUnit(RoomUnit walker, RoomUnit target, Room room, List<Runnable> targetReached, List<Runnable> failedReached)
|
|
{
|
|
this.walker = walker;
|
|
this.target = target;
|
|
this.room = room;
|
|
this.targetReached = targetReached;
|
|
this.failedReached = failedReached;
|
|
this.minDistance = 1;
|
|
}
|
|
|
|
public RoomUnitWalkToRoomUnit(RoomUnit walker, RoomUnit target, Room room, List<Runnable> targetReached, List<Runnable> failedReached, int minDistance)
|
|
{
|
|
this.walker = walker;
|
|
this.target = target;
|
|
this.room = room;
|
|
this.targetReached = targetReached;
|
|
this.failedReached = failedReached;
|
|
this.minDistance = minDistance;
|
|
}
|
|
|
|
@Override
|
|
public void run()
|
|
{
|
|
if(this.goalTile == null)
|
|
{
|
|
this.findNewLocation();
|
|
Emulator.getThreading().run(this, 500);
|
|
}
|
|
|
|
if(this.goalTile == null)
|
|
return;
|
|
|
|
if(this.walker.getGoal().equals(this.goalTile)) //Check if the goal is still the same. Chances are something is running the same task. If so we dump this task.
|
|
{
|
|
//Check if arrived.
|
|
if(this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance)
|
|
{
|
|
for(Runnable r : this.targetReached)
|
|
{
|
|
Emulator.getThreading().run(r);
|
|
|
|
WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, this.target, this.room, new Object[]{this.walker});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
List<RoomTile> tiles = this.room.getLayout().getTilesAround(this.target.getCurrentLocation());
|
|
|
|
for(RoomTile t : tiles)
|
|
{
|
|
if(t.equals(this.goalTile))
|
|
{
|
|
Emulator.getThreading().run(this, 500);
|
|
return;
|
|
}
|
|
}
|
|
|
|
this.findNewLocation();
|
|
|
|
Emulator.getThreading().run(this, 500);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void findNewLocation()
|
|
{
|
|
this.goalTile = this.room.getLayout().getTileInFront(this.target.getCurrentLocation(), this.target.getBodyRotation().getValue());
|
|
|
|
if (this.goalTile == null)
|
|
return;
|
|
|
|
if (!this.room.tileWalkable(this.goalTile))
|
|
{
|
|
List<RoomTile> tiles = this.room.getLayout().getTilesAround(this.target.getCurrentLocation());
|
|
|
|
for (RoomTile t : tiles)
|
|
{
|
|
if (this.room.tileWalkable(t))
|
|
{
|
|
this.goalTile = t;
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
this.walker.setGoalLocation(this.goalTile);
|
|
|
|
if (this.walker.getPath().isEmpty() && this.failedReached != null)
|
|
{
|
|
for(Runnable r : this.failedReached)
|
|
{
|
|
Emulator.getThreading().run(r);
|
|
}
|
|
}
|
|
}
|
|
}
|