This commit is contained in:
harmonic 2020-09-06 12:55:39 +01:00
commit b7446bca45
10 changed files with 235 additions and 270 deletions

View File

@ -130,12 +130,10 @@ public class BotManager {
RoomUnit roomUnit = new RoomUnit(); RoomUnit roomUnit = new RoomUnit();
roomUnit.setRotation(RoomUserRotation.SOUTH); roomUnit.setRotation(RoomUserRotation.SOUTH);
roomUnit.setLocation(location); roomUnit.setLocation(location);
HabboItem topItem = room.getTopItemAt(location.x, location.y);
double topItemHeight = 0;
if (topItem != null) topItemHeight = Item.getCurrentHeight(topItem);
roomUnit.setPreviousLocationZ(roomUnit.getCurrentLocation().getStackHeight() - topItemHeight);
double stackHeight = room.getStackHeight(location.x, location.y, false);
roomUnit.setPreviousLocationZ(stackHeight);
roomUnit.setZ(stackHeight);
roomUnit.setPathFinderRoom(room); roomUnit.setPathFinderRoom(room);
roomUnit.setRoomUnitType(RoomUnitType.BOT); roomUnit.setRoomUnitType(RoomUnitType.BOT);
@ -150,6 +148,8 @@ public class BotManager {
habbo.getClient().sendResponse(new RemoveBotComposer(bot)); habbo.getClient().sendResponse(new RemoveBotComposer(bot));
bot.onPlace(habbo, room); bot.onPlace(habbo, room);
HabboItem topItem = room.getTopItemAt(location.x, location.y);
if (topItem != null) { if (topItem != null) {
try { try {
topItem.onWalkOn(bot.getRoomUnit(), room, null); topItem.onWalkOn(bot.getRoomUnit(), room, null);
@ -157,6 +157,7 @@ public class BotManager {
LOGGER.error("Caught exception", e); LOGGER.error("Caught exception", e);
} }
} }
bot.cycle(false); bot.cycle(false);
} else { } else {
habbo.getClient().sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key, FurnitureMovementError.NO_RIGHTS.errorCode)); habbo.getClient().sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key, FurnitureMovementError.NO_RIGHTS.errorCode));

View File

@ -29,7 +29,7 @@ public class InteractionEffectVendingMachine extends InteractionVendingMachine {
} }
@Override @Override
public void giveVendingMachineItem(Habbo habbo, Room room) { public void giveVendingMachineItem(Room room, RoomUnit unit) {
room.giveEffect(habbo.getRoomUnit(), this.getBaseItem().getRandomVendingItem(), 30); room.giveEffect(unit, this.getBaseItem().getRandomVendingItem(), 30);
} }
} }

View File

@ -4,6 +4,7 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -18,7 +19,18 @@ public class InteractionNoSidesVendingMachine extends InteractionVendingMachine
} }
@Override @Override
public RoomTile getRequiredTile(Habbo habbo, Room room) { public THashSet<RoomTile> getActivatorTiles(Room room) {
return habbo.getRoomUnit().getClosestAdjacentTile(this.getX(), this.getY(), true);
THashSet<RoomTile> tiles = new THashSet<RoomTile>();
for(int x = -1; x <= 1; x++) {
for(int y = -1; y <= 1; y++) {
RoomTile tile = room.getLayout().getTile((short)(this.getX() + x), (short)(this.getY() + y));
if(tile != null) {
tiles.add(tile);
}
}
}
return tiles;
} }
} }

View File

@ -6,18 +6,23 @@ 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.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender; import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem; import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
import com.eu.habbo.util.pathfinding.Rotation; import com.eu.habbo.util.pathfinding.Rotation;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
public class InteractionVendingMachine extends InteractionDefault { public class InteractionVendingMachine extends HabboItem {
public InteractionVendingMachine(ResultSet set, Item baseItem) throws SQLException { public InteractionVendingMachine(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
this.setExtradata("0"); this.setExtradata("0");
@ -28,6 +33,65 @@ public class InteractionVendingMachine extends InteractionDefault {
this.setExtradata("0"); this.setExtradata("0");
} }
public THashSet<RoomTile> getActivatorTiles(Room room) {
THashSet<RoomTile> tiles = new THashSet<RoomTile>();
tiles.add(getSquareInFront(room.getLayout(), this));
tiles.add(room.getLayout().getTile(this.getX(), this.getY()));
return tiles;
}
@Override
public void serializeExtradata(ServerMessage serverMessage) {
serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata());
super.serializeExtradata(serverMessage);
}
private void tryInteract(GameClient client, Room room, RoomUnit unit) {
THashSet<RoomTile> activatorTiles = getActivatorTiles(room);
if(activatorTiles.size() == 0)
return;
boolean inActivatorSpace = false;
for(RoomTile tile : activatorTiles) {
if(unit.getCurrentLocation().is(unit.getX(), unit.getY())) {
inActivatorSpace = true;
}
}
if(inActivatorSpace) {
useVendingMachine(client, room, unit);
}
}
private void useVendingMachine(GameClient client, Room room, RoomUnit unit) {
this.setExtradata("1");
room.updateItem(this);
if(!unit.isWalking()) {
this.rotateToMachine(room, unit);
}
Emulator.getThreading().run(() -> {
giveVendingMachineItem(room, unit);
if (this.getBaseItem().getEffectM() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.M)
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1);
if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F)
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1);
Emulator.getThreading().run(this, 500);
}, 1500);
}
public void giveVendingMachineItem(Room room, RoomUnit unit) {
Emulator.getThreading().run(new RoomUnitGiveHanditem(unit, room, this.getBaseItem().getRandomVendingItem()));
}
@Override @Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception { public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
super.onClick(client, room, objects); super.onClick(client, room, objects);
@ -36,81 +100,49 @@ public class InteractionVendingMachine extends InteractionDefault {
return; return;
} }
RoomTile tile = this.getRequiredTile(client.getHabbo(), room); RoomUnit unit = client.getHabbo().getRoomUnit();
if (tile != null && THashSet<RoomTile> activatorTiles = getActivatorTiles(room);
tile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) {
if (!this.getExtradata().equals("0") || this.getExtradata().length() != 0) {
return;
}
if (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT) && (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || tile.equals(client.getHabbo().getRoomUnit().getGoal()))) { if(activatorTiles.size() == 0)
room.updateHabbo(client.getHabbo()); return;
this.rotateToMachine(client.getHabbo().getRoomUnit());
client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
room.scheduledComposers.add(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
}
super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"}); boolean inActivatorSpace = false;
this.setExtradata("1"); for(RoomTile tile : activatorTiles) {
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose()); if(unit.getCurrentLocation().is(tile.x, tile.y)) {
inActivatorSpace = true;
}
}
this.runGiveItemThread(client, room); if(!inActivatorSpace) {
} else { RoomTile tileToWalkTo = null;
if (!tile.isWalkable() && tile.state != RoomTileState.SIT && tile.state != RoomTileState.LAY) { for(RoomTile tile : activatorTiles) {
for (RoomTile t : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) { if(room.getLayout().tileWalkable(tile.x, tile.y) && (tileToWalkTo == null || tileToWalkTo.distance(unit.getCurrentLocation()) > tile.distance(unit.getCurrentLocation()))) {
if (t != null && t.isWalkable()) { tileToWalkTo = tile;
tile = t;
break;
}
} }
} }
RoomTile finalTile = tile; if(tileToWalkTo != null) {
client.getHabbo().getRoomUnit().setGoalLocation(tile); List<Runnable> onSuccess = new ArrayList<Runnable>();
List<Runnable> onFail = new ArrayList<Runnable>();
Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), tile, room, () -> { onSuccess.add(() -> {
this.setExtradata("1"); tryInteract(client, room, unit);
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose()); });
try { unit.setGoalLocation(tileToWalkTo);
super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"}); Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tileToWalkTo, room, onSuccess, onFail));
} catch (Exception e) { }
e.printStackTrace(); }
} else {
useVendingMachine(client, room, unit);
Emulator.getThreading().run(() -> client.getHabbo().getRoomUnit().setMoveBlockingTask(Emulator.getThreading().run(() -> {
if (client.getHabbo().getRoomUnit().getCurrentLocation().equals(finalTile)) {
this.rotateToMachine(client.getHabbo().getRoomUnit());
room.sendComposer(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
}
this.runGiveItemThread(client, room);
}, 300)), 250);
}, null));
} }
} }
private void runGiveItemThread(GameClient client, Room room) { @Override
try { public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
ScheduledFuture thread = Emulator.getThreading().run(() -> {
Emulator.getThreading().run(this, 1000);
this.giveVendingMachineItem(client.getHabbo(), room);
if (this.getBaseItem().getEffectM() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.M)
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1);
if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F)
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1);
}, 500);
if (thread.isDone()) {
thread.get();
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
} }
@Override @Override
@ -125,54 +157,27 @@ public class InteractionVendingMachine extends InteractionDefault {
} }
} }
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
return true;
}
@Override
public boolean isWalkable() {
return this.getBaseItem().allowWalk();
}
@Override @Override
public boolean isUsable() { public boolean isUsable() {
return true; return true;
} }
private void rotateToMachine(RoomUnit unit) { private void rotateToMachine(Room room, RoomUnit unit) {
if (unit.getCurrentLocation().getState() != RoomTileState.OPEN) {
// if sitting on a chair or laying on a bed, skip rotating altogether
return;
}
RoomUserRotation rotation = RoomUserRotation.values()[Rotation.Calculate(unit.getX(), unit.getY(), this.getX(), this.getY())]; RoomUserRotation rotation = RoomUserRotation.values()[Rotation.Calculate(unit.getX(), unit.getY(), this.getX(), this.getY())];
boolean onlyHead = false;
switch (unit.getBodyRotation()) { if(Math.abs(unit.getBodyRotation().getValue() - rotation.getValue()) > 1) {
case NORTH_EAST:
if (rotation.equals(RoomUserRotation.NORTH) || rotation.equals(RoomUserRotation.EAST))
onlyHead = true;
break;
case NORTH_WEST:
if (rotation.equals(RoomUserRotation.NORTH) || rotation.equals(RoomUserRotation.WEST))
onlyHead = true;
break;
case SOUTH_EAST:
if (rotation.equals(RoomUserRotation.SOUTH) || rotation.equals(RoomUserRotation.EAST))
onlyHead = true;
break;
case SOUTH_WEST:
if (rotation.equals(RoomUserRotation.SOUTH) || rotation.equals(RoomUserRotation.WEST))
onlyHead = true;
break;
}
if (onlyHead) {
unit.setHeadRotation(rotation);
} else {
unit.setRotation(rotation); unit.setRotation(rotation);
unit.statusUpdate(true);
} }
} }
public void giveVendingMachineItem(Habbo habbo, Room room) {
Emulator.getThreading().run(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.getBaseItem().getRandomVendingItem()));
}
public RoomTile getRequiredTile(Habbo habbo, Room room) {
return getSquareInFront(room.getLayout(), this);
}
} }

View File

@ -114,6 +114,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public static int IDLE_CYCLES = 240; public static int IDLE_CYCLES = 240;
public static int IDLE_CYCLES_KICK = 480; public static int IDLE_CYCLES_KICK = 480;
public static String PREFIX_FORMAT = "[<font color=\"%color%\">%prefix%</font>] "; public static String PREFIX_FORMAT = "[<font color=\"%color%\">%prefix%</font>] ";
public static int ROLLERS_MAXIMUM_ROLL_AVATARS = 1;
static { static {
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {
@ -426,7 +427,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (this.itemCount() > Room.MAXIMUM_FURNI) { if (this.itemCount() > Room.MAXIMUM_FURNI) {
LOGGER.error("Room ID: {} has exceeded the furniture limit ({} > {}).", this.getId(), this.itemCount(), Room.MAXIMUM_FURNI); LOGGER.error("Room ID: {} has exceeded the furniture limit ({} > {}).", this.getId(), this.itemCount(), Room.MAXIMUM_FURNI);
} }
} }
private synchronized void loadWiredData(Connection connection) { private synchronized void loadWiredData(Connection connection) {
@ -542,7 +542,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public void updateTile(RoomTile tile) { public void updateTile(RoomTile tile) {
if (tile != null) { if (tile != null) {
tile.setStackHeight(this.getStackHeight(tile.x, tile.y, false)); tile.setStackHeight(this.getStackHeight(tile.x, tile.y, false));
tile.setState(this.calculateTileState(tile)); tile.setState(this.calculateTileState(tile));
} }
} }
@ -566,17 +565,28 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return RoomTileState.INVALID; return RoomTileState.INVALID;
RoomTileState result = RoomTileState.OPEN; RoomTileState result = RoomTileState.OPEN;
HabboItem lowestItem = null; HabboItem highestItem = null;
HabboItem lowestChair = this.getLowestChair(tile); HabboItem lowestChair = this.getLowestChair(tile);
THashSet<HabboItem> items = this.getItemsAt(tile); THashSet<HabboItem> items = this.getItemsAt(tile);
if (items == null) return RoomTileState.INVALID;
if (items.stream().anyMatch(i -> i.getBaseItem().allowLay())) return RoomTileState.LAY; if (items == null) return RoomTileState.INVALID;
for (HabboItem item : items) { for (HabboItem item : items) {
if (exclude != null && item == exclude) continue; if (exclude != null && item == exclude) continue;
if (lowestChair != null && item.getZ() > lowestChair.getZ() + 1.5) { if(item.getBaseItem().allowLay()) {
return RoomTileState.LAY;
}
if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
continue;
highestItem = item;
if (result == RoomTileState.OPEN) {
result = this.checkStateForItem(item, tile);
}
/*if (lowestChair != null && item.getZ() > lowestChair.getZ() + 1.5) {
continue; continue;
} }
@ -588,7 +598,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (result == RoomTileState.OPEN) { if (result == RoomTileState.OPEN) {
result = this.checkStateForItem(item, tile); result = this.checkStateForItem(item, tile);
} }
} }*/
} }
if (lowestChair != null) return RoomTileState.SIT; if (lowestChair != null) return RoomTileState.SIT;
@ -1400,9 +1410,13 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
HabboItem nextTileChair = this.getLowestChair(tileInFront); HabboItem nextTileChair = this.getLowestChair(tileInFront);
THashSet<Integer> usersRolledThisTile = new THashSet<>();
for (RoomUnit unit : unitsOnTile) { for (RoomUnit unit : unitsOnTile) {
if (rolledUnitIds.contains(unit.getId())) continue; if (rolledUnitIds.contains(unit.getId())) continue;
if(usersRolledThisTile.size() >= Room.ROLLERS_MAXIMUM_ROLL_AVATARS) break;
if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable())) if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable()))
continue; continue;
@ -1437,6 +1451,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
} }
usersRolledThisTile.add(unit.getId());
rolledUnitIds.add(unit.getId()); rolledUnitIds.add(unit.getId());
updatedUnit.remove(unit); updatedUnit.remove(unit);
messages.add(new RoomUnitOnRollerComposer(unit, roller, unit.getCurrentLocation(), unit.getZ() + (isRiding ? 1 : 0), tile, tile.getStackHeight() + (isRiding ? 1 : 0) + (nextTileChair != null ? -1 : 0), room)); messages.add(new RoomUnitOnRollerComposer(unit, roller, unit.getCurrentLocation(), unit.getZ() + (isRiding ? 1 : 0), tile, tile.getStackHeight() + (isRiding ? 1 : 0) + (nextTileChair != null ? -1 : 0), room));
@ -2601,7 +2616,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
habbo.getRoomUnit().getCurrentLocation().removeUnit(habbo.getRoomUnit()); habbo.getRoomUnit().getCurrentLocation().removeUnit(habbo.getRoomUnit());
} }
if (sendRemovePacket && habbo.getRoomUnit() != null) { if (sendRemovePacket && habbo.getRoomUnit() != null && !habbo.getRoomUnit().isTeleporting) {
this.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose()); this.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose());
} }
@ -3005,7 +3020,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public void talk(Habbo habbo, RoomChatMessage roomChatMessage, RoomChatType chatType) { public void talk(Habbo habbo, RoomChatMessage roomChatMessage, RoomChatType chatType) {
this.talk(habbo, roomChatMessage, chatType, true); this.talk(habbo, roomChatMessage, chatType, false);
} }
public void talk(final Habbo habbo, final RoomChatMessage roomChatMessage, RoomChatType chatType, boolean ignoreWired) { public void talk(final Habbo habbo, final RoomChatMessage roomChatMessage, RoomChatType chatType, boolean ignoreWired) {
@ -3311,6 +3326,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public THashSet<HabboItem> getItemsAt(RoomTile tile) { public THashSet<HabboItem> getItemsAt(RoomTile tile) {
return getItemsAt(tile, false);
}
public THashSet<HabboItem> getItemsAt(RoomTile tile, boolean returnOnFirst) {
THashSet<HabboItem> items = new THashSet<>(0); THashSet<HabboItem> items = new THashSet<>(0);
if (tile == null) if (tile == null)
@ -3339,19 +3358,24 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (item.getBaseItem().getType() != FurnitureType.FLOOR) if (item.getBaseItem().getType() != FurnitureType.FLOOR)
continue; continue;
if (item.getX() == tile.x && item.getY() == tile.y) { int width, length;
items.add(item);
} else {
if (item.getBaseItem().getWidth() <= 1 && item.getBaseItem().getLength() <= 1) {
continue;
}
THashSet<RoomTile> tiles = this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); if (item.getRotation() != 2 && item.getRotation() != 6) {
for (RoomTile t : tiles) { width = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
if ((t.x == tile.x) && (t.y == tile.y) && (!items.contains(item))) { length = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
items.add(item); }
} else {
} width = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
length = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
}
if (!(tile.x >= item.getX() && tile.x <= item.getX() + width - 1 && tile.y >= item.getY() && tile.y <= item.getY() + length - 1))
continue;
items.add(item);
if(returnOnFirst) {
return items;
} }
} }
@ -3369,20 +3393,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (item.getZ() < minZ) if (item.getZ() < minZ)
continue; continue;
if (item.getX() == x && item.getY() == y && item.getZ() >= minZ) { items.add(item);
items.add(item);
} else {
if (item.getBaseItem().getWidth() <= 1 && item.getBaseItem().getLength() <= 1) {
continue;
}
THashSet<RoomTile> tiles = this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
for (RoomTile tile : tiles) {
if ((tile.x == x) && (tile.y == y) && (!items.contains(item))) {
items.add(item);
}
}
}
} }
return items; return items;
} }
@ -3390,54 +3401,22 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public THashSet<HabboItem> getItemsAt(Class<? extends HabboItem> type, int x, int y) { public THashSet<HabboItem> getItemsAt(Class<? extends HabboItem> type, int x, int y) {
THashSet<HabboItem> items = new THashSet<>(); THashSet<HabboItem> items = new THashSet<>();
TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator(); for (HabboItem item : this.getItemsAt(x, y)) {
if (!item.getClass().equals(type))
continue;
for (int i = this.roomItems.size(); i-- > 0; ) { items.add(item);
HabboItem item;
try {
iterator.advance();
item = iterator.value();
} catch (Exception e) {
break;
}
if (item.getClass().equals(type)) {
if (item.getX() == x && item.getY() == y) {
items.add(item);
} else {
if (item.getBaseItem().getWidth() <= 1 && item.getBaseItem().getLength() <= 1) {
continue;
}
THashSet<RoomTile> tiles = this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
for (RoomTile tile : tiles) {
if ((tile.x == x) && (tile.y == y) && (!items.contains(item))) {
items.add(item);
}
}
}
}
} }
return items; return items;
} }
public boolean hasItemsAt(int x, int y) { public boolean hasItemsAt(int x, int y) {
TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator(); RoomTile tile = this.getLayout().getTile((short) x, (short) y);
for (int i = this.roomItems.size(); i-- > 0; ) { if(tile == null)
HabboItem habboItem; return false;
try {
iterator.advance();
habboItem = iterator.value();
} catch (Exception e) {
break;
}
if (habboItem.getX() == x && habboItem.getY() == y) return true; return this.getItemsAt(tile, true).size() > 0;
}
return false;
} }
public HabboItem getTopItemAt(int x, int y) { public HabboItem getTopItemAt(int x, int y) {
@ -3445,55 +3424,24 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public HabboItem getTopItemAt(int x, int y, HabboItem exclude) { public HabboItem getTopItemAt(int x, int y, HabboItem exclude) {
HabboItem item = null; RoomTile tile = this.getLayout().getTile((short) x, (short) y);
TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator(); if(tile == null)
return null;
for (int i = this.roomItems.size(); i-- > 0; ) { HabboItem highestItem = null;
HabboItem habboItem;
try {
iterator.advance();
habboItem = iterator.value();
} catch (Exception e) {
break;
}
if (habboItem.getBaseItem().getType() != FurnitureType.FLOOR) for (HabboItem item : this.getItemsAt(x, y)) {
if(exclude != null && exclude == item)
continue; continue;
if (exclude != null) { if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
if (exclude == habboItem) continue;
continue;
}
if (habboItem.getX() == x && habboItem.getY() == y) { highestItem = item;
if (item == null || (habboItem.getZ() + Item.getCurrentHeight(habboItem)) > (item.getZ() + Item.getCurrentHeight(item))) {
item = habboItem;
}
} else {
if (habboItem.getBaseItem().getWidth() <= 1 && habboItem.getBaseItem().getLength() <= 1) {
continue;
}
if (this.layout == null) continue;
THashSet<RoomTile> tiles = this.layout.getTilesAt(
this.layout.getTile(habboItem.getX(), habboItem.getY()),
habboItem.getBaseItem().getWidth(),
habboItem.getBaseItem().getLength(),
habboItem.getRotation()
);
for (RoomTile tile : tiles) {
if (((tile.x == x) && (tile.y == y))) {
if (item == null || item.getZ() < habboItem.getZ())
item = habboItem;
}
}
}
} }
return item; return highestItem;
} }
public double getTopHeightAt(int x, int y) { public double getTopHeightAt(int x, int y) {
@ -3524,17 +3472,14 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
THashSet<HabboItem> items = this.getItemsAt(tile); THashSet<HabboItem> items = this.getItemsAt(tile);
if (items != null && !items.isEmpty()) { if (items != null && !items.isEmpty()) {
for (HabboItem item : items) { for (HabboItem item : items) {
if (item.getBaseItem().allowSit()) {
if (lowestChair == null || item.getZ() < lowestChair.getZ()) {
lowestChair = item;
}
}
if (lowestChair != null) { if(!item.getBaseItem().allowSit())
if (item.getZ() > lowestChair.getZ() && item.getZ() - lowestChair.getZ() < 1.5) { continue;
lowestChair = null;
} if(lowestChair != null && lowestChair.getZ() < item.getZ())
} continue;
lowestChair = item;
} }
} }
@ -3542,37 +3487,32 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public double getStackHeight(short x, short y, boolean calculateHeightmap, HabboItem exclude) { public double getStackHeight(short x, short y, boolean calculateHeightmap, HabboItem exclude) {
if (x < 0 || y < 0 || this.layout == null) if (x < 0 || y < 0 || this.layout == null)
return calculateHeightmap ? Short.MAX_VALUE : 0.0; return calculateHeightmap ? Short.MAX_VALUE : 0.0;
double height = this.layout.getHeightAtSquare(x, y); double height = this.layout.getHeightAtSquare(x, y);
boolean canStack = true; boolean canStack = true;
boolean stackHelper = false;
THashSet<HabboItem> items = this.getItemsAt(x, y); THashSet<HabboItem> stackHelpers = this.getItemsAt(InteractionStackHelper.class, x, y);
if (items != null) {
for (HabboItem item : items) { if(stackHelpers.size() > 0) {
for(HabboItem item : stackHelpers) {
if (item == exclude) continue; if (item == exclude) continue;
return calculateHeightmap ? item.getZ() * 256.0D : item.getZ();
if (item instanceof InteractionStackHelper) {
stackHelper = true;
height = item.getExtradata().isEmpty() ? Double.valueOf("0.0") : (Double.valueOf(item.getExtradata()) / 100);
canStack = true;
}
} }
}
if (!stackHelper) { HabboItem item = this.getTopItemAt(x, y, exclude);
HabboItem item = this.getTopItemAt(x, y, exclude); if (item != null) {
if (item != null) { canStack = item.getBaseItem().allowStack();
canStack = item.getBaseItem().allowStack(); height = item.getZ() + Item.getCurrentHeight(item);
height = item.getZ() + Item.getCurrentHeight(item); }
}
HabboItem lowestChair = this.getLowestChair(x, y); HabboItem lowestChair = this.getLowestChair(x, y);
if (lowestChair != null && lowestChair != exclude) { if (lowestChair != null && lowestChair != exclude) {
canStack = true; canStack = true;
height = lowestChair.getZ(); height = lowestChair.getZ();
}
}
} }
if (calculateHeightmap) { if (calculateHeightmap) {

View File

@ -386,8 +386,8 @@ public class RoomManager {
if (Emulator.getPluginManager().fireEvent(new RoomUncachedEvent(room)).isCancelled()) if (Emulator.getPluginManager().fireEvent(new RoomUncachedEvent(room)).isCancelled())
continue; continue;
this.activeRooms.remove(room.getId());
room.dispose(); room.dispose();
this.activeRooms.remove(room.getId());
} }
} }
@ -586,11 +586,11 @@ public class RoomManager {
habbo.getClient().sendResponse(new HideDoorbellComposer("")); habbo.getClient().sendResponse(new HideDoorbellComposer(""));
if (habbo.getRoomUnit() != null) { if (habbo.getRoomUnit() != null) {
Room existingRoom = habbo.getRoomUnit().getRoom(); RoomUnit existingRoom = habbo.getRoomUnit();
if (existingRoom != null) { if (existingRoom.getRoom() != null) {
if (habbo.getRoomUnit().getCurrentLocation() != null) if (existingRoom.getCurrentLocation() != null)
habbo.getRoomUnit().getCurrentLocation().removeUnit(habbo.getRoomUnit()); existingRoom.getCurrentLocation().removeUnit(existingRoom);
habbo.getRoomUnit().getRoom().sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose()); existingRoom.getRoom().sendComposer(new RoomUserRemoveComposer(existingRoom).compose());
} }
habbo.getRoomUnit().setRoom(null); habbo.getRoomUnit().setRoom(null);
} }

View File

@ -25,6 +25,9 @@ public class GuildChangeNameDescEvent extends MessageHandler {
if (guild.getName().equals(nameEvent.name) && guild.getDescription().equals(nameEvent.description)) if (guild.getName().equals(nameEvent.name) && guild.getDescription().equals(nameEvent.description))
return; return;
if(nameEvent.name.length() > 29 || nameEvent.description.length() > 254)
return;
guild.setName(nameEvent.name); guild.setName(nameEvent.name);
guild.setDescription(nameEvent.description); guild.setDescription(nameEvent.description);
guild.needsUpdate = true; guild.needsUpdate = true;

View File

@ -21,6 +21,12 @@ public class RequestGuildBuyEvent extends MessageHandler {
@Override @Override
public void handle() throws Exception { public void handle() throws Exception {
String name = this.packet.readString();
String description = this.packet.readString();
if(name.length() > 29 || description.length() > 254)
return;
if (Emulator.getConfig().getBoolean("catalog.guild.hc_required", true) && this.client.getHabbo().getHabboStats().getClubExpireTimestamp() < Emulator.getIntUnixTimestamp()) { if (Emulator.getConfig().getBoolean("catalog.guild.hc_required", true) && this.client.getHabbo().getHabboStats().getClubExpireTimestamp() < Emulator.getIntUnixTimestamp()) {
this.client.sendResponse(new GuildEditFailComposer(GuildEditFailComposer.HC_REQUIRED)); this.client.sendResponse(new GuildEditFailComposer(GuildEditFailComposer.HC_REQUIRED));
return; return;
@ -36,9 +42,6 @@ public class RequestGuildBuyEvent extends MessageHandler {
} }
} }
String name = this.packet.readString();
String description = this.packet.readString();
int roomId = this.packet.readInt(); int roomId = this.packet.readInt();
Room r = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); Room r = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId);

View File

@ -106,6 +106,7 @@ public class PluginManager {
Room.HAND_ITEM_TIME = Emulator.getConfig().getInt("hotel.rooms.handitem.time"); Room.HAND_ITEM_TIME = Emulator.getConfig().getInt("hotel.rooms.handitem.time");
Room.IDLE_CYCLES = Emulator.getConfig().getInt("hotel.roomuser.idle.cycles", 240); Room.IDLE_CYCLES = Emulator.getConfig().getInt("hotel.roomuser.idle.cycles", 240);
Room.IDLE_CYCLES_KICK = Emulator.getConfig().getInt("hotel.roomuser.idle.cycles.kick", 480); Room.IDLE_CYCLES_KICK = Emulator.getConfig().getInt("hotel.roomuser.idle.cycles.kick", 480);
Room.ROLLERS_MAXIMUM_ROLL_AVATARS = Emulator.getConfig().getInt("hotel.room.rollers.roll_avatars.max", 1);
RoomManager.MAXIMUM_ROOMS_VIP = Emulator.getConfig().getInt("hotel.max.rooms.vip"); RoomManager.MAXIMUM_ROOMS_VIP = Emulator.getConfig().getInt("hotel.max.rooms.vip");
RoomManager.MAXIMUM_ROOMS_USER = Emulator.getConfig().getInt("hotel.max.rooms.user"); RoomManager.MAXIMUM_ROOMS_USER = Emulator.getConfig().getInt("hotel.max.rooms.user");
RoomManager.HOME_ROOM_ID = Emulator.getConfig().getInt("hotel.home.room"); RoomManager.HOME_ROOM_ID = Emulator.getConfig().getInt("hotel.home.room");

View File

@ -59,7 +59,7 @@ class TeleportActionThree implements Runnable {
this.client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[targetTeleport.getRotation() % 8]); this.client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[targetTeleport.getRotation() % 8]);
if (targetRoom != this.room) { if (targetRoom != this.room) {
this.room.removeHabbo(this.client.getHabbo(), true); this.room.removeHabbo(this.client.getHabbo(), false);
Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed"), teleportLocation); Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed"), teleportLocation);
} }