From 01d1fefdffbc5af38803c7240f778c854053c99e Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 31 Oct 2020 03:11:33 +0100 Subject: [PATCH] Wired fixes --- .../games/InteractionGameTimer.java | 9 +++- .../WiredConditionNotMatchStatePosition.java | 6 +-- .../WiredEffectChangeFurniDirection.java | 22 ++++----- .../effects/WiredEffectMoveRotateFurni.java | 23 ++++++---- .../habbo/habbohotel/wired/WiredHandler.java | 46 ++++++++++++++++--- 5 files changed, 74 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java index 6197b017..1f7396e9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GameState; +import com.eu.habbo.habbohotel.games.wired.WiredGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; @@ -98,11 +99,15 @@ public class InteractionGameTimer extends HabboItem implements Runnable { } public void endGame(Room room) { + endGame(room, false); + } + + public void endGame(Room room, boolean isStart) { this.isRunning = false; this.isPaused = false; for (Game game : room.getGames()) { - if (!game.getState().equals(GameState.IDLE)) { + if (!game.getState().equals(GameState.IDLE) && !(isStart && game instanceof WiredGame)) { game.onEnd(); game.stop(); } @@ -226,7 +231,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { return; boolean wasPaused = this.isPaused; - this.endGame(room); + this.endGame(room, true); if(wasPaused) { WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{}); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java index 698cd2c3..054806d4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java @@ -50,8 +50,8 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi boolean positionMatches = !this.position || (setting.x == item.getX() && setting.y == item.getY()); boolean directionMatches = !this.rotation || setting.rotation == item.getRotation(); - if (stateMatches && positionMatches && directionMatches) - return false; + if (!stateMatches || !positionMatches || !directionMatches) + return true; } else { s.add(setting); } @@ -63,7 +63,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi } } - return true; + return false; } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java index d77a2877..2cf32aba 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java @@ -86,19 +86,19 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { room.moveFurniTo(entry.getKey(), targetTile, entry.getValue().rotation, null, true); } - if (targetTile != null && targetTile.state != RoomTileState.INVALID && room.furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) { - boolean hasRoomUnits = false; - THashSet 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; - } + boolean hasRoomUnits = false; + THashSet 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 (targetTile != null && targetTile.state != RoomTileState.INVALID && room.furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) { if (!hasRoomUnits) { RoomTile oldLocation = room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()); double oldZ = entry.getKey().getZ(); @@ -243,7 +243,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { private RoomUserRotation nextRotation(RoomUserRotation currentRotation) { switch (this.blockedAction) { case ACTION_TURN_BACK: - return RoomUserRotation.fromValue(currentRotation.getValue() + 4); + return RoomUserRotation.fromValue(currentRotation.getValue()).getOpposite(); case ACTION_TURN_LEFT_45: return RoomUserRotation.counterClockwise(currentRotation); case ACTION_TURN_LEFT_90: diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java index 33b633a9..d933aaae 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java @@ -2,32 +2,25 @@ 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.ICycleable; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionRoller; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.Habbo; 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.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; -import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer; import gnu.trove.set.hash.THashSet; -import org.apache.commons.math3.util.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.awt.*; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Iterator; -public class WiredEffectMoveRotateFurni extends InteractionWiredEffect { - +public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implements ICycleable { private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectMoveRotateFurni.class); @@ -35,13 +28,16 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect { private final THashSet items = new THashSet<>(WiredHandler.MAXIMUM_FURNI_SELECTION / 2); private int direction; private int rotation; + private THashSet itemCooldowns; public WiredEffectMoveRotateFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); + this.itemCooldowns = new THashSet<>(); } public WiredEffectMoveRotateFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { super(id, userId, item, extradata, limitedStack, limitedSells); + this.itemCooldowns = new THashSet<>(); } @Override @@ -50,6 +46,9 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect { this.items.removeIf(item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); for (HabboItem item : this.items) { + if(this.itemCooldowns.contains(item)) + continue; + 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()); @@ -68,6 +67,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect { FurnitureMovementError furniMoveTest = room.furnitureFitsAt(newLocation, item, newRotation, true); if(newLocation != null && newLocation.state != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && (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) { + this.itemCooldowns.add(item); if(slideAnimation) { room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose()); } @@ -298,4 +298,9 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect { } return movemementDirection; } + + @Override + public void cycle(Room room) { + this.itemCooldowns.clear(); + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java index 7478b1ed..ec7db738 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java @@ -68,6 +68,9 @@ public class WiredHandler { if (triggers == null || triggers.isEmpty()) return false; + long millis = System.currentTimeMillis(); + THashSet effectsToExecute = new THashSet(); + List triggeredTiles = new ArrayList<>(); for (InteractionWiredTrigger trigger : triggers) { RoomTile tile = room.getLayout().getTile(trigger.getX(), trigger.getY()); @@ -75,7 +78,11 @@ public class WiredHandler { if (triggeredTiles.contains(tile)) continue; - if (handle(trigger, roomUnit, room, stuff)) { + THashSet tEffectsToExecute = new THashSet(); + + if (handle(trigger, roomUnit, room, stuff, tEffectsToExecute)) { + effectsToExecute.addAll(tEffectsToExecute); + if (triggerType.equals(WiredTriggerType.SAY_SOMETHING)) talked = true; @@ -83,12 +90,14 @@ public class WiredHandler { } } + for (InteractionWiredEffect effect : effectsToExecute) { + triggerEffect(effect, roomUnit, room, stuff, millis); + } + return talked; } public static boolean handleCustomTrigger(Class triggerType, RoomUnit roomUnit, Room room, Object[] stuff) { - boolean talked = false; - if (!Emulator.isReady) return false; @@ -106,6 +115,9 @@ public class WiredHandler { if (triggers == null || triggers.isEmpty()) return false; + long millis = System.currentTimeMillis(); + THashSet effectsToExecute = new THashSet(); + List triggeredTiles = new ArrayList<>(); for (InteractionWiredTrigger trigger : triggers) { if (trigger.getClass() != triggerType) continue; @@ -115,15 +127,35 @@ public class WiredHandler { if (triggeredTiles.contains(tile)) continue; - if (handle(trigger, roomUnit, room, stuff)) { + THashSet tEffectsToExecute = new THashSet(); + + if (handle(trigger, roomUnit, room, stuff, tEffectsToExecute)) { + effectsToExecute.addAll(tEffectsToExecute); triggeredTiles.add(tile); } } - return talked; + for (InteractionWiredEffect effect : effectsToExecute) { + triggerEffect(effect, roomUnit, room, stuff, millis); + } + + return effectsToExecute.size() > 0; } public static boolean handle(InteractionWiredTrigger trigger, final RoomUnit roomUnit, final Room room, final Object[] stuff) { + long millis = System.currentTimeMillis(); + THashSet effectsToExecute = new THashSet(); + + if(handle(trigger, roomUnit, room, stuff, effectsToExecute)) { + for (InteractionWiredEffect effect : effectsToExecute) { + triggerEffect(effect, roomUnit, room, stuff, millis); + } + return true; + } + return false; + } + + public static boolean handle(InteractionWiredTrigger trigger, final RoomUnit roomUnit, final Room room, final Object[] stuff, final THashSet effectsToExecute) { long millis = System.currentTimeMillis(); if (Emulator.isReady && trigger.canExecute(millis) && trigger.execute(roomUnit, room, stuff)) { trigger.activateBox(room); @@ -173,13 +205,13 @@ public class WiredHandler { if (extra instanceof WiredExtraUnseen) { extra.setExtradata(extra.getExtradata().equals("1") ? "0" : "1"); InteractionWiredEffect effect = ((WiredExtraUnseen) extra).getUnseenEffect(effectList); - triggerEffect(effect, roomUnit, room, stuff, millis); + effectsToExecute.add(effect); // triggerEffect(effect, roomUnit, room, stuff, millis); break; } } } else { for (final InteractionWiredEffect effect : effectList) { - boolean executed = triggerEffect(effect, roomUnit, room, stuff, millis); + boolean executed = effectsToExecute.add(effect); //triggerEffect(effect, roomUnit, room, stuff, millis); if (hasExtraRandom && executed) { break; }