2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionCrackable;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeBlock;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
|
|
|
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.habbohotel.wired.WiredHandler;
|
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import gnu.trove.procedure.TObjectProcedure;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class WiredEffectToggleRandom extends InteractionWiredEffect
|
|
|
|
{
|
|
|
|
public static final WiredEffectType type = WiredEffectType.TOGGLE_RANDOM;
|
|
|
|
|
2018-09-28 21:25:00 +02:00
|
|
|
private final THashSet<HabboItem> items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
public WiredEffectToggleRandom(ResultSet set, Item baseItem) throws SQLException
|
|
|
|
{
|
|
|
|
super(set, baseItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
public WiredEffectToggleRandom(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells)
|
|
|
|
{
|
|
|
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).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("");
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getType().code);
|
|
|
|
message.appendInt(this.getDelay());
|
|
|
|
|
|
|
|
if (this.requiresTriggeringUser())
|
|
|
|
{
|
|
|
|
List<Integer> invalidTriggers = new ArrayList<>();
|
|
|
|
room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(new TObjectProcedure<InteractionWiredTrigger>()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean execute(InteractionWiredTrigger object)
|
|
|
|
{
|
|
|
|
if (!object.isTriggeredByRoomUnit())
|
|
|
|
{
|
|
|
|
invalidTriggers.add(object.getBaseItem().getSpriteId());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
message.appendInt(invalidTriggers.size());
|
|
|
|
for (Integer i : invalidTriggers)
|
|
|
|
{
|
|
|
|
message.appendInt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean saveData(ClientMessage packet, GameClient gameClient)
|
|
|
|
{
|
2018-12-22 11:39:00 +01:00
|
|
|
packet.readInt();
|
|
|
|
packet.readString();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-12-22 11:39:00 +01:00
|
|
|
this.items.clear();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-12-22 11:39:00 +01:00
|
|
|
int count = packet.readInt();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-12-22 11:39:00 +01:00
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
HabboItem item = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt());
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-12-22 11:39:00 +01:00
|
|
|
if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
|
|
|
|
continue;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-12-22 11:39:00 +01:00
|
|
|
this.items.add(item);
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-12-22 11:39:00 +01:00
|
|
|
this.setDelay(packet.readInt());
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff)
|
|
|
|
{
|
|
|
|
THashSet<HabboItem> items = this.items;
|
|
|
|
|
|
|
|
for(HabboItem item : items)
|
|
|
|
{
|
|
|
|
if(item.getRoomId() == 0)
|
|
|
|
{
|
|
|
|
this.items.remove(item);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
item.setExtradata(Emulator.getRandom().nextInt(item.getBaseItem().getStateCount() + 1) + "");
|
|
|
|
room.updateItem(item);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Emulator.getLogging().logErrorLine(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getWiredData()
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t");
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
this.items.clear();
|
|
|
|
String[] wiredData = set.getString("wired_data").split("\t");
|
|
|
|
|
|
|
|
if (wiredData.length >= 1)
|
|
|
|
{
|
|
|
|
this.setDelay(Integer.valueOf(wiredData[0]));
|
|
|
|
}
|
|
|
|
if (wiredData.length == 2)
|
|
|
|
{
|
|
|
|
if (wiredData[1].contains(";"))
|
|
|
|
{
|
|
|
|
for (String s : wiredData[1].split(";"))
|
|
|
|
{
|
|
|
|
HabboItem item = room.getHabboItem(Integer.valueOf(s));
|
|
|
|
|
|
|
|
if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
this.items.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPickUp()
|
|
|
|
{
|
|
|
|
this.items.clear();
|
|
|
|
this.setDelay(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public WiredEffectType getType()
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
}
|