2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions;
|
|
|
|
|
2020-10-13 03:42:30 +02:00
|
|
|
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;
|
2020-10-13 03:42:30 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomTile;
|
2020-10-13 03:42:30 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomTileState;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredEffectType;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.items.ItemExtraDataComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.items.RoomFloorItemsComposer;
|
|
|
|
import gnu.trove.TCollections;
|
|
|
|
import gnu.trove.map.TIntObjectMap;
|
2018-07-06 15:30:00 +02:00
|
|
|
import gnu.trove.map.hash.THashMap;
|
2020-10-13 03:42:30 +02:00
|
|
|
import gnu.trove.map.hash.TIntObjectHashMap;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class InteractionMuteArea extends InteractionCustomValues {
|
|
|
|
public static THashMap<String, String> defaultValues = new THashMap<String, String>() {
|
2019-03-18 02:22:00 +01:00
|
|
|
{
|
2019-05-26 20:14:53 +02:00
|
|
|
this.put("tilesLeft", "0");
|
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
{
|
2019-05-26 20:14:53 +02:00
|
|
|
this.put("tilesRight", "0");
|
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
{
|
2019-05-26 20:14:53 +02:00
|
|
|
this.put("tilesFront", "0");
|
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
{
|
2019-05-26 20:14:53 +02:00
|
|
|
this.put("tilesBack", "0");
|
|
|
|
}
|
2020-10-13 03:42:30 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
this.put("state", "0");
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
};
|
|
|
|
|
2020-10-13 03:42:30 +02:00
|
|
|
private THashSet<RoomTile> tiles;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionMuteArea(ResultSet set, Item baseItem) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(set, baseItem, defaultValues);
|
2020-10-13 03:42:30 +02:00
|
|
|
tiles = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionMuteArea(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, defaultValues);
|
2020-10-13 03:42:30 +02:00
|
|
|
tiles = new THashSet<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
|
|
|
|
super.onClick(client, room, objects);
|
|
|
|
|
|
|
|
if((objects.length >= 2 && objects[1] instanceof WiredEffectType) || (client != null && room.hasRights(client.getHabbo()))) {
|
|
|
|
this.values.put("state", this.values.get("state").equals("0") ? "1" : "0");
|
|
|
|
room.sendComposer(new ItemExtraDataComposer(this).compose());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPlace(Room room) {
|
|
|
|
super.onPlace(room);
|
|
|
|
this.regenAffectedTiles(room);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPickUp(Room room) {
|
|
|
|
super.onPickUp(room);
|
|
|
|
this.tiles.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
|
|
|
|
super.onMove(room, oldLocation, newLocation);
|
|
|
|
this.regenAffectedTiles(room);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean inSquare(RoomTile location) {
|
2020-10-13 03:42:30 +02:00
|
|
|
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
|
|
|
|
|
|
|
if(!this.values.get("state").equals("1"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(room != null && this.tiles.size() == 0) {
|
|
|
|
regenAffectedTiles(room);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.tiles.contains(location);
|
|
|
|
|
|
|
|
/*try {
|
2018-07-06 15:30:00 +02:00
|
|
|
return new Rectangle(
|
2020-10-13 03:42:30 +02:00
|
|
|
this.getX() - Integer.parseInt(this.values.get("tilesBack")),
|
2019-05-26 20:14:53 +02:00
|
|
|
this.getY() + Integer.valueOf(this.values.get("tilesLeft")) - (Integer.valueOf(this.values.get("tilesLeft")) + Integer.valueOf(this.values.get("tilesRight"))),
|
|
|
|
Integer.valueOf(this.values.get("tilesLeft")) + Integer.valueOf(this.values.get("tilesRight")) + 1,
|
|
|
|
Integer.valueOf(this.values.get("tilesFront")) + Integer.valueOf(this.values.get("tilesBack")) + 1).contains(location.x, location.y);
|
|
|
|
} catch (Exception e) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
2020-10-13 03:42:30 +02:00
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
private void regenAffectedTiles(Room room) {
|
|
|
|
int minX = Math.max(0, this.getX() - Integer.parseInt(this.values.get("tilesBack")));
|
|
|
|
int minY = Math.max(0, this.getY() - Integer.parseInt(this.values.get("tilesRight")));
|
|
|
|
int maxX = Math.min(room.getLayout().getMapSizeX(), this.getX() + Integer.parseInt(this.values.get("tilesFront")));
|
|
|
|
int maxY = Math.min(room.getLayout().getMapSizeY(), this.getY() + Integer.parseInt(this.values.get("tilesLeft")));
|
|
|
|
|
|
|
|
this.tiles.clear();
|
|
|
|
|
|
|
|
for(int x = minX; x <= maxX; x++) {
|
|
|
|
for(int y = minY; y <= maxY; y++) {
|
|
|
|
RoomTile tile = room.getLayout().getTile((short)x, (short)y);
|
|
|
|
if(tile != null && tile.state != RoomTileState.INVALID)
|
|
|
|
this.tiles.add(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-03-20 04:14:23 +01:00
|
|
|
public void onCustomValuesSaved(Room room, GameClient client, THashMap<String, String> oldValues) {
|
|
|
|
super.onCustomValuesSaved(room, client, oldValues);
|
2020-10-13 03:42:30 +02:00
|
|
|
|
|
|
|
this.regenAffectedTiles(room);
|
|
|
|
|
|
|
|
// show the effect
|
|
|
|
Item effectItem = Emulator.getGameEnvironment().getItemManager().getItem("mutearea_sign2");
|
|
|
|
|
|
|
|
if(effectItem != null) {
|
|
|
|
TIntObjectMap<String> ownerNames = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
|
|
|
|
ownerNames.put(-1, "System");
|
|
|
|
THashSet<HabboItem> items = new THashSet<>();
|
|
|
|
|
|
|
|
int id = 0;
|
|
|
|
for(RoomTile tile : this.tiles) {
|
|
|
|
id--;
|
|
|
|
HabboItem item = new InteractionDefault(id, -1, effectItem, "1", 0, 0);
|
|
|
|
item.setX(tile.x);
|
|
|
|
item.setY(tile.y);
|
|
|
|
item.setZ(tile.relativeHeight());
|
|
|
|
items.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
client.sendResponse(new RoomFloorItemsComposer(ownerNames, items));
|
|
|
|
Emulator.getThreading().run(() -> {
|
|
|
|
for(HabboItem item : items) {
|
|
|
|
client.sendResponse(new RemoveFloorItemComposer(item, true));
|
|
|
|
}
|
|
|
|
}, 3000);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|