mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-06-24 09:55:33 +02:00
153 lines
4.7 KiB
Java
153 lines
4.7 KiB
Java
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;
|
|
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
|
|
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;
|
|
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 java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
|
|
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
|
|
|
|
private int amount = 0;
|
|
|
|
public WiredEffectGiveHotelviewHofPoints(ResultSet set, Item baseItem) throws SQLException {
|
|
super(set, baseItem);
|
|
}
|
|
|
|
public WiredEffectGiveHotelviewHofPoints(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) {
|
|
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());
|
|
|
|
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(WiredSettings settings, GameClient gameClient) {
|
|
try {
|
|
this.amount = Integer.parseInt(settings.getStringParam());
|
|
} catch (Exception e) {
|
|
return false;
|
|
}
|
|
|
|
this.setDelay(settings.getDelay());
|
|
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public WiredEffectType getType() {
|
|
return type;
|
|
}
|
|
|
|
@Override
|
|
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
|
|
Habbo habbo = room.getHabbo(roomUnit);
|
|
|
|
if (habbo == null)
|
|
return false;
|
|
|
|
if (this.amount > 0) {
|
|
habbo.getHabboStats().hofPoints += this.amount;
|
|
Emulator.getThreading().run(habbo.getHabboStats());
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public String getWiredData() {
|
|
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.amount, this.getDelay()));
|
|
}
|
|
|
|
@Override
|
|
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
|
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;
|
|
|
|
if (wiredData.split("\t").length >= 2) {
|
|
super.setDelay(Integer.valueOf(wiredData.split("\t")[0]));
|
|
|
|
try {
|
|
this.amount = Integer.valueOf(this.getWiredData().split("\t")[1]);
|
|
} catch (Exception e) {
|
|
}
|
|
}
|
|
|
|
this.needsUpdate(true);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPickUp() {
|
|
this.amount = 0;
|
|
this.setDelay(0);
|
|
}
|
|
|
|
@Override
|
|
public boolean requiresTriggeringUser() {
|
|
return true;
|
|
}
|
|
|
|
static class JsonData {
|
|
int amount;
|
|
int delay;
|
|
|
|
public JsonData(int amount, int delay) {
|
|
this.amount = amount;
|
|
this.delay = delay;
|
|
}
|
|
}
|
|
}
|