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

88 lines
3.0 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
2020-09-18 13:35:25 +02:00
import com.eu.habbo.habbohotel.rooms.RoomTile;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public class InteractionGate extends HabboItem {
public InteractionGate(ResultSet set, Item baseItem) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set, baseItem);
}
2019-05-26 20:14:53 +02:00
public InteractionGate(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);
}
@Override
2019-05-26 20:14:53 +02:00
public void serializeExtradata(ServerMessage serverMessage) {
2018-07-06 15:30:00 +02:00
serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata());
super.serializeExtradata(serverMessage);
}
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;
}
2019-05-26 20:14:53 +02:00
public boolean isWalkable() {
2018-07-06 15:30:00 +02:00
return this.getExtradata().equals("1");
}
@Override
2019-05-26 20:14:53 +02:00
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
boolean executedByWired = (objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE);
if (client != null && !room.hasRights(client.getHabbo()) && !executedByWired)
2018-07-06 15:30:00 +02:00
return;
2020-09-18 14:24:42 +02:00
// If a Habbo is standing on a tile occupied by the gate, the gate shouldn't open/close
for (RoomTile tile : room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()))
if (room.hasHabbosAt(tile.x, tile.y))
return;
2018-07-06 15:30:00 +02:00
2020-09-18 14:24:42 +02:00
// Gate closed = 0, open = 1
2019-05-26 20:14:53 +02:00
if (this.getExtradata().length() == 0)
2018-07-06 15:30:00 +02:00
this.setExtradata("0");
2020-09-18 14:24:42 +02:00
this.setExtradata((Integer.parseInt(this.getExtradata()) + 1) % 2 + "");
2018-07-06 15:30:00 +02:00
room.updateTile(room.getLayout().getTile(this.getX(), this.getY()));
this.needsUpdate(true);
room.updateItemState(this);
2020-01-27 21:38:41 +01:00
super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"});
2018-07-06 15:30:00 +02:00
}
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
super.onWalkOn(roomUnit, room, objects);
}
@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);
}
@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);
}
@Override
2019-05-26 20:14:53 +02:00
public boolean allowWiredResetState() {
2018-07-06 15:30:00 +02:00
return true;
}
2018-10-07 00:28:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public boolean isUsable() {
2018-10-07 00:28:00 +02:00
return true;
}
2018-07-06 15:30:00 +02:00
}