Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java

153 lines
4.7 KiB
Java
Raw Normal View History

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.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
2022-11-16 16:56:06 +01:00
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
2018-07-06 15:30:00 +02:00
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.wired.WiredEffectType;
2020-11-16 12:12:24 +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 gnu.trove.procedure.TObjectProcedure;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
2019-05-26 20:14:53 +02:00
public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
2018-07-06 15:30:00 +02:00
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
private int amount = 0;
2019-05-26 20:14:53 +02:00
public WiredEffectGiveHotelviewHofPoints(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 WiredEffectGiveHotelviewHofPoints(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 void serializeWiredData(ServerMessage message, Room room) {
2018-07-06 15:30:00 +02:00
message.appendBoolean(false);
message.appendInt(0);
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString(this.amount + "");
message.appendInt(0);
message.appendInt(0);
message.appendInt(type.code);
message.appendInt(this.getDelay());
2019-05-26 20:14:53 +02:00
if (this.requiresTriggeringUser()) {
2018-07-06 15:30:00 +02:00
List<Integer> invalidTriggers = new ArrayList<>();
2019-05-26 20:14:53 +02:00
room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(new TObjectProcedure<InteractionWiredTrigger>() {
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public boolean execute(InteractionWiredTrigger object) {
if (!object.isTriggeredByRoomUnit()) {
2018-07-06 15:30:00 +02:00
invalidTriggers.add(object.getBaseItem().getSpriteId());
}
return true;
}
});
message.appendInt(invalidTriggers.size());
2019-05-26 20:14:53 +02:00
for (Integer i : invalidTriggers) {
2018-07-06 15:30:00 +02:00
message.appendInt(i);
}
2019-05-26 20:14:53 +02:00
} else {
2018-07-06 15:30:00 +02:00
message.appendInt(0);
}
}
@Override
2022-11-16 16:56:06 +01:00
public boolean saveData(WiredSettings settings, GameClient gameClient) {
2019-05-26 20:14:53 +02:00
try {
2022-11-16 16:56:06 +01:00
this.amount = Integer.parseInt(settings.getStringParam());
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2018-07-06 15:30:00 +02:00
return false;
}
2022-11-16 16:56:06 +01:00
this.setDelay(settings.getDelay());
2018-07-06 15:30:00 +02:00
return true;
}
@Override
2019-05-26 20:14:53 +02:00
public WiredEffectType getType() {
2018-07-06 15:30:00 +02:00
return type;
}
@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
Habbo habbo = room.getHabbo(roomUnit);
2019-05-26 20:14:53 +02:00
if (habbo == null)
2018-07-06 15:30:00 +02:00
return false;
2019-05-26 20:14:53 +02:00
if (this.amount > 0) {
2018-07-06 15:30:00 +02:00
habbo.getHabboStats().hofPoints += this.amount;
Emulator.getThreading().run(habbo.getHabboStats());
}
return true;
}
@Override
2019-05-26 20:14:53 +02:00
public String getWiredData() {
2020-11-16 12:12:24 +01:00
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.amount, this.getDelay()));
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 {
2020-11-16 12:12:24 +01:00
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.amount = data.amount;
this.setDelay(data.delay);
}
else {
this.amount = 0;
2018-07-06 15:30:00 +02:00
2020-11-16 12:12:24 +01:00
if (wiredData.split("\t").length >= 2) {
super.setDelay(Integer.valueOf(wiredData.split("\t")[0]));
2018-07-06 15:30:00 +02:00
2020-11-16 12:12:24 +01:00
try {
this.amount = Integer.valueOf(this.getWiredData().split("\t")[1]);
} catch (Exception e) {
}
2018-07-06 15:30:00 +02:00
}
2020-11-16 12:12:24 +01:00
this.needsUpdate(true);
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.amount = 0;
this.setDelay(0);
}
@Override
2019-05-26 20:14:53 +02:00
public boolean requiresTriggeringUser() {
2018-07-06 15:30:00 +02:00
return true;
}
2020-11-16 12:12:24 +01:00
static class JsonData {
int amount;
int delay;
public JsonData(int amount, int delay) {
this.amount = amount;
this.delay = delay;
}
}
2018-07-06 15:30:00 +02:00
}