Fix Interaction Water

This commit is contained in:
brenoepic 2022-04-16 03:19:30 -03:00 committed by Harmonic
parent 0fb8dad0ea
commit 9f9bbf1a37
2 changed files with 79 additions and 66 deletions

View File

@ -59,6 +59,7 @@ public class InteractionWater extends InteractionDefault {
} catch (Exception e) {
}
}
}
@Override
@ -72,6 +73,8 @@ public class InteractionWater extends InteractionDefault {
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
roomUnit.isSwimming = true;
Pet pet = room.getPet(roomUnit);
if (pet == null)
@ -79,19 +82,23 @@ public class InteractionWater extends InteractionDefault {
if (!pet.getRoomUnit().hasStatus(RoomUnitStatus.SWIM) && pet.getPetData().canSwim) {
pet.getRoomUnit().setStatus(RoomUnitStatus.SWIM, "");
pet.packetUpdate = true;
}
}
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
roomUnit.isSwimming = false;
super.onWalkOff(roomUnit, room, objects);
if ( roomUnit.getRoomUnitType() != RoomUnitType.PET) return;
Pet pet = room.getPet(roomUnit);
if(pet == null)
return;
if (pet == null) return;
pet.getRoomUnit().removeStatus(RoomUnitStatus.SWIM);
roomUnit.removeStatus(RoomUnitStatus.SWIM);
pet.packetUpdate = true;
}
@Override
@ -108,11 +115,10 @@ public class InteractionWater extends InteractionDefault {
public boolean canStackAt(Room room, List<Pair<RoomTile, THashSet<HabboItem>>> itemsAtLocation) {
for (Pair<RoomTile, THashSet<HabboItem>> set : itemsAtLocation) {
for (HabboItem item : set.getValue()) {
if (!(item instanceof InteractionWater)) {
if(item != this)
return false;
}
}
}
return super.canStackAt(room, itemsAtLocation);
}

View File

@ -78,8 +78,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@ -2968,8 +2968,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
list.add(bot.getRoomUnit());
}
for(Habbo habbo : this.getHabbosAt(tile))
{
for (Habbo habbo : this.getHabbosAt(tile)) {
list.add(habbo.getRoomUnit());
}
@ -3356,6 +3355,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
/**
* Sends the given message to the receiving Habbo if the Habbo has the ACC_SEE_TENTCHAT permission and is not within the tent
*
* @param receivingHabbo The receiving Habbo
* @param roomChatMessage The message to receive
* @param tentRectangle The whole tent area from where the sending Habbo is saying something
@ -3472,8 +3472,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (item.getRotation() != 2 && item.getRotation() != 6) {
width = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
length = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
}
else {
} else {
width = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
length = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
}
@ -4137,7 +4136,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
duration += Emulator.getIntUnixTimestamp();
}
if (this.allowEffects) {
if (this.allowEffects && !roomUnit.isSwimming) {
roomUnit.setEffectId(effectId, duration);
this.sendComposer(new RoomUserEffectComposer(roomUnit).compose());
}
@ -4520,6 +4519,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (item instanceof InteractionStackHelper) return FurnitureMovementError.NONE;
THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
for (RoomTile t : occupiedTiles) {
if(t.state == RoomTileState.INVALID) return FurnitureMovementError.INVALID_MOVE;
@ -4530,6 +4530,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
Optional<HabboItem> stackHelper = this.getItemsAt(tile).stream().filter(i -> i instanceof InteractionStackHelper).findAny();
List<Pair<RoomTile, THashSet<HabboItem>>> tileFurniList = new ArrayList<>();
for (RoomTile t : occupiedTiles) {
tileFurniList.add(Pair.create(t, this.getItemsAt(t)));
@ -4538,6 +4540,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (topItem != null && !topItem.getBaseItem().allowStack() && !t.getAllowStack()) {
return FurnitureMovementError.CANT_STACK;
}
if ((stackHelper.isPresent() && item.getBaseItem().getInteractionType().getType() == InteractionWater.class) || topItem != null && (topItem.getBaseItem().getInteractionType().getType() == InteractionWater.class && (item.getBaseItem().getInteractionType().getType() == InteractionWater.class || item.getBaseItem().getInteractionType().getType() != InteractionWaterItem.class))) {
return FurnitureMovementError.CANT_STACK;
}
}
if (!item.canStackAt(this, tileFurniList)) {
@ -4663,14 +4669,14 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
HabboItem topItem = this.getTopItemAt(occupiedTiles, null);
if (!stackHelper.isPresent() && !pluginHelper) {
if ((!stackHelper.isPresent() && !pluginHelper) || item.getBaseItem().getInteractionType().getType() == InteractionWater.class) {
if (oldLocation != tile) {
for (RoomTile t : occupiedTiles) {
HabboItem tileTopItem = this.getTopItemAt(t.x, t.y);
if (!magicTile && ((tileTopItem != null && tileTopItem != item ? (t.state.equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack()) : this.calculateTileState(t, item).equals(RoomTileState.INVALID))))
if ((!magicTile && ((tileTopItem != null && tileTopItem != item ? (t.state.equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack() || (tileTopItem.getBaseItem().getInteractionType().getType() == InteractionWater.class && item.getBaseItem().getInteractionType().getType() == InteractionWater.class || item.getBaseItem().getInteractionType().getType() != InteractionWaterItem.class)) : this.calculateTileState(t, item).equals(RoomTileState.INVALID))) || stackHelper.isPresent() && item.getBaseItem().getInteractionType().getType() == InteractionWater.class))
return FurnitureMovementError.CANT_STACK;
if(!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit() && !item.getBaseItem().allowLay())) {
if(!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit())) {
if (checkForUnits) {
if (!magicTile && this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS;
if (!magicTile && this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS;
@ -4706,8 +4712,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
if((!stackHelper.isPresent() && topItem != null && topItem != item && !topItem.getBaseItem().allowStack())|| (topItem != null && topItem != item && topItem.getZ() + Item.getCurrentHeight(topItem) + Item.getCurrentHeight(item) > MAXIMUM_FURNI_HEIGHT))
{
if ((!stackHelper.isPresent() && topItem != null && topItem != item && !topItem.getBaseItem().allowStack()) || (topItem != null && topItem != item && topItem.getZ() + Item.getCurrentHeight(topItem) + Item.getCurrentHeight(item) > MAXIMUM_FURNI_HEIGHT)) {
item.setRotation(oldRotation);
return FurnitureMovementError.CANT_STACK;
}
@ -4742,6 +4747,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
if(height > MAXIMUM_FURNI_HEIGHT) return FurnitureMovementError.CANT_STACK;
if(height < this.getLayout().getHeightAtSquare(tile.x, tile.y)) return FurnitureMovementError.CANT_STACK; //prevent furni going under the floor
item.setX(tile.x);
item.setY(tile.y);
item.setZ(height);
@ -4785,8 +4793,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
for (Habbo h : this.getHabbosAt(t.x, t.y)) {
try {
item.onWalkOn(h.getRoomUnit(), this, null);
}
catch(Exception e) {
} catch (Exception e) {
}
}