Refactored All Wireds

This commit is contained in:
Stankman 2023-06-16 19:30:07 -05:00
parent 00a81ed5c3
commit 94dd34a11e
88 changed files with 846 additions and 5139 deletions

View File

@ -6,14 +6,12 @@ import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredInteraction;
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.WiredExclusionStrategy;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.OneWayDoorStatusMessageComposer;
import gnu.trove.map.hash.TLongLongHashMap;
import gnu.trove.set.hash.THashSet;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@ -22,13 +20,11 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public abstract class InteractionWired extends InteractionDefault implements IWiredInteraction {
@Getter
@Setter
private THashSet<HabboItem> items;
@Getter
@Setter
private String wiredData;
@ -42,7 +38,6 @@ public abstract class InteractionWired extends InteractionDefault implements IWi
public InteractionWired(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
this.wiredData = "";
this.wiredSettings = new WiredSettings();
this.setExtradata("0");
@ -50,18 +45,19 @@ public abstract class InteractionWired extends InteractionDefault implements IWi
InteractionWired(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
this.wiredData = "";
this.wiredSettings = new WiredSettings();
this.setExtradata("0");
}
public abstract boolean execute(RoomUnit roomUnit, Room room, Object[] stuff);
public abstract boolean saveData() throws WiredSaveException;
@Override
public void run() {
if (this.needsUpdate()) {
//TODO HERE IS WERE WIRED_SAVE_EXCEPTION WILL BE THROWN
//EXAMPLE: if StringParam should be number, throw error here, maybe activating a flag in wiredSettings that string params are numbers
WiredExclusionStrategy exclusionStrategy = new WiredExclusionStrategy(this.wiredSettings);
String wiredData = WiredHandler.getGsonBuilder().setExclusionStrategies(exclusionStrategy).create().toJson(this.wiredSettings);
@ -83,7 +79,8 @@ public abstract class InteractionWired extends InteractionDefault implements IWi
@Override
public void onPickUp(Room room) {
this.items.clear();
this.wiredSettings = null;
//TODO not sure about this
}
public void activateBox(Room room) {
@ -143,25 +140,25 @@ public abstract class InteractionWired extends InteractionDefault implements IWi
WiredSettings settings = new WiredSettings();
int intParamCount = packet.readInt();
int[] integerParams = new int[intParamCount];
List<Integer> integerParams = new ArrayList<>();
for(int i = 0; i < intParamCount; i++)
{
integerParams[i] = packet.readInt();
integerParams.add(packet.readInt());
}
settings.setIntegerParams(integerParams);
settings.setStringParam(packet.readString());
int itemCount = packet.readInt();
int[] itemIds = new int[itemCount];
List<Integer> itemIds = new ArrayList<>();
for(int i = 0; i < itemCount; i++)
{
itemIds[i] = packet.readInt();
itemIds.add(packet.readInt());
}
settings.setItems(itemIds);
settings.setItemIds(itemIds);
if(isWiredEffect)
{

View File

@ -23,6 +23,10 @@ public abstract class InteractionWiredEffect extends InteractionWired implements
@Setter
private List<Integer> blockedTriggers;
@Getter
@Setter
private WiredEffectType type;
public InteractionWiredEffect(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -54,8 +58,6 @@ public abstract class InteractionWiredEffect extends InteractionWired implements
}
}
public abstract WiredEffectType getType();
public boolean requiresTriggeringUser() {
return false;
}

View File

@ -2,10 +2,8 @@ package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredTriggerInteraction;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.outgoing.wired.WiredTriggerDataComposer;
import gnu.trove.set.hash.THashSet;
@ -22,6 +20,10 @@ public abstract class InteractionWiredTrigger extends InteractionWired implement
@Setter
private List<Integer> blockedEffects;
@Getter
@Setter
private WiredTriggerType type;
protected InteractionWiredTrigger(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -53,8 +55,6 @@ public abstract class InteractionWiredTrigger extends InteractionWired implement
}
}
public abstract WiredTriggerType getType();
public boolean isTriggeredByRoomUnit() {
return false;
}

View File

@ -1,13 +1,20 @@
package com.eu.habbo.habbohotel.items.interactions.wired;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.HabboItem;
import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
public class WiredSettings implements IWiredSettings {
@Getter
@Setter
private int[] integerParams;
private List<Integer> integerParams;
@Getter
@Setter
@ -15,7 +22,7 @@ public class WiredSettings implements IWiredSettings {
@Getter
@Setter
private int[] items;
private List<Integer> itemIds;
@Getter
@Setter
private int delay;
@ -25,10 +32,27 @@ public class WiredSettings implements IWiredSettings {
private int selectionType;
public WiredSettings() {
this.items = new int[0];
this.integerParams = new int[0];
this.itemIds = new ArrayList<>();
this.integerParams = new ArrayList<>();
this.stringParam = "";
this.delay = 0;
this.selectionType = 0;
}
public THashSet<HabboItem> getItems(Room room) {
THashSet<HabboItem> items = new THashSet<>();
for(int itemId : this.itemIds) {
HabboItem item = room.getHabboItem(itemId);
if(item == null || item.getRoomId() == 0) {
this.itemIds.remove(itemId);
continue;
}
items.add(item);
}
return items;
}
}

View File

@ -1,5 +0,0 @@
package com.eu.habbo.habbohotel.items.interactions.wired;
public interface WiredTriggerReset {
void resetTimer();
}

View File

@ -3,12 +3,9 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
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.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -18,10 +15,8 @@ import java.sql.SQLException;
* a given range.
*/
public class WiredConditionDateRangeActive extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.DATE_RANGE;
private int startDate; // the start of the date range
private int endDate; // the end of the date range
public final int PARAM_START_DATE = 0;
public final int PARAM_END_DATE = 1;
/**
* Creates a new instance of this class.
@ -46,27 +41,6 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
/**
* Returns the {@link WiredConditionType} of this object.
* @return the type of this wired condition
*/
@Override
public WiredConditionType getType() {
return type;
}
/**
* Saves the given {@link WiredSettings} object to this wired condition.
* @return {@code true} if the settings were saved successfully, {@code false} otherwise
* */
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 2) return false;
this.startDate = this.getWiredSettings().getIntegerParams()[0];
this.endDate = this.getWiredSettings().getIntegerParams()[1];
return true;
}
/**
* Determines if the wired condition is met.
* @param roomUnit the room unit that triggered the condition
@ -78,63 +52,19 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int time = Emulator.getIntUnixTimestamp();
return this.startDate < time && this.endDate >= time;
int startDate = this.getWiredSettings().getIntegerParams().get(PARAM_START_DATE);
int endDate = this.getWiredSettings().getIntegerParams().get(PARAM_END_DATE);
return startDate < time && endDate >= time;
}
/**
* Gets the wired data for this wired condition in JSON format.
* @return the wired data in JSON format
* Returns the {@link WiredConditionType} of this object.
* @return the type of this wired condition
*/
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.startDate,
this.endDate
));
}
/**
* Loads the wired data for this wired condition from a database.
* @param set the ResultSet object to get data from
* @param room the room that this wired condition is in
* @throws SQLException if an error occurs while getting data from the ResultSet object
*/
@Override
public void loadWiredSettings(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.startDate = data.startDate;
this.endDate = data.endDate;
} else {
String[] data = wiredData.split("\t");
if (data.length == 2) {
try {
this.startDate = Integer.parseInt(data[0]);
this.endDate = Integer.parseInt(data[1]);
} catch (Exception ignored) {
}
}
}
}
/**
* A nested class for storing the wired data for this wired condition in JSON format.
*/
static class JsonData {
int startDate;
int endDate;
/**
* Creates a new instance of this class.
* @param startDate the start of the date range
* @param endDate the end of the date range
*/
public JsonData(int startDate, int endDate) {
this.startDate = startDate;
this.endDate = endDate;
}
public WiredConditionType getType() {
return WiredConditionType.DATE_RANGE;
}
}

View File

@ -3,14 +3,12 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
@ -20,119 +18,41 @@ import java.util.List;
import java.util.Objects;
public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.FURNI_HAS_FURNI;
private boolean all;
private final THashSet<HabboItem> items;
public final int PARAM_ALL_FURNI = 0;
public WiredConditionFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredConditionFurniHaveFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.refresh();
if (this.items.isEmpty())
if(this.getWiredSettings().getItemIds().isEmpty()) {
return true;
if (this.all) {
return this.items.stream().allMatch(item -> {
double minZ = item.getZ() + Item.getCurrentHeight(item);
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
});
} else {
return this.items.stream().anyMatch(item -> {
double minZ = item.getZ() + Item.getCurrentHeight(item);
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
});
}
}
@Override
public String getWiredData() {
this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.all,
this.items.stream().map(HabboItem::getId).toList()
));
}
@Override
public void loadWiredSettings(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.all = data.all;
data.itemIds.stream().mapToInt(id -> id).mapToObj(room::getHabboItem).filter(Objects::nonNull).forEach(this.items::add);
boolean allFurni = this.getWiredSettings().getIntegerParams().get(PARAM_ALL_FURNI) == 1;
if (allFurni) {
return this.getWiredSettings().getItems(room).stream().allMatch(item -> {
double minZ = item.getZ() + Item.getCurrentHeight(item);
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
});
} else {
String[] data = wiredData.split(":");
if (data.length >= 1) {
this.all = (data[0].equals("1"));
if (data.length == 2) {
String[] itemsSplit = data[1].split(";");
Arrays.stream(itemsSplit).map(s -> room.getHabboItem(Integer.parseInt(s))).filter(Objects::nonNull).forEach(this.items::add);
}
}
return this.getWiredSettings().getItems(room).stream().anyMatch(item -> {
double minZ = item.getZ() + Item.getCurrentHeight(item);
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
});
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if (this.getWiredSettings().getIntegerParams().length < 1) return false;
this.all = this.getWiredSettings().getIntegerParams()[0] == 1;
int count = this.getWiredSettings().getItems().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(this.getWiredSettings().getItems()[i]);
if (item != null)
this.items.add(item);
}
return true;
}
return false;
}
private void refresh() {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
this.items.removeIf(i -> room.getHabboItem(i.getId()) == null);
}
static class JsonData {
boolean all;
List<Integer> itemIds;
public JsonData(boolean all, List<Integer> itemIds) {
this.all = all;
this.itemIds = itemIds;
}
return WiredConditionType.FURNI_HAS_FURNI;
}
}

View File

@ -4,7 +4,6 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
@ -13,7 +12,6 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
@ -23,31 +21,25 @@ import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.FURNI_HAVE_HABBO;
protected THashSet<HabboItem> items;
public WiredConditionFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredConditionFurniHaveHabbo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.refresh();
if (this.items.isEmpty())
if (this.getWiredSettings().getItemIds().isEmpty()) {
return true;
}
Collection<Habbo> habbos = room.getHabbos();
Collection<Bot> bots = room.getCurrentBots().valueCollection();
Collection<Pet> pets = room.getCurrentPets().valueCollection();
return this.items.stream().allMatch(item -> {
return this.getWiredSettings().getItems(room).stream().allMatch(item -> {
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
@ -55,98 +47,8 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
});
}
@Override
public String getWiredData() {
this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(":");
if (data.length >= 1) {
String[] items = data[1].split(";");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
int count = this.getWiredSettings().getItems().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(this.getWiredSettings().getItems()[i]);
if (item != null)
this.items.add(item);
}
return true;
}
return false;
}
private void refresh() {
THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
items.addAll(this.items);
} else {
for (HabboItem item : this.items) {
if (room.getHabboItem(item.getId()) == null)
items.add(item);
}
}
for (HabboItem item : items) {
this.items.remove(item);
}
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
return WiredConditionType.FURNI_HAVE_HABBO;
}
}

View File

@ -3,13 +3,11 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
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.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
@ -18,10 +16,6 @@ import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.STUFF_IS;
private final THashSet<HabboItem> items = new THashSet<>();
public WiredConditionFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -32,104 +26,23 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.refresh();
if(this.getWiredSettings().getItemIds().isEmpty()) {
return true;
}
if(items.isEmpty())
return false;
if(stuff.length == 0) {
return true;
}
if (stuff != null) {
if (stuff.length >= 1) {
if (stuff[0] instanceof HabboItem triggeringItem) {
return this.items.stream().anyMatch(item -> item == triggeringItem);
}
}
if (stuff[0] instanceof HabboItem triggeringItem) {
return this.getWiredSettings().getItems(room).stream().anyMatch(item -> item == triggeringItem);
}
return false;
}
@Override
public String getWiredData() {
this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(";");
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null) {
this.items.add(item);
}
}
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
int count = this.getWiredSettings().getItems().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
for (int i = 0; i < count; i++) {
this.items.add(room.getHabboItem(this.getWiredSettings().getItems()[i]));
}
}
return true;
}
private void refresh() {
THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
items.addAll(this.items);
} else {
for (HabboItem item : this.items) {
if (room.getHabboItem(item.getId()) == null)
items.add(item);
}
}
for (HabboItem item : items) {
this.items.remove(item);
}
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
return WiredConditionType.STUFF_IS;
}
}

View File

@ -13,8 +13,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionGroupMember extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_IN_GROUP;
public WiredConditionGroupMember(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -25,26 +23,17 @@ public class WiredConditionGroupMember extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (room.getGuildId() == 0)
if (room.getGuildId() == 0) {
return false;
}
Habbo habbo = room.getHabbo(roomUnit);
return habbo != null && habbo.getHabboStats().hasGuild(room.getGuildId());
}
@Override
public String getWiredData() {
return "";
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
return true;
return WiredConditionType.ACTOR_IN_GROUP;
}
}

View File

@ -13,9 +13,8 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionHabboCount extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.USER_COUNT;
private int lowerLimit = 0;
private int upperLimit = 50;
public final int PARAM_LOWER_LIMIT = 0;
public final int PARAM_UPPER_LIMIT = 1;
public WiredConditionHabboCount(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -27,56 +26,15 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int count = room.getUserCount();
int lowerLimit = this.getWiredSettings().getIntegerParams().get(PARAM_LOWER_LIMIT);
int upperLimit = this.getWiredSettings().getIntegerParams().get(PARAM_UPPER_LIMIT);
int userCount = room.getUserCount();
return count >= this.lowerLimit && count <= this.upperLimit;
return userCount >= lowerLimit && userCount <= upperLimit;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.lowerLimit,
this.upperLimit
));
}
@Override
public void loadWiredSettings(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.lowerLimit = data.lowerLimit;
this.upperLimit = data.upperLimit;
} else {
String[] data = wiredData.split(":");
this.lowerLimit = Integer.parseInt(data[0]);
this.upperLimit = Integer.parseInt(data[1]);
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 2) return false;
this.lowerLimit = this.getWiredSettings().getIntegerParams()[0];
this.upperLimit = this.getWiredSettings().getIntegerParams()[1];
return true;
}
static class JsonData {
int lowerLimit;
int upperLimit;
public JsonData(int lowerLimit, int upperLimit) {
this.lowerLimit = lowerLimit;
this.upperLimit = upperLimit;
}
return WiredConditionType.USER_COUNT;
}
}

View File

@ -13,9 +13,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_EFFECT;
protected int effectId = 0;
public final int PARAM_EFFECT_ID = 0;
public WiredConditionHabboHasEffect(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -27,47 +25,17 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (roomUnit == null) return false;
return roomUnit.getEffectId() == this.effectId;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.effectId
));
}
@Override
public void loadWiredSettings(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.effectId = data.effectId;
} else {
this.effectId = Integer.parseInt(wiredData);
if (roomUnit == null) {
return false;
}
int effectId = this.getWiredSettings().getIntegerParams().get(PARAM_EFFECT_ID);
return roomUnit.getEffectId() == effectId;
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.effectId = this.getWiredSettings().getIntegerParams()[0];
return true;
}
static class JsonData {
int effectId;
public JsonData(int effectId) {
this.effectId = effectId;
}
return WiredConditionType.ACTOR_WEARS_EFFECT;
}
}

View File

@ -2,12 +2,9 @@ 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.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import lombok.extern.slf4j.Slf4j;
import java.sql.ResultSet;
@ -15,10 +12,7 @@ import java.sql.SQLException;
@Slf4j
public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_HAS_HANDITEM;
private int handItem;
public final int PARAM_HAND_ITEM_ID = 0;
public WiredConditionHabboHasHandItem(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -28,53 +22,19 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.handItem = this.getWiredSettings().getIntegerParams()[0];
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (roomUnit == null) return false;
return roomUnit.getHandItem() == this.handItem;
if (roomUnit == null) {
return false;
}
int handItemId = this.getWiredSettings().getIntegerParams().get(PARAM_HAND_ITEM_ID);
return roomUnit.getHandItem() == handItemId;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.handItem
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) {
try {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.handItem = data.handItemId;
} else {
this.handItem = Integer.parseInt(wiredData);
}
} catch (Exception e) {
log.error("Caught exception", e);
}
}
static class JsonData {
int handItemId;
public JsonData(int handItemId) {
this.handItemId = handItemId;
}
public WiredConditionType getType() {
return WiredConditionType.ACTOR_HAS_HANDITEM;
}
}

View File

@ -15,10 +15,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_BADGE;
protected String badge = "";
public WiredConditionHabboWearsBadge(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -29,56 +25,30 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getStringParam().isEmpty()) {
return true;
}
String badgeCode = this.getWiredSettings().getStringParam();
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) {
for (HabboBadge badge : habbo.getInventory().getBadgesComponent().getWearingBadges()) {
if (badge.getCode().equalsIgnoreCase(this.badge)) {
return true;
}
if(habbo == null) {
return false;
}
synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) {
for (HabboBadge badge : habbo.getInventory().getBadgesComponent().getWearingBadges()) {
if (badge.getCode().equalsIgnoreCase(badgeCode)) {
return true;
}
}
}
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.badge
));
}
@Override
public void loadWiredSettings(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.badge = data.badge;
} else {
this.badge = wiredData;
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
this.badge = this.getWiredSettings().getStringParam();
return true;
}
static class JsonData {
String badge;
public JsonData(String badge) {
this.badge = badge;
}
return WiredConditionType.ACTOR_WEARS_BADGE;
}
}

View File

@ -14,9 +14,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionLessTimeElapsed extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.TIME_LESS_THAN;
private int cycles;
public final int PARAM_CYCLE = 0;
public WiredConditionLessTimeElapsed(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -28,49 +26,12 @@ public class WiredConditionLessTimeElapsed extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 < this.cycles;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.cycles
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
String wiredData = set.getString("wired_data");
try {
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.cycles = data.cycles;
} else {
if (!wiredData.equals(""))
this.cycles = Integer.parseInt(wiredData);
}
} catch (Exception ignored) {
}
int cycles = this.getWiredSettings().getIntegerParams().get(PARAM_CYCLE);
return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 < cycles;
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.cycles = this.getWiredSettings().getIntegerParams()[0];
return true;
}
static class JsonData {
int cycles;
public JsonData(int cycles) {
this.cycles = cycles;
}
return WiredConditionType.TIME_LESS_THAN;
}
}

View File

@ -3,201 +3,89 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings;
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.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import lombok.Getter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings {
public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT;
private final THashSet<WiredMatchFurniSetting> wiredMatchSettings;
private boolean state;
private boolean position;
private boolean direction;
public final int PARAM_STATE = 0;
public final int PARAM_ROTATION = 1;
public final int PARAM_POSITION = 2;
@Getter
private THashSet<WiredMatchFurniSetting> matchFurniSettings;
public WiredConditionMatchStatePosition(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.wiredMatchSettings = new THashSet<>();
}
public WiredConditionMatchStatePosition(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.wiredMatchSettings = new THashSet<>();
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 3) return false;
this.state = this.getWiredSettings().getIntegerParams()[0] == 1;
this.direction = this.getWiredSettings().getIntegerParams()[1] == 1;
this.position = this.getWiredSettings().getIntegerParams()[2] == 1;
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null)
return true;
int count = this.getWiredSettings().getItems().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.wiredMatchSettings.clear();
for (int i = 0; i < count; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem item = room.getHabboItem(itemId);
if (item != null)
this.wiredMatchSettings.add(new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY()));
}
return true;
return WiredConditionType.MATCH_SSHOT;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (this.wiredMatchSettings.isEmpty())
if(this.getWiredSettings().getItemIds().isEmpty()) {
return true;
THashSet<WiredMatchFurniSetting> s = new THashSet<>();
for (WiredMatchFurniSetting setting : this.wiredMatchSettings) {
HabboItem item = room.getHabboItem(setting.getItem_id());
if (item != null) {
if (this.state) {
if (!item.getExtradata().equals(setting.getState()))
return false;
}
if (this.position) {
if (!(setting.getX() == item.getX() && setting.getY() == item.getY()))
return false;
}
if (this.direction) {
if (setting.getRotation() != item.getRotation())
return false;
}
} else {
s.add(setting);
}
}
if (!s.isEmpty()) {
for (WiredMatchFurniSetting setting : s) {
this.wiredMatchSettings.remove(setting);
boolean state = this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1;
boolean position = this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1;
boolean rotation = this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1;
for(HabboItem item : this.getWiredSettings().getItems(room)) {
WiredMatchFurniSetting setting = new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY());
this.matchFurniSettings.add(setting);
if(state) {
if(!item.getExtradata().equals(setting.getState())) {
return false;
}
}
if(position) {
if (!(setting.getX() == item.getX() && setting.getY() == item.getY())) {
return false;
}
}
if(rotation) {
if (setting.getRotation() != item.getRotation()) {
return false;
}
}
}
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.state,
this.position,
this.direction,
new ArrayList<>(this.wiredMatchSettings)
));
}
@Override
public void loadWiredSettings(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.state = data.state;
this.position = data.position;
this.direction = data.direction;
this.wiredMatchSettings.addAll(data.settings);
} else {
String[] data = wiredData.split(":");
int itemCount = Integer.parseInt(data[0]);
String[] items = data[1].split(";");
for (int i = 0; i < itemCount; i++) {
String[] stuff = items[i].split("-");
if (stuff.length >= 5)
this.wiredMatchSettings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4])));
}
this.state = data[2].equals("1");
this.direction = data[3].equals("1");
this.position = data[4].equals("1");
}
}
private void refresh() {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
THashSet<WiredMatchFurniSetting> remove = new THashSet<>();
for (WiredMatchFurniSetting setting : this.wiredMatchSettings) {
HabboItem item = room.getHabboItem(setting.getItem_id());
if (item == null) {
remove.add(setting);
}
}
for (WiredMatchFurniSetting setting : remove) {
this.wiredMatchSettings.remove(setting);
}
}
}
@Override
public THashSet<WiredMatchFurniSetting> getMatchFurniSettings() {
return this.wiredMatchSettings;
}
@Override
public boolean shouldMatchState() {
return this.state;
return this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1;
}
@Override
public boolean shouldMatchRotation() {
return this.direction;
return this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1;
}
@Override
public boolean shouldMatchPosition() {
return this.position;
}
static class JsonData {
boolean state;
boolean position;
boolean direction;
List<WiredMatchFurniSetting> settings;
public JsonData(boolean state, boolean position, boolean direction, List<WiredMatchFurniSetting> settings) {
this.state = state;
this.position = position;
this.direction = direction;
this.settings = settings;
}
return this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1;
}
}

View File

@ -13,11 +13,8 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionMoreTimeElapsed extends InteractionWiredCondition {
private static final WiredConditionType type = WiredConditionType.TIME_MORE_THAN;
private static final int PARAM_CYCLE = 0;
private int cycles;
public WiredConditionMoreTimeElapsed(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -28,48 +25,11 @@ public class WiredConditionMoreTimeElapsed extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 > this.cycles;
int cycles = this.getWiredSettings().getIntegerParams().get(PARAM_CYCLE);
return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 > cycles;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.cycles
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
String wiredData = set.getString("wired_data");
try {
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.cycles = data.cycles;
} else {
if (!wiredData.equals(""))
this.cycles = Integer.parseInt(wiredData);
}
} catch (Exception ignored) {
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
this.cycles = this.getWiredSettings().getIntegerParams()[PARAM_CYCLE];
return true;
}
static class JsonData {
int cycles;
public JsonData(int cycles) {
this.cycles = cycles;
}
return WiredConditionType.TIME_MORE_THAN;
}
}

View File

@ -3,7 +3,6 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
@ -11,7 +10,6 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
@ -20,37 +18,33 @@ import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_FURNI;
private boolean all;
private final THashSet<HabboItem> items;
public final int PARAM_ALL_FURNI = 0;
public WiredConditionNotFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredConditionNotFurniHaveFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.refresh();
if (this.items.isEmpty())
if(this.getWiredSettings().getItemIds().isEmpty()) {
return true;
}
if(this.all) {
return this.items.stream().allMatch(item -> {
boolean allFurni = this.getWiredSettings().getIntegerParams().get(PARAM_ALL_FURNI) == 1;
if(allFurni) {
return this.getWiredSettings().getItems(room).stream().allMatch(item -> {
double minZ = item.getZ() + Item.getCurrentHeight(item);
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
});
}
else {
return this.items.stream().anyMatch(item -> {
return this.getWiredSettings().getItems(room).stream().anyMatch(item -> {
double minZ = item.getZ() + Item.getCurrentHeight(item);
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
@ -58,97 +52,9 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
}
}
@Override
public String getWiredData() {
this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.all,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.all = data.all;
for (int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(":");
if (data.length >= 1) {
this.all = (data[0].equals("1"));
if (data.length == 2) {
String[] items = data[1].split(";");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.all = this.getWiredSettings().getIntegerParams()[0] == 1;
int count = this.getWiredSettings().getItems().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(this.getWiredSettings().getItems()[i]);
if (item != null)
this.items.add(item);
}
return true;
}
return false;
}
private void refresh() {
THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
items.addAll(this.items);
} else {
for (HabboItem item : this.items) {
if (room.getHabboItem(item.getId()) == null)
items.add(item);
}
}
for (HabboItem item : items) {
this.items.remove(item);
}
return WiredConditionType.NOT_FURNI_HAVE_FURNI;
}
@Override
@ -157,14 +63,4 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
//return this.all ? WiredConditionOperator.AND : WiredConditionOperator.OR;
return WiredConditionOperator.AND;
}
static class JsonData {
boolean all;
List<Integer> itemIds;
public JsonData(boolean all, List<Integer> itemIds) {
this.all = all;
this.itemIds = itemIds;
}
}
}

View File

@ -4,7 +4,6 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
@ -13,7 +12,6 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
@ -23,32 +21,25 @@ import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_HABBO;
protected THashSet<HabboItem> items;
public WiredConditionNotFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredConditionNotFurniHaveHabbo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.refresh();
if (this.items.isEmpty())
if(this.getWiredSettings().getItemIds().isEmpty()) {
return true;
}
Collection<Habbo> habbos = room.getHabbos();
Collection<Bot> bots = room.getCurrentBots().valueCollection();
Collection<Pet> pets = room.getCurrentPets().valueCollection();
return this.items.stream().noneMatch(item -> {
return this.getWiredSettings().getItems(room).stream().noneMatch(item -> {
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
@ -56,96 +47,8 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
});
}
@Override
public String getWiredData() {
this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
WiredConditionFurniHaveHabbo.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(":");
if (data.length >= 1) {
String[] items = data[1].split(";");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
int count = this.getWiredSettings().getItems().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(this.getWiredSettings().getItems()[i]);
if (item != null)
this.items.add(item);
}
return true;
}
return false;
}
private void refresh() {
THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
items.addAll(this.items);
} else {
for (HabboItem item : this.items) {
if (room.getHabboItem(item.getId()) == null)
items.add(item);
}
}
for (HabboItem item : items) {
this.items.remove(item);
}
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
return WiredConditionType.NOT_FURNI_HAVE_HABBO;
}
}

View File

@ -3,13 +3,11 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
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.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
@ -31,104 +29,23 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.refresh();
if(items.isEmpty())
if(this.getWiredSettings().getItemIds().isEmpty()) {
return true;
if (stuff != null) {
if (stuff.length >= 1) {
if (stuff[0] instanceof HabboItem triggeringItem) {
return this.items.stream().noneMatch(item -> item == triggeringItem);
}
}
}
return true;
}
@Override
public String getWiredData() {
this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
WiredConditionFurniTypeMatch.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = set.getString("wired_data").split(";");
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null) {
this.items.add(item);
}
}
if(stuff.length == 0) {
return true;
}
if (stuff[0] instanceof HabboItem triggeringItem) {
return this.getWiredSettings().getItems(room).stream().noneMatch(item -> item == triggeringItem);
}
return false;
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
int count = this.getWiredSettings().getItems().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
for (int i = 0; i < count; i++) {
this.items.add(room.getHabboItem(this.getWiredSettings().getItems()[i]));
}
}
return true;
}
private void refresh() {
THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
items.addAll(this.items);
} else {
for (HabboItem item : this.items) {
if (room.getHabboItem(item.getId()) == null)
items.add(item);
}
}
for (HabboItem item : items) {
this.items.remove(item);
}
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
return WiredConditionType.NOT_STUFF_IS;
}
}

View File

@ -12,12 +12,7 @@ import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionNotHabboCount extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_USER_COUNT;
private int lowerLimit = 10;
private int upperLimit = 20;
public class WiredConditionNotHabboCount extends WiredConditionHabboCount {
public WiredConditionNotHabboCount(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -28,55 +23,11 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int count = room.getUserCount();
return count < this.lowerLimit || count > this.upperLimit;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.lowerLimit,
this.upperLimit
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
WiredConditionHabboCount.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionHabboCount.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]);
}
return !super.execute(roomUnit, room, stuff);
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 2) return false;
this.lowerLimit = this.getWiredSettings().getIntegerParams()[0];
this.upperLimit = this.getWiredSettings().getIntegerParams()[1];
return true;
}
static class JsonData {
int lowerLimit;
int upperLimit;
public JsonData(int lowerLimit, int upperLimit) {
this.lowerLimit = lowerLimit;
this.upperLimit = upperLimit;
}
return WiredConditionType.NOT_USER_COUNT;
}
}

View File

@ -12,11 +12,7 @@ import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
private static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_EFFECT;
protected int effectId;
public class WiredConditionNotHabboHasEffect extends WiredConditionHabboHasEffect {
public WiredConditionNotHabboHasEffect(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -27,47 +23,11 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (roomUnit == null) return false;
return roomUnit.getEffectId() != this.effectId;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.effectId
));
}
@Override
public void loadWiredSettings(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.effectId = data.effectId;
} else {
this.effectId = Integer.parseInt(wiredData);
}
return !super.execute(roomUnit, room, stuff);
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.effectId = this.getWiredSettings().getIntegerParams()[0];
return true;
}
static class JsonData {
int effectId;
public JsonData(int effectId) {
this.effectId = effectId;
}
return WiredConditionType.NOT_ACTOR_WEARS_EFFECT;
}
}

View File

@ -1,20 +1,14 @@
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.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.users.HabboBadge;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition {
public class WiredConditionNotHabboWearsBadge extends WiredConditionHabboWearsBadge {
public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_BADGE;
protected String badge = "";
@ -29,57 +23,11 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) {
for (HabboBadge b : habbo.getInventory().getBadgesComponent().getWearingBadges()) {
if (b.getCode().equalsIgnoreCase(this.badge))
return false;
}
}
return true;
}
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.badge
));
}
@Override
public void loadWiredSettings(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.badge = data.badge;
} else {
this.badge = wiredData;
}
return !super.execute(roomUnit, room, stuff);
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
this.badge = this.getWiredSettings().getStringParam();
return true;
}
static class JsonData {
String badge;
public JsonData(String badge) {
this.badge = badge;
}
return WiredConditionType.NOT_ACTOR_WEARS_BADGE;
}
}

View File

@ -13,8 +13,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionNotInGroup extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_GROUP;
public WiredConditionNotInGroup(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -33,21 +31,8 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition {
return habbo == null || !habbo.getHabboStats().hasGuild(room.getGuildId());
}
@Override
public String getWiredData() {
return "";
}
@Override
public void loadWiredSettings(ResultSet set, Room room) {}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
return true;
return WiredConditionType.NOT_ACTOR_IN_GROUP;
}
}

View File

@ -15,9 +15,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionNotInTeam extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_TEAM;
private GameTeamColors teamColor = GameTeamColors.RED;
public final int PARAM_TEAM = 0;
public WiredConditionNotInTeam(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -29,57 +27,25 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int teamValue = this.getWiredSettings().getIntegerParams().get(PARAM_TEAM);
if(teamValue < 1 || teamValue > 4) {
return false;
}
GameTeamColors teamColor = GameTeamColors.values()[teamValue];
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
return habbo.getHabboInfo().getGamePlayer() == null || !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); // user is not part of any team
return habbo.getHabboInfo().getGamePlayer() == null || !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(teamColor);
}
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.teamColor
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) {
try {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.teamColor = data.teamColor;
} else {
if (!wiredData.equals(""))
this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)];
}
} catch (Exception e) {
this.teamColor = GameTeamColors.RED;
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.teamColor = GameTeamColors.values()[this.getWiredSettings().getIntegerParams()[0]];
return true;
}
static class JsonData {
GameTeamColors teamColor;
public JsonData(GameTeamColors teamColor) {
this.teamColor = teamColor;
}
return WiredConditionType.NOT_ACTOR_IN_TEAM;
}
}

View File

@ -9,8 +9,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionNotMatchStatePosition extends WiredConditionMatchStatePosition {
public static final WiredConditionType type = WiredConditionType.NOT_MATCH_SSHOT;
public WiredConditionNotMatchStatePosition(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -26,6 +24,6 @@ public class WiredConditionNotMatchStatePosition extends WiredConditionMatchStat
@Override
public WiredConditionType getType() {
return type;
return WiredConditionType.NOT_MATCH_SSHOT;
}
}

View File

@ -21,15 +21,7 @@ public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurn
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (roomUnit == null)
return false;
this.refresh();
if (this.items.isEmpty())
return true;
return !triggerOnFurni(roomUnit, room);
return !super.execute(roomUnit, room, stuff);
}
@Override

View File

@ -15,9 +15,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionTeamMember extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_IN_TEAM;
private GameTeamColors teamColor = GameTeamColors.RED;
public final int PARAM_TEAM = 0;
public WiredConditionTeamMember(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -29,58 +27,27 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int teamValue = this.getWiredSettings().getIntegerParams().get(PARAM_TEAM);
if(teamValue < 1 || teamValue > 4) {
return false;
}
GameTeamColors teamColor = GameTeamColors.values()[teamValue];
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
if (habbo.getHabboInfo().getGamePlayer() != null) {
return habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor);
return habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(teamColor);
}
}
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.teamColor
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) {
try {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.teamColor = data.teamColor;
} else {
if (!wiredData.equals(""))
this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)];
}
} catch (Exception e) {
this.teamColor = GameTeamColors.RED;
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.teamColor = GameTeamColors.values()[this.getWiredSettings().getIntegerParams()[0]];
return true;
}
static class JsonData {
GameTeamColors teamColor;
public JsonData(GameTeamColors teamColor) {
this.teamColor = teamColor;
}
return WiredConditionType.ACTOR_IN_TEAM;
}
}

View File

@ -3,14 +3,12 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
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.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
@ -19,10 +17,6 @@ import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI;
protected THashSet<HabboItem> items = new THashSet<>();
public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -33,99 +27,16 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (roomUnit == null)
if(this.getWiredSettings().getItemIds().isEmpty()) {
return true;
}
if(roomUnit == null) {
return false;
}
this.refresh();
if (this.items.isEmpty())
return false;
return triggerOnFurni(roomUnit, room);
}
protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) {
THashSet<HabboItem> itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation());
return this.items.stream().anyMatch(itemsAtUser::contains);
}
@Override
public String getWiredData() {
this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(";");
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null) {
this.items.add(item);
}
}
}
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public boolean saveData() {
int count = this.getWiredSettings().getItems().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(this.getWiredSettings().getItems()[i]);
if (item != null) {
this.items.add(item);
}
}
}
return true;
}
protected void refresh() {
THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
items.addAll(this.items);
} else {
for (HabboItem item : this.items) {
if (item.getRoomId() != room.getId())
items.add(item);
}
}
this.items.removeAll(items);
return this.getWiredSettings().getItems(room).stream().anyMatch(itemsAtUser::contains);
}
@Override
@ -133,11 +44,8 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
return WiredConditionOperator.AND;
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
@Override
public WiredConditionType getType() {
return WiredConditionType.TRIGGER_ON_FURNI;
}
}

View File

@ -19,11 +19,6 @@ import java.util.List;
import java.util.regex.Pattern;
public class WiredEffectBotClothes extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_CLOTHES;
private String botName = "";
private String botLook = "";
public WiredEffectBotClothes(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -33,83 +28,26 @@ public class WiredEffectBotClothes extends InteractionWiredEffect {
}
@Override
public boolean saveData() throws WiredSaveException {
String dataString = this.getWiredSettings().getStringParam();
int delay = this.getWiredSettings().getDelay();
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
String[] stringParams = this.getWiredSettings().getStringParam().split("\t");
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
String botName = stringParams[0].substring(0, Math.min(stringParams[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
String botLook = stringParams[1];
String splitBy = "\t";
if(!dataString.contains(splitBy))
throw new WiredSaveException("Malformed data string");
List<Bot> bots = room.getBots(botName);
String[] data = dataString.split(Pattern.quote(splitBy));
if(bots.size() == 0) {
return false;
}
if (data.length != 2)
throw new WiredSaveException("Malformed data string. Invalid data length");
this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.botLook = data[1];
this.getWiredSettings().setDelay(delay);
Bot bot = bots.get(0);
bot.setFigure(botLook);
return true;
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
List<Bot> bots = room.getBots(this.botName);
if (bots.size() == 1) {
Bot bot = bots.get(0);
bot.setFigure(this.botLook);
}
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.botLook, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.botName = data.bot_name;
this.botLook = data.look;
}
else {
String[] data = wiredData.split(((char) 9) + "");
if (data.length >= 3) {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
this.botName = data[1];
this.botLook = data[2];
}
this.needsUpdate(true);
}
}
static class JsonData {
String bot_name;
String look;
int delay;
public JsonData(String bot_name, String look, int delay) {
this.bot_name = bot_name;
this.look = look;
this.delay = delay;
}
return WiredEffectType.BOT_CLOTHES;
}
}

View File

@ -20,10 +20,7 @@ import java.util.ArrayList;
import java.util.List;
public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_FOLLOW_AVATAR;
private String botName = "";
private int mode = 0;
public final int PARAM_MODE = 0;
public WiredEffectBotFollowHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -33,45 +30,15 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 1) throw new WiredSaveException("Mode is invalid");
int mode = this.getWiredSettings().getIntegerParams()[0];
if(mode != 0 && mode != 1)
throw new WiredSaveException("Mode is invalid");
String botName = this.getWiredSettings().getStringParam().replace("\t", "");
botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.botName = botName;
this.mode = mode;
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
Habbo habbo = room.getHabbo(roomUnit);
List<Bot> bots = room.getBots(this.botName);
List<Bot> bots = room.getBots(this.getWiredSettings().getStringParam());
if (habbo != null && bots.size() == 1) {
Bot bot = bots.get(0);
if (this.mode == 1) {
if (this.getWiredSettings().getIntegerParams().get(PARAM_MODE) == 1) {
bot.startFollowingHabbo(habbo);
} else {
bot.stopFollowingHabbo();
@ -84,47 +51,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.mode = data.mode;
this.botName = data.bot_name;
}
else {
String[] data = wiredData.split(((char) 9) + "");
if (data.length == 3) {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
this.mode = (data[1].equalsIgnoreCase("1") ? 1 : 0);
this.botName = data[2];
}
this.needsUpdate(true);
}
}
@Override
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
String bot_name;
int mode;
int delay;
public JsonData(String bot_name, int mode, int delay) {
this.bot_name = bot_name;
this.mode = mode;
this.delay = delay;
}
public WiredEffectType getType() {
return WiredEffectType.BOT_FOLLOW_AVATAR;
}
}

View File

@ -24,11 +24,7 @@ import java.util.ArrayList;
import java.util.List;
public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_GIVE_HANDITEM;
private String botName = "";
private int itemId;
public final int PARAM_ITEM_ID = 0;
public WiredEffectBotGiveHandItem(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -37,44 +33,17 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 1) throw new WiredSaveException("Missing item id");
int itemId = this.getWiredSettings().getIntegerParams()[0];
if(itemId < 0)
itemId = 0;
String botName = this.getWiredSettings().getStringParam();
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.itemId = itemId;
this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
Habbo habbo = room.getHabbo(roomUnit);
List<Bot> bots = room.getBots(this.botName);
List<Bot> bots = room.getBots(this.getWiredSettings().getStringParam());
int itemId = this.getWiredSettings().getIntegerParams().get(PARAM_ITEM_ID);
if (habbo != null && bots.size() == 1) {
Bot bot = bots.get(0);
List<Runnable> tasks = new ArrayList<>();
tasks.add(new RoomUnitGiveHanditem(roomUnit, room, this.itemId));
tasks.add(new RoomUnitGiveHanditem(roomUnit, room, itemId));
tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0));
tasks.add(() -> {
if(roomUnit.getRoom() != null && roomUnit.getRoom().getId() == room.getId() && roomUnit.getCurrentLocation().distance(bot.getRoomUnit().getCurrentLocation()) < 2) {
@ -88,7 +57,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
bot.getRoomUnit().setGoalLocation(tile);
}
Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId));
Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, itemId));
Emulator.getThreading().run(new RoomUnitWalkToLocation(bot.getRoomUnit(), tile, room, tasks, tasks));
return true;
@ -98,47 +67,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.itemId, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.itemId = data.item_id;
this.botName = data.bot_name;
}
else {
String[] data = wiredData.split(((char) 9) + "");
if (data.length == 3) {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
this.itemId = Integer.parseInt(data[1]);
this.botName = data[2];
}
this.needsUpdate(true);
}
}
@Override
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
String bot_name;
int item_id;
int delay;
public JsonData(String bot_name, int item_id, int delay) {
this.bot_name = bot_name;
this.item_id = item_id;
this.delay = delay;
}
public WiredEffectType getType() {
return WiredEffectType.BOT_GIVE_HANDITEM;
}
}

View File

@ -21,11 +21,7 @@ import java.util.List;
import java.util.regex.Pattern;
public class WiredEffectBotTalk extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_TALK;
private int mode;
private String botName = "";
private String message = "";
public final int PARAM_MODE = 0;
public WiredEffectBotTalk(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -35,46 +31,12 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 1) throw new WiredSaveException("Mode is invalid");
int mode = this.getWiredSettings().getIntegerParams()[0];
if(mode != 0 && mode != 1)
throw new WiredSaveException("Mode is invalid");
String dataString = this.getWiredSettings().getStringParam();
String splitBy = "\t";
if(!dataString.contains(splitBy))
throw new WiredSaveException("Malformed data string");
String[] data = dataString.split(Pattern.quote(splitBy));
if (data.length != 2)
throw new WiredSaveException("Malformed data string. Invalid data length");
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.getWiredSettings().setDelay(delay);
this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.message = data[1].substring(0, Math.min(data[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.mode = mode;
return true;
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
String message = this.message;
String[] stringParams = this.getWiredSettings().getStringParam().split("\t");
String botName = stringParams[0].substring(0, Math.min(stringParams[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
String message = stringParams[1].substring(0, Math.min(stringParams[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
Habbo habbo = room.getHabbo(roomUnit);
@ -85,18 +47,18 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
.replace(Emulator.getTexts().getValue("wired.variable.points", "%points%"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "")
.replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), room.getOwnerName())
.replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), room.itemCount() + "")
.replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.botName)
.replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), botName)
.replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), room.getName())
.replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getUserCount() + "");
}
List<Bot> bots = room.getBots(this.botName);
List<Bot> bots = room.getBots(botName);
if (bots.size() == 1) {
Bot bot = bots.get(0);
if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ message })) {
if (this.mode == 1) {
if (this.getWiredSettings().getIntegerParams().get(PARAM_MODE) == 1) {
bot.shout(message);
} else {
bot.talk(message);
@ -108,51 +70,12 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.mode = data.mode;
this.botName = data.bot_name;
this.message = data.message;
}
else {
String[] data = wiredData.split(((char) 9) + "");
if (data.length == 4) {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0;
this.botName = data[2];
this.message = data[3];
}
this.needsUpdate(true);
}
public WiredEffectType getType() {
return WiredEffectType.BOT_TALK;
}
@Override
protected long requiredCooldown() {
return 500;
}
static class JsonData {
String bot_name;
int mode;
String message;
int delay;
public JsonData(String bot_name, int mode, String message, int delay) {
this.bot_name = bot_name;
this.mode = mode;
this.message = message;
this.delay = delay;
}
}
}

View File

@ -22,11 +22,7 @@ import java.util.List;
import java.util.regex.Pattern;
public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_TALK_TO_AVATAR;
private int mode;
private String botName = "";
private String message = "";
public final int PARAM_MODE = 0;
public WiredEffectBotTalkToHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -36,59 +32,27 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 1) throw new WiredSaveException("Missing mode");
int mode = this.getWiredSettings().getIntegerParams()[0];
if(mode != 0 && mode != 1)
throw new WiredSaveException("Mode is invalid");
String dataString = this.getWiredSettings().getStringParam();
String splitBy = "\t";
if(!dataString.contains(splitBy))
throw new WiredSaveException("Malformed data string");
String[] data = dataString.split(Pattern.quote(splitBy));
if (data.length != 2)
throw new WiredSaveException("Malformed data string. Invalid data length");
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.message = data[1].substring(0, Math.min(data[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.mode = mode;
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
String[] stringParams = this.getWiredSettings().getStringParam().split("\t");
String botName = stringParams[0].substring(0, Math.min(stringParams[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
String message = stringParams[1].substring(0, Math.min(stringParams[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
String m = this.message;
m = m.replace(Emulator.getTexts().getValue("wired.variable.username", "%username%"), habbo.getHabboInfo().getUsername())
message = message.replace(Emulator.getTexts().getValue("wired.variable.username", "%username%"), habbo.getHabboInfo().getUsername())
.replace(Emulator.getTexts().getValue("wired.variable.credits", "%credits%"), habbo.getHabboInfo().getCredits() + "")
.replace(Emulator.getTexts().getValue("wired.variable.pixels", "%pixels%"), habbo.getHabboInfo().getPixels() + "")
.replace(Emulator.getTexts().getValue("wired.variable.points", "%points%"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "")
.replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), room.getOwnerName())
.replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), room.itemCount() + "")
.replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.botName)
.replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), botName)
.replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), room.getName())
.replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getUserCount() + "");
List<Bot> bots = room.getBots(this.botName);
List<Bot> bots = room.getBots(botName);
if (bots.size() != 1) {
return false;
@ -96,11 +60,11 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
Bot bot = bots.get(0);
if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ m })) {
if (this.mode == 1) {
bot.whisper(m, habbo);
if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ message })) {
if (this.getWiredSettings().getIntegerParams().get(PARAM_MODE) == 1) {
bot.whisper(message, habbo);
} else {
bot.talk(habbo.getHabboInfo().getUsername() + ": " + m);
bot.talk(habbo.getHabboInfo().getUsername() + ": " + message);
}
}
@ -111,51 +75,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.mode = data.mode;
this.botName = data.bot_name;
this.message = data.message;
}
else {
String[] data = wiredData.split(((char) 9) + "");
if (data.length == 4) {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0;
this.botName = data[2];
this.message = data[3];
}
this.needsUpdate(true);
}
}
@Override
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
String bot_name;
int mode;
String message;
int delay;
public JsonData(String bot_name, int mode, String message, int delay) {
this.bot_name = bot_name;
this.mode = mode;
this.message = message;
this.delay = delay;
}
public WiredEffectType getType() {
return WiredEffectType.BOT_TALK_TO_AVATAR;
}
}

View File

@ -19,24 +19,48 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class WiredEffectBotTeleport extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_TELEPORT;
private THashSet<HabboItem> items;
private String botName = "";
public WiredEffectBotTeleport(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredEffectBotTeleport(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getItemIds().isEmpty()) {
return false;
}
String botName = this.getWiredSettings().getStringParam();
List<Bot> bots = room.getBots(botName);
if (bots.size() == 0) {
return false;
}
Bot bot = bots.get(0);
int i = Emulator.getRandom().nextInt(this.getWiredSettings().getItemIds().size()) + 1;
int j = 1;
for (HabboItem item : this.getWiredSettings().getItems(room)) {
if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
if (i == j) {
teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getX(), item.getY()));
return true;
} else {
j++;
}
}
}
return true;
}
public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) {
@ -80,140 +104,8 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY);
}
@Override
public boolean saveData() throws WiredSaveException {
String botName = this.getWiredSettings().getStringParam();
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it);
}
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.items.clear();
this.items.addAll(newItems);
this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (this.items.isEmpty())
return false;
List<Bot> bots = room.getBots(this.botName);
if (bots.size() != 1) {
return false;
}
Bot bot = bots.get(0);
int i = Emulator.getRandom().nextInt(this.items.size()) + 1;
int j = 1;
for (HabboItem item : this.items) {
if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
if (i == j) {
teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getX(), item.getY()));
return true;
} else {
j++;
}
}
}
return true;
}
@Override
public String getWiredData() {
ArrayList<Integer> itemIds = new ArrayList<>();
if (this.items != null) {
for (HabboItem item : this.items) {
if (item.getRoomId() != 0) {
itemIds.add(item.getId());
}
}
}
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
this.botName = data.bot_name;
for(int itemId : data.items) {
HabboItem item = room.getHabboItem(itemId);
if (item != null)
this.items.add(item);
}
}
else {
String[] wiredDataSplit = set.getString("wired_data").split("\t");
if (wiredDataSplit.length >= 2) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredDataSplit[0]));
String[] data = wiredDataSplit[1].split(";");
if (data.length > 1) {
this.botName = data[0];
for (int i = 1; i < data.length; i++) {
HabboItem item = room.getHabboItem(Integer.parseInt(data[i]));
if (item != null)
this.items.add(item);
}
}
}
this.needsUpdate(true);
}
}
static class JsonData {
String bot_name;
List<Integer> items;
int delay;
public JsonData(String bot_name, List<Integer> items, int delay) {
this.bot_name = bot_name;
this.items = items;
this.delay = delay;
}
return WiredEffectType.BOT_TELEPORT;
}
}

View File

@ -2,18 +2,14 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
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.wired.WiredSettings;
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.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -22,73 +18,32 @@ import java.util.List;
import java.util.stream.Collectors;
public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_MOVE;
private List<HabboItem> items;
private String botName = "";
public WiredEffectBotWalkToFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new ArrayList<>();
}
public WiredEffectBotWalkToFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new ArrayList<>();
}
@Override
public boolean saveData() throws WiredSaveException {
String botName = this.getWiredSettings().getStringParam();
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it);
}
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.items.clear();
this.items.addAll(newItems);
this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
List<Bot> bots = room.getBots(this.botName);
if(this.getWiredSettings().getItemIds().isEmpty()) {
return false;
}
if (this.items.isEmpty() || bots.size() != 1) {
return true;
String botName = this.getWiredSettings().getStringParam();
List<Bot> bots = room.getBots(botName);
if (bots.size() == 0) {
return false;
}
Bot bot = bots.get(0);
this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
this.getWiredSettings().getItems(room).removeIf(item -> item == null || item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
// Bots shouldn't walk to the tile they are already standing on
List<HabboItem> possibleItems = this.items.stream()
List<HabboItem> possibleItems = this.getWiredSettings().getItems(room).stream()
.filter(item -> !room.getBotsOnItem(item).contains(bot))
.collect(Collectors.toList());
@ -105,70 +60,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
}
@Override
public String getWiredData() {
ArrayList<Integer> itemIds = new ArrayList<>();
if (this.items != null) {
for (HabboItem item : this.items) {
if (item.getRoomId() != 0) {
itemIds.add(item.getId());
}
}
}
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items = new ArrayList<>();
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
this.botName = data.bot_name;
for(int itemId : data.items) {
HabboItem item = room.getHabboItem(itemId);
if (item != null)
this.items.add(item);
}
}
else {
String[] wiredDataSplit = set.getString("wired_data").split("\t");
if (wiredDataSplit.length >= 2) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredDataSplit[0]));
String[] data = wiredDataSplit[1].split(";");
if (data.length > 1) {
this.botName = data[0];
for (int i = 1; i < data.length; i++) {
HabboItem item = room.getHabboItem(Integer.parseInt(data[i]));
if (item != null)
this.items.add(item);
}
}
}
this.needsUpdate(true);
}
}
static class JsonData {
String bot_name;
List<Integer> items;
int delay;
public JsonData(String bot_name, List<Integer> items, int delay) {
this.bot_name = bot_name;
this.items = items;
this.delay = delay;
}
public WiredEffectType getType() {
return WiredEffectType.BOT_MOVE;
}
}

View File

@ -1,17 +1,14 @@
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.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredChangeDirectionSetting;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import gnu.trove.map.hash.THashMap;
@ -19,11 +16,11 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
public final int PARAM_START_ROTATION = 0;
public final int PARAM_BLOCKED_ACTION = 1;
public static final int ACTION_WAIT = 0;
public static final int ACTION_TURN_RIGHT_45 = 1;
public static final int ACTION_TURN_RIGHT_90 = 2;
@ -32,12 +29,6 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
public static final int ACTION_TURN_BACK = 5;
public static final int ACTION_TURN_RANDOM = 6;
public static final WiredEffectType type = WiredEffectType.MOVE_DIRECTION;
private final THashMap<HabboItem, WiredChangeDirectionSetting> items = new THashMap<>(0);
private RoomUserRotation startRotation = RoomUserRotation.NORTH;
private int blockedAction = 0;
public WiredEffectChangeFurniDirection(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -48,67 +39,67 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
THashSet<HabboItem> items = new THashSet<>();
for (HabboItem item : this.items.keySet()) {
if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
items.add(item);
if(this.getWiredSettings().getItemIds().isEmpty()) {
return false;
}
for (HabboItem item : items) {
this.items.remove(item);
int startRotationValue = this.getWiredSettings().getIntegerParams().get(PARAM_START_ROTATION);
int blockActionValue = this.getWiredSettings().getIntegerParams().get(PARAM_BLOCKED_ACTION);
if(startRotationValue < 0 || startRotationValue > 7 || (startRotationValue % 2) != 0) {
return false;
}
if (this.items.isEmpty()) return false;
if(blockActionValue < 0 || blockActionValue > 6) {
return false;
}
for (Map.Entry<HabboItem, WiredChangeDirectionSetting> entry : this.items.entrySet()) {
HabboItem item = entry.getKey();
RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().getDirection().getValue());
RoomUserRotation startRotation = RoomUserRotation.fromValue(startRotationValue);
for(HabboItem item : this.getWiredSettings().getItems(room)) {
WiredChangeDirectionSetting setting = new WiredChangeDirectionSetting(item.getId(), item.getRotation(), startRotation);
RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), setting.getDirection().getValue());
int count = 1;
while ((targetTile == null || targetTile.getState() == RoomTileState.INVALID || room.furnitureFitsAt(targetTile, item, item.getRotation(), false) != FurnitureMovementError.NONE) && count < 8) {
entry.getValue().setDirection(this.nextRotation(entry.getValue().getDirection()));
setting.setDirection(this.nextRotation(setting.getDirection()));
RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().getDirection().getValue());
RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), setting.getDirection().getValue());
if (tile != null && tile.getState() != RoomTileState.INVALID) {
targetTile = tile;
}
count++;
}
}
for (Map.Entry<HabboItem, WiredChangeDirectionSetting> entry : this.items.entrySet()) {
HabboItem item = entry.getKey();
int newDirection = entry.getValue().getDirection().getValue();
int newDirectionValue = setting.getDirection().getValue();
RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), newDirection);
RoomTile newTargetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), newDirectionValue);
if(item.getRotation() != entry.getValue().getRotation()) {
if(room.furnitureFitsAt(targetTile, item, entry.getValue().getRotation(), false) != FurnitureMovementError.NONE)
if(item.getRotation() != setting.getRotation()) {
if(room.furnitureFitsAt(newTargetTile, item, setting.getRotation(), false) != FurnitureMovementError.NONE)
continue;
room.moveFurniTo(entry.getKey(), targetTile, entry.getValue().getRotation(), null, true);
room.moveFurniTo(item, newTargetTile, setting.getRotation(), null, true);
}
boolean hasRoomUnits = false;
THashSet<RoomTile> newOccupiedTiles = room.getLayout().getTilesAt(targetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
THashSet<RoomTile> newOccupiedTiles = room.getLayout().getTilesAt(newTargetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
for(RoomTile tile : newOccupiedTiles) {
for (RoomUnit _roomUnit : room.getRoomUnits(tile)) {
hasRoomUnits = true;
if(_roomUnit.getCurrentLocation() == targetTile) {
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{entry.getKey()}));
if(_roomUnit.getCurrentLocation() == newTargetTile) {
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{item}));
break;
}
}
}
if (targetTile != null && targetTile.getState() != RoomTileState.INVALID && room.furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) {
if (newTargetTile != null && newTargetTile.getState() != RoomTileState.INVALID && room.furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) {
if (!hasRoomUnits) {
RoomTile oldLocation = room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY());
double oldZ = entry.getKey().getZ();
if(room.moveFurniTo(entry.getKey(), targetTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
room.sendComposer(new FloorItemOnRollerComposer(entry.getKey(), null, oldLocation, oldZ, targetTile, entry.getKey().getZ(), 0, room).compose());
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
double oldZ = item.getZ();
if(room.moveFurniTo(item, newTargetTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, targetTile, item.getZ(), 0, room).compose());
}
}
}
@ -117,129 +108,11 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
return false;
}
@Override
public String getWiredData() {
ArrayList<WiredChangeDirectionSetting> settings = new ArrayList<>(this.items.values());
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if(wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
this.startRotation = data.start_direction;
this.blockedAction = data.blocked_action;
for(WiredChangeDirectionSetting setting : data.items) {
HabboItem item = room.getHabboItem(setting.getItem_id());
if (item != null) {
this.items.put(item, setting);
}
}
}
else {
String[] data = wiredData.split("\t");
if (data.length >= 4) {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
this.startRotation = RoomUserRotation.fromValue(Integer.parseInt(data[1]));
this.blockedAction = Integer.parseInt(data[2]);
int itemCount = Integer.parseInt(data[3]);
if (itemCount > 0) {
for (int i = 4; i < data.length; i++) {
String[] subData = data[i].split(":");
if (subData.length >= 2) {
HabboItem item = room.getHabboItem(Integer.parseInt(subData[0]));
if (item != null) {
int rotation = item.getRotation();
if (subData.length > 2) {
rotation = Integer.parseInt(subData[2]);
}
this.items.put(item, new WiredChangeDirectionSetting(item.getId(), rotation, RoomUserRotation.fromValue(Integer.parseInt(subData[1]))));
}
}
}
}
}
this.needsUpdate(true);
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 2) throw new WiredSaveException("Invalid data");
int startDirectionInt = this.getWiredSettings().getIntegerParams()[0];
if(startDirectionInt < 0 || startDirectionInt > 7 || (startDirectionInt % 2) != 0) {
throw new WiredSaveException("Start direction is invalid");
}
RoomUserRotation startDirection = RoomUserRotation.fromValue(startDirectionInt);
int blockedActionInt = this.getWiredSettings().getIntegerParams()[1];
if(blockedActionInt < 0 || blockedActionInt > 6) {
throw new WiredSaveException("Blocked action is invalid");
}
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
THashMap<HabboItem, WiredChangeDirectionSetting> newItems = new THashMap<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.put(it, new WiredChangeDirectionSetting(it.getId(), it.getRotation(), startDirection));
}
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.items.clear();
this.items.putAll(newItems);
this.startRotation = startDirection;
this.blockedAction = blockedActionInt;
this.getWiredSettings().setDelay(delay);
return true;
}
private RoomUserRotation nextRotation(RoomUserRotation currentRotation) {
return switch (this.blockedAction) {
return switch (this.getWiredSettings().getIntegerParams().get(PARAM_BLOCKED_ACTION)) {
case ACTION_TURN_BACK -> RoomUserRotation.fromValue(currentRotation.getValue()).getOpposite();
case ACTION_TURN_LEFT_45 -> RoomUserRotation.counterClockwise(currentRotation);
case ACTION_TURN_LEFT_90 ->
RoomUserRotation.counterClockwise(RoomUserRotation.counterClockwise(currentRotation));
case ACTION_TURN_LEFT_90 -> RoomUserRotation.counterClockwise(RoomUserRotation.counterClockwise(currentRotation));
case ACTION_TURN_RIGHT_45 -> RoomUserRotation.clockwise(currentRotation);
case ACTION_TURN_RIGHT_90 -> RoomUserRotation.clockwise(RoomUserRotation.clockwise(currentRotation));
case ACTION_TURN_RANDOM -> RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8));
@ -253,17 +126,8 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
return 495;
}
static class JsonData {
RoomUserRotation start_direction;
int blocked_action;
List<WiredChangeDirectionSetting> items;
int delay;
public JsonData(RoomUserRotation start_direction, int blocked_action, List<WiredChangeDirectionSetting> items, int delay) {
this.start_direction = start_direction;
this.blocked_action = blocked_action;
this.items = items;
this.delay = delay;
}
@Override
public WiredEffectType getType() {
return WiredEffectType.MOVE_DIRECTION;
}
}

View File

@ -18,6 +18,10 @@ public class WiredEffectGiveEffect extends WiredEffectWhisper {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getStringParam().isEmpty()) {
return false;
}
int effectId;
try {

View File

@ -19,6 +19,10 @@ public class WiredEffectGiveHandItem extends WiredEffectWhisper {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getStringParam().isEmpty()) {
return false;
}
try {
int itemId = Integer.parseInt(this.getWiredSettings().getStringParam());

View File

@ -18,11 +18,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
private int amount = 0;
public class WiredEffectGiveHotelviewBonusRarePoints extends WiredEffectWhisper {
public WiredEffectGiveHotelviewBonusRarePoints(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -32,76 +28,30 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
}
@Override
public boolean saveData() {
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getStringParam().isEmpty()) {
return false;
}
int amount;
try {
this.amount = Integer.parseInt(this.getWiredSettings().getStringParam());
amount = Integer.parseInt(this.getWiredSettings().getStringParam());
} catch (Exception e) {
return false;
}
this.getWiredSettings().setDelay(this.getWiredSettings().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)
if (habbo == null) {
return false;
}
if (this.amount > 0) {
habbo.givePoints(Emulator.getConfig().getInt("hotelview.promotional.points.type"), this.amount);
if (amount > 0) {
habbo.givePoints(Emulator.getConfig().getInt("hotelview.promotional.points.type"), amount);
habbo.getClient().sendResponse(new BonusRareInfoMessageComposer(habbo));
}
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getWiredSettings().getDelay(), this.amount));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
String wiredData = set.getString("wired_data");
this.amount = 0;
if(wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
this.amount = data.amount;
} else {
if (wiredData.split("\t").length >= 2) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredData.split("\t")[0]));
try {
this.amount = Integer.parseInt(wiredData.split("\t")[1]);
} catch (Exception ignored) {
}
}
}
}
@Override
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
int delay;
int amount;
public JsonData(int delay, int amount) {
this.delay = delay;
this.amount = amount;
}
}
}

View File

@ -18,10 +18,6 @@ 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);
}
@ -31,32 +27,27 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
}
@Override
public boolean saveData() {
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getStringParam().isEmpty()) {
return false;
}
int amount;
try {
this.amount = Integer.parseInt(this.getWiredSettings().getStringParam());
amount = Integer.parseInt(this.getWiredSettings().getStringParam());
} catch (Exception e) {
return false;
}
this.getWiredSettings().setDelay(this.getWiredSettings().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)
if (habbo == null) {
return false;
}
if (this.amount > 0) {
habbo.getHabboStats().hofPoints += this.amount;
if (amount > 0) {
habbo.getHabboStats().hofPoints += amount;
Emulator.getThreading().run(habbo.getHabboStats());
}
@ -64,47 +55,7 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.amount, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
}
else {
this.amount = 0;
if (wiredData.split("\t").length >= 2) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredData.split("\t")[0]));
try {
this.amount = Integer.parseInt(this.getWiredData().split("\t")[1]);
} catch (Exception ignored) {
}
}
this.needsUpdate(true);
}
}
@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;
}
public WiredEffectType getType() {
return WiredEffectType.SHOW_MESSAGE;
}
}

View File

@ -19,10 +19,6 @@ import java.util.ArrayList;
import java.util.List;
public class WiredEffectGiveRespect extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
private int respects = 0;
public WiredEffectGiveRespect(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -30,81 +26,34 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
public WiredEffectGiveRespect(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() {
try {
this.respects = Integer.parseInt(this.getWiredSettings().getStringParam());
} catch (Exception e) {
return false;
}
this.getWiredSettings().setDelay(this.getWiredSettings().getDelay());
return true;
}
@Override
public WiredEffectType getType() {
return type;
return WiredEffectType.SHOW_MESSAGE;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getStringParam().isEmpty()) {
return false;
}
int respects;
try {
respects = Integer.parseInt(this.getWiredSettings().getStringParam());
} catch (Exception e) {
return false;
}
Habbo habbo = room.getHabbo(roomUnit);
if (habbo == null)
if (habbo == null) {
return false;
}
habbo.getHabboStats().increaseRespectPointsReceived(respects);
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectEarned"), this.respects);
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectEarned"), respects);
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.respects, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.respects = data.amount;
this.getWiredSettings().setDelay(data.delay);
}
else {
String[] data = wiredData.split("\t");
this.respects = 0;
if (data.length >= 2) {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
try {
this.respects = Integer.parseInt(data[1]);
} catch (Exception ignored) {
}
}
this.needsUpdate(true);
}
}
@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;
}
}
}

View File

@ -30,13 +30,12 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
public final static int LIMIT_N_DAY = 1;
public final static int LIMIT_N_HOURS = 2;
public final static int LIMIT_N_MINUTES = 3;
private final static WiredEffectType type = WiredEffectType.GIVE_REWARD;
private int limit;
private int limitationInterval;
public final int PARAM_REWARD_LIMIT = 0;
public final int PARAM_UNIQUE_REWARD = 1;
public final int PARAM_LIMIT = 2;
public final int PARAM_LIMITATION_INTERVAL = 3;
public THashSet<WiredGiveRewardItem> rewardItems = new THashSet<>();
private int given;
private int rewardTime;
private boolean uniqueRewards;
private final THashSet<WiredGiveRewardItem> rewardItems = new THashSet<>();
public WiredEffectGiveReward(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -48,115 +47,49 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int rewardTime = this.getWiredSettings().getIntegerParams().get(PARAM_REWARD_LIMIT);
boolean uniqueRewards = this.getWiredSettings().getIntegerParams().get(PARAM_UNIQUE_REWARD) == 1;
int limit = this.getWiredSettings().getIntegerParams().get(PARAM_LIMIT);
int limitationInterval = this.getWiredSettings().getIntegerParams().get(PARAM_LIMITATION_INTERVAL);
String data = this.getWiredSettings().getStringParam();
String[] items = data.split(";");
int i = 1;
for(String item : items) {
String[] d = item.split(",");
if(d.length == 3) {
if(!(d[1].contains(":") || d[1].contains(";"))) {
this.rewardItems.add(new WiredGiveRewardItem(i, d[0].equalsIgnoreCase("0"), d[1], Integer.valueOf(d[2])));
continue;
}
}
return false;
}
Habbo habbo = room.getHabbo(roomUnit);
return habbo != null && WiredHandler.getReward(habbo, this);
}
@Override
public String getWiredData() {
ArrayList<WiredGiveRewardItem> rewards = new ArrayList<>(this.rewardItems);
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getWiredSettings().getDelay()));
public int getLimit() {
return this.getWiredSettings().getIntegerParams().get(PARAM_LIMIT);
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.limit = data.limit;
this.given = data.given;
this.rewardTime = data.reward_time;
this.uniqueRewards = data.unique_rewards;
this.limitationInterval = data.limit_interval;
this.rewardItems.clear();
this.rewardItems.addAll(data.rewards);
} else {
String[] data = wiredData.split(":");
if (data.length > 0) {
this.limit = Integer.parseInt(data[0]);
this.given = Integer.parseInt(data[1]);
this.rewardTime = Integer.parseInt(data[2]);
this.uniqueRewards = data[3].equals("1");
this.limitationInterval = Integer.parseInt(data[4]);
this.getWiredSettings().setDelay(Integer.parseInt(data[5]));
if (data.length > 6) {
if (!data[6].equalsIgnoreCase("\t")) {
String[] items = data[6].split(";");
this.rewardItems.clear();
for (String s : items) {
try {
this.rewardItems.add(new WiredGiveRewardItem(s));
} catch (Exception ignored) {
}
}
}
}
this.needsUpdate(true);
}
}
public int getRewardTime() {
return this.getWiredSettings().getIntegerParams().get(PARAM_REWARD_LIMIT);
}
@Override
public WiredEffectType getType() {
return type;
public boolean isUniqueRewards() {
return this.getWiredSettings().getIntegerParams().get(PARAM_UNIQUE_REWARD) == 1;
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
super.onClick(client, room, objects);
if (client.getHabbo().hasRight(Permission.ACC_SUPERWIRED)) {
client.getHabbo().whisper(Emulator.getTexts().getValue("hotel.wired.superwired.info"), RoomChatMessageBubbles.BOT);
}
}
@Override
public boolean saveData() throws WiredSaveException {
if (this.getWiredSettings().getIntegerParams().length < 4) throw new WiredSaveException("Invalid data");
this.rewardTime = this.getWiredSettings().getIntegerParams()[0];
this.uniqueRewards = this.getWiredSettings().getIntegerParams()[1] == 1;
this.limit = this.getWiredSettings().getIntegerParams()[2];
this.limitationInterval = this.getWiredSettings().getIntegerParams()[3];
this.given = 0;
String data = this.getWiredSettings().getStringParam();
String[] items = data.split(";");
this.rewardItems.clear();
int i = 1;
for (String s : items) {
String[] d = s.split(",");
if (d.length == 3) {
if (!(d[1].contains(":") || d[1].contains(";"))) {
this.rewardItems.add(new WiredGiveRewardItem(i, d[0].equalsIgnoreCase("0"), d[1], Integer.parseInt(d[2])));
continue;
}
}
//TODO THROW ERROR
// gameClient.sendResponse(new WiredValidationErrorComposer(Emulator.getTexts().getValue("alert.superwired.invalid")));
return false;
}
this.getWiredSettings().setDelay(this.getWiredSettings().getDelay());
WiredHandler.dropRewards(this.getId());
return true;
}
@Override
public boolean requiresTriggeringUser() {
return true;
public int getLimitationInterval() {
return this.getWiredSettings().getIntegerParams().get(PARAM_LIMITATION_INTERVAL);
}
@Override
@ -165,26 +98,11 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
}
public void incrementGiven() {
given++;
this.given++;
}
static class JsonData {
int limit;
int given;
int reward_time;
boolean unique_rewards;
int limit_interval;
List<WiredGiveRewardItem> rewards;
int delay;
public JsonData(int limit, int given, int reward_time, boolean unique_rewards, int limit_interval, List<WiredGiveRewardItem> rewards, int delay) {
this.limit = limit;
this.given = given;
this.reward_time = reward_time;
this.unique_rewards = unique_rewards;
this.limit_interval = limit_interval;
this.rewards = rewards;
this.delay = delay;
}
@Override
public WiredEffectType getType() {
return WiredEffectType.GIVE_REWARD;
}
}
}

View File

@ -1,17 +1,14 @@
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.games.Game;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
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.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.iterator.TObjectIntIterator;
import gnu.trove.map.TObjectIntMap;
@ -20,16 +17,11 @@ import gnu.trove.map.hash.TObjectIntHashMap;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class WiredEffectGiveScore extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.GIVE_SCORE;
private int score;
private int count;
public final int PARAM_SCORE = 0;
public final int PARAM_TIMES_PER_GAME = 1;
private final TObjectIntMap<Map.Entry<Integer, Integer>> data = new TObjectIntHashMap<>();
public WiredEffectGiveScore(ResultSet set, Item baseItem) throws SQLException {
@ -42,6 +34,17 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int score = this.getWiredSettings().getIntegerParams().get(PARAM_SCORE);
int timesPerGame = this.getWiredSettings().getIntegerParams().get(PARAM_TIMES_PER_GAME);
if(score < 1 || score > 100) {
return false;
}
if(timesPerGame < 1 || timesPerGame > 10) {
return false;
}
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null && habbo.getHabboInfo().getCurrentGame() != null) {
@ -63,10 +66,10 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
if (map.getValue() == habbo.getHabboInfo().getId()) {
if (map.getKey() == gameStartTime) {
if (iterator.value() < this.count) {
if (iterator.value() < timesPerGame) {
iterator.setValue(iterator.value() + 1);
habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);
habbo.getHabboInfo().getGamePlayer().addScore(score, true);
return true;
}
@ -85,7 +88,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
if (habbo.getHabboInfo().getGamePlayer() != null) {
habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);
habbo.getHabboInfo().getGamePlayer().addScore(score, true);
}
return true;
@ -94,79 +97,8 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.score, this.count, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.score = data.score;
this.count = data.count;
this.getWiredSettings().setDelay(data.delay);
}
else {
String[] data = wiredData.split(";");
if (data.length == 3) {
this.score = Integer.parseInt(data[0]);
this.count = Integer.parseInt(data[1]);
this.getWiredSettings().setDelay(Integer.parseInt(data[2]));
}
this.needsUpdate(true);
}
}
@Override
public WiredEffectType getType() {
return WiredEffectGiveScore.type;
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 2) throw new WiredSaveException("Invalid data");
int score = this.getWiredSettings().getIntegerParams()[0];
if(score < 1 || score > 100)
throw new WiredSaveException("Score is invalid");
int timesPerGame = this.getWiredSettings().getIntegerParams()[1];
if(timesPerGame < 1 || timesPerGame > 10)
throw new WiredSaveException("Times per game is invalid");
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.score = score;
this.count = timesPerGame;
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
int score;
int count;
int delay;
public JsonData(int score, int count, int delay) {
this.score = score;
this.count = count;
this.delay = delay;
}
return WiredEffectType.GIVE_SCORE;
}
}

View File

@ -1,19 +1,16 @@
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.games.Game;
import com.eu.habbo.habbohotel.games.GameState;
import com.eu.habbo.habbohotel.games.GameTeam;
import com.eu.habbo.habbohotel.games.GameTeamColors;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
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.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.map.hash.TIntIntHashMap;
@ -21,12 +18,9 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.GIVE_SCORE_TEAM;
private int points;
private int count;
private GameTeamColors teamColor = GameTeamColors.RED;
public final int PARAM_SCORE = 0;
public final int PARAM_TIMES_PER_GAME = 1;
public final int PARAM_TEAM = 2;
private final TIntIntHashMap startTimes = new TIntIntHashMap();
public WiredEffectGiveScoreToTeam(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
@ -39,16 +33,33 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int score = this.getWiredSettings().getIntegerParams().get(PARAM_SCORE);
int timesPerGame = this.getWiredSettings().getIntegerParams().get(PARAM_TIMES_PER_GAME);
int teamValue = this.getWiredSettings().getIntegerParams().get(PARAM_TEAM);
if(score < 1 || score > 100) {
return false;
}
if(timesPerGame < 1 || timesPerGame > 10) {
return false;
}
if(teamValue < 1 || teamValue > 4) {
return false;
}
GameTeamColors teamColor = GameTeamColors.values()[teamValue];
for (Game game : room.getGames()) {
if (game != null && game.state.equals(GameState.RUNNING)) {
int c = this.startTimes.get(game.getStartTime());
if (c < this.count) {
GameTeam team = game.getTeam(this.teamColor);
if (c < timesPerGame) {
GameTeam team = game.getTeam(teamColor);
if (team != null) {
team.addTeamScore(this.points);
team.addTeamScore(score);
this.startTimes.put(game.getStartTime(), c + 1);
}
}
@ -58,84 +69,8 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.points, this.count, this.teamColor, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.points = data.score;
this.count = data.count;
this.teamColor = data.team;
this.getWiredSettings().setDelay(data.delay);
}
else {
String[] data = set.getString("wired_data").split(";");
if (data.length == 4) {
this.points = Integer.parseInt(data[0]);
this.count = Integer.parseInt(data[1]);
this.teamColor = GameTeamColors.values()[Integer.parseInt(data[2])];
this.getWiredSettings().setDelay(Integer.parseInt(data[3]));
}
this.needsUpdate(true);
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 3) throw new WiredSaveException("Invalid data");
int points = this.getWiredSettings().getIntegerParams()[0];
if(points < 1 || points > 100)
throw new WiredSaveException("Points is invalid");
int timesPerGame = this.getWiredSettings().getIntegerParams()[1];
if(timesPerGame < 1 || timesPerGame > 10)
throw new WiredSaveException("Times per game is invalid");
int team = this.getWiredSettings().getIntegerParams()[2];
if(team < 1 || team > 4)
throw new WiredSaveException("Team is invalid");
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.points = points;
this.count = timesPerGame;
this.teamColor = GameTeamColors.values()[team];
this.getWiredSettings().setDelay(delay);
return true;
}
static class JsonData {
int score;
int count;
GameTeamColors team;
int delay;
public JsonData(int score, int count, GameTeamColors team, int delay) {
this.score = score;
this.count = count;
this.team = team;
this.delay = delay;
}
return WiredEffectType.GIVE_SCORE_TEAM;
}
}

View File

@ -22,9 +22,7 @@ import java.util.ArrayList;
import java.util.List;
public class WiredEffectJoinTeam extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.JOIN_TEAM;
private GameTeamColors teamColor = GameTeamColors.RED;
public final int PARAM_TEAM = 0;
public WiredEffectJoinTeam(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -36,19 +34,26 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int teamValue = this.getWiredSettings().getIntegerParams().get(PARAM_TEAM);
if(teamValue < 1 || teamValue > 4) {
return false;
}
GameTeamColors teamColor = GameTeamColors.values()[teamValue];
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
WiredGame game = (WiredGame) room.getGameOrCreate(WiredGame.class);
if (habbo.getHabboInfo().getGamePlayer() != null && habbo.getHabboInfo().getCurrentGame() != null && (habbo.getHabboInfo().getCurrentGame() != WiredGame.class || (habbo.getHabboInfo().getCurrentGame() == WiredGame.class && habbo.getHabboInfo().getGamePlayer().getTeamColor() != this.teamColor))) {
// remove from current game
if (habbo.getHabboInfo().getGamePlayer() != null && habbo.getHabboInfo().getCurrentGame() != null && (habbo.getHabboInfo().getCurrentGame() != WiredGame.class || (habbo.getHabboInfo().getCurrentGame() == WiredGame.class && habbo.getHabboInfo().getGamePlayer().getTeamColor() != teamColor))) {
Game currentGame = room.getGame(habbo.getHabboInfo().getCurrentGame());
currentGame.removeHabbo(habbo);
}
if(habbo.getHabboInfo().getGamePlayer() == null) {
game.addHabbo(habbo, this.teamColor);
game.addHabbo(habbo, teamColor);
}
return true;
@ -57,72 +62,8 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.teamColor, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.teamColor = data.team;
}
else {
String[] data = set.getString("wired_data").split("\t");
if (data.length >= 1) {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
if (data.length >= 2) {
this.teamColor = GameTeamColors.values()[Integer.parseInt(data[1])];
}
}
this.needsUpdate(true);
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 1) throw new WiredSaveException("invalid data");
int team = this.getWiredSettings().getIntegerParams()[0];
if(team < 1 || team > 4)
throw new WiredSaveException("Team is invalid");
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.teamColor = GameTeamColors.values()[team];
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
GameTeamColors team;
int delay;
public JsonData(GameTeamColors team, int delay) {
this.team = team;
this.delay = delay;
}
return WiredEffectType.JOIN_TEAM;
}
}

View File

@ -24,10 +24,6 @@ import java.util.ArrayList;
import java.util.List;
public class WiredEffectKickHabbo extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.KICK_USER;
private String message = "";
public WiredEffectKickHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -56,8 +52,9 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
room.giveEffect(habbo, 4, 2);
if (!this.message.isEmpty())
habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.message, habbo, habbo, RoomChatMessageBubbles.ALERT)));
if (!this.getWiredSettings().getStringParam().isEmpty()) {
habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.getWiredSettings().getStringParam(), habbo, habbo, RoomChatMessageBubbles.ALERT)));
}
Emulator.getThreading().run(new RoomUnitKick(habbo, room, true), 2000);
@ -67,71 +64,8 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.message = data.message;
}
else {
try {
String[] data = set.getString("wired_data").split("\t");
if (data.length >= 1) {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
if (data.length >= 2) {
this.message = data[1];
}
}
} catch (Exception e) {
this.message = "";
this.getWiredSettings().setDelay(0);
}
this.needsUpdate(true);
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
String message = this.getWiredSettings().getStringParam();
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.message = message.substring(0, Math.min(message.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
String message;
int delay;
public JsonData(String message, int delay) {
this.message = message;
this.delay = delay;
}
return WiredEffectType.KICK_USER;
}
}

View File

@ -21,8 +21,6 @@ import java.util.ArrayList;
import java.util.List;
public class WiredEffectLeaveTeam extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.LEAVE_TEAM;
public WiredEffectLeaveTeam(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -52,45 +50,8 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
}
else {
this.getWiredSettings().setDelay(Integer.parseInt(wiredData));
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.getWiredSettings().setDelay(delay);
return true;
}
static class JsonData {
int delay;
public JsonData(int delay) {
this.delay = delay;
}
return WiredEffectType.LEAVE_TEAM;
}
}

View File

@ -1,20 +1,18 @@
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.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings;
import com.eu.habbo.habbohotel.rooms.*;
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.habbohotel.wired.WiredMatchFurniSetting;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import gnu.trove.set.hash.THashSet;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.sql.ResultSet;
@ -25,219 +23,86 @@ import java.util.regex.Pattern;
@Slf4j
public class WiredEffectMatchFurni extends InteractionWiredEffect implements InteractionWiredMatchFurniSettings {
private static final WiredEffectType type = WiredEffectType.MATCH_SSHOT;
private final boolean checkForWiredResetPermission = true;
private final THashSet<WiredMatchFurniSetting> wiredMatchSettings;
private boolean state = false;
private boolean direction = false;
private boolean position = false;
public final int PARAM_STATE = 0;
public final int PARAM_ROTATION = 1;
public final int PARAM_POSITION = 2;
@Getter
private THashSet<WiredMatchFurniSetting> matchFurniSettings;
public WiredEffectMatchFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.wiredMatchSettings = new THashSet<>(0);
}
public WiredEffectMatchFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.wiredMatchSettings = new THashSet<>(0);
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.wiredMatchSettings.isEmpty())
if(this.getWiredSettings().getItemIds().isEmpty()) {
return true;
}
for (WiredMatchFurniSetting setting : this.wiredMatchSettings) {
HabboItem item = room.getHabboItem(setting.getItem_id());
if (item != null) {
if (this.state && (this.checkForWiredResetPermission && item.allowWiredResetState())) {
if (!setting.getState().equals(" ") && !item.getExtradata().equals(setting.getState())) {
item.setExtradata(setting.getState());
room.updateItemState(item);
}
boolean state = this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1;
boolean position = this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1;
boolean rotation = this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1;
for(HabboItem item : this.getWiredSettings().getItems(room)) {
WiredMatchFurniSetting setting = new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY());
this.matchFurniSettings.add(setting);
if (state && (this.checkForWiredResetPermission && item.allowWiredResetState())) {
if (!setting.getState().equals(" ") && !item.getExtradata().equals(setting.getState())) {
item.setExtradata(setting.getState());
room.updateItemState(item);
}
}
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
double oldZ = item.getZ();
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
double oldZ = item.getZ();
if(this.direction && !this.position) {
if(item.getRotation() != setting.getRotation() && room.furnitureFitsAt(oldLocation, item, setting.getRotation(), false) == FurnitureMovementError.NONE) {
room.moveFurniTo(item, oldLocation, setting.getRotation(), null, true);
}
if(rotation && !position) {
if(item.getRotation() != setting.getRotation() && room.furnitureFitsAt(oldLocation, item, setting.getRotation(), false) == FurnitureMovementError.NONE) {
room.moveFurniTo(item, oldLocation, setting.getRotation(), null, true);
}
else if(this.position) {
boolean slideAnimation = !this.direction || item.getRotation() == setting.getRotation();
RoomTile newLocation = room.getLayout().getTile((short) setting.getX(), (short) setting.getY());
int newRotation = this.direction ? setting.getRotation() : item.getRotation();
}
else if(position) {
boolean slideAnimation = !rotation || item.getRotation() == setting.getRotation();
RoomTile newLocation = room.getLayout().getTile((short) setting.getX(), (short) setting.getY());
int newRotation = rotation ? setting.getRotation() : item.getRotation();
if(newLocation != null && newLocation.getState() != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && room.furnitureFitsAt(newLocation, item, newRotation, true) == FurnitureMovementError.NONE) {
if(room.moveFurniTo(item, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) {
if(slideAnimation) {
room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose());
}
if(newLocation != null && newLocation.getState() != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && room.furnitureFitsAt(newLocation, item, newRotation, true) == FurnitureMovementError.NONE) {
if(room.moveFurniTo(item, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) {
if(slideAnimation) {
room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose());
}
}
}
}
}
return true;
}
@Override
public String getWiredData() {
this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList<>(this.wiredMatchSettings), this.getWiredSettings().getDelay()));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.state = data.state;
this.direction = data.direction;
this.position = data.position;
this.wiredMatchSettings.clear();
this.wiredMatchSettings.addAll(data.items);
}
else {
String[] data = set.getString("wired_data").split(":");
int itemCount = Integer.parseInt(data[0]);
String[] items = data[1].split(Pattern.quote(";"));
for (String item : items) {
try {
String[] stuff = item.split(Pattern.quote("-"));
if (stuff.length >= 5) {
this.wiredMatchSettings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4])));
}
} catch (Exception e) {
log.error("Caught exception", e);
}
}
this.state = data[2].equals("1");
this.direction = data[3].equals("1");
this.position = data[4].equals("1");
this.getWiredSettings().setDelay(Integer.parseInt(data[5]));
this.needsUpdate(true);
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 3) throw new WiredSaveException("Invalid data");
boolean setState = this.getWiredSettings().getIntegerParams()[0] == 1;
boolean setDirection = this.getWiredSettings().getIntegerParams()[1] == 1;
boolean setPosition = this.getWiredSettings().getIntegerParams()[2] == 1;
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null)
throw new WiredSaveException("Trying to save wired in unloaded room");
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
List<WiredMatchFurniSetting> newSettings = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
newSettings.add(new WiredMatchFurniSetting(it.getId(), this.checkForWiredResetPermission && it.allowWiredResetState() ? it.getExtradata() : " ", it.getRotation(), it.getX(), it.getY()));
}
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.state = setState;
this.direction = setDirection;
this.position = setPosition;
this.wiredMatchSettings.clear();
this.wiredMatchSettings.addAll(newSettings);
this.getWiredSettings().setDelay(delay);
return true;
}
private void refresh() {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null && room.isLoaded()) {
THashSet<WiredMatchFurniSetting> remove = new THashSet<>();
for (WiredMatchFurniSetting setting : this.wiredMatchSettings) {
HabboItem item = room.getHabboItem(setting.getItem_id());
if (item == null) {
remove.add(setting);
}
}
for (WiredMatchFurniSetting setting : remove) {
this.wiredMatchSettings.remove(setting);
}
}
}
@Override
public THashSet<WiredMatchFurniSetting> getMatchFurniSettings() {
return this.wiredMatchSettings;
}
@Override
public boolean shouldMatchState() {
return this.state;
return this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1;
}
@Override
public boolean shouldMatchRotation() {
return this.direction;
return this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1;
}
@Override
public boolean shouldMatchPosition() {
return this.position;
return this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1;
}
static class JsonData {
boolean state;
boolean direction;
boolean position;
List<WiredMatchFurniSetting> items;
int delay;
public JsonData(boolean state, boolean direction, boolean position, List<WiredMatchFurniSetting> items, int delay) {
this.state = state;
this.direction = direction;
this.position = position;
this.items = items;
this.delay = delay;
}
@Override
public WiredEffectType getType() {
return WiredEffectType.MATCH_SSHOT;
}
}

View File

@ -1,32 +1,20 @@
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.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.*;
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.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.FLEE;
private THashSet<HabboItem> items = new THashSet<>();
public WiredEffectMoveFurniAway(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -37,16 +25,7 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
THashSet<HabboItem> items = new THashSet<>();
for (HabboItem item : this.items) {
if (item.getRoomId() == 0)
items.add(item);
}
this.items.removeAll(items);
for (HabboItem item : this.items) {
for (HabboItem item : this.getWiredSettings().getItems(room)) {
RoomTile t = room.getLayout().getTile(item.getX(), item.getY());
RoomUnit target = room.getRoomUnits().stream().min(Comparator.comparingDouble(a -> a.getCurrentLocation().distance(t))).orElse(null);
@ -96,96 +75,13 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getWiredSettings().getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (wiredDataOld.length >= 1) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it);
}
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.items.clear();
this.items.addAll(newItems);
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
protected long requiredCooldown() {
return 495;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
@Override
public WiredEffectType getType() {
return WiredEffectType.FLEE;
}
}

View File

@ -1,17 +1,14 @@
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.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
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.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import gnu.trove.set.hash.THashSet;
@ -25,11 +22,8 @@ import java.util.Map;
import java.util.stream.Collectors;
public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.MOVE_FURNI_TO;
private final List<HabboItem> items = new ArrayList<>();
private int direction;
private int spacing = 1;
private final Map<Integer, Integer> indexOffset = new LinkedHashMap<>();
public final int PARAM_DIRECTION = 0;
public final int PARAM_SPACING = 1;
public WiredEffectMoveFurniTo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -39,80 +33,44 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() throws WiredSaveException {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null)
return false;
this.items.clear();
this.indexOffset.clear();
if(this.getWiredSettings().getIntegerParams().length < 2) throw new WiredSaveException("invalid data");
this.direction = this.getWiredSettings().getIntegerParams()[0];
this.spacing = this.getWiredSettings().getIntegerParams()[1];
int count = this.getWiredSettings().getItems().length;
for (int i = 0; i < count; i++) {
this.items.add(room.getHabboItem(this.getWiredSettings().getItems()[i]));
}
this.getWiredSettings().setDelay(this.getWiredSettings().getDelay());
return true;
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
List<HabboItem> items = new ArrayList<>();
for (HabboItem item : this.items) {
if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
items.add(item);
}
for (HabboItem item : items) {
this.items.remove(item);
}
if (this.items.isEmpty())
if(this.getWiredSettings().getItemIds().isEmpty()) {
return false;
}
if (stuff != null && stuff.length > 0) {
for (Object object : stuff) {
if (object instanceof HabboItem) {
HabboItem targetItem = this.items.get(Emulator.getRandom().nextInt(this.items.size()));
if(stuff == null || stuff.length == 0) {
return false;
}
if (targetItem != null) {
int indexOffset = 0;
if (!this.indexOffset.containsKey(targetItem.getId())) {
this.indexOffset.put(targetItem.getId(), indexOffset);
} else {
indexOffset = this.indexOffset.get(targetItem.getId()) + this.spacing;
int direction = this.getWiredSettings().getIntegerParams().get(PARAM_DIRECTION);
int spacing = this.getWiredSettings().getIntegerParams().get(PARAM_SPACING);
for (Object object : stuff) {
if (object instanceof HabboItem) {
int randomItemIndex = Emulator.getRandom().nextInt(this.getWiredSettings().getItemIds().size());
HabboItem[] items = this.getWiredSettings().getItems(room).toArray(new HabboItem[this.getWiredSettings().getItemIds().size()]);
HabboItem randomItem = items[randomItemIndex];
if (randomItem != null) {
int indexOffset = 0;
RoomTile objectTile = room.getLayout().getTile(randomItem.getX(), randomItem.getY());
if (objectTile != null) {
THashSet<RoomTile> refreshTiles = room.getLayout().getTilesAt(room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY()), ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation());
RoomTile tile = room.getLayout().getTileInFront(objectTile, direction, indexOffset);
if (tile == null || !tile.getAllowStack()) {
indexOffset = 0;
tile = room.getLayout().getTileInFront(objectTile, direction, indexOffset);
}
RoomTile objectTile = room.getLayout().getTile(targetItem.getX(), targetItem.getY());
if (objectTile != null) {
THashSet<RoomTile> refreshTiles = room.getLayout().getTilesAt(room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY()), ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation());
RoomTile tile = room.getLayout().getTileInFront(objectTile, this.direction, indexOffset);
if (tile == null || !tile.getAllowStack()) {
indexOffset = 0;
tile = room.getLayout().getTileInFront(objectTile, this.direction, indexOffset);
}
room.sendComposer(new FloorItemOnRollerComposer((HabboItem) object, null, tile, tile.getStackHeight() - ((HabboItem) object).getZ(), room).compose());
refreshTiles.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY()), ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation()));
room.updateTiles(refreshTiles);
this.indexOffset.put(targetItem.getId(), indexOffset);
}
room.sendComposer(new FloorItemOnRollerComposer((HabboItem) object, null, tile, tile.getStackHeight() - ((HabboItem) object).getZ(), room).compose());
refreshTiles.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY()), ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation()));
room.updateTiles(refreshTiles);
}
}
}
@ -121,81 +79,13 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
return true;
}
@Override
public String getWiredData() {
THashSet<HabboItem> itemsToRemove = new THashSet<>();
for (HabboItem item : this.items) {
if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
itemsToRemove.add(item);
}
for (HabboItem item : itemsToRemove) {
this.items.remove(item);
}
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.direction,
this.spacing,
this.getWiredSettings().getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.direction = data.direction;
this.spacing = data.spacing;
this.getWiredSettings().setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split("\t");
if (data.length == 4) {
try {
this.direction = Integer.parseInt(data[0]);
this.spacing = Integer.parseInt(data[1]);
this.getWiredSettings().setDelay(Integer.parseInt(data[2]));
} catch (Exception ignored) {
}
for (String s : data[3].split("\r")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@Override
protected long requiredCooldown() {
return 495;
}
static class JsonData {
int direction;
int spacing;
int delay;
List<Integer> itemIds;
public JsonData(int direction, int spacing, int delay, List<Integer> itemIds) {
this.direction = direction;
this.spacing = spacing;
this.delay = delay;
this.itemIds = itemIds;
}
@Override
public WiredEffectType getType() {
return WiredEffectType.MOVE_FURNI_TO;
}
}

View File

@ -1,15 +1,12 @@
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.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.*;
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.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import com.eu.habbo.threading.runnables.WiredCollissionRunnable;
@ -30,21 +27,15 @@ import java.util.stream.Collectors;
* @author Beny.
*/
public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.CHASE;
private THashSet<HabboItem> items;
private THashMap<Integer, RoomUserRotation> lastDirections;
public WiredEffectMoveFurniTowards(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
this.lastDirections = new THashMap<>();
}
public WiredEffectMoveFurniTowards(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
this.lastDirections = new THashMap<>();
}
@ -82,23 +73,11 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
THashSet<HabboItem> items = new THashSet<>();
for (HabboItem item : this.items) {
if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
items.add(item);
if(this.getWiredSettings().getItemIds().isEmpty()) {
return false;
}
for (HabboItem item : items) {
this.items.remove(item);
}
for (HabboItem item : this.items) {
if (item == null)
continue;
for (HabboItem item : this.getWiredSettings().getItems(room)) {
// direction the furni will move in
RoomUserRotation moveDirection = null;
RoomUserRotation lastDirection = lastDirections.get(item.getId());
@ -230,97 +209,13 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getWiredSettings().getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (wiredDataOld.length >= 1) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it);
}
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.items.clear();
this.items.addAll(newItems);
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
protected long requiredCooldown() {
return 495;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
@Override
public WiredEffectType getType() {
return WiredEffectType.CHASE;
}
}

View File

@ -1,16 +1,13 @@
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.ICycleable;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.*;
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.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import gnu.trove.set.hash.THashSet;
@ -24,39 +21,34 @@ import java.util.stream.Collectors;
@Slf4j
public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implements ICycleable {
public static final WiredEffectType type = WiredEffectType.MOVE_ROTATE;
private final THashSet<HabboItem> items = new THashSet<>(WiredHandler.MAXIMUM_FURNI_SELECTION / 2);
private int direction;
private int rotation;
private final THashSet<HabboItem> itemCooldowns;
public final int PARAM_DIRECTION = 0;
public final int PARAM_ROTATION = 1;
public WiredEffectMoveRotateFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.itemCooldowns = new THashSet<>();
}
public WiredEffectMoveRotateFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.itemCooldowns = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
// remove items that are no longer in the room
this.items.removeIf(item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
if(this.getWiredSettings().getItemIds().isEmpty()) {
return false;
}
for (HabboItem item : this.items) {
if(this.itemCooldowns.contains(item))
continue;
int direction = this.getWiredSettings().getIntegerParams().get(PARAM_DIRECTION);
int rotation = this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION);
int newRotation = this.rotation > 0 ? this.getNewRotation(item) : item.getRotation();
for (HabboItem item : this.getWiredSettings().getItems(room)) {
int newRotation = rotation > 0 ? this.getNewRotation(item, rotation) : item.getRotation();
RoomTile newLocation = room.getLayout().getTile(item.getX(), item.getY());
RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
double oldZ = item.getZ();
if(this.direction > 0) {
RoomUserRotation moveDirection = this.getMovementDirection();
if(direction > 0) {
RoomUserRotation moveDirection = this.getMovementDirection(direction);
newLocation = room.getLayout().getTile(
(short) (item.getX() + ((moveDirection == RoomUserRotation.WEST || moveDirection == RoomUserRotation.NORTH_WEST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : (((moveDirection == RoomUserRotation.EAST || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.NORTH_EAST) ? 1 : 0)))),
(short) (item.getY() + ((moveDirection == RoomUserRotation.NORTH || moveDirection == RoomUserRotation.NORTH_EAST || moveDirection == RoomUserRotation.NORTH_WEST) ? 1 : ((moveDirection == RoomUserRotation.SOUTH || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : 0)))
@ -68,7 +60,6 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
FurnitureMovementError furniMoveTest = room.furnitureFitsAt(newLocation, item, newRotation, true);
if(newLocation != null && newLocation.getState() != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && (furniMoveTest == FurnitureMovementError.NONE || ((furniMoveTest == FurnitureMovementError.TILE_HAS_BOTS || furniMoveTest == FurnitureMovementError.TILE_HAS_HABBOS || furniMoveTest == FurnitureMovementError.TILE_HAS_PETS) && newLocation == oldLocation))) {
if(room.furnitureFitsAt(newLocation, item, newRotation, false) == FurnitureMovementError.NONE && room.moveFurniTo(item, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) {
this.itemCooldowns.add(item);
if(slideAnimation) {
room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose());
}
@ -79,105 +70,13 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
return true;
}
@Override
public String getWiredData() {
THashSet<HabboItem> itemsToRemove = new THashSet<>(this.items.size() / 2);
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
for (HabboItem item : this.items) {
if (item.getRoomId() != this.getRoomId() || (room != null && room.getHabboItem(item.getId()) == null))
itemsToRemove.add(item);
}
for (HabboItem item : itemsToRemove) {
this.items.remove(item);
}
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.direction,
this.rotation,
this.getWiredSettings().getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
this.direction = data.direction;
this.rotation = data.rotation;
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split("\t");
if (data.length == 4) {
try {
this.direction = Integer.parseInt(data[0]);
this.rotation = Integer.parseInt(data[1]);
this.getWiredSettings().setDelay(Integer.parseInt(data[2]));
} catch (Exception e) {
System.out.println(e);
}
for (String s : data[3].split("\r")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean saveData() throws WiredSaveException {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null)
return false;
if(this.getWiredSettings().getIntegerParams().length < 2) throw new WiredSaveException("invalid data");
this.direction = this.getWiredSettings().getIntegerParams()[0];
this.rotation = this.getWiredSettings().getIntegerParams()[1];
int count = this.getWiredSettings().getItems().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count", 5)) return false;
this.items.clear();
for (int i = 0; i < count; i++) {
this.items.add(room.getHabboItem(this.getWiredSettings().getItems()[i]));
}
this.getWiredSettings().setDelay(this.getWiredSettings().getDelay());
return true;
}
/**
* Returns a new rotation for an item based on the wired options
*
* @param item HabboItem
* @return new rotation
*/
private int getNewRotation(HabboItem item) {
private int getNewRotation(HabboItem item, int rotation) {
if(item.getMaximumRotations() == 2) {
return item.getRotation() == 0 ? 4 : 0;
@ -186,11 +85,11 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
return item.getRotation();
}
else if(item.getMaximumRotations() > 4) {
if (this.rotation == 1) {
if (rotation == 1) {
return item.getRotation() == item.getMaximumRotations() - 1 ? 0 : item.getRotation() + 1;
} else if (this.rotation == 2) {
} else if (rotation == 2) {
return item.getRotation() > 0 ? item.getRotation() - 1 : item.getMaximumRotations() - 1;
} else if (this.rotation == 3) { //Random rotation
} else if (rotation == 3) { //Random rotation
THashSet<Integer> possibleRotations = new THashSet<>();
for (int i = 0; i < item.getMaximumRotations(); i++)
{
@ -210,15 +109,15 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
}
}
else {
if (this.rotation == 1) {
if (rotation == 1) {
return (item.getRotation() + 2) % 8;
} else if (this.rotation == 2) {
} else if (rotation == 2) {
int rot = (item.getRotation() - 2) % 8;
if(rot < 0) {
rot += 8;
}
return rot;
} else if (this.rotation == 3) { //Random rotation
} else if (rotation == 3) { //Random rotation
THashSet<Integer> possibleRotations = new THashSet<>();
for (int i = 0; i < item.getMaximumRotations(); i++)
{
@ -246,46 +145,35 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
*
* @return direction
*/
private RoomUserRotation getMovementDirection() {
private RoomUserRotation getMovementDirection(int direction) {
RoomUserRotation movemementDirection = RoomUserRotation.NORTH;
if (this.direction == 1) {
if (direction == 1) {
movemementDirection = RoomUserRotation.values()[Emulator.getRandom().nextInt(RoomUserRotation.values().length / 2) * 2];
} else if (this.direction == 2) {
} else if (direction == 2) {
if (Emulator.getRandom().nextInt(2) == 1) {
movemementDirection = RoomUserRotation.EAST;
} else {
movemementDirection = RoomUserRotation.WEST;
}
} else if (this.direction == 3) {
} else if (direction == 3) {
if (Emulator.getRandom().nextInt(2) != 1) {
movemementDirection = RoomUserRotation.SOUTH;
}
} else if (this.direction == 4) {
} else if (direction == 4) {
movemementDirection = RoomUserRotation.SOUTH;
} else if (this.direction == 5) {
} else if (direction == 5) {
movemementDirection = RoomUserRotation.EAST;
} else if (this.direction == 7) {
} else if (direction == 7) {
movemementDirection = RoomUserRotation.WEST;
}
return movemementDirection;
}
@Override
public void cycle(Room room) {
this.itemCooldowns.clear();
}
public void cycle(Room room) {}
static class JsonData {
int direction;
int rotation;
int delay;
List<Integer> itemIds;
public JsonData(int direction, int rotation, int delay, List<Integer> itemIds) {
this.direction = direction;
this.rotation = rotation;
this.delay = delay;
this.itemIds = itemIds;
}
@Override
public WiredEffectType getType() {
return WiredEffectType.MOVE_ROTATE;
}
}

View File

@ -1,29 +1,21 @@
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.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
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.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.WhisperMessageComposer;
import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredEffectMuteHabbo extends InteractionWiredEffect {
private static final WiredEffectType type = WiredEffectType.MUTE_TRIGGER;
private int length = 5;
private String message = "";
private final int PARAM_LENGTH = 0;
public WiredEffectMuteHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -33,20 +25,11 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() throws WiredSaveException {
if(this.getWiredSettings().getIntegerParams().length < 1) throw new WiredSaveException("invalid data");
this.length = this.getWiredSettings().getIntegerParams()[0];
this.message = this.getWiredSettings().getStringParam();
this.getWiredSettings().setDelay(this.getWiredSettings().getDelay());
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int length = this.getWiredSettings().getIntegerParams().get(PARAM_LENGTH);
String message = this.getWiredSettings().getStringParam();
if (roomUnit == null)
return true;
@ -58,63 +41,15 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
room.muteHabbo(habbo, 60);
habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), habbo, habbo, RoomChatMessageBubbles.WIRED)));
habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), habbo, habbo, RoomChatMessageBubbles.WIRED)));
}
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getWiredSettings().getDelay(),
this.length,
this.message
));
}
@Override
public void loadWiredSettings(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.getWiredSettings().setDelay(data.delay);
this.length = data.length;
this.message = data.message;
} else {
String[] data = wiredData.split("\t");
if (data.length >= 3) {
try {
this.getWiredSettings().setDelay(Integer.parseInt(data[0]));
this.length = Integer.parseInt(data[1]);
this.message = data[2];
} catch (Exception ignored) {
}
}
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
int delay;
int length;
String message;
public JsonData(int delay, int length, String message) {
this.delay = delay;
this.length = length;
this.message = message;
}
return WiredEffectType.MUTE_TRIGGER;
}
}

View File

@ -1,29 +1,18 @@
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.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.threading.runnables.WiredResetTimers;
import gnu.trove.procedure.TObjectProcedure;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class WiredEffectResetTimers extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.RESET_TIMERS;
private int delay = 0;
public WiredEffectResetTimers(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -32,55 +21,14 @@ public class WiredEffectResetTimers extends InteractionWiredEffect {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() {
this.getWiredSettings().setDelay(this.getWiredSettings().getDelay());
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
Emulator.getThreading().run(new WiredResetTimers(room), this.delay);
Emulator.getThreading().run(new WiredResetTimers(room), this.getWiredSettings().getDelay());
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.delay
));
}
@Override
public void loadWiredSettings(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.delay = data.delay;
} else {
try {
if (!wiredData.equals("")) {
this.delay = Integer.parseInt(wiredData);
}
} catch (Exception ignored) {
}
}
this.getWiredSettings().setDelay(this.delay);
}
@Override
public WiredEffectType getType() {
return type;
}
static class JsonData {
int delay;
public JsonData(int delay) {
this.delay = delay;
}
return WiredEffectType.RESET_TIMERS;
}
}

View File

@ -1,10 +1,8 @@
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.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomTileState;
@ -12,12 +10,10 @@ 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.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.AvatarEffectMessageComposer;
import com.eu.habbo.threading.runnables.RoomUnitTeleport;
import com.eu.habbo.threading.runnables.SendRoomUnitEffectComposer;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -41,6 +37,23 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
this.items = new ArrayList<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getItemIds().isEmpty()) {
return false;
}
int randomItemIndex = Emulator.getRandom().nextInt(this.getWiredSettings().getItemIds().size());
HabboItem[] items = this.getWiredSettings().getItems(room).toArray(new HabboItem[this.getWiredSettings().getItemIds().size()]);
HabboItem randomItem = items[randomItemIndex];
teleportUnitToTile(roomUnit, room.getLayout().getTile(randomItem.getX(), randomItem.getY()));
return true;
}
public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) {
if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting())
return;
@ -81,118 +94,14 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
Emulator.getThreading().run(() -> { roomUnit.setWiredTeleporting(true); }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500));
Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY);
}
@Override
public boolean saveData() throws WiredSaveException {
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it);
}
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.items.clear();
this.items.addAll(newItems);
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId()
|| Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
if (!this.items.isEmpty()) {
int i = Emulator.getRandom().nextInt(this.items.size());
HabboItem item = this.items.get(i);
teleportUnitToTile(roomUnit, room.getLayout().getTile(item.getX(), item.getY()));
return true;
}
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getWiredSettings().getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items = new ArrayList<>();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (wiredDataOld.length >= 1) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean requiresTriggeringUser() {
return true;
}
@Override
protected long requiredCooldown() {
return 50L;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
@Override
public WiredEffectType getType() {
return WiredEffectType.TELEPORT;
}
}

View File

@ -1,7 +1,5 @@
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.*;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate;
@ -15,14 +13,11 @@ import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreeze
import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField;
import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole;
import com.eu.habbo.habbohotel.items.interactions.pets.*;
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.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.set.hash.THashSet;
import lombok.extern.slf4j.Slf4j;
@ -30,15 +25,10 @@ import lombok.extern.slf4j.Slf4j;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
public class WiredEffectToggleFurni extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.TOGGLE_STATE;
private static final List<Class<? extends HabboItem>> FORBIDDEN_TYPES = new ArrayList<>() {
{
this.add(InteractionWired.class);
@ -83,139 +73,54 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
public WiredEffectToggleFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.setItems(new THashSet<>());
}
public WiredEffectToggleFurni(int id, int userId, Item item, String extraData, int limitedStack, int limitedSells) {
super(id, userId, item, extraData, limitedStack, limitedSells);
this.setItems(new THashSet<>());
}
@Override
public boolean saveData() throws WiredSaveException {
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
THashSet<HabboItem> newItems = new THashSet<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null) {
throw new WiredSaveException(String.format("Item %s not found", itemId));
}
newItems.add(it);
}
if(this.getWiredSettings().getDelay() > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) {
throw new WiredSaveException("Delay too long");
}
this.setItems(newItems);
this.getWiredSettings().setDelay(this.getWiredSettings().getDelay());
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getItemIds().isEmpty()) {
return false;
}
Habbo habbo = room.getHabbo(roomUnit);
THashSet<HabboItem> itemsToRemove = new THashSet<>();
for (HabboItem item : this.getItems()) {
for (HabboItem item : this.getWiredSettings().getItems(room)) {
if (item == null || item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) {
itemsToRemove.add(item);
continue;
}
try {
if (item.getBaseItem().getStateCount() > 1 || item instanceof InteractionGameTimer) {
int state = 0;
if (!item.getExtradata().isEmpty()) {
try {
state = Integer.parseInt(item.getExtradata()); // assumes that extradata is state, could be something else for trophies etc.
} catch (NumberFormatException ignored) {
if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) {
continue;
}
if (item.getBaseItem().getStateCount() > 1 || item instanceof InteractionGameTimer) {
int state = 0;
if (!item.getExtradata().isEmpty()) {
try {
state = Integer.parseInt(item.getExtradata()); // assumes that extradata is state, could be something else for trophies etc.
} catch (NumberFormatException ignored) {
}
}
item.onClick(habbo != null && !(item instanceof InteractionGameTimer) ? habbo.getClient() : null, room, new Object[]{state, this.getType()});
}
} catch (Exception e) {
log.error("Caught exception", e);
try {
item.onClick(habbo != null && !(item instanceof InteractionGameTimer) ? habbo.getClient() : null, room, new Object[]{state, this.getType()});
} catch (Exception e) {
log.error("Caught exception", e);
}
}
}
this.getItems().removeAll(itemsToRemove);
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getWiredSettings().getDelay(),
this.getItems().stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.getItems().clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) {
continue;
}
if (item != null) {
this.getItems().add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (wiredDataOld.length >= 1) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable)
continue;
if (item != null)
this.getItems().add(item);
}
}
}
}
}
@Override
public WiredEffectType getType() {
return type;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
return WiredEffectType.TOGGLE_STATE;
}
}

View File

@ -1,7 +1,6 @@
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.*;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate;
@ -15,13 +14,11 @@ import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreeze
import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField;
import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole;
import com.eu.habbo.habbohotel.items.interactions.pets.*;
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.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.set.hash.THashSet;
import lombok.extern.slf4j.Slf4j;
@ -34,11 +31,6 @@ import java.util.stream.Collectors;
@Slf4j
public class WiredEffectToggleRandom extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.TOGGLE_RANDOM;
private final THashSet<HabboItem> items = new THashSet<>();
private static final List<Class<? extends HabboItem>> FORBIDDEN_TYPES = new ArrayList<>() {
{
this.add(InteractionWired.class);
@ -87,45 +79,10 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() throws WiredSaveException {
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it);
}
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.items.clear();
this.items.addAll(newItems);
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
THashSet<HabboItem> items = this.items;
for (HabboItem item : items) {
for (HabboItem item : this.getWiredSettings().getItems(room)) {
if (item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) {
this.items.remove(item);
continue;
}
@ -139,65 +96,8 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getWiredSettings().getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
continue;
if (item != null)
this.items.add(item);
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (wiredDataOld.length >= 1) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
continue;
if (item != null)
this.items.add(item);
}
}
}
}
}
@Override
public WiredEffectType getType() {
return type;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
return WiredEffectType.TOGGLE_RANDOM;
}
}

View File

@ -1,17 +1,14 @@
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.wired.WiredSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
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.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.set.hash.THashSet;
@ -22,54 +19,19 @@ import java.util.List;
import java.util.stream.Collectors;
public class WiredEffectTriggerStacks extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.CALL_STACKS;
private THashSet<HabboItem> items;
public WiredEffectTriggerStacks(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredEffectTriggerStacks(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public boolean saveData() throws WiredSaveException {
int itemsCount = this.getWiredSettings().getItems().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) {
int itemId = this.getWiredSettings().getItems()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it);
}
int delay = this.getWiredSettings().getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.items.clear();
this.items.addAll(newItems);
this.getWiredSettings().setDelay(delay);
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getItemIds().isEmpty()) {
return false;
}
if (stuff == null || (stuff.length >= 1 && stuff[stuff.length - 1] instanceof WiredEffectTriggerStacks)) {
return false;
@ -79,7 +41,7 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
boolean found;
for (HabboItem item : this.items) {
for (HabboItem item : this.getWiredSettings().getItems(room)) {
//if(item instanceof InteractionWiredTrigger)
{
found = false;
@ -104,64 +66,13 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getWiredSettings().getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.getWiredSettings().setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (wiredDataOld.length >= 1) {
this.getWiredSettings().setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
protected long requiredCooldown() {
return 250;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
@Override
public WiredEffectType getType() {
return WiredEffectType.CALL_STACKS;
}
}

View File

@ -11,15 +11,12 @@ 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.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.WhisperMessageComposer;
import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredEffectWhisper extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
public WiredEffectWhisper(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -28,45 +25,38 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean saveData() {
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (this.getWiredSettings().getStringParam().length() > 0) {
if (roomUnit != null) {
Habbo habbo = room.getHabbo(roomUnit);
if(this.getWiredSettings().getStringParam().isEmpty()) {
return false;
}
if (habbo != null) {
String msg = this.getWiredSettings().getStringParam().replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + "");
habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(msg, habbo, habbo, RoomChatMessageBubbles.WIRED)));
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, roomUnit, room, new Object[]{ msg }));
if (roomUnit != null) {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo.getRoomUnit().isIdle()) {
habbo.getRoomUnit().getRoom().unIdle(habbo);
}
return true;
if (habbo != null) {
String msg = this.getWiredSettings().getStringParam().replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + "");
habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(msg, habbo, habbo, RoomChatMessageBubbles.WIRED)));
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, roomUnit, room, new Object[]{ msg }));
if (habbo.getRoomUnit().isIdle()) {
habbo.getRoomUnit().getRoom().unIdle(habbo);
}
} else {
for (Habbo h : room.getHabbos()) {
h.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.getWiredSettings().getStringParam().replace("%user%", h.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), h, h, RoomChatMessageBubbles.WIRED)));
}
return true;
}
} else {
for (Habbo h : room.getHabbos()) {
h.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.getWiredSettings().getStringParam().replace("%user%", h.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), h, h, RoomChatMessageBubbles.WIRED)));
}
return true;
}
return false;
}
@Override
public WiredEffectType getType() {
return type;
}
@Override
public boolean requiresTriggeringUser() {
return true;
return WiredEffectType.SHOW_MESSAGE;
}
}

View File

@ -23,22 +23,4 @@ public class WiredExtraRandom extends InteractionWiredExtra {
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return false;
}
@Override
public String getWiredData() {
return null;
}
@Override
public void loadWiredSettings(ResultSet set, Room room) {}
@Override
public boolean saveData() throws WiredSaveException {
return true;
}
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) {
}
}

View File

@ -32,26 +32,6 @@ public class WiredExtraUnseen extends InteractionWiredExtra {
return false;
}
@Override
public String getWiredData() {
return null;
}
@Override
public void loadWiredSettings(ResultSet set, Room room) {
}
@Override
public boolean saveData() throws WiredSaveException {
return false;
}
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) {
}
@Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
super.onMove(room, oldLocation, newLocation);

View File

@ -1,10 +1,13 @@
package com.eu.habbo.habbohotel.items.interactions.wired.interfaces;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import java.util.List;
public interface IWiredEffectInteraction {
WiredEffectType getType();
void setType(WiredEffectType value);
List<Integer> getBlockedTriggers(Room room);
void setBlockedTriggers(List<Integer> value);
}

View File

@ -3,19 +3,10 @@ package com.eu.habbo.habbohotel.items.interactions.wired.interfaces;
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.HabboItem;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.set.hash.THashSet;
import java.util.Map;
public interface IWiredInteraction {
THashSet<HabboItem> getItems();
void setItems(THashSet<HabboItem> value);
String getWiredData();
void setWiredData(String value);
WiredSettings getWiredSettings();
void setWiredSettings(WiredSettings value);
boolean execute(RoomUnit roomUnit, Room room, Object[] stuff);
boolean saveData() throws WiredSaveException;
}

View File

@ -3,13 +3,15 @@ package com.eu.habbo.habbohotel.items.interactions.wired.interfaces;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
public interface IWiredSettings {
int[] getIntegerParams();
void setIntegerParams(int[] value);
List<Integer> getIntegerParams();
void setIntegerParams(List<Integer> value);
String getStringParam();
void setStringParam(String value);
int[] getItems();
void setItems(int[] value);
List<Integer> getItemIds();
void setItemIds(List<Integer> value);
int getDelay();
void setDelay(int value);
int getSelectionType();

View File

@ -1,10 +1,13 @@
package com.eu.habbo.habbohotel.items.interactions.wired.interfaces;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import java.util.List;
public interface IWiredTriggerInteraction {
WiredTriggerType getType();
void setType(WiredTriggerType value);
List<Integer> getBlockedEffects(Room room);
void setBlockedEffects(List<Integer> value);
}

View File

@ -0,0 +1,5 @@
package com.eu.habbo.habbohotel.items.interactions.wired.interfaces;
public interface WiredTriggerReset {
void resetTimer();
}

View File

@ -3,24 +3,19 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.threading.runnables.WiredExecuteTask;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements WiredTriggerReset {
public final static WiredTriggerType type = WiredTriggerType.AT_GIVEN_TIME;
public final int PARAM_EXECUTE_TIME = 0;
public int executeTime;
public int taskId;
public WiredTriggerAtSetTime(ResultSet set, Item baseItem) throws SQLException {
@ -33,48 +28,7 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.executeTime
));
}
@Override
public void loadWiredSettings(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.executeTime = data.executeTime;
} else {
if (wiredData.length() >= 1) {
this.executeTime = (Integer.parseInt(wiredData));
}
}
if (this.executeTime < 500) {
this.executeTime = 20 * 500;
}
this.taskId = 1;
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.executeTime = this.getWiredSettings().getIntegerParams()[0] * 500;
this.resetTimer();
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.getWiredSettings().getIntegerParams().get(PARAM_EXECUTE_TIME)); //TODO *500?
return true;
}
@ -82,14 +36,11 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi
public void resetTimer() {
this.taskId++;
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.getWiredSettings().getIntegerParams().get(PARAM_EXECUTE_TIME));
}
static class JsonData {
int executeTime;
public JsonData(int executeTime) {
this.executeTime = executeTime;
}
@Override
public WiredTriggerType getType() {
return WiredTriggerType.AT_GIVEN_TIME;
}
}

View File

@ -3,24 +3,19 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.threading.runnables.WiredExecuteTask;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements WiredTriggerReset {
private static final WiredTriggerType type = WiredTriggerType.AT_GIVEN_TIME;
public final int PARAM_EXECUTE_TIME = 0;
public int taskId;
private int executeTime;
public WiredTriggerAtTimeLong(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -32,61 +27,19 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.executeTime
));
}
@Override
public void loadWiredSettings(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.executeTime = data.executeTime;
} else {
if (wiredData.length() >= 1) {
this.executeTime = (Integer.parseInt(wiredData));
}
}
if (this.executeTime < 500) {
this.executeTime = 20 * 500;
}
this.taskId = 1;
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.executeTime = this.getWiredSettings().getIntegerParams()[0] * 500;
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.getWiredSettings().getIntegerParams().get(PARAM_EXECUTE_TIME));
return true;
}
@Override
public void resetTimer() {
this.taskId++;
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.getWiredSettings().getIntegerParams().get(PARAM_EXECUTE_TIME));
}
static class JsonData {
int executeTime;
public JsonData(int executeTime) {
this.executeTime = executeTime;
}
@Override
public WiredTriggerType getType() {
return WiredTriggerType.AT_GIVEN_TIME;
}
}

View File

@ -3,124 +3,44 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
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.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import lombok.extern.slf4j.Slf4j;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
public final static WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI;
private final THashSet<HabboItem> items;
private String botName = "";
public WiredTriggerBotReachedFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredTriggerBotReachedFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
this.botName = this.getWiredSettings().getStringParam();
this.items.clear();
int count = this.getWiredSettings().getItems().length;
for (int i = 0; i < count; i++) {
this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(this.getWiredSettings().getItems()[i]));
}
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (stuff.length >= 1) {
if (stuff[0] instanceof HabboItem) {
return this.items.contains(stuff[0]) && room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
}
if(stuff.length == 0) {
return false;
}
if (stuff[0] instanceof HabboItem) {
return this.getWiredSettings().getItems(room).contains(stuff[0]) && room.getBots(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
}
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.botName,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.botName = data.botName;
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(":");
if (data.length == 1) {
this.botName = data[0];
} else if (data.length == 2) {
this.botName = data[0];
String[] items = data[1].split(";");
for (String id : items) {
try {
HabboItem item = room.getHabboItem(Integer.parseInt(id));
if (item != null)
this.items.add(item);
} catch (Exception e) {
log.error("Caught exception", e);
}
}
}
}
}
static class JsonData {
String botName;
List<Integer> itemIds;
public JsonData(String botName, List<Integer> itemIds) {
this.botName = botName;
this.itemIds = itemIds;
}
public WiredTriggerType getType() {
return WiredTriggerType.WALKS_ON_FURNI;
}
}

View File

@ -13,10 +13,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger {
public final static WiredTriggerType type = WiredTriggerType.BOT_REACHED_AVTR;
private String botName = "";
public WiredTriggerBotReachedHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -25,51 +21,13 @@ public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
this.botName = this.getWiredSettings().getStringParam();
return true;
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
return room.getBots(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.botName
));
}
@Override
public void loadWiredSettings(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.botName = data.botName;
} else {
this.botName = wiredData;
}
}
@Override
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
String botName;
public JsonData(String botName) {
this.botName = botName;
}
public WiredTriggerType getType() {
return WiredTriggerType.BOT_REACHED_AVTR;
}
}

View File

@ -29,26 +29,8 @@ public class WiredTriggerCollision extends InteractionWiredTrigger {
return stuff.length > 0 && stuff[0] instanceof HabboItem;
}
@Override
public String getWiredData() {
return "";
}
@Override
public void loadWiredSettings(ResultSet set, Room room) {}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
return true;
}
@Override
public boolean isTriggeredByRoomUnit() {
return true;
return WiredTriggerType.COLLISION;
}
}

View File

@ -3,7 +3,6 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
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;
@ -11,7 +10,6 @@ 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.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
@ -20,104 +18,29 @@ import java.util.List;
import java.util.stream.Collectors;
public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
private static final WiredTriggerType type = WiredTriggerType.STATE_CHANGED;
private THashSet<HabboItem> items;
public WiredTriggerFurniStateToggled(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredTriggerFurniStateToggled(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (stuff.length >= 1) {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
for (Object object : stuff) {
if (object instanceof WiredEffectType) {
return false;
}
}
if (stuff[0] instanceof HabboItem) {
return this.items.contains(stuff[0]);
}
}
if(stuff.length == 0 || room.getHabbo(roomUnit) == null) {
return false;
}
if (stuff[0] instanceof HabboItem && !(stuff[0] instanceof WiredEffectType)) {
return this.getWiredSettings().getItems(room).contains(stuff[0]);
}
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
if (wiredData.split(":").length >= 3) {
// this.getWiredSettings().setDelay(Integer.parseInt(wiredData.split(":")[0])); TODO Trigger has delay???
if (!wiredData.split(":")[2].equals("\t")) {
for (String s : wiredData.split(":")[2].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
this.items.clear();
int count = this.getWiredSettings().getItems().length;
for (int i = 0; i < count; i++) {
this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(this.getWiredSettings().getItems()[i]));
}
return true;
}
@Override
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
return WiredTriggerType.STATE_CHANGED;
}
}

View File

@ -14,8 +14,6 @@ import java.util.ArrayList;
import java.util.List;
public class WiredTriggerGameEnds extends InteractionWiredTrigger {
private static final WiredTriggerType type = WiredTriggerType.GAME_ENDS;
public WiredTriggerGameEnds(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -29,21 +27,8 @@ public class WiredTriggerGameEnds extends InteractionWiredTrigger {
return true;
}
@Override
public String getWiredData() {
return "";
}
@Override
public void loadWiredSettings(ResultSet set, Room room) {}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
return true;
return WiredTriggerType.GAME_ENDS;
}
}

View File

@ -14,8 +14,6 @@ import java.util.ArrayList;
import java.util.List;
public class WiredTriggerGameStarts extends InteractionWiredTrigger {
private static final WiredTriggerType type = WiredTriggerType.GAME_STARTS;
public WiredTriggerGameStarts(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -29,22 +27,8 @@ public class WiredTriggerGameStarts extends InteractionWiredTrigger {
return true;
}
@Override
public String getWiredData() {
return "";
}
@Override
public void loadWiredSettings(ResultSet set, Room room) {
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
return true;
return WiredTriggerType.GAME_STARTS;
}
}

View File

@ -14,10 +14,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger {
public static final WiredTriggerType type = WiredTriggerType.ENTER_ROOM;
private String username = "";
public WiredTriggerHabboEntersRoom(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -28,59 +24,21 @@ public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if(this.getWiredSettings().getStringParam().isEmpty()) {
return true;
}
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
if (this.username.length() > 0) {
return habbo.getHabboInfo().getUsername().equalsIgnoreCase(this.username);
}
return true;
return habbo.getHabboInfo().getUsername().equalsIgnoreCase(this.getWiredSettings().getStringParam());
}
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.username
));
}
@Override
public void loadWiredSettings(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.username = data.username;
} else {
this.username = wiredData;
}
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
this.username = this.getWiredSettings().getStringParam();
return true;
}
@Override
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
String username;
public JsonData(String username) {
this.username = username;
}
return WiredTriggerType.ENTER_ROOM;
}
}

View File

@ -14,8 +14,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger {
private static final WiredTriggerType type = WiredTriggerType.SAY_SOMETHING;
private static int PARAM_OWNER_ONLY = 0;
public WiredTriggerHabboSaysKeyword(ResultSet set, Item baseItem) throws SQLException {
@ -32,7 +30,7 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger {
return false;
}
boolean ownerOnly = this.getWiredSettings().getIntegerParams()[PARAM_OWNER_ONLY] == 1;
boolean ownerOnly = this.getWiredSettings().getIntegerParams().get(PARAM_OWNER_ONLY) == 1;
if (stuff[0] instanceof String) {
if (((String) stuff[0]).toLowerCase().contains(this.getWiredSettings().getStringParam().toLowerCase())) {
@ -44,23 +42,8 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger {
return false;
}
@Override
public String getWiredData() {
return "";
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
return true;
}
@Override
public boolean isTriggeredByRoomUnit() {
return true;
return WiredTriggerType.SAY_SOMETHING;
}
}

View File

@ -3,13 +3,11 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
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.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
@ -18,100 +16,29 @@ import java.util.List;
import java.util.stream.Collectors;
public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
public static final WiredTriggerType type = WiredTriggerType.WALKS_OFF_FURNI;
private final THashSet<HabboItem> items;
public WiredTriggerHabboWalkOffFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredTriggerHabboWalkOffFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (stuff.length >= 1) {
if (stuff[0] instanceof HabboItem) {
return this.items.contains(stuff[0]);
}
if(stuff.length == 0) {
return false;
}
if (stuff[0] instanceof HabboItem) {
return this.getWiredSettings().getItems(room).contains(stuff[0]);
}
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new WiredTriggerFurniStateToggled.JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
if (wiredData.split(":").length >= 3) {
// super.setDelay(Integer.parseInt(wiredData.split(":")[0])); TODO THIS TRIGGER HAS DELAY?
if (!wiredData.split(":")[2].equals("\t")) {
for (String s : wiredData.split(":")[2].split(";")) {
if (s.isEmpty())
continue;
try {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
} catch (Exception ignored) {
}
}
}
}
}
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
this.items.clear();
int count = this.getWiredSettings().getItems().length;
for (int i = 0; i < count; i++) {
this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(this.getWiredSettings().getItems()[i]));
}
return true;
}
@Override
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
return WiredTriggerType.WALKS_OFF_FURNI;
}
}

View File

@ -1,117 +1,39 @@
package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
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.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
public static final WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI;
private THashSet<HabboItem> items;
public WiredTriggerHabboWalkOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
}
public WiredTriggerHabboWalkOnFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.items = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (stuff.length >= 1) {
if (stuff[0] instanceof HabboItem) {
return this.items.contains(stuff[0]);
}
if(stuff.length == 0) {
return false;
}
if (stuff[0] instanceof HabboItem) {
return this.getWiredSettings().getItems(room).contains(stuff[0]);
}
return false;
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
this.items.clear();
int count = this.getWiredSettings().getItems().length;
for (int i = 0; i < count; i++) {
this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(this.getWiredSettings().getItems()[i]));
}
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredSettings(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
if (wiredData.split(":").length >= 3) {
// super.setDelay(Integer.parseInt(wiredData.split(":")[0])); TODO this trigger has delay???
if (!wiredData.split(":")[2].equals("\t")) {
for (String s : wiredData.split(":")[2].split(";")) {
if (s.isEmpty())
continue;
try {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
} catch (Exception ignored) {
}
}
}
}
}
}
@Override
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
return WiredTriggerType.WALKS_ON_FURNI;
}
}

View File

@ -4,26 +4,20 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.ICycleable;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset {
public static final WiredTriggerType type = WiredTriggerType.PERIODICALLY;
public static final int DEFAULT_DELAY = 10 * 500;
protected int repeatTime = DEFAULT_DELAY;
public final int PARAM_REPEAT_TIME = 0;
protected int counter = 0;
public WiredTriggerRepeater(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -38,52 +32,25 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.repeatTime
));
}
public void cycle(Room room) {
if(this.getWiredSettings() == null) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
try (PreparedStatement statement = connection.prepareStatement("SELECT id, wired_data FROM items WHERE room_id = ? AND wired_data<>''")) {
statement.setInt(1, room.getId());
@Override
public void loadWiredSettings(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.repeatTime = data.repeatTime;
} else {
if (wiredData.length() >= 1) {
this.repeatTime = (Integer.parseInt(wiredData));
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
this.loadWiredSettings(set, room);
}
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
if (this.repeatTime < 500) {
this.repeatTime = 20 * 500;
}
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.repeatTime = this.getWiredSettings().getIntegerParams()[0] * 500;
this.counter = 0;
if (this.repeatTime < 500) {
this.repeatTime = 500;
}
return true;
}
@Override
public void cycle(Room room) {
this.counter += 500;
if (this.counter >= this.repeatTime) {
if (this.counter >= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 500) {
this.counter = 0;
if (this.getRoomId() != 0) {
if (room.isLoaded()) {
@ -104,11 +71,8 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
}
}
static class JsonData {
int repeatTime;
public JsonData(int repeatTime) {
this.repeatTime = repeatTime;
}
@Override
public WiredTriggerType getType() {
return WiredTriggerType.PERIODICALLY;
}
}

View File

@ -4,22 +4,18 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.ICycleable;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset {
public static final int DEFAULT_DELAY = 10 * 5000;
private static final WiredTriggerType type = WiredTriggerType.PERIODICALLY_LONG;
private static final int PARAM_REPEAT_TIME = 0;
private int repeatTime = DEFAULT_DELAY;
private int counter = 0;
@ -36,49 +32,10 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements
return true;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.repeatTime
));
}
@Override
public void loadWiredSettings(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.repeatTime = data.repeatTime;
} else {
if (wiredData.length() >= 1) {
this.repeatTime = (Integer.parseInt(wiredData));
}
}
if (this.repeatTime < 5000) {
this.repeatTime = 20 * 5000;
}
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.repeatTime = this.getWiredSettings().getIntegerParams()[0] * 5000;
this.counter = 0;
return true;
}
@Override
public void cycle(Room room) {
this.counter += 500;
if (this.counter >= this.repeatTime) {
if (this.counter >= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME)) {
this.counter = 0;
if (this.getRoomId() != 0) {
if (room.isLoaded()) {
@ -99,11 +56,8 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements
}
}
static class JsonData {
int repeatTime;
public JsonData(int repeatTime) {
this.repeatTime = repeatTime;
}
@Override
public WiredTriggerType getType() {
return WiredTriggerType.PERIODICALLY_LONG;
}
}

View File

@ -13,8 +13,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredTriggerScoreAchieved extends InteractionWiredTrigger {
private static final WiredTriggerType type = WiredTriggerType.SCORE_ACHIEVED;
private int score = 0;
public final int PARAM_SCORE = 0;
public WiredTriggerScoreAchieved(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -30,56 +29,14 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger {
int points = (Integer) stuff[0];
int amountAdded = (Integer) stuff[1];
return points - amountAdded < this.score && points >= this.score;
return points - amountAdded < this.getWiredSettings().getIntegerParams().get(PARAM_SCORE) && points >= this.getWiredSettings().getIntegerParams().get(PARAM_SCORE);
}
return false;
}
@Override
public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.score
));
}
@Override
public void loadWiredSettings(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.score = data.score;
} else {
try {
this.score = Integer.parseInt(wiredData);
} catch (Exception ignored) {
}
}
}
@Override
public WiredTriggerType getType() {
return type;
}
@Override
public boolean saveData() {
if(this.getWiredSettings().getIntegerParams().length < 1) return false;
this.score = this.getWiredSettings().getIntegerParams()[0];
return true;
}
@Override
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
int score;
public JsonData(int score) {
this.score = score;
}
return WiredTriggerType.SCORE_ACHIEVED;
}
}

View File

@ -1086,8 +1086,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
synchronized (this.loadLock) {
if (this.loaded) {
try {
Emulator.getThreading().run(
Room.this::cycle);
Emulator.getThreading().run(Room.this::cycle);
} catch (Exception e) {
log.error(CAUGHT_EXCEPTION, e);
}

View File

@ -17,11 +17,11 @@ public class WiredExclusionStrategy implements ExclusionStrategy {
case "stringParam":
return this.wiredSettings.getStringParam().isEmpty();
case "integerParams":
return this.wiredSettings.getIntegerParams().length == 0;
return this.wiredSettings.getIntegerParams().size() == 0;
case "delay":
return this.wiredSettings.getDelay() == 0;
case "items":
return this.wiredSettings.getItems().length == 0;
case "itemIds":
return this.wiredSettings.getItemIds().size() == 0;
case "selectionType":
default:
return true;

View File

@ -7,7 +7,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredExtra;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset;
import com.eu.habbo.habbohotel.items.interactions.wired.effects.WiredEffectGiveReward;
import com.eu.habbo.habbohotel.items.interactions.wired.effects.WiredEffectTriggerStacks;
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraRandom;

View File

@ -2,7 +2,6 @@ package com.eu.habbo.messages.outgoing.wired;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
@ -21,16 +20,16 @@ public class WiredConditionDataComposer extends MessageComposer {
this.response.appendBoolean(false);
this.response.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
this.response.appendInt(this.condition.getItems().size());
this.response.appendInt(this.condition.getWiredSettings().getItemIds().size());
for (HabboItem item : this.condition.getItems()) {
this.response.appendInt(item.getId());
for (int itemId : this.condition.getWiredSettings().getItemIds()) {
this.response.appendInt(itemId);
}
this.response.appendInt(this.condition.getBaseItem().getSpriteId());
this.response.appendInt(this.condition.getId());
this.response.appendString(this.condition.getWiredSettings().getStringParam());
this.response.appendInt(this.condition.getWiredSettings().getIntegerParams().length);
this.response.appendInt(this.condition.getWiredSettings().getIntegerParams().size());
for (int param : this.condition.getWiredSettings().getIntegerParams()) {
this.response.appendInt(param);

View File

@ -2,7 +2,6 @@ package com.eu.habbo.messages.outgoing.wired;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
@ -22,16 +21,16 @@ public class WiredEffectDataComposer extends MessageComposer {
this.response.appendBoolean(false);
this.response.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
this.response.appendInt(this.effect.getItems().size());
this.response.appendInt(this.effect.getWiredSettings().getItemIds().size());
for (HabboItem item : this.effect.getItems()) {
this.response.appendInt(item.getId());
for (int itemId : this.effect.getWiredSettings().getItemIds()) {
this.response.appendInt(itemId);
}
this.response.appendInt(this.effect.getBaseItem().getSpriteId());
this.response.appendInt(this.effect.getId());
this.response.appendString(this.effect.getWiredSettings().getStringParam());
this.response.appendInt(this.effect.getWiredSettings().getIntegerParams().length);
this.response.appendInt(this.effect.getWiredSettings().getIntegerParams().size());
for (int param : this.effect.getWiredSettings().getIntegerParams()) {
this.response.appendInt(param);

View File

@ -2,7 +2,6 @@ package com.eu.habbo.messages.outgoing.wired;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
@ -21,16 +20,16 @@ public class WiredTriggerDataComposer extends MessageComposer {
this.response.appendBoolean(false);
this.response.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
this.response.appendInt(this.trigger.getItems().size());
this.response.appendInt(this.trigger.getWiredSettings().getItemIds().size());
for (HabboItem item : this.trigger.getItems()) {
this.response.appendInt(item.getId());
for (int itemId : this.trigger.getWiredSettings().getItemIds()) {
this.response.appendInt(itemId);
}
this.response.appendInt(this.trigger.getBaseItem().getSpriteId());
this.response.appendInt(this.trigger.getId());
this.response.appendString(this.trigger.getWiredSettings().getStringParam());
this.response.appendInt(this.trigger.getWiredSettings().getIntegerParams().length);
this.response.appendInt(this.trigger.getWiredSettings().getIntegerParams().size());
for (int param : this.trigger.getWiredSettings().getIntegerParams()) {
this.response.appendInt(param);