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

95 lines
2.8 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.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomLayout;
import com.eu.habbo.habbohotel.rooms.RoomTile;
2018-12-22 11:39:00 +01:00
import com.eu.habbo.habbohotel.users.Habbo;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.users.HabboItem;
import gnu.trove.set.hash.THashSet;
import java.awt.*;
import java.sql.ResultSet;
import java.sql.SQLException;
public class InteractionWaterItem extends InteractionMultiHeight {
2019-05-26 20:14:53 +02:00
public InteractionWaterItem(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 InteractionWaterItem(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 onPlace(Room room) {
2018-07-06 15:30:00 +02:00
this.update();
2019-05-26 21:33:51 +02:00
super.onPlace(room);
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onPickUp(Room room) {
super.onPickUp(room);
2018-07-06 15:30:00 +02:00
this.setExtradata("0");
this.needsUpdate(true);
}
@Override
2019-05-26 20:14:53 +02:00
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
super.onMove(room, oldLocation, newLocation);
2018-07-06 15:30:00 +02:00
this.update();
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
super.onClick(client, room, new Object[] { });
}
2019-05-26 20:14:53 +02:00
public void update() {
2018-07-06 15:30:00 +02:00
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
2020-05-04 05:53:28 +02:00
if (room == null) {
2018-07-06 15:30:00 +02:00
return;
2020-05-04 05:53:28 +02:00
}
2018-07-06 15:30:00 +02:00
2020-05-04 05:53:28 +02:00
Rectangle rectangle = this.getRectangle();
2018-07-06 15:30:00 +02:00
2020-05-04 05:53:28 +02:00
// Check if every tile of the furni is in water.
2018-12-22 11:39:00 +01:00
boolean foundWater = true;
2020-05-04 05:53:28 +02:00
2019-05-26 20:14:53 +02:00
for (short x = (short) rectangle.x; x < rectangle.getWidth() + rectangle.x && foundWater; x++) {
for (short y = (short) rectangle.y; y < rectangle.getHeight() + rectangle.y && foundWater; y++) {
2018-12-22 11:39:00 +01:00
boolean tile = false;
THashSet<HabboItem> items = room.getItemsAt(room.getLayout().getTile(x, y));
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
for (HabboItem item : items) {
if (item instanceof InteractionWater) {
2018-12-22 11:39:00 +01:00
tile = true;
break;
2018-07-06 15:30:00 +02:00
}
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
if (!tile) {
2018-12-22 11:39:00 +01:00
foundWater = false;
}
2018-07-06 15:30:00 +02:00
}
}
2020-05-04 05:53:28 +02:00
// Update data if changed.
String updatedData = foundWater ? "1" : "0";
if (!this.getExtradata().equals(updatedData)) {
this.setExtradata(updatedData);
2018-12-22 11:39:00 +01:00
this.needsUpdate(true);
room.updateItemState(this);
2018-12-22 11:39:00 +01:00
}
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 false;
}
}