diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java index 5580a89f..4f00ddb3 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -344,9 +344,7 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("totem_head", InteractionTotemHead.class)); this.interactionsList.add(new ItemInteraction("totem_planet", InteractionTotemPlanet.class)); - /* Habbo 2.0 * By AlfreviD */ - - this.interactionsList.add(new ItemInteraction("tile_walk_magic", InteractionTileWalkMagic.class)); + this.interactionsList.add(new ItemInteraction("tile_walkmagic", InteractionTileWalkMagic.class)); } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileWalkMagic.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileWalkMagic.java index 258b4ef9..be76fc11 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileWalkMagic.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileWalkMagic.java @@ -2,8 +2,6 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomTileState; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; @@ -22,12 +20,17 @@ public class InteractionTileWalkMagic extends HabboItem { @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - return true; + return false; } @Override - public RoomTileState getOverrideTileState(RoomTile tile, Room room) { - return RoomTileState.OPEN; + public boolean isWalkable() { + return false; + } + + @Override + public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { + } @Override @@ -39,17 +42,7 @@ public class InteractionTileWalkMagic extends HabboItem { } @Override - public boolean canOverrideTile(RoomUnit unit, Room room, RoomTile tile) { + public boolean isUsable() { return true; } - - @Override - public boolean isWalkable() { - return true; - } - - @Override - public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { - - } } \ No newline at end of file diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index 9d1b3359..724bd56f 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -640,9 +640,7 @@ public class Room implements Comparable, ISerialize, Runnable { result = overriddenState; } - Optional stackHelper = this.getItemsAt(tile).stream().filter(itemS -> itemS instanceof InteractionTileWalkMagic).findAny(); - - if (stackHelper.isPresent()) { + if (this.getItemsAt(tile).stream().anyMatch(i -> i instanceof InteractionTileWalkMagic)) { result = RoomTileState.OPEN; } @@ -836,15 +834,63 @@ public class Room implements Comparable, ISerialize, Runnable { } } + public void updatePetsAt(short x, short y) { + HabboItem topItem = this.getTopItemAt(x, y); + + THashSet roomUnits = new THashSet<>(); + + for (Pet pet : this.getPetsAt(this.layout.getTile(x, y))) { + if (topItem != null) { + if (topItem.getBaseItem().allowSit()) { + pet.getRoomUnit().setZ(topItem.getZ()); + pet.getRoomUnit().setPreviousLocationZ(topItem.getZ()); + pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(topItem.getRotation())); + } else { + pet.getRoomUnit().setZ(topItem.getZ() + Item.getCurrentHeight(topItem)); + + if (topItem.getBaseItem().allowLay()) { + pet.getRoomUnit().setStatus(RoomUnitStatus.LAY, (topItem.getZ() + topItem.getBaseItem().getHeight()) + ""); + } + } + } else { + pet.getRoomUnit().setZ(pet.getRoomUnit().getCurrentLocation().getStackHeight()); + pet.getRoomUnit().setPreviousLocationZ(pet.getRoomUnit().getCurrentLocation().getStackHeight()); + } + + roomUnits.add(pet.getRoomUnit()); + } + + if (!roomUnits.isEmpty()) { + this.sendComposer(new RoomUserStatusComposer(roomUnits, true).compose()); + } + } + + + public void pickupPetsForHabbo(Habbo habbo) { THashSet pets = new THashSet<>(); + + + + + + synchronized (this.currentPets) { for (Pet pet : this.currentPets.valueCollection()) { if (pet.getUserId() == habbo.getHabboInfo().getId()) { pets.add(pet); + + + } + + } + + + + } for (Pet pet : pets) { @@ -1242,7 +1288,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (Emulator.getConfig().getBoolean("hotel.rooms.deco_hosting")) { //Check if the user isn't the owner id if (this.ownerId != habbo.getHabboInfo().getId()) { - //Check if the time already have 1 minute (120 / 2 = 60s) + //Check if the time already have 1 minute (120 / 2 = 60s) if (habbo.getRoomUnit().getTimeInRoom() >= 120) { AchievementManager.progressAchievement(this.ownerId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting")); habbo.getRoomUnit().resetTimeInRoom(); @@ -2952,6 +2998,28 @@ public class Room implements Comparable, ISerialize, Runnable { return bots; } + public THashSet getPetsAt(RoomTile tile) { + THashSet pets = new THashSet<>(); + synchronized (this.currentPets) { + TIntObjectIterator petIterator = this.currentPets.iterator(); + + for (int i = this.currentPets.size(); i-- > 0; ) { + try { + petIterator.advance(); + + if (petIterator.value().getRoomUnit().getCurrentLocation().equals(tile)) { + pets.add(petIterator.value()); + } + } catch (Exception e) { + break; + } + } + } + + return pets; + } + + public THashSet getHabbosAt(short x, short y) { return this.getHabbosAt(this.layout.getTile(x, y)); } @@ -4523,7 +4591,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (!this.layout.fitsOnMap(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation)) return FurnitureMovementError.INVALID_MOVE; - if (item instanceof InteractionStackHelper) return FurnitureMovementError.NONE; + if (item instanceof InteractionStackHelper || item instanceof InteractionTileWalkMagic) return FurnitureMovementError.NONE; THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); for (RoomTile t : occupiedTiles) { @@ -4726,11 +4794,24 @@ public class Room implements Comparable, ISerialize, Runnable { height = stackHelper.get().getExtradata().isEmpty() ? Double.parseDouble("0.0") : (Double.parseDouble(stackHelper.get().getExtradata()) / 100); } else if (item == topItem) { height = item.getZ(); + } else if(magicTile) { + if(topItem == null) { + height = this.getStackHeight(tile.x, tile.y, false, item); + for(RoomTile til : occupiedTiles) { + double sHeight = this.getStackHeight(til.x, til.y, false, item); + if(sHeight > height) { + height = sHeight; + } + } + } + else { + height = topItem.getZ() + topItem.getBaseItem().getHeight(); + } } else { height = this.getStackHeight(tile.x, tile.y, false, item); - for (RoomTile til : occupiedTiles) { + for(RoomTile til : occupiedTiles) { double sHeight = this.getStackHeight(til.x, til.y, false, item); - if (sHeight > height) { + if(sHeight > height) { height = sHeight; } } @@ -4804,7 +4885,7 @@ public class Room implements Comparable, ISerialize, Runnable { HabboItem topItem = this.getTopItemAt(tile.x, tile.y); - boolean magicTile = item instanceof InteractionStackHelper; + boolean magicTile = item instanceof InteractionStackHelper || item instanceof InteractionTileWalkMagic; //Check if can be placed at new position THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); @@ -4842,6 +4923,80 @@ public class Room implements Comparable, ISerialize, Runnable { return FurnitureMovementError.NONE; } + public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, double z, Habbo actor, boolean sendUpdates, boolean checkForUnits) { + if (tile == null) { + return FurnitureMovementError.INVALID_MOVE; + } + RoomTile oldLocation = this.layout.getTile(item.getX(), item.getY()); + boolean pluginHelper = false; + + if (Emulator.getPluginManager().isRegistered(FurnitureMovedEvent.class, true)) { + FurnitureMovedEvent event = Emulator.getPluginManager().fireEvent(new FurnitureMovedEvent(item, actor, oldLocation, tile)); + if(event.isCancelled()) { + return FurnitureMovementError.CANCEL_PLUGIN_MOVE; + } + pluginHelper = event.hasPluginHelper(); + } + + boolean magicTile = item instanceof InteractionStackHelper; + + THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); + THashSet oldOccupiedTiles = this.layout.getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + + if (item.getRotation() != rotation) { + item.setRotation(rotation); + } + + if(z > MAXIMUM_FURNI_HEIGHT) return FurnitureMovementError.CANT_STACK; + if(z < this.getLayout().getHeightAtSquare(tile.x, tile.y)) return FurnitureMovementError.CANT_STACK; //prevent furni going under the floor + + if (Emulator.getPluginManager().isRegistered(FurnitureBuildheightEvent.class, true)) { + FurnitureBuildheightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureBuildheightEvent(item, actor, 0.00, z)); + if (event.hasChangedHeight()) { + z = event.getUpdatedHeight(); + } + } + + item.setX(tile.x); + item.setY(tile.y); + item.setZ(z); + if (magicTile) { + item.setZ(tile.z); + item.setExtradata("" + item.getZ() * 100); + } + if (item.getZ() > MAXIMUM_FURNI_HEIGHT) { + item.setZ(MAXIMUM_FURNI_HEIGHT); + } + + //Update Furniture + item.onMove(this, oldLocation, tile); + item.needsUpdate(true); + Emulator.getThreading().run(item); + + if(sendUpdates) { + this.sendComposer(new FloorItemUpdateComposer(item).compose()); + } + + //Update old & new tiles + occupiedTiles.removeAll(oldOccupiedTiles); + occupiedTiles.addAll(oldOccupiedTiles); + this.updateTiles(occupiedTiles); + + //Update Habbos at old position + for (RoomTile t : occupiedTiles) { + this.updateHabbosAt( + t.x, + t.y, + this.getHabbosAt(t.x, t.y) + /*.stream() + .filter(h -> !h.getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || h.getRoomUnit().getGoal() == t) + .collect(Collectors.toCollection(THashSet::new))*/ + ); + this.updateBotsAt(t.x, t.y); + } + return FurnitureMovementError.NONE; + } + public THashSet getRoomUnits() { return getRoomUnits(null); } @@ -4874,4 +5029,4 @@ public class Room implements Comparable, ISerialize, Runnable { THashSet roomUnits = getRoomUnits(); return roomUnits.stream().filter(unit -> unit.getCurrentLocation() == tile).collect(Collectors.toSet()); } -} +} \ No newline at end of file diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java index 8d27ad54..aeabd6fe 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -332,7 +332,7 @@ public class RoomUnit { zHeight += room.getLayout().getHeightAtSquare(next.x, next.y); } - Optional stackHelper = this.room.getItemsAt(next).stream().filter(itemS -> itemS instanceof InteractionTileWalkMagic).findAny(); + Optional stackHelper = this.room.getItemsAt(next).stream().filter(i -> i instanceof InteractionTileWalkMagic).findAny(); if (stackHelper.isPresent()) { zHeight = stackHelper.get().getZ(); diff --git a/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java b/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java index 94ac300b..edc29cc2 100644 --- a/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java +++ b/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java @@ -53,12 +53,9 @@ public class SetStackHelperHeightEvent extends MessageHandler { if (item instanceof InteractionTileWalkMagic) { for (RoomTile t : tiles) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().updateHabbosAt( - t.x, - t.y, - this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabbosAt(t.x, t.y) - ); + this.client.getHabbo().getHabboInfo().getCurrentRoom().updateHabbosAt(t.x, t.y); this.client.getHabbo().getHabboInfo().getCurrentRoom().updateBotsAt(t.x, t.y); + this.client.getHabbo().getHabboInfo().getCurrentRoom().updatePetsAt(t.x, t.y); } }