mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-18 23:46:28 +01:00
Fixed item movement errors including in wireds
This commit is contained in:
parent
12eb55637f
commit
2f1820ae74
@ -38,6 +38,7 @@ public class Item implements ISerialize {
|
||||
private String clothingOnWalk;
|
||||
|
||||
private ItemInteraction interactionType;
|
||||
private int rotations;
|
||||
|
||||
public Item(ResultSet set) throws SQLException {
|
||||
this.load(set);
|
||||
@ -119,6 +120,13 @@ public class Item implements ISerialize {
|
||||
this.multiHeights = new double[0];
|
||||
}
|
||||
}
|
||||
|
||||
this.rotations = 4;
|
||||
|
||||
try {
|
||||
this.rotations = set.getInt("rotations");
|
||||
}
|
||||
catch (SQLException ignored) { }
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@ -223,6 +231,10 @@ public class Item implements ISerialize {
|
||||
|
||||
public String getClothingOnWalk() { return clothingOnWalk; }
|
||||
|
||||
public int getRotations() {
|
||||
return rotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ServerMessage message) {
|
||||
message.appendString(this.type.code.toLowerCase());
|
||||
|
@ -6,12 +6,18 @@ import com.eu.habbo.habbohotel.items.Item;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
||||
import com.eu.habbo.messages.ServerMessage;
|
||||
import gnu.trove.set.hash.THashSet;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class InteractionGuildFurni extends InteractionDefault {
|
||||
private int guildId;
|
||||
private static final THashSet<String> ROTATION_8_ITEMS = new THashSet<String>() {
|
||||
{
|
||||
this.add("gld_wall_tall");
|
||||
}
|
||||
};
|
||||
|
||||
public InteractionGuildFurni(ResultSet set, Item baseItem) throws SQLException {
|
||||
super(set, baseItem);
|
||||
@ -23,6 +29,14 @@ public class InteractionGuildFurni extends InteractionDefault {
|
||||
this.guildId = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumRotations() {
|
||||
if(ROTATION_8_ITEMS.stream().anyMatch(x -> x.equalsIgnoreCase(this.getBaseItem().getName()))) {
|
||||
return 8;
|
||||
}
|
||||
return this.getBaseItem().getRotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeExtradata(ServerMessage serverMessage) {
|
||||
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guildId);
|
||||
|
@ -23,6 +23,11 @@ public class InteractionMannequin extends HabboItem {
|
||||
super(id, userId, item, extradata, limitedStack, limitedSells);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumRotations() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeExtradata(ServerMessage serverMessage) {
|
||||
serverMessage.appendInt(1 + (this.isLimited() ? 256 : 0));
|
||||
|
@ -15,6 +15,7 @@ import gnu.trove.set.hash.THashSet;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
@ -68,40 +69,43 @@ public class InteractionMultiHeight extends HabboItem {
|
||||
this.setExtradata("0");
|
||||
|
||||
if (this.getBaseItem().getMultiHeights().length > 0) {
|
||||
this.setExtradata("" + (Integer.valueOf(this.getExtradata()) + 1) % (this.getBaseItem().getMultiHeights().length));
|
||||
this.setExtradata("" + (Integer.parseInt(this.getExtradata()) + 1) % (this.getBaseItem().getMultiHeights().length));
|
||||
this.needsUpdate(true);
|
||||
room.updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()));
|
||||
room.updateItemState(this);
|
||||
//room.sendComposer(new UpdateStackHeightComposer(this.getX(), this.getY(), this.getBaseItem().getMultiHeights()[Integer.valueOf(this.getExtradata())] * 256.0D).compose());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isWalkable()) {
|
||||
List<RoomUnit> unitsOnItem = new ArrayList<>();
|
||||
unitsOnItem.addAll(room.getHabbosOnItem(this).stream().map(Habbo::getRoomUnit).filter(Objects::nonNull).collect(Collectors.toList()));
|
||||
unitsOnItem.addAll(room.getBotsOnItem(this).stream().map(Bot::getRoomUnit).filter(Objects::nonNull).collect(Collectors.toList()));
|
||||
public void updateUnitsOnItem(Room room) {
|
||||
Collection<RoomUnit> unitsOnItem = room.getRoomUnitsAt(room.getLayout().getTile(this.getX(), this.getY()));
|
||||
|
||||
THashSet<RoomUnit> updatedUnits = new THashSet<>();
|
||||
for (RoomUnit unit : unitsOnItem) {
|
||||
if (unit.hasStatus(RoomUnitStatus.MOVE))
|
||||
continue;
|
||||
|
||||
if (this.getBaseItem().getMultiHeights().length >= 0) {
|
||||
if (this.getBaseItem().allowSit()) {
|
||||
unit.setStatus(RoomUnitStatus.SIT, this.getBaseItem().getMultiHeights()[(this.getExtradata().isEmpty() ? 0 : Integer.valueOf(this.getExtradata()) % (this.getBaseItem().getMultiHeights().length))] * 1.0D + "");
|
||||
this.getBaseItem().getMultiHeights();
|
||||
/*if (this.getBaseItem().allowSit()) {
|
||||
unit.setStatus(RoomUnitStatus.SIT, this.getBaseItem().getMultiHeights()[(this.getExtradata().isEmpty() ? 0 : Integer.parseInt(this.getExtradata()) % (this.getBaseItem().getMultiHeights().length))] * 1.0D + "");
|
||||
} else {
|
||||
|
||||
}*/
|
||||
|
||||
if(this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) {
|
||||
unit.sitUpdate = true;
|
||||
}
|
||||
|
||||
unit.setZ(unit.getCurrentLocation().getStackHeight());
|
||||
unit.setPreviousLocationZ(unit.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
updatedUnits.add(unit);
|
||||
}
|
||||
|
||||
room.sendComposer(new RoomUserStatusComposer(updatedUnits, true).compose());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) {
|
||||
|
@ -6,9 +6,7 @@ import com.eu.habbo.habbohotel.items.Item;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
|
||||
import com.eu.habbo.habbohotel.rooms.*;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import com.eu.habbo.habbohotel.wired.WiredEffectType;
|
||||
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
||||
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
|
||||
import com.eu.habbo.habbohotel.wired.*;
|
||||
import com.eu.habbo.messages.ClientMessage;
|
||||
import com.eu.habbo.messages.ServerMessage;
|
||||
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
|
||||
@ -31,9 +29,9 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
|
||||
public static final WiredEffectType type = WiredEffectType.MOVE_DIRECTION;
|
||||
|
||||
private final THashMap<HabboItem, RoomUserRotation> items = new THashMap<>(0);
|
||||
private final THashMap<HabboItem, WiredChangeDirectionSetting> items = new THashMap<>(0);
|
||||
private RoomUserRotation startRotation = RoomUserRotation.NORTH;
|
||||
private int rotateAction = 0;
|
||||
private int blockedAction = 0;
|
||||
|
||||
public WiredEffectChangeFurniDirection(ResultSet set, Item baseItem) throws SQLException {
|
||||
super(set, baseItem);
|
||||
@ -58,32 +56,55 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
|
||||
if (this.items.isEmpty()) return false;
|
||||
|
||||
for (Map.Entry<HabboItem, RoomUserRotation> entry : this.items.entrySet()) {
|
||||
RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getValue().getValue());
|
||||
for (Map.Entry<HabboItem, WiredChangeDirectionSetting> entry : this.items.entrySet()) {
|
||||
HabboItem item = entry.getKey();
|
||||
RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().direction.getValue());
|
||||
|
||||
int count = 1;
|
||||
while ((targetTile == null || !targetTile.getAllowStack() || targetTile.state == RoomTileState.INVALID) && count < 8) {
|
||||
entry.setValue(this.nextRotation(entry.getValue()));
|
||||
targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getValue().getValue());
|
||||
while ((targetTile == null || targetTile.state == RoomTileState.INVALID || room.furnitureFitsAt(targetTile, item, item.getRotation(), false) != FurnitureMovementError.NONE) && count < 8) {
|
||||
entry.getValue().direction = this.nextRotation(entry.getValue().direction);
|
||||
|
||||
RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().direction.getValue());
|
||||
if (tile != null && tile.state != RoomTileState.INVALID) {
|
||||
targetTile = tile;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<HabboItem, RoomUserRotation> entry : this.items.entrySet()) {
|
||||
RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getValue().getValue());
|
||||
for (Map.Entry<HabboItem, WiredChangeDirectionSetting> entry : this.items.entrySet()) {
|
||||
HabboItem item = entry.getKey();
|
||||
int newDirection = entry.getValue().direction.getValue();
|
||||
|
||||
if (targetTile != null && targetTile.state != RoomTileState.INVALID) {
|
||||
boolean hasRoomUnits = false;
|
||||
for (RoomUnit _roomUnit : room.getRoomUnitsAt(targetTile)) {
|
||||
hasRoomUnits = true;
|
||||
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{entry.getKey()}));
|
||||
RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), newDirection);
|
||||
|
||||
if(item.getRotation() != entry.getValue().rotation) {
|
||||
if(room.furnitureFitsAt(targetTile, item, entry.getValue().rotation, false) != FurnitureMovementError.NONE)
|
||||
continue;
|
||||
|
||||
room.moveFurniTo(entry.getKey(), targetTile, entry.getValue().rotation, null, true);
|
||||
}
|
||||
|
||||
if (!hasRoomUnits && targetTile.getAllowStack() && targetTile.state != RoomTileState.INVALID) {
|
||||
THashSet<RoomTile> refreshTiles = room.getLayout().getTilesAt(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getKey().getBaseItem().getWidth(), entry.getKey().getBaseItem().getLength(), entry.getKey().getRotation());
|
||||
room.sendComposer(new FloorItemOnRollerComposer(entry.getKey(), null, targetTile, targetTile.getStackHeight() - entry.getKey().getZ(), room).compose());
|
||||
room.getLayout().getTilesAt(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getKey().getBaseItem().getWidth(), entry.getKey().getBaseItem().getLength(), entry.getKey().getRotation());
|
||||
room.updateTiles(refreshTiles);
|
||||
if (targetTile != null && targetTile.state != RoomTileState.INVALID && room.furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) {
|
||||
boolean hasRoomUnits = false;
|
||||
THashSet<RoomTile> newOccupiedTiles = room.getLayout().getTilesAt(targetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
|
||||
for(RoomTile tile : newOccupiedTiles) {
|
||||
for (RoomUnit _roomUnit : room.getRoomUnits(tile)) {
|
||||
hasRoomUnits = true;
|
||||
if(_roomUnit.getCurrentLocation() == targetTile) {
|
||||
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{entry.getKey()}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasRoomUnits) {
|
||||
RoomTile oldLocation = room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY());
|
||||
double oldZ = entry.getKey().getZ();
|
||||
if(room.moveFurniTo(entry.getKey(), targetTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
|
||||
room.sendComposer(new FloorItemOnRollerComposer(entry.getKey(), null, oldLocation, oldZ, targetTile, entry.getKey().getZ(), 0, room).compose());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -93,10 +114,10 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
|
||||
@Override
|
||||
public String getWiredData() {
|
||||
StringBuilder data = new StringBuilder(this.getDelay() + "\t" + this.startRotation.getValue() + "\t" + this.rotateAction + "\t" + this.items.size());
|
||||
StringBuilder data = new StringBuilder(this.getDelay() + "\t" + this.startRotation.getValue() + "\t" + this.blockedAction + "\t" + this.items.size());
|
||||
|
||||
for (Map.Entry<HabboItem, RoomUserRotation> entry : this.items.entrySet()) {
|
||||
data.append("\t").append(entry.getKey().getId()).append(":").append(entry.getValue().getValue());
|
||||
for (Map.Entry<HabboItem, WiredChangeDirectionSetting> entry : this.items.entrySet()) {
|
||||
data.append("\t").append(entry.getKey().getId()).append(":").append(entry.getValue().direction.getValue()).append(":").append(entry.getValue().rotation);
|
||||
}
|
||||
|
||||
return data.toString();
|
||||
@ -109,7 +130,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
if (data.length >= 4) {
|
||||
this.setDelay(Integer.parseInt(data[0]));
|
||||
this.startRotation = RoomUserRotation.fromValue(Integer.parseInt(data[1]));
|
||||
this.rotateAction = Integer.parseInt(data[2]);
|
||||
this.blockedAction = Integer.parseInt(data[2]);
|
||||
|
||||
int itemCount = Integer.parseInt(data[3]);
|
||||
|
||||
@ -117,11 +138,17 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
for (int i = 4; i < data.length; i++) {
|
||||
String[] subData = data[i].split(":");
|
||||
|
||||
if (subData.length == 2) {
|
||||
if (subData.length >= 2) {
|
||||
HabboItem item = room.getHabboItem(Integer.parseInt(subData[0]));
|
||||
|
||||
if (item != null) {
|
||||
this.items.put(item, RoomUserRotation.fromValue(Integer.parseInt(subData[1])));
|
||||
int rotation = item.getRotation();
|
||||
|
||||
if(subData.length > 2) {
|
||||
rotation = Integer.parseInt(subData[2]);
|
||||
}
|
||||
|
||||
this.items.put(item, new WiredChangeDirectionSetting(item.getId(), rotation, RoomUserRotation.fromValue(Integer.parseInt(subData[1]))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -133,7 +160,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
public void onPickUp() {
|
||||
this.setDelay(0);
|
||||
this.items.clear();
|
||||
this.rotateAction = 0;
|
||||
this.blockedAction = 0;
|
||||
this.startRotation = RoomUserRotation.NORTH;
|
||||
}
|
||||
|
||||
@ -147,7 +174,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
message.appendBoolean(false);
|
||||
message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
|
||||
message.appendInt(this.items.size());
|
||||
for (Map.Entry<HabboItem, RoomUserRotation> item : this.items.entrySet()) {
|
||||
for (Map.Entry<HabboItem, WiredChangeDirectionSetting> item : this.items.entrySet()) {
|
||||
message.appendInt(item.getKey().getId());
|
||||
}
|
||||
message.appendInt(this.getBaseItem().getSpriteId());
|
||||
@ -155,7 +182,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
message.appendString("");
|
||||
message.appendInt(2);
|
||||
message.appendInt(this.startRotation.getValue());
|
||||
message.appendInt(this.rotateAction);
|
||||
message.appendInt(this.blockedAction);
|
||||
message.appendInt(0);
|
||||
message.appendInt(this.getType().code);
|
||||
message.appendInt(this.getDelay());
|
||||
@ -165,17 +192,17 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
@Override
|
||||
public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
|
||||
packet.readInt();
|
||||
int startRotationInt = packet.readInt();
|
||||
int startDirectionInt = packet.readInt();
|
||||
|
||||
if(startRotationInt < 0 || startRotationInt > 7 || (startRotationInt % 2) != 0) {
|
||||
throw new WiredSaveException("Direction is invalid");
|
||||
if(startDirectionInt < 0 || startDirectionInt > 7 || (startDirectionInt % 2) != 0) {
|
||||
throw new WiredSaveException("Start direction is invalid");
|
||||
}
|
||||
|
||||
RoomUserRotation startRotation = RoomUserRotation.fromValue(startRotationInt);
|
||||
RoomUserRotation startDirection = RoomUserRotation.fromValue(startDirectionInt);
|
||||
|
||||
int rotateAction = packet.readInt();
|
||||
int blockedActionInt = packet.readInt();
|
||||
|
||||
if(rotateAction < 0 || rotateAction > 6) {
|
||||
if(blockedActionInt < 0 || blockedActionInt > 6) {
|
||||
throw new WiredSaveException("Blocked action is invalid");
|
||||
}
|
||||
|
||||
@ -187,7 +214,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
throw new WiredSaveException("Too many furni selected");
|
||||
}
|
||||
|
||||
THashMap<HabboItem, RoomUserRotation> newItems = new THashMap<>();
|
||||
THashMap<HabboItem, WiredChangeDirectionSetting> newItems = new THashMap<>();
|
||||
|
||||
for (int i = 0; i < itemsCount; i++) {
|
||||
int itemId = packet.readInt();
|
||||
@ -196,7 +223,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
if(it == null)
|
||||
throw new WiredSaveException(String.format("Item %s not found", itemId));
|
||||
|
||||
newItems.put(it, startRotation);
|
||||
newItems.put(it, new WiredChangeDirectionSetting(it.getId(), it.getRotation(), startDirection));
|
||||
}
|
||||
|
||||
int delay = packet.readInt();
|
||||
@ -206,18 +233,17 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
|
||||
this.items.clear();
|
||||
this.items.putAll(newItems);
|
||||
this.startRotation = startRotation;
|
||||
this.rotateAction = rotateAction;
|
||||
this.startRotation = startDirection;
|
||||
this.blockedAction = blockedActionInt;
|
||||
this.setDelay(delay);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private RoomUserRotation nextRotation(RoomUserRotation currentRotation) {
|
||||
switch (this.rotateAction) {
|
||||
switch (this.blockedAction) {
|
||||
case ACTION_TURN_BACK:
|
||||
return RoomUserRotation.fromValue(currentRotation.getValue() + 4);
|
||||
|
||||
case ACTION_TURN_LEFT_45:
|
||||
return RoomUserRotation.counterClockwise(currentRotation);
|
||||
case ACTION_TURN_LEFT_90:
|
||||
@ -231,8 +257,6 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
|
||||
case ACTION_WAIT:
|
||||
default:
|
||||
return currentRotation;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,10 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects;
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
||||
import com.eu.habbo.habbohotel.items.Item;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionMultiHeight;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionRoller;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
|
||||
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.rooms.*;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import com.eu.habbo.habbohotel.wired.WiredEffectType;
|
||||
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
||||
@ -49,11 +47,9 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect {
|
||||
|
||||
@Override
|
||||
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
|
||||
THashSet<RoomTile> tilesToUpdate = new THashSet<>(this.settings.size());
|
||||
//this.refresh();
|
||||
|
||||
if(this.settings.isEmpty())
|
||||
return false;
|
||||
return true;
|
||||
|
||||
for (WiredMatchFurniSetting setting : this.settings) {
|
||||
HabboItem item = room.getHabboItem(setting.itemId);
|
||||
@ -62,93 +58,33 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect {
|
||||
if (!setting.state.equals(" ")) {
|
||||
item.setExtradata(setting.state);
|
||||
room.updateItemState(item);
|
||||
tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
|
||||
}
|
||||
}
|
||||
|
||||
int oldRotation = item.getRotation();
|
||||
boolean slideAnimation = true;
|
||||
double offsetZ = 0;
|
||||
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
|
||||
double oldZ = item.getZ();
|
||||
|
||||
if (this.direction && item.getRotation() != setting.rotation) {
|
||||
item.setRotation(setting.rotation);
|
||||
slideAnimation = false;
|
||||
|
||||
room.scheduledTasks.add(() -> {
|
||||
room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), oldRotation).forEach(t -> {
|
||||
room.updateBotsAt(t.x, t.y);
|
||||
room.updateHabbosAt(t.x, t.y);
|
||||
});
|
||||
room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), setting.rotation).forEach(t -> {
|
||||
room.updateBotsAt(t.x, t.y);
|
||||
room.updateHabbosAt(t.x, t.y);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
RoomTile t = null;
|
||||
|
||||
if (this.position) {
|
||||
t = room.getLayout().getTile((short) setting.x, (short) setting.y);
|
||||
|
||||
if (t != null && t.state != RoomTileState.INVALID) {
|
||||
boolean canMove = true;
|
||||
|
||||
if (t.x == item.getX() && t.y == item.getY() || room.hasHabbosAt(t.x, t.y)) {
|
||||
canMove = !(room.getTopItemAt(t.x, t.y) == item);
|
||||
slideAnimation = false;
|
||||
}
|
||||
|
||||
|
||||
if (canMove && !room.hasHabbosAt(t.x, t.y)) {
|
||||
THashSet<RoomTile> tiles = room.getLayout().getTilesAt(t, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), setting.rotation);
|
||||
double highestZ = -1d;
|
||||
for (RoomTile tile : tiles) {
|
||||
if (tile.state == RoomTileState.INVALID) {
|
||||
highestZ = -1d;
|
||||
break;
|
||||
}
|
||||
|
||||
if (item instanceof InteractionRoller && room.hasItemsAt(tile.x, tile.y)) {
|
||||
highestZ = -1d;
|
||||
break;
|
||||
}
|
||||
|
||||
double stackHeight = room.getStackHeight(tile.x, tile.y, false, item);
|
||||
if (stackHeight > highestZ) {
|
||||
highestZ = stackHeight;
|
||||
if(this.direction && !this.position) {
|
||||
if(item.getRotation() != setting.rotation && room.furnitureFitsAt(oldLocation, item, setting.rotation, false) == FurnitureMovementError.NONE) {
|
||||
room.moveFurniTo(item, oldLocation, setting.rotation, null, true);
|
||||
}
|
||||
}
|
||||
else if(this.position) {
|
||||
boolean slideAnimation = !this.direction || item.getRotation() == setting.rotation;
|
||||
RoomTile newLocation = room.getLayout().getTile((short) setting.x, (short) setting.y);
|
||||
|
||||
if (highestZ != -1d) {
|
||||
tilesToUpdate.addAll(tiles);
|
||||
|
||||
offsetZ = highestZ - item.getZ();
|
||||
double totalHeight = item.getZ() + offsetZ;
|
||||
if (totalHeight > 40) break;
|
||||
tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), oldRotation));
|
||||
|
||||
if (!slideAnimation) {
|
||||
item.setX(t.x);
|
||||
item.setY(t.y);
|
||||
}
|
||||
if(newLocation != null && newLocation.state != RoomTileState.INVALID && room.furnitureFitsAt(newLocation, item, this.direction ? setting.rotation : item.getRotation(), true) == FurnitureMovementError.NONE) {
|
||||
if(room.moveFurniTo(item, newLocation, this.direction ? setting.rotation : item.getRotation(), null, !slideAnimation) == FurnitureMovementError.NONE) {
|
||||
if(slideAnimation) {
|
||||
room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (slideAnimation && t != null) {
|
||||
room.sendComposer(new FloorItemOnRollerComposer(item, null, t, offsetZ, room).compose());
|
||||
} else {
|
||||
room.updateItem(item);
|
||||
}
|
||||
|
||||
item.needsUpdate(true);
|
||||
}
|
||||
}
|
||||
|
||||
room.updateTiles(tilesToUpdate);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -82,20 +82,13 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
|
||||
y++;
|
||||
}
|
||||
|
||||
RoomTile newTile = room.getLayout().getTile((short) (item.getX() + x), (short) (item.getY() + y));
|
||||
RoomTile newLocation = room.getLayout().getTile((short) (item.getX() + x), (short) (item.getY() + y));
|
||||
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
|
||||
double oldZ = item.getZ();
|
||||
|
||||
if (newTile != null && newTile.state == RoomTileState.OPEN) {
|
||||
if (room.getLayout().tileExists(newTile.x, newTile.y)) {
|
||||
HabboItem topItem = room.getTopItemAt(newTile.x, newTile.y);
|
||||
|
||||
if (topItem == null || topItem.getBaseItem().allowStack()) {
|
||||
double offsetZ = 0;
|
||||
|
||||
if (topItem != null)
|
||||
offsetZ = topItem.getZ() + topItem.getBaseItem().getHeight() - item.getZ();
|
||||
|
||||
room.sendComposer(new FloorItemOnRollerComposer(item, null, newTile, offsetZ, room).compose());
|
||||
}
|
||||
if(newLocation != null && newLocation.state != RoomTileState.INVALID && room.furnitureFitsAt(newLocation, item, item.getRotation(), true) == FurnitureMovementError.NONE) {
|
||||
if(room.moveFurniTo(item, newLocation, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
|
||||
room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,13 +215,15 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
|
||||
|
||||
RoomTile newTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), moveDirection.getValue());
|
||||
|
||||
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
|
||||
double oldZ = item.getZ();
|
||||
|
||||
if(newTile != null) {
|
||||
lastDirections.put(item.getId(), moveDirection);
|
||||
|
||||
FurnitureMovementError error = room.furnitureFitsAt(newTile, item, item.getRotation());
|
||||
if (error == FurnitureMovementError.NONE) {
|
||||
double offset = room.getStackHeight(newTile.x, newTile.y, false, item) - item.getZ();
|
||||
room.sendComposer(new FloorItemOnRollerComposer(item, null, newTile, offset, room).compose());
|
||||
if(newTile.state != RoomTileState.INVALID && room.furnitureFitsAt(newTile, item, item.getRotation(), true) == FurnitureMovementError.NONE) {
|
||||
if (room.moveFurniTo(item, newTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
|
||||
room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newTile, item.getZ(), 0, room).compose());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import java.awt.*;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
|
||||
|
||||
@ -48,120 +49,31 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
|
||||
// remove items that are no longer in the room
|
||||
this.items.removeIf(item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
|
||||
|
||||
THashSet<RoomTile> tilesToUpdate = new THashSet<>(Math.min(this.items.size(), 10));
|
||||
|
||||
for (HabboItem item : this.items) {
|
||||
//Handle rotation
|
||||
if (this.rotation > 0) {
|
||||
tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
|
||||
int newRotation = this.getNewRotation(item);
|
||||
int newRotation = this.rotation > 0 ? this.getNewRotation(item) : item.getRotation();
|
||||
RoomTile newLocation = room.getLayout().getTile(item.getX(), item.getY());
|
||||
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
|
||||
double oldZ = item.getZ();
|
||||
|
||||
//Verify if rotation result in a valid position
|
||||
FurnitureMovementError rotateError = room.furnitureFitsAt(room.getLayout().getTile(item.getX(), item.getY()), item, newRotation);
|
||||
if (item.getRotation() != newRotation && (rotateError.equals(FurnitureMovementError.TILE_HAS_HABBOS) || rotateError.equals(FurnitureMovementError.TILE_HAS_PETS) ||
|
||||
rotateError.equals(FurnitureMovementError.TILE_HAS_BOTS) || rotateError.equals(FurnitureMovementError.NONE))) {
|
||||
item.setRotation(newRotation);
|
||||
if (this.direction == 0) {
|
||||
tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
|
||||
room.sendComposer(new FloorItemUpdateComposer(item).compose());
|
||||
for (RoomTile t : tilesToUpdate) {
|
||||
room.updateHabbosAt(t.x, t.y);
|
||||
room.updateBotsAt(t.x, t.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//handle movement
|
||||
if(this.direction > 0) {
|
||||
RoomUserRotation moveDirection = this.getMovementDirection();
|
||||
boolean validMove;
|
||||
RoomLayout layout = room.getLayout();
|
||||
if (layout == null) return false;
|
||||
|
||||
RoomTile newTile = layout.getTile(
|
||||
newLocation = room.getLayout().getTile(
|
||||
(short) (item.getX() + ((moveDirection == RoomUserRotation.WEST || moveDirection == RoomUserRotation.NORTH_WEST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : (((moveDirection == RoomUserRotation.EAST || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.NORTH_EAST) ? 1 : 0)))),
|
||||
(short) (item.getY() + ((moveDirection == RoomUserRotation.NORTH || moveDirection == RoomUserRotation.NORTH_EAST || moveDirection == RoomUserRotation.NORTH_WEST) ? 1 : ((moveDirection == RoomUserRotation.SOUTH || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : 0)))
|
||||
);
|
||||
|
||||
if (newTile != null) {
|
||||
boolean hasRoomUnits = false;
|
||||
for (RoomUnit _roomUnit : room.getRoomUnitsAt(newTile)) {
|
||||
hasRoomUnits = true;
|
||||
// this wired isn't meant to do a collision
|
||||
//WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{item});
|
||||
}
|
||||
|
||||
if (!hasRoomUnits && room.getStackHeight(newTile.x, newTile.y, true, item) != Short.MAX_VALUE) {
|
||||
java.awt.Rectangle rectangle = new Rectangle(newTile.x,
|
||||
newTile.y,
|
||||
item.getBaseItem().getWidth(),
|
||||
item.getBaseItem().getLength());
|
||||
boolean slideAnimation = item.getRotation() == newRotation;
|
||||
|
||||
double offset = -Short.MAX_VALUE;
|
||||
validMove = true;
|
||||
for (short x = (short) rectangle.x; x < rectangle.x + rectangle.getWidth(); x++) {
|
||||
if (!validMove) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (short y = (short) rectangle.y; y < rectangle.y + rectangle.getHeight(); y++) {
|
||||
RoomTile tile = layout.getTile(x, y);
|
||||
if (tile == null || tile.state == RoomTileState.INVALID || !tile.getAllowStack()) {
|
||||
validMove = false;
|
||||
break;
|
||||
}
|
||||
|
||||
THashSet<HabboItem> itemsAtNewTile = room.getItemsAt(tile);
|
||||
if (item instanceof InteractionRoller && !itemsAtNewTile.isEmpty()) {
|
||||
validMove = false;
|
||||
break;
|
||||
}
|
||||
|
||||
ArrayList<Pair<RoomTile, THashSet<HabboItem>>> tileItems = new ArrayList<>(rectangle.width * rectangle.height);
|
||||
tileItems.add(Pair.create(tile, itemsAtNewTile));
|
||||
if (!item.canStackAt(room, tileItems)) {
|
||||
validMove = false;
|
||||
break;
|
||||
}
|
||||
|
||||
HabboItem i = room.getTopItemAt(x, y, item);
|
||||
if (i != null && !i.getBaseItem().allowStack()) {
|
||||
validMove = false;
|
||||
break;
|
||||
}
|
||||
|
||||
offset = Math.max(room.getStackHeight(newTile.x, newTile.y, false, item) - item.getZ(), offset);
|
||||
|
||||
tilesToUpdate.add(tile);
|
||||
}
|
||||
}
|
||||
if (item.getZ() + offset > 40) {
|
||||
offset = 40 - item.getZ();
|
||||
}
|
||||
|
||||
if (validMove) {
|
||||
if (this.rotation > 0) {
|
||||
item.setX(newTile.x);
|
||||
item.setY(newTile.y);
|
||||
item.setZ(item.getZ() + offset);
|
||||
room.sendComposer(new FloorItemUpdateComposer(item).compose());
|
||||
for (RoomTile t : tilesToUpdate) {
|
||||
room.updateHabbosAt(t.x, t.y);
|
||||
room.updateBotsAt(t.x, t.y);
|
||||
}
|
||||
} else {
|
||||
room.sendComposer(new FloorItemOnRollerComposer(item, null, newTile, offset, room).compose());
|
||||
FurnitureMovementError furniMoveTest = room.furnitureFitsAt(newLocation, item, newRotation, true);
|
||||
if(newLocation != null && newLocation.state != RoomTileState.INVALID && (furniMoveTest == FurnitureMovementError.NONE || ((furniMoveTest == FurnitureMovementError.TILE_HAS_BOTS || furniMoveTest == FurnitureMovementError.TILE_HAS_HABBOS || furniMoveTest == FurnitureMovementError.TILE_HAS_PETS) && newLocation == oldLocation))) {
|
||||
if(room.furnitureFitsAt(newLocation, item, newRotation, false) == FurnitureMovementError.NONE && room.moveFurniTo(item, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) {
|
||||
if(slideAnimation) {
|
||||
room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!tilesToUpdate.isEmpty()) {
|
||||
room.updateTiles(tilesToUpdate);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -231,7 +143,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
|
||||
|
||||
@Override
|
||||
public void serializeWiredData(ServerMessage message, Room room) {
|
||||
THashSet<HabboItem> items = new THashSet<>(this.items.size() / 2);
|
||||
THashSet<HabboItem> items = new THashSet<>();
|
||||
|
||||
for (HabboItem item : this.items) {
|
||||
if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
|
||||
@ -295,21 +207,67 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
|
||||
*/
|
||||
private int getNewRotation(HabboItem item) {
|
||||
int rotationToAdd = 0;
|
||||
if (this.rotation == 1) {
|
||||
rotationToAdd = 2;
|
||||
} else if (this.rotation == 2) {
|
||||
rotationToAdd = 6;
|
||||
|
||||
if(item.getMaximumRotations() == 2) {
|
||||
return item.getRotation() == 0 ? 4 : 0;
|
||||
}
|
||||
else if(item.getMaximumRotations() == 1) {
|
||||
return item.getRotation();
|
||||
}
|
||||
else if(item.getMaximumRotations() > 4) {
|
||||
if (this.rotation == 1) {
|
||||
return item.getRotation() == item.getMaximumRotations() - 1 ? 0 : item.getRotation() + 1;
|
||||
} else if (this.rotation == 2) {
|
||||
return item.getRotation() > 0 ? item.getRotation() - 1 : item.getMaximumRotations() - 1;
|
||||
} else if (this.rotation == 3) { //Random rotation
|
||||
THashSet<Integer> possibleRotations = new THashSet<>();
|
||||
for (int i = 0; i < item.getMaximumRotations(); i++)
|
||||
{
|
||||
possibleRotations.add(i);
|
||||
}
|
||||
|
||||
possibleRotations.remove(item.getRotation());
|
||||
|
||||
if(possibleRotations.size() > 0) {
|
||||
int index = Emulator.getRandom().nextInt(possibleRotations.size());
|
||||
Iterator<Integer> iter = possibleRotations.iterator();
|
||||
for (int i = 0; i < index; i++) {
|
||||
iter.next();
|
||||
}
|
||||
return iter.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.rotation == 1) {
|
||||
return (item.getRotation() + 2) % 8;
|
||||
} else if (this.rotation == 2) {
|
||||
int rot = (item.getRotation() - 2) % 8;
|
||||
if(rot < 0) {
|
||||
rot += 8;
|
||||
}
|
||||
return rot;
|
||||
} else if (this.rotation == 3) { //Random rotation
|
||||
THashSet<Integer> possibleRotations = new THashSet<>();
|
||||
for (int i = 0; i < item.getMaximumRotations(); i++)
|
||||
{
|
||||
possibleRotations.add(i * 2);
|
||||
}
|
||||
|
||||
possibleRotations.remove(item.getRotation());
|
||||
|
||||
if(possibleRotations.size() > 0) {
|
||||
int index = Emulator.getRandom().nextInt(possibleRotations.size());
|
||||
Iterator<Integer> iter = possibleRotations.iterator();
|
||||
for (int i = 0; i < index; i++) {
|
||||
iter.next();
|
||||
}
|
||||
return iter.next();
|
||||
}
|
||||
//Random rotation
|
||||
else if (this.rotation == 3) {
|
||||
if (Emulator.getRandom().nextInt(2) == 1) {
|
||||
rotationToAdd = 2;
|
||||
} else {
|
||||
rotationToAdd = 6;
|
||||
}
|
||||
}
|
||||
|
||||
return ((item.getRotation() + rotationToAdd) % 8) % (item.getBaseItem().getWidth() > 1 || item.getBaseItem().getLength() > 1 ? 4 : 8);
|
||||
return item.getRotation();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3485,6 +3485,27 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
return highestItem;
|
||||
}
|
||||
|
||||
public HabboItem getTopItemAt(THashSet<RoomTile> tiles, HabboItem exclude) {
|
||||
HabboItem highestItem = null;
|
||||
for(RoomTile tile : tiles) {
|
||||
|
||||
if (tile == null)
|
||||
continue;
|
||||
|
||||
for (HabboItem item : this.getItemsAt(tile.x, tile.y)) {
|
||||
if (exclude != null && exclude == item)
|
||||
continue;
|
||||
|
||||
if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
|
||||
continue;
|
||||
|
||||
highestItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
return highestItem;
|
||||
}
|
||||
|
||||
public double getTopHeightAt(int x, int y) {
|
||||
HabboItem item = this.getTopItemAt(x, y);
|
||||
|
||||
@ -4082,6 +4103,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
if (this.layout == null) return;
|
||||
|
||||
this.updateTiles(this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
|
||||
|
||||
if(item instanceof InteractionMultiHeight) {
|
||||
((InteractionMultiHeight)item).updateUnitsOnItem(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4400,6 +4425,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
|
||||
public FurnitureMovementError furnitureFitsAt(RoomTile tile, HabboItem item, int rotation) {
|
||||
return furnitureFitsAt(tile, item, rotation, true);
|
||||
}
|
||||
|
||||
public FurnitureMovementError furnitureFitsAt(RoomTile tile, HabboItem item, int rotation, boolean checkForUnits) {
|
||||
if (!this.layout.fitsOnMap(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation))
|
||||
return FurnitureMovementError.INVALID_MOVE;
|
||||
|
||||
@ -4407,10 +4436,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
|
||||
THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
|
||||
for (RoomTile t : occupiedTiles) {
|
||||
|
||||
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;
|
||||
if(t.state == RoomTileState.INVALID) return FurnitureMovementError.INVALID_MOVE;
|
||||
if (checkForUnits && this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS;
|
||||
if (checkForUnits && this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS;
|
||||
if (checkForUnits && this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS;
|
||||
}
|
||||
|
||||
List<Pair<RoomTile, THashSet<HabboItem>>> tileFurniList = new ArrayList<>();
|
||||
@ -4510,6 +4539,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
|
||||
public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor) {
|
||||
return moveFurniTo(item, tile, rotation, actor, true);
|
||||
}
|
||||
|
||||
public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor, boolean sendUpdates) {
|
||||
RoomTile oldLocation = this.layout.getTile(item.getX(), item.getY());
|
||||
|
||||
boolean pluginHelper = false;
|
||||
@ -4521,8 +4554,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
pluginHelper = event.hasPluginHelper();
|
||||
}
|
||||
|
||||
HabboItem topItem = this.getTopItemAt(tile.x, tile.y);
|
||||
|
||||
boolean magicTile = item instanceof InteractionStackHelper;
|
||||
|
||||
Optional<HabboItem> stackHelper = this.getItemsAt(tile).stream().filter(i -> i instanceof InteractionStackHelper).findAny();
|
||||
@ -4530,6 +4561,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
//Check if can be placed at new position
|
||||
THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
|
||||
|
||||
HabboItem topItem = this.getTopItemAt(occupiedTiles, null);
|
||||
|
||||
if (!stackHelper.isPresent() && !pluginHelper) {
|
||||
if (topItem != item) {
|
||||
for (RoomTile t : occupiedTiles) {
|
||||
@ -4574,10 +4607,16 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
|
||||
if (stackHelper.isPresent()) {
|
||||
height = stackHelper.get().getExtradata().isEmpty() ? Double.parseDouble("0.0") : (Double.parseDouble(stackHelper.get().getExtradata()) / 100);
|
||||
} else if (item.equals(topItem) && tile.x == item.getX() && tile.y == item.getY()) {
|
||||
} else if (item.equals(topItem)) {
|
||||
height = item.getZ();
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Emulator.getPluginManager().isRegistered(FurnitureBuildheightEvent.class, true)) {
|
||||
@ -4606,7 +4645,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
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);
|
||||
@ -4671,22 +4713,26 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
|
||||
public THashSet<RoomUnit> getRoomUnits() {
|
||||
return getRoomUnits(null);
|
||||
}
|
||||
|
||||
public THashSet<RoomUnit> getRoomUnits(RoomTile atTile) {
|
||||
THashSet<RoomUnit> units = new THashSet<>();
|
||||
|
||||
for (Habbo habbo : this.currentHabbos.values()) {
|
||||
if (habbo != null && habbo.getRoomUnit() != null && habbo.getRoomUnit().getRoom() != null && habbo.getRoomUnit().getRoom().getId() == this.getId()) {
|
||||
if (habbo != null && habbo.getRoomUnit() != null && habbo.getRoomUnit().getRoom() != null && habbo.getRoomUnit().getRoom().getId() == this.getId() && (atTile == null || habbo.getRoomUnit().getCurrentLocation() == atTile)) {
|
||||
units.add(habbo.getRoomUnit());
|
||||
}
|
||||
}
|
||||
|
||||
for (Pet pet : this.currentPets.valueCollection()) {
|
||||
if (pet != null && pet.getRoomUnit() != null && pet.getRoomUnit().getRoom() != null && pet.getRoomUnit().getRoom().getId() == this.getId()) {
|
||||
if (pet != null && pet.getRoomUnit() != null && pet.getRoomUnit().getRoom() != null && pet.getRoomUnit().getRoom().getId() == this.getId() && (atTile == null || pet.getRoomUnit().getCurrentLocation() == atTile)) {
|
||||
units.add(pet.getRoomUnit());
|
||||
}
|
||||
}
|
||||
|
||||
for (Bot bot : this.currentBots.valueCollection()) {
|
||||
if (bot != null && bot.getRoomUnit() != null && bot.getRoomUnit().getRoom() != null && bot.getRoomUnit().getRoom().getId() == this.getId()) {
|
||||
if (bot != null && bot.getRoomUnit() != null && bot.getRoomUnit().getRoom() != null && bot.getRoomUnit().getRoom().getId() == this.getId() && (atTile == null || bot.getRoomUnit().getCurrentLocation() == atTile)) {
|
||||
units.add(bot.getRoomUnit());
|
||||
}
|
||||
}
|
||||
|
@ -243,6 +243,8 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
|
||||
return this.limitedSells;
|
||||
}
|
||||
|
||||
public int getMaximumRotations() { return this.baseItem.getRotations(); }
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.eu.habbo.habbohotel.wired;
|
||||
|
||||
import com.eu.habbo.habbohotel.rooms.RoomUserRotation;
|
||||
|
||||
public class WiredChangeDirectionSetting {
|
||||
public final int itemId;
|
||||
public int rotation;
|
||||
public RoomUserRotation direction;
|
||||
|
||||
public WiredChangeDirectionSetting(int itemId, int rotation, RoomUserRotation direction) {
|
||||
this.itemId = itemId;
|
||||
this.rotation = rotation;
|
||||
this.direction = direction;
|
||||
}
|
||||
}
|
@ -8,12 +8,16 @@ import com.eu.habbo.messages.outgoing.MessageComposer;
|
||||
import com.eu.habbo.messages.outgoing.Outgoing;
|
||||
import com.eu.habbo.messages.outgoing.rooms.UpdateStackHeightComposer;
|
||||
import gnu.trove.set.hash.THashSet;
|
||||
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
|
||||
|
||||
public class FloorItemOnRollerComposer extends MessageComposer {
|
||||
private final HabboItem item;
|
||||
private final HabboItem roller;
|
||||
private final RoomTile oldLocation;
|
||||
private final RoomTile newLocation;
|
||||
private final double heightOffset;
|
||||
private final double oldZ;
|
||||
private final double newZ;
|
||||
private final Room room;
|
||||
|
||||
public FloorItemOnRollerComposer(HabboItem item, HabboItem roller, RoomTile newLocation, double heightOffset, Room room) {
|
||||
@ -22,6 +26,20 @@ public class FloorItemOnRollerComposer extends MessageComposer {
|
||||
this.newLocation = newLocation;
|
||||
this.heightOffset = heightOffset;
|
||||
this.room = room;
|
||||
this.oldLocation = null;
|
||||
this.oldZ = -1;
|
||||
this.newZ = -1;
|
||||
}
|
||||
|
||||
public FloorItemOnRollerComposer(HabboItem item, HabboItem roller, RoomTile oldLocation, double oldZ, RoomTile newLocation, double newZ, double heightOffset, Room room) {
|
||||
this.item = item;
|
||||
this.roller = roller;
|
||||
this.oldLocation = oldLocation;
|
||||
this.oldZ = oldZ;
|
||||
this.newLocation = newLocation;
|
||||
this.newZ = newZ;
|
||||
this.heightOffset = heightOffset;
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,16 +48,17 @@ public class FloorItemOnRollerComposer extends MessageComposer {
|
||||
short oldY = this.item.getY();
|
||||
|
||||
this.response.init(Outgoing.ObjectOnRollerComposer);
|
||||
this.response.appendInt(this.item.getX());
|
||||
this.response.appendInt(this.item.getY());
|
||||
this.response.appendInt(this.oldLocation != null ? this.oldLocation.x : this.item.getX());
|
||||
this.response.appendInt(this.oldLocation != null ? this.oldLocation.y : this.item.getY());
|
||||
this.response.appendInt(this.newLocation.x);
|
||||
this.response.appendInt(this.newLocation.y);
|
||||
this.response.appendInt(1);
|
||||
this.response.appendInt(this.item.getId());
|
||||
this.response.appendString(Double.toString(this.item.getZ()));
|
||||
this.response.appendString(Double.toString(this.item.getZ() + this.heightOffset));
|
||||
this.response.appendString(Double.toString(this.oldLocation != null ? this.oldZ : this.item.getZ()));
|
||||
this.response.appendString(Double.toString(this.oldLocation != null ? this.newZ : (this.item.getZ() + this.heightOffset)));
|
||||
this.response.appendInt(this.roller != null ? this.roller.getId() : -1);
|
||||
|
||||
if(this.oldLocation != null) {
|
||||
this.item.onMove(this.room, this.room.getLayout().getTile(this.item.getX(), this.item.getY()), this.newLocation);
|
||||
this.item.setX(this.newLocation.x);
|
||||
this.item.setY(this.newLocation.y);
|
||||
@ -54,6 +73,7 @@ public class FloorItemOnRollerComposer extends MessageComposer {
|
||||
this.room.sendComposer(new UpdateStackHeightComposer(oldX, oldY, this.room.getStackHeight(oldX, oldY, true)).compose());
|
||||
//
|
||||
//this.room.updateHabbosAt(RoomLayout.getRectangle(this.item.getX(), this.item.getY(), this.item.getBaseItem().getWidth(), this.item.getBaseItem().getLength(), this.item.getRotation()));
|
||||
}
|
||||
|
||||
return this.response;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user