Fix rotating furniture with a stack helper

This commit is contained in:
Alejandro 2020-03-04 18:45:33 +02:00
parent a8f3829216
commit 8d6cd27b85
2 changed files with 31 additions and 18 deletions

View File

@ -4471,26 +4471,31 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
boolean magicTile = item instanceof InteractionStackHelper; boolean magicTile = item instanceof InteractionStackHelper;
Optional<HabboItem> stackHelper = this.getItemsAt(tile).stream().filter(i -> i instanceof InteractionStackHelper).findAny();
//Check if can be placed at new position //Check if can be placed at new position
THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
if (topItem != item) {
for (RoomTile t : occupiedTiles) { if (!stackHelper.isPresent()) {
HabboItem tileTopItem = this.getTopItemAt(t.x, t.y); if (topItem != item) {
if (!magicTile && ((tileTopItem != null && tileTopItem != item ? (t.state.equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack()) : this.calculateTileState(t, item).equals(RoomTileState.INVALID)))) for (RoomTile t : occupiedTiles) {
return FurnitureMovementError.CANT_STACK; HabboItem tileTopItem = this.getTopItemAt(t.x, t.y);
if (this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS; if (!magicTile && ((tileTopItem != null && tileTopItem != item ? (t.state.equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack()) : this.calculateTileState(t, item).equals(RoomTileState.INVALID))))
if (this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS; return FurnitureMovementError.CANT_STACK;
if (this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS; if (this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS;
if (this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS;
if (this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS;
}
} }
}
List<Pair<RoomTile, THashSet<HabboItem>>> tileFurniList = new ArrayList<>(); List<Pair<RoomTile, THashSet<HabboItem>>> tileFurniList = new ArrayList<>();
for (RoomTile t : occupiedTiles) { for (RoomTile t : occupiedTiles) {
tileFurniList.add(Pair.create(t, this.getItemsAt(t))); tileFurniList.add(Pair.create(t, this.getItemsAt(t)));
} }
if (!magicTile && !item.canStackAt(this, tileFurniList)) { if (!magicTile && !item.canStackAt(this, tileFurniList)) {
return FurnitureMovementError.CANT_STACK; return FurnitureMovementError.CANT_STACK;
}
} }
THashSet<RoomTile> oldOccupiedTiles = this.layout.getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); THashSet<RoomTile> oldOccupiedTiles = this.layout.getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
@ -4511,8 +4516,16 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
//Place at new position //Place at new position
double height = this.getStackHeight(tile.x, tile.y, false, item); double height;
if (item.equals(topItem) && tile.x == item.getX() && tile.y == item.getY()) height = item.getZ();
if (stackHelper.isPresent()) {
height = stackHelper.get().getExtradata().isEmpty() ? Double.valueOf("0.0") : (Double.valueOf(stackHelper.get().getExtradata()) / 100);
} else if (item.equals(topItem) && tile.x == item.getX() && tile.y == item.getY()) {
height = item.getZ();
} else {
height = this.getStackHeight(tile.x, tile.y, false, item);
}
if(height > 40d) return FurnitureMovementError.CANT_STACK; if(height > 40d) return FurnitureMovementError.CANT_STACK;
item.setX(tile.x); item.setX(tile.x);

View File

@ -8,7 +8,7 @@ import java.util.Collection;
public class HabboAddedToRoomEvent extends UserEvent { public class HabboAddedToRoomEvent extends UserEvent {
public final Room room; public final Room room;
public final Collection<Habbo> habbosToSendEnter; public Collection<Habbo> habbosToSendEnter;
public HabboAddedToRoomEvent(Habbo habbo, Room room, Collection<Habbo> habbosToSendEnter) { public HabboAddedToRoomEvent(Habbo habbo, Room room, Collection<Habbo> habbosToSendEnter) {