2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
|
|
|
|
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredConditionType;
|
2021-01-04 22:00:18 +01:00
|
|
|
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class WiredConditionHabboCount extends InteractionWiredCondition {
|
2018-07-06 15:30:00 +02:00
|
|
|
public static final WiredConditionType type = WiredConditionType.USER_COUNT;
|
|
|
|
|
|
|
|
private int lowerLimit = 0;
|
|
|
|
private int upperLimit = 50;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredConditionHabboCount(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 WiredConditionHabboCount(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 boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
|
2018-07-06 15:30:00 +02:00
|
|
|
int count = room.getUserCount();
|
|
|
|
|
|
|
|
return count >= this.lowerLimit && count <= this.upperLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getWiredData() {
|
2021-01-04 22:00:18 +01:00
|
|
|
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
|
|
|
|
this.lowerLimit,
|
|
|
|
this.upperLimit
|
|
|
|
));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
2021-01-04 22:00:18 +01:00
|
|
|
String wiredData = set.getString("wired_data");
|
|
|
|
|
|
|
|
if (wiredData.startsWith("{")) {
|
|
|
|
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
|
|
|
this.lowerLimit = data.lowerLimit;
|
|
|
|
this.upperLimit = data.upperLimit;
|
|
|
|
} else {
|
|
|
|
String[] data = wiredData.split(":");
|
|
|
|
|
|
|
|
this.lowerLimit = Integer.parseInt(data[0]);
|
|
|
|
this.upperLimit = Integer.parseInt(data[1]);
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onPickUp() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.lowerLimit = 0;
|
|
|
|
this.upperLimit = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredConditionType getType() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void serializeWiredData(ServerMessage message, Room room) {
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendBoolean(false);
|
|
|
|
message.appendInt(5);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getBaseItem().getSpriteId());
|
|
|
|
message.appendInt(this.getId());
|
|
|
|
message.appendString("");
|
|
|
|
message.appendInt(2);
|
2019-05-26 20:14:53 +02:00
|
|
|
message.appendInt(this.lowerLimit);
|
|
|
|
message.appendInt(this.upperLimit);
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getType().code);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean saveData(ClientMessage packet) {
|
2018-07-06 15:30:00 +02:00
|
|
|
packet.readInt();
|
|
|
|
|
|
|
|
this.lowerLimit = packet.readInt();
|
|
|
|
this.upperLimit = packet.readInt();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-04 22:00:18 +01:00
|
|
|
|
|
|
|
static class JsonData {
|
|
|
|
int lowerLimit;
|
|
|
|
int upperLimit;
|
|
|
|
|
|
|
|
public JsonData(int lowerLimit, int upperLimit) {
|
|
|
|
this.lowerLimit = lowerLimit;
|
|
|
|
this.upperLimit = upperLimit;
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|