mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-23 15:20:52 +01:00
Make user walk to puzzle box if not adjacent (closes #336)
This commit is contained in:
parent
1cfbac1cfb
commit
9a161e1184
@ -1,16 +1,17 @@
|
|||||||
package com.eu.habbo.habbohotel.items.interactions;
|
package com.eu.habbo.habbohotel.items.interactions;
|
||||||
|
|
||||||
import com.eu.habbo.Emulator;
|
|
||||||
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
||||||
import com.eu.habbo.habbohotel.items.Item;
|
import com.eu.habbo.habbohotel.items.Item;
|
||||||
import com.eu.habbo.habbohotel.rooms.*;
|
import com.eu.habbo.habbohotel.rooms.*;
|
||||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||||
import com.eu.habbo.messages.ServerMessage;
|
import com.eu.habbo.messages.ServerMessage;
|
||||||
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
|
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
|
||||||
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class InteractionPuzzleBox extends HabboItem {
|
public class InteractionPuzzleBox extends HabboItem {
|
||||||
public InteractionPuzzleBox(ResultSet set, Item baseItem) throws SQLException {
|
public InteractionPuzzleBox(ResultSet set, Item baseItem) throws SQLException {
|
||||||
@ -26,41 +27,60 @@ public class InteractionPuzzleBox extends HabboItem {
|
|||||||
if (client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.MOVE))
|
if (client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.MOVE))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!RoomLayout.tilesAdjecent(room.getLayout().getTile(super.getX(), super.getY()), client.getHabbo().getRoomUnit().getCurrentLocation()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
RoomTile boxLocation = room.getLayout().getTile(this.getX(), this.getY());
|
RoomTile boxLocation = room.getLayout().getTile(this.getX(), this.getY());
|
||||||
client.getHabbo().getRoomUnit().lookAtPoint(boxLocation);
|
RoomUserRotation rotation = null;
|
||||||
room.sendComposer(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
|
|
||||||
|
|
||||||
switch (client.getHabbo().getRoomUnit().getBodyRotation()) {
|
if (this.getX() == client.getHabbo().getRoomUnit().getX()) {
|
||||||
case NORTH_EAST:
|
if (this.getY() == client.getHabbo().getRoomUnit().getY() + 1) {
|
||||||
case NORTH_WEST:
|
rotation = RoomUserRotation.SOUTH;
|
||||||
case SOUTH_EAST:
|
} else if (this.getY() == client.getHabbo().getRoomUnit().getY() - 1) {
|
||||||
case SOUTH_WEST:
|
rotation = RoomUserRotation.NORTH;
|
||||||
|
}
|
||||||
|
} else if (this.getY() == client.getHabbo().getRoomUnit().getY()) {
|
||||||
|
if (this.getX() == client.getHabbo().getRoomUnit().getX() + 1) {
|
||||||
|
rotation = RoomUserRotation.EAST;
|
||||||
|
} else if (this.getX() == client.getHabbo().getRoomUnit().getX() - 1) {
|
||||||
|
rotation = RoomUserRotation.WEST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rotation == null) {
|
||||||
|
Optional<RoomTile> nearestTile = Arrays.stream(
|
||||||
|
new RoomTile[]{
|
||||||
|
room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH.getValue()),
|
||||||
|
room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH.getValue()),
|
||||||
|
room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.EAST.getValue()),
|
||||||
|
room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.WEST.getValue())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.filter(t -> t.isWalkable() && !room.hasHabbosAt(t.x, t.y))
|
||||||
|
.min(Comparator.comparingDouble(a -> a.distance(client.getHabbo().getRoomUnit().getCurrentLocation())));
|
||||||
|
|
||||||
|
nearestTile.ifPresent(roomTile -> client.getHabbo().getRoomUnit().setGoalLocation(roomTile));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), client.getHabbo().getRoomUnit().getBodyRotation().getValue());
|
RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), rotation.getValue());
|
||||||
|
|
||||||
if (tile == null || !room.tileWalkable(tile) || room.hasHabbosAt(tile.x, tile.y)) {
|
if (tile == null || room.hasHabbosAt(tile.x, tile.y)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double offset = room.getStackHeight(tile.x, tile.y, false) - this.getZ();
|
if (!boxLocation.equals(room.getLayout().getTileInFront(client.getHabbo().getRoomUnit().getCurrentLocation(), rotation.getValue())))
|
||||||
|
|
||||||
if (!boxLocation.equals(room.getLayout().getTileInFront(client.getHabbo().getRoomUnit().getCurrentLocation(), client.getHabbo().getRoomUnit().getBodyRotation().getValue())))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
HabboItem item = room.getTopItemAt(tile.x, tile.y);
|
HabboItem item = room.getTopItemAt(tile.x, tile.y);
|
||||||
|
|
||||||
if (item == null || (item.getZ() <= this.getZ() && item.getBaseItem().allowWalk())) {
|
if (item != null && !room.getTopItemAt(tile.x, tile.y).getBaseItem().allowStack()) return;
|
||||||
room.scheduledComposers.add(new FloorItemOnRollerComposer(this, null, tile, offset, room).compose());
|
|
||||||
|
this.setZ(room.getStackHeight(tile.x, tile.y, false));
|
||||||
|
this.needsUpdate(true);
|
||||||
|
room.updateItem(this);
|
||||||
|
|
||||||
|
room.scheduledComposers.add(new FloorItemOnRollerComposer(this, null, tile, 0, room).compose());
|
||||||
room.scheduledTasks.add(() -> client.getHabbo().getRoomUnit().setGoalLocation(boxLocation));
|
room.scheduledTasks.add(() -> client.getHabbo().getRoomUnit().setGoalLocation(boxLocation));
|
||||||
this.needsUpdate(true);
|
this.needsUpdate(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serializeExtradata(ServerMessage serverMessage) {
|
public void serializeExtradata(ServerMessage serverMessage) {
|
||||||
|
Loading…
Reference in New Issue
Block a user