2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredEffectType;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
|
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger
|
|
|
|
{
|
|
|
|
private static final WiredTriggerType type = WiredTriggerType.STATE_CHANGED;
|
|
|
|
|
|
|
|
private THashSet<HabboItem> items;
|
|
|
|
private String message = "";
|
|
|
|
|
|
|
|
public WiredTriggerFurniStateToggled(ResultSet set, Item baseItem) throws SQLException
|
|
|
|
{
|
|
|
|
super(set, baseItem);
|
2018-09-28 21:25:00 +02:00
|
|
|
this.items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public WiredTriggerFurniStateToggled(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells)
|
|
|
|
{
|
|
|
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
2018-09-28 21:25:00 +02:00
|
|
|
this.items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff)
|
|
|
|
{
|
|
|
|
if(stuff.length >= 1)
|
|
|
|
{
|
|
|
|
Habbo habbo = room.getHabbo(roomUnit);
|
|
|
|
|
|
|
|
if (habbo != null)
|
|
|
|
{
|
|
|
|
for (Object object : stuff)
|
|
|
|
{
|
|
|
|
if (object instanceof WiredEffectType)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stuff[0] instanceof HabboItem)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
return this.items.contains(stuff[0]);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getWiredData()
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
StringBuilder wiredData = new StringBuilder(super.getDelay() + ":\t:");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
if(this.items != null)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
if (!this.items.isEmpty())
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
|
|
|
for (HabboItem item : this.items)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
wiredData.append(item.getId()).append(";");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
} else
|
2019-03-18 02:22:00 +01:00
|
|
|
wiredData.append("\t");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
return wiredData.toString();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadWiredData(ResultSet set, Room room) throws SQLException
|
|
|
|
{
|
2018-09-28 21:25:00 +02:00
|
|
|
this.items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
String wiredData = set.getString("wired_data");
|
|
|
|
if(wiredData.split(":").length >= 3)
|
|
|
|
{
|
|
|
|
super.setDelay(Integer.valueOf(wiredData.split(":")[0]));
|
|
|
|
this.message = wiredData.split(":")[1];
|
|
|
|
|
|
|
|
if (!wiredData.split(":")[2].equals("\t"))
|
|
|
|
{
|
|
|
|
for (String s : wiredData.split(":")[2].split(";"))
|
|
|
|
{
|
|
|
|
HabboItem item = room.getHabboItem(Integer.valueOf(s));
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
this.items.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPickUp()
|
|
|
|
{
|
|
|
|
this.items.clear();
|
|
|
|
this.message = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public WiredTriggerType getType()
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void serializeWiredData(ServerMessage message, Room room)
|
|
|
|
{
|
2018-09-28 21:25:00 +02:00
|
|
|
THashSet<HabboItem> items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
for(HabboItem item : this.items)
|
|
|
|
{
|
|
|
|
if(item.getRoomId() != this.getRoomId())
|
|
|
|
{
|
|
|
|
items.add(item);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (room.getHabboItem(item.getId()) == null)
|
|
|
|
{
|
|
|
|
items.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(HabboItem item : items)
|
|
|
|
{
|
|
|
|
this.items.remove(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
message.appendBoolean(false);
|
|
|
|
message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
|
|
|
|
message.appendInt(this.items.size());
|
|
|
|
for(HabboItem item : this.items)
|
|
|
|
{
|
|
|
|
message.appendInt(item.getId());
|
|
|
|
}
|
|
|
|
message.appendInt(this.getBaseItem().getSpriteId());
|
|
|
|
message.appendInt(this.getId());
|
|
|
|
message.appendString(this.message);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getType().code);
|
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean saveData(ClientMessage packet)
|
|
|
|
{
|
|
|
|
packet.readInt();
|
|
|
|
packet.readString();
|
|
|
|
|
|
|
|
this.items.clear();
|
|
|
|
|
|
|
|
int count = packet.readInt();
|
|
|
|
|
|
|
|
for(int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isTriggeredByRoomUnit()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|