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

133 lines
3.3 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;
2018-07-06 15:30:00 +02:00
import java.sql.ResultSet;
import java.sql.SQLException;
2018-10-07 00:28:00 +02:00
public class InteractionPressurePlate extends HabboItem
2018-07-06 15:30:00 +02:00
{
public InteractionPressurePlate(ResultSet set, Item baseItem) throws SQLException
{
super(set, baseItem);
}
public InteractionPressurePlate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells)
{
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects)
{
return true;
}
@Override
public boolean isWalkable()
{
return true;
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception
{
super.onClick(client, room, objects);
}
2018-10-07 00:28:00 +02:00
@Override
public void serializeExtradata(ServerMessage serverMessage)
{
serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata());
super.serializeExtradata(serverMessage);
}
2018-07-06 15:30:00 +02:00
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception
{
}
@Override
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception
{
super.onWalkOn(roomUnit, room, objects);
2019-04-22 01:42:00 +02:00
Emulator.getThreading().run(new Runnable()
2018-09-28 21:25:00 +02:00
{
2019-04-22 01:42:00 +02:00
@Override
public void run()
2018-09-28 21:25:00 +02:00
{
2019-04-22 01:42:00 +02:00
updateState(room);
2018-09-28 21:25:00 +02:00
}
2019-04-22 01:42:00 +02:00
}, 100);
2018-07-06 15:30:00 +02:00
}
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception
{
super.onWalkOff(roomUnit, room, objects);
2019-04-22 01:42:00 +02:00
Emulator.getThreading().run(new Runnable()
{
@Override
public void run()
{
updateState(room);
}
}, 100);
2018-07-06 15:30:00 +02:00
}
@Override
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);
}
public void updateState(Room room)
{
boolean occupied = false;
for (RoomTile tile : room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()))
2018-12-22 11:39:00 +01:00
{
2019-04-22 01:42:00 +02:00
boolean hasHabbos = room.hasHabbosAt(tile.x, tile.y);
if (!hasHabbos && this.requiresAllTilesOccupied())
{
occupied = false;
break;
}
if (hasHabbos)
{
occupied = true;
}
2018-12-22 11:39:00 +01:00
}
2019-04-22 01:42:00 +02:00
this.setExtradata(occupied ? "1" : "0");
room.updateItem(this);
2018-07-06 15:30:00 +02:00
}
@Override
public boolean allowWiredResetState()
{
return true;
}
2018-12-22 11:39:00 +01:00
2019-04-22 01:42:00 +02:00
public boolean requiresAllTilesOccupied()
{
return false;
}
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
}