Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java

113 lines
3.2 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions;
2019-04-22 01:42:00 +02:00
import com.eu.habbo.Emulator;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
2018-10-07 00:28:00 +02:00
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.items.ItemStateComposer;
2019-05-17 13:32:13 +02:00
import gnu.trove.set.hash.THashSet;
2018-07-06 15:30:00 +02:00
import java.sql.ResultSet;
import java.sql.SQLException;
public class InteractionPressurePlate extends InteractionDefault {
2019-05-26 20:14:53 +02:00
public InteractionPressurePlate(ResultSet set, Item baseItem) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set, baseItem);
this.setExtradata("0");
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public InteractionPressurePlate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
2018-07-06 15:30:00 +02:00
super(id, userId, item, extradata, limitedStack, limitedSells);
this.setExtradata("0");
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
2018-07-06 15:30:00 +02:00
return true;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean isWalkable() {
2018-07-06 15:30:00 +02:00
return true;
}
@Override
2019-05-26 20:14:53 +02:00
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
2022-03-03 23:27:30 +01:00
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
super.onWalkOn(roomUnit, room, objects);
2020-04-23 19:08:37 +02:00
Emulator.getThreading().run(() -> updateState(room), 100);
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
super.onWalkOff(roomUnit, room, objects);
2020-04-23 19:08:37 +02:00
Emulator.getThreading().run(() -> updateState(room), 100);
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
2018-12-22 11:39:00 +01:00
super.onMove(room, oldLocation, newLocation);
2019-04-22 01:42:00 +02:00
updateState(room);
}
2022-03-03 23:27:30 +01:00
@Override
public void onPickUp(Room room) {
this.setExtradata("0");
}
2019-05-26 20:14:53 +02:00
public void updateState(Room room) {
2019-04-22 01:42:00 +02:00
boolean occupied = false;
2019-05-17 13:32:13 +02:00
if (room == null || room.getLayout() == null || this.getBaseItem() == null) return;
RoomTile tileAtItem = room.getLayout().getTile(this.getX(), this.getY());
if (tileAtItem == null) return;
THashSet<RoomTile> tiles = room.getLayout().getTilesAt(tileAtItem, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation());
if (tiles == null) return;
2019-05-26 20:14:53 +02:00
for (RoomTile tile : tiles) {
2019-04-22 01:42:00 +02:00
boolean hasHabbos = room.hasHabbosAt(tile.x, tile.y);
2019-05-26 20:14:53 +02:00
if (!hasHabbos && this.requiresAllTilesOccupied()) {
2019-04-22 01:42:00 +02:00
occupied = false;
break;
}
2019-05-26 20:14:53 +02:00
if (hasHabbos) {
2019-04-22 01:42:00 +02:00
occupied = true;
}
2018-12-22 11:39:00 +01:00
}
2019-04-22 01:42:00 +02:00
this.setExtradata(occupied ? "1" : "0");
room.updateItemState(this);
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public boolean allowWiredResetState() {
2018-07-06 15:30:00 +02:00
return true;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public boolean requiresAllTilesOccupied() {
2019-04-22 01:42:00 +02:00
return false;
}
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
}