Wired fixes

This commit is contained in:
Beny 2020-10-31 03:11:33 +01:00
parent abc1c6905f
commit 01d1fefdff
5 changed files with 74 additions and 32 deletions

View File

@ -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[]{});

View File

@ -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

View File

@ -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<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;
}
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 (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:

View File

@ -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<HabboItem> items = new THashSet<>(WiredHandler.MAXIMUM_FURNI_SELECTION / 2);
private int direction;
private int rotation;
private THashSet<HabboItem> 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();
}
}

View File

@ -68,6 +68,9 @@ public class WiredHandler {
if (triggers == null || triggers.isEmpty())
return false;
long millis = System.currentTimeMillis();
THashSet<InteractionWiredEffect> effectsToExecute = new THashSet<InteractionWiredEffect>();
List<RoomTile> 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<InteractionWiredEffect> tEffectsToExecute = new THashSet<InteractionWiredEffect>();
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<? extends InteractionWiredTrigger> 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<InteractionWiredEffect> effectsToExecute = new THashSet<InteractionWiredEffect>();
List<RoomTile> 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<InteractionWiredEffect> tEffectsToExecute = new THashSet<InteractionWiredEffect>();
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<InteractionWiredEffect> effectsToExecute = new THashSet<InteractionWiredEffect>();
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<InteractionWiredEffect> 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;
}