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;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
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.messages.ServerMessage;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
2020-05-04 22:24:09 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
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 InteractionGift extends HabboItem {
|
2020-05-04 22:24:09 +02:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(InteractionGift.class);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean explode = false;
|
2018-07-06 15:30:00 +02:00
|
|
|
private int[] itemId;
|
|
|
|
private int colorId = 0;
|
|
|
|
private int ribbonId = 0;
|
|
|
|
private boolean showSender = false;
|
|
|
|
private String message = "";
|
|
|
|
private String sender = "";
|
|
|
|
private String look = "";
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionGift(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
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.loadData();
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.warn("Incorrect extradata for gift with ID " + this.getId());
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionGift(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);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.loadData();
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.warn("Incorrect extradata for gift with ID " + this.getId());
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void serializeExtradata(ServerMessage serverMessage) {
|
2018-07-06 15:30:00 +02:00
|
|
|
//serverMessage.appendInt(this.colorId * 1000 + this.ribbonId);
|
|
|
|
serverMessage.appendInt(1);
|
|
|
|
serverMessage.appendInt(6);
|
|
|
|
serverMessage.appendString("EXTRA_PARAM");
|
|
|
|
serverMessage.appendString("");
|
|
|
|
serverMessage.appendString("MESSAGE");
|
|
|
|
serverMessage.appendString(this.message);
|
|
|
|
serverMessage.appendString("PURCHASER_NAME");
|
|
|
|
serverMessage.appendString(this.showSender ? this.sender : "");
|
|
|
|
serverMessage.appendString("PURCHASER_FIGURE");
|
|
|
|
serverMessage.appendString(this.showSender ? this.look : "");
|
|
|
|
serverMessage.appendString("PRODUCT_CODE");
|
|
|
|
serverMessage.appendString(""); //this.gift.getItemId()
|
|
|
|
serverMessage.appendString("state");
|
|
|
|
serverMessage.appendString(this.explode ? "1" : "0");
|
|
|
|
|
|
|
|
super.serializeExtradata(serverMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isWalkable() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
private void loadData() throws NumberFormatException {
|
2018-07-06 15:30:00 +02:00
|
|
|
String[] data = null;
|
|
|
|
|
|
|
|
if (this.getExtradata().contains("\t"))
|
|
|
|
data = this.getExtradata().split("\t");
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (data != null && data.length >= 5) {
|
2018-07-06 15:30:00 +02:00
|
|
|
int count = Integer.valueOf(data[0]);
|
|
|
|
|
|
|
|
this.itemId = new int[count];
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.itemId[i] = Integer.valueOf(data[i + 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.colorId = Integer.valueOf(data[count + 1]);
|
|
|
|
this.ribbonId = Integer.valueOf(data[count + 2]);
|
|
|
|
this.showSender = data[count + 3].equalsIgnoreCase("1");
|
|
|
|
this.message = data[count + 4];
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (data.length - count >= 7 && this.showSender) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.sender = data[count + 5];
|
|
|
|
this.look = data[count + 6];
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.itemId = new int[0];
|
|
|
|
this.colorId = 0;
|
|
|
|
this.ribbonId = 0;
|
|
|
|
this.showSender = false;
|
|
|
|
this.message = "Please delete this present. Thanks!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getColorId() {
|
2019-03-18 02:22:00 +01:00
|
|
|
return this.colorId;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getRibbonId() {
|
2019-03-18 02:22:00 +01:00
|
|
|
return this.ribbonId;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2018-11-17 14:28:00 +01:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public THashSet<HabboItem> loadItems() {
|
2018-11-17 14:28:00 +01:00
|
|
|
THashSet<HabboItem> items = new THashSet<>();
|
2019-05-26 20:14:53 +02:00
|
|
|
for (int anItemId : this.itemId) {
|
2018-11-17 14:28:00 +01:00
|
|
|
if (anItemId == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
items.add(Emulator.getGameEnvironment().getItemManager().loadHabboItem(anItemId));
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|