wired: add source selection to conditions/effects

This commit is contained in:
Lorenzune
2026-03-15 19:01:54 +01:00
parent cc82c413cd
commit 777c1d2aa1
50 changed files with 1246 additions and 504 deletions
@@ -11,6 +11,7 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
@@ -24,6 +25,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
private boolean all; private boolean all;
private THashSet<HabboItem> items; private THashSet<HabboItem> items;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException { public WiredConditionFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -41,14 +43,15 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
this.refresh(); this.refresh();
if(this.items.isEmpty()) List<HabboItem> targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
if(targets.isEmpty())
return true; return true;
if (room.getLayout() == null) if (room.getLayout() == null)
return false; return false;
if(this.all) { if(this.all) {
return this.items.stream().allMatch(item -> { return targets.stream().allMatch(item -> {
if (item == null) return false; if (item == null) return false;
RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
if (baseTile == null) return false; if (baseTile == null) return false;
@@ -59,7 +62,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
}); });
} }
else { else {
return this.items.stream().anyMatch(item -> { return targets.stream().anyMatch(item -> {
if (item == null) return false; if (item == null) return false;
RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
if (baseTile == null) return false; if (baseTile == null) return false;
@@ -82,7 +85,8 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
this.refresh(); this.refresh();
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.all, this.all,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) this.items.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -93,6 +97,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.all = data.all; this.all = data.all;
this.furniSource = data.furniSource;
for(int id : data.itemIds) { for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -119,6 +124,10 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
} }
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
}
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -126,6 +135,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.all = false; this.all = false;
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -147,8 +157,9 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(1); message.appendInt(2);
message.appendInt(this.all ? 1 : 0); message.appendInt(this.all ? 1 : 0);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -159,26 +170,28 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
if(settings.getIntParams().length < 1) return false; if(settings.getIntParams().length < 1) return false;
this.all = settings.getIntParams()[0] == 1; int[] params = settings.getIntParams();
this.all = params[0] == 1;
this.furniSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
int count = settings.getFurniIds().length; int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear(); this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) return false;
if (room != null) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); HabboItem item = room.getHabboItem(settings.getFurniIds()[i]);
if (item != null) if (item != null)
this.items.add(item); this.items.add(item);
} }
return true;
} }
return false; return true;
} }
private void refresh() { private void refresh() {
@@ -202,10 +215,12 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
static class JsonData { static class JsonData {
boolean all; boolean all;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(boolean all, List<Integer> itemIds) { public JsonData(boolean all, List<Integer> itemIds, int furniSource) {
this.all = all; this.all = all;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
@@ -26,6 +27,7 @@ import java.util.stream.Collectors;
public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.FURNI_HAVE_HABBO; public static final WiredConditionType type = WiredConditionType.FURNI_HAVE_HABBO;
protected THashSet<HabboItem> items; protected THashSet<HabboItem> items;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException { public WiredConditionFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -40,6 +42,7 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -48,7 +51,8 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
this.refresh(); this.refresh();
if (this.items.isEmpty()) List<HabboItem> targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
if (targets.isEmpty())
return true; return true;
if (room.getLayout() == null) if (room.getLayout() == null)
@@ -58,7 +62,7 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
Collection<Bot> bots = room.getCurrentBots().valueCollection(); Collection<Bot> bots = room.getCurrentBots().valueCollection();
Collection<Pet> pets = room.getCurrentPets().valueCollection(); Collection<Pet> pets = room.getCurrentPets().valueCollection();
return this.items.stream().filter(item -> item != null).allMatch(item -> { return targets.stream().filter(item -> item != null).allMatch(item -> {
RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
if (baseTile == null) return false; if (baseTile == null) return false;
@@ -79,7 +83,8 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
public String getWiredData() { public String getWiredData() {
this.refresh(); this.refresh();
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) this.items.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -90,6 +95,7 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.furniSource = data.furniSource;
for(int id : data.itemIds) { for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -112,6 +118,10 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
this.items.add(item); this.items.add(item);
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
}
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -134,7 +144,8 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -147,22 +158,25 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
this.items.clear(); this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) return false;
if (room != null) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); HabboItem item = room.getHabboItem(settings.getFurniIds()[i]);
if (item != null) if (item != null)
this.items.add(item); this.items.add(item);
} }
return true;
} }
return false; return true;
} }
private void refresh() { private void refresh() {
@@ -185,9 +199,11 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
static class JsonData { static class JsonData {
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(List<Integer> itemIds) { public JsonData(List<Integer> itemIds, int furniSource) {
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
@@ -22,6 +23,7 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.STUFF_IS; public static final WiredConditionType type = WiredConditionType.STUFF_IS;
private THashSet<HabboItem> items = new THashSet<>(); private THashSet<HabboItem> items = new THashSet<>();
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException { public WiredConditionFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -34,6 +36,7 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -43,12 +46,9 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
if(items.isEmpty()) if(items.isEmpty())
return false; return false;
HabboItem triggeringItem = ctx.sourceItem().orElse(null); List<HabboItem> targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
if (triggeringItem != null) { if (targets.isEmpty()) return false;
return this.items.stream().anyMatch(item -> item == triggeringItem); return targets.stream().anyMatch(this.items::contains);
}
return false;
} }
@Deprecated @Deprecated
@@ -61,7 +61,8 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
public String getWiredData() { public String getWiredData() {
this.refresh(); this.refresh();
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) this.items.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -72,6 +73,7 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.furniSource = data.furniSource;
for(int id : data.itemIds) { for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -90,6 +92,10 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
this.items.add(item); this.items.add(item);
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
}
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -112,7 +118,8 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -124,13 +131,18 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
int count = settings.getFurniIds().length; int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
this.items.clear(); this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) { if (room != null) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
this.items.add(room.getHabboItem(settings.getFurniIds()[i])); this.items.add(room.getHabboItem(settings.getFurniIds()[i]));
}
} }
} }
@@ -157,9 +169,11 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
static class JsonData { static class JsonData {
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(List<Integer> itemIds) { public JsonData(List<Integer> itemIds, int furniSource) {
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -8,13 +8,16 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionGroupMember extends InteractionWiredCondition { public class WiredConditionGroupMember extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_IN_GROUP; public static final WiredConditionType type = WiredConditionType.ACTOR_IN_GROUP;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionGroupMember(ResultSet set, Item baseItem) throws SQLException { public WiredConditionGroupMember(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -26,14 +29,20 @@ public class WiredConditionGroupMember extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null);
Room room = ctx.room(); Room room = ctx.room();
if (room.getGuildId() == 0) if (room.getGuildId() == 0)
return false; return false;
Habbo habbo = room.getHabbo(roomUnit); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (targets.isEmpty()) return false;
return habbo != null && habbo.getHabboStats().hasGuild(room.getGuildId()); for (RoomUnit roomUnit : targets) {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null && habbo.getHabboStats().hasGuild(room.getGuildId())) {
return true;
}
}
return false;
} }
@Deprecated @Deprecated
@@ -44,17 +53,26 @@ public class WiredConditionGroupMember extends InteractionWiredCondition {
@Override @Override
public String getWiredData() { public String getWiredData() {
return ""; return String.valueOf(this.userSource);
} }
@Override @Override
public void loadWiredData(ResultSet set, Room room) throws SQLException { public void loadWiredData(ResultSet set, Room room) throws SQLException {
String wiredData = set.getString("wired_data");
if (wiredData != null && !wiredData.isEmpty()) {
try {
this.userSource = Integer.parseInt(wiredData);
} catch (NumberFormatException ignored) {
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
}
} else {
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
}
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -70,7 +88,8 @@ public class WiredConditionGroupMember extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -79,6 +98,8 @@ public class WiredConditionGroupMember extends InteractionWiredCondition {
@Override @Override
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
} }
@@ -8,6 +8,7 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
@@ -18,6 +19,7 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
private int lowerLimit = 0; private int lowerLimit = 0;
private int upperLimit = 50; private int upperLimit = 50;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionHabboCount(ResultSet set, Item baseItem) throws SQLException { public WiredConditionHabboCount(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -29,7 +31,9 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
int count = ctx.room().getUserCount(); int count = (this.userSource == WiredSourceUtil.SOURCE_TRIGGER)
? ctx.room().getUserCount()
: WiredSourceUtil.resolveUsers(ctx, this.userSource).size();
return count >= this.lowerLimit && count <= this.upperLimit; return count >= this.lowerLimit && count <= this.upperLimit;
} }
@@ -44,7 +48,8 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.lowerLimit, this.lowerLimit,
this.upperLimit this.upperLimit,
this.userSource
)); ));
} }
@@ -56,11 +61,13 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.lowerLimit = data.lowerLimit; this.lowerLimit = data.lowerLimit;
this.upperLimit = data.upperLimit; this.upperLimit = data.upperLimit;
this.userSource = data.userSource;
} else { } else {
String[] data = wiredData.split(":"); String[] data = wiredData.split(":");
this.lowerLimit = Integer.parseInt(data[0]); this.lowerLimit = Integer.parseInt(data[0]);
this.upperLimit = Integer.parseInt(data[1]); this.upperLimit = Integer.parseInt(data[1]);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@@ -68,6 +75,7 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
public void onPickUp() { public void onPickUp() {
this.lowerLimit = 0; this.lowerLimit = 0;
this.upperLimit = 50; this.upperLimit = 50;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -83,9 +91,10 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(2); message.appendInt(3);
message.appendInt(this.lowerLimit); message.appendInt(this.lowerLimit);
message.appendInt(this.upperLimit); message.appendInt(this.upperLimit);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -97,6 +106,8 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
if(settings.getIntParams().length < 2) return false; if(settings.getIntParams().length < 2) return false;
this.lowerLimit = settings.getIntParams()[0]; this.lowerLimit = settings.getIntParams()[0];
this.upperLimit = settings.getIntParams()[1]; this.upperLimit = settings.getIntParams()[1];
int[] params = settings.getIntParams();
this.userSource = (params.length > 2) ? params[2] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
@@ -104,10 +115,12 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
static class JsonData { static class JsonData {
int lowerLimit; int lowerLimit;
int upperLimit; int upperLimit;
int userSource;
public JsonData(int lowerLimit, int upperLimit) { public JsonData(int lowerLimit, int upperLimit, int userSource) {
this.lowerLimit = lowerLimit; this.lowerLimit = lowerLimit;
this.upperLimit = upperLimit; this.upperLimit = upperLimit;
this.userSource = userSource;
} }
} }
} }
@@ -8,15 +8,18 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionHabboHasEffect extends InteractionWiredCondition { public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_EFFECT; public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_EFFECT;
protected int effectId = 0; protected int effectId = 0;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionHabboHasEffect(ResultSet set, Item baseItem) throws SQLException { public WiredConditionHabboHasEffect(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -28,9 +31,14 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (roomUnit == null) return false; if (targets.isEmpty()) return false;
return roomUnit.getEffectId() == this.effectId; for (RoomUnit roomUnit : targets) {
if (roomUnit != null && roomUnit.getEffectId() == this.effectId) {
return true;
}
}
return false;
} }
@Deprecated @Deprecated
@@ -42,7 +50,8 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.effectId this.effectId,
this.userSource
)); ));
} }
@@ -53,14 +62,17 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.effectId = data.effectId; this.effectId = data.effectId;
this.userSource = data.userSource;
} else { } else {
this.effectId = Integer.parseInt(wiredData); this.effectId = Integer.parseInt(wiredData);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.effectId = 0; this.effectId = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -76,8 +88,9 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(1); message.appendInt(2);
message.appendInt(this.effectId); message.appendInt(this.effectId);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -88,15 +101,19 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
if(settings.getIntParams().length < 1) return false; if(settings.getIntParams().length < 1) return false;
this.effectId = settings.getIntParams()[0]; this.effectId = settings.getIntParams()[0];
int[] params = settings.getIntParams();
this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
static class JsonData { static class JsonData {
int effectId; int effectId;
int userSource;
public JsonData(int effectId) { public JsonData(int effectId, int userSource) {
this.effectId = effectId; this.effectId = effectId;
this.userSource = userSource;
} }
} }
} }
@@ -8,12 +8,14 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
private static final Logger LOGGER = LoggerFactory.getLogger(WiredConditionHabboHasHandItem.class); private static final Logger LOGGER = LoggerFactory.getLogger(WiredConditionHabboHasHandItem.class);
@@ -21,6 +23,7 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_HAS_HANDITEM; public static final WiredConditionType type = WiredConditionType.ACTOR_HAS_HANDITEM;
private int handItem; private int handItem;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionHabboHasHandItem(ResultSet set, Item baseItem) throws SQLException { public WiredConditionHabboHasHandItem(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -43,8 +46,9 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(1); message.appendInt(2);
message.appendInt(this.handItem); message.appendInt(this.handItem);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -55,15 +59,22 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
if(settings.getIntParams().length < 1) return false; if(settings.getIntParams().length < 1) return false;
this.handItem = settings.getIntParams()[0]; this.handItem = settings.getIntParams()[0];
int[] params = settings.getIntParams();
this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (roomUnit == null) return false; if (targets.isEmpty()) return false;
return roomUnit.getHandItem() == this.handItem; for (RoomUnit roomUnit : targets) {
if (roomUnit != null && roomUnit.getHandItem() == this.handItem) {
return true;
}
}
return false;
} }
@Deprecated @Deprecated
@@ -75,7 +86,8 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.handItem this.handItem,
this.userSource
)); ));
} }
@@ -87,8 +99,10 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.handItem = data.handItemId; this.handItem = data.handItemId;
this.userSource = data.userSource;
} else { } else {
this.handItem = Integer.parseInt(wiredData); this.handItem = Integer.parseInt(wiredData);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Caught exception", e); LOGGER.error("Caught exception", e);
@@ -98,13 +112,16 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
@Override @Override
public void onPickUp() { public void onPickUp() {
this.handItem = 0; this.handItem = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
int handItemId; int handItemId;
int userSource;
public JsonData(int handItemId) { public JsonData(int handItemId, int userSource) {
this.handItemId = handItemId; this.handItemId = handItemId;
this.userSource = userSource;
} }
} }
} }
@@ -10,15 +10,18 @@ import com.eu.habbo.habbohotel.users.HabboBadge;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_BADGE; public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_BADGE;
protected String badge = ""; protected String badge = "";
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionHabboWearsBadge(ResultSet set, Item baseItem) throws SQLException { public WiredConditionHabboWearsBadge(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -30,15 +33,18 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null);
Room room = ctx.room(); Room room = ctx.room();
Habbo habbo = room.getHabbo(roomUnit); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (targets.isEmpty()) return false;
if (habbo != null) { for (RoomUnit roomUnit : targets) {
synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) { Habbo habbo = room.getHabbo(roomUnit);
for (HabboBadge badge : habbo.getInventory().getBadgesComponent().getWearingBadges()) { if (habbo != null) {
if (badge.getCode().equalsIgnoreCase(this.badge)) { synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) {
return true; for (HabboBadge badge : habbo.getInventory().getBadgesComponent().getWearingBadges()) {
if (badge.getCode().equalsIgnoreCase(this.badge)) {
return true;
}
} }
} }
} }
@@ -55,7 +61,8 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.badge this.badge,
this.userSource
)); ));
} }
@@ -66,14 +73,17 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.badge = data.badge; this.badge = data.badge;
this.userSource = data.userSource;
} else { } else {
this.badge = wiredData; this.badge = wiredData;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.badge = ""; this.badge = "";
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -89,7 +99,8 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.badge); message.appendString(this.badge);
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -99,15 +110,19 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
@Override @Override
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
this.badge = settings.getStringParam(); this.badge = settings.getStringParam();
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
static class JsonData { static class JsonData {
String badge; String badge;
int userSource;
public JsonData(String badge) { public JsonData(String badge, int userSource) {
this.badge = badge; this.badge = badge;
this.userSource = userSource;
} }
} }
} }
@@ -12,13 +12,16 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings {
public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT; public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT;
@@ -28,6 +31,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
private boolean state; private boolean state;
private boolean position; private boolean position;
private boolean direction; private boolean direction;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionMatchStatePosition(ResultSet set, Item baseItem) throws SQLException { public WiredConditionMatchStatePosition(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -62,7 +66,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
message.appendInt(this.state ? 1 : 0); message.appendInt(this.state ? 1 : 0);
message.appendInt(this.direction ? 1 : 0); message.appendInt(this.direction ? 1 : 0);
message.appendInt(this.position ? 1 : 0); message.appendInt(this.position ? 1 : 0);
message.appendInt(10); message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -72,9 +76,11 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
@Override @Override
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
if(settings.getIntParams().length < 3) return false; if(settings.getIntParams().length < 3) return false;
this.state = settings.getIntParams()[0] == 1; int[] params = settings.getIntParams();
this.direction = settings.getIntParams()[1] == 1; this.state = params[0] == 1;
this.position = settings.getIntParams()[2] == 1; this.direction = params[1] == 1;
this.position = params[2] == 1;
this.furniSource = (params.length > 3) ? params[3] : WiredSourceUtil.SOURCE_TRIGGER;
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
@@ -86,12 +92,14 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
this.settings.clear(); this.settings.clear();
for (int i = 0; i < count; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
int itemId = settings.getFurniIds()[i]; for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(itemId); int itemId = settings.getFurniIds()[i];
HabboItem item = room.getHabboItem(itemId);
if (item != null) if (item != null)
this.settings.add(new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY())); this.settings.add(new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY()));
}
} }
return true; return true;
@@ -103,12 +111,30 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
if (this.settings.isEmpty()) if (this.settings.isEmpty())
return true; return true;
THashSet<WiredMatchFurniSetting> s = new THashSet<>(); List<HabboItem> targets = null;
Set<Integer> targetIds = null;
if (this.furniSource != WiredSourceUtil.SOURCE_SELECTED) {
targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, null);
if (targets.isEmpty()) return false;
targetIds = new HashSet<>();
for (HabboItem item : targets) {
if (item != null) targetIds.add(item.getId());
}
if (targetIds.isEmpty()) return false;
}
THashSet<WiredMatchFurniSetting> toRemove = new THashSet<>();
Set<Integer> settingsIds = new HashSet<>();
for (WiredMatchFurniSetting setting : this.settings) { for (WiredMatchFurniSetting setting : this.settings) {
if (targetIds != null && !targetIds.contains(setting.item_id)) {
continue;
}
HabboItem item = room.getHabboItem(setting.item_id); HabboItem item = room.getHabboItem(setting.item_id);
if (item != null) { if (item != null) {
settingsIds.add(setting.item_id);
if (this.state) { if (this.state) {
if (!item.getExtradata().equals(setting.state)) if (!item.getExtradata().equals(setting.state))
return false; return false;
@@ -124,12 +150,16 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
return false; return false;
} }
} else { } else {
s.add(setting); toRemove.add(setting);
} }
} }
if (!s.isEmpty()) { if (targetIds != null && !settingsIds.containsAll(targetIds)) {
for (WiredMatchFurniSetting setting : s) { return false;
}
if (!toRemove.isEmpty()) {
for (WiredMatchFurniSetting setting : toRemove) {
this.settings.remove(setting); this.settings.remove(setting);
} }
} }
@@ -149,7 +179,8 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
this.state, this.state,
this.position, this.position,
this.direction, this.direction,
new ArrayList<>(this.settings) new ArrayList<>(this.settings),
this.furniSource
)); ));
} }
@@ -163,6 +194,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
this.position = data.position; this.position = data.position;
this.direction = data.direction; this.direction = data.direction;
this.settings.addAll(data.settings); this.settings.addAll(data.settings);
this.furniSource = data.furniSource;
} else { } else {
String[] data = wiredData.split(":"); String[] data = wiredData.split(":");
@@ -180,6 +212,10 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
this.state = data[2].equals("1"); this.state = data[2].equals("1");
this.direction = data[3].equals("1"); this.direction = data[3].equals("1");
this.position = data[4].equals("1"); this.position = data[4].equals("1");
this.furniSource = this.settings.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
}
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.settings.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -189,6 +225,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
this.direction = false; this.direction = false;
this.position = false; this.position = false;
this.state = false; this.state = false;
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
private void refresh() { private void refresh() {
@@ -235,12 +272,14 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
boolean position; boolean position;
boolean direction; boolean direction;
List<WiredMatchFurniSetting> settings; List<WiredMatchFurniSetting> settings;
int furniSource;
public JsonData(boolean state, boolean position, boolean direction, List<WiredMatchFurniSetting> settings) { public JsonData(boolean state, boolean position, boolean direction, List<WiredMatchFurniSetting> settings, int furniSource) {
this.state = state; this.state = state;
this.position = position; this.position = position;
this.direction = direction; this.direction = direction;
this.settings = settings; this.settings = settings;
this.furniSource = furniSource;
} }
} }
} }
@@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
@@ -25,6 +26,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
private boolean all; private boolean all;
private THashSet<HabboItem> items; private THashSet<HabboItem> items;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionNotFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException { public WiredConditionNotFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -42,14 +44,15 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
this.refresh(); this.refresh();
if (this.items.isEmpty()) List<HabboItem> targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
if (targets.isEmpty())
return true; return true;
if (room.getLayout() == null) if (room.getLayout() == null)
return true; return true;
if(this.all) { if(this.all) {
return this.items.stream().allMatch(item -> { return targets.stream().allMatch(item -> {
if (item == null) return true; if (item == null) return true;
RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
if (baseTile == null) return true; if (baseTile == null) return true;
@@ -60,7 +63,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
}); });
} }
else { else {
return this.items.stream().anyMatch(item -> { return targets.stream().anyMatch(item -> {
if (item == null) return true; if (item == null) return true;
RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
if (baseTile == null) return true; if (baseTile == null) return true;
@@ -83,7 +86,8 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
this.refresh(); this.refresh();
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.all, this.all,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) this.items.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -95,6 +99,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.all = data.all; this.all = data.all;
this.furniSource = data.furniSource;
for (int id : data.itemIds) { for (int id : data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -120,6 +125,10 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
} }
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
}
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -127,6 +136,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
public void onPickUp() { public void onPickUp() {
this.all = false; this.all = false;
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -148,8 +158,9 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(1); message.appendInt(2);
message.appendInt(this.all ? 1 : 0); message.appendInt(this.all ? 1 : 0);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -159,26 +170,28 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
@Override @Override
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
if(settings.getIntParams().length < 1) return false; if(settings.getIntParams().length < 1) return false;
this.all = settings.getIntParams()[0] == 1; int[] params = settings.getIntParams();
this.all = params[0] == 1;
this.furniSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
int count = settings.getFurniIds().length; int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear(); this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) return false;
if (room != null) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); HabboItem item = room.getHabboItem(settings.getFurniIds()[i]);
if (item != null) if (item != null)
this.items.add(item); this.items.add(item);
} }
return true;
} }
return false; return true;
} }
private void refresh() { private void refresh() {
@@ -209,10 +222,12 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
static class JsonData { static class JsonData {
boolean all; boolean all;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(boolean all, List<Integer> itemIds) { public JsonData(boolean all, List<Integer> itemIds, int furniSource) {
this.all = all; this.all = all;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
@@ -27,6 +28,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_HABBO; public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_HABBO;
protected THashSet<HabboItem> items; protected THashSet<HabboItem> items;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionNotFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException { public WiredConditionNotFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -41,6 +43,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -49,7 +52,8 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
this.refresh(); this.refresh();
if (this.items.isEmpty()) List<HabboItem> targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
if (targets.isEmpty())
return true; return true;
if (room.getLayout() == null) if (room.getLayout() == null)
@@ -59,7 +63,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
Collection<Bot> bots = room.getCurrentBots().valueCollection(); Collection<Bot> bots = room.getCurrentBots().valueCollection();
Collection<Pet> pets = room.getCurrentPets().valueCollection(); Collection<Pet> pets = room.getCurrentPets().valueCollection();
return this.items.stream().filter(item -> item != null).noneMatch(item -> { return targets.stream().filter(item -> item != null).noneMatch(item -> {
RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
if (baseTile == null) return false; if (baseTile == null) return false;
@@ -80,7 +84,8 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
public String getWiredData() { public String getWiredData() {
this.refresh(); this.refresh();
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) this.items.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -91,6 +96,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
WiredConditionFurniHaveHabbo.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class); WiredConditionFurniHaveHabbo.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class);
this.furniSource = data.furniSource;
for(int id : data.itemIds) { for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -112,6 +118,10 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
this.items.add(item); this.items.add(item);
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
}
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -134,7 +144,8 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -146,22 +157,25 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
int count = settings.getFurniIds().length; int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
this.items.clear(); this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) return false;
if (room != null) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); HabboItem item = room.getHabboItem(settings.getFurniIds()[i]);
if (item != null) if (item != null)
this.items.add(item); this.items.add(item);
} }
return true;
} }
return false; return true;
} }
private void refresh() { private void refresh() {
@@ -184,9 +198,11 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
static class JsonData { static class JsonData {
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(List<Integer> itemIds) { public JsonData(List<Integer> itemIds, int furniSource) {
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
@@ -22,6 +23,7 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_STUFF_IS; public static final WiredConditionType type = WiredConditionType.NOT_STUFF_IS;
private THashSet<HabboItem> items = new THashSet<>(); private THashSet<HabboItem> items = new THashSet<>();
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionNotFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException { public WiredConditionNotFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -38,12 +40,9 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
if(items.isEmpty()) if(items.isEmpty())
return true; return true;
HabboItem triggeringItem = ctx.sourceItem().orElse(null); List<HabboItem> targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
if (triggeringItem != null) { if (targets.isEmpty()) return true;
return this.items.stream().noneMatch(item -> item == triggeringItem); return targets.stream().noneMatch(this.items::contains);
}
return true;
} }
@Deprecated @Deprecated
@@ -56,7 +55,8 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
public String getWiredData() { public String getWiredData() {
this.refresh(); this.refresh();
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) this.items.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -67,6 +67,7 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
WiredConditionFurniTypeMatch.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class); WiredConditionFurniTypeMatch.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class);
this.furniSource = data.furniSource;
for(int id : data.itemIds) { for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -85,12 +86,17 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
this.items.add(item); this.items.add(item);
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
}
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -112,7 +118,8 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -124,13 +131,18 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
int count = settings.getFurniIds().length; int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
this.items.clear(); this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) { if (room != null) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
this.items.add(room.getHabboItem(settings.getFurniIds()[i])); this.items.add(room.getHabboItem(settings.getFurniIds()[i]));
}
} }
} }
@@ -157,9 +169,11 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
static class JsonData { static class JsonData {
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(List<Integer> itemIds) { public JsonData(List<Integer> itemIds, int furniSource) {
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -8,6 +8,7 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
@@ -18,6 +19,7 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
private int lowerLimit = 10; private int lowerLimit = 10;
private int upperLimit = 20; private int upperLimit = 20;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionNotHabboCount(ResultSet set, Item baseItem) throws SQLException { public WiredConditionNotHabboCount(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -29,7 +31,9 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
int count = ctx.room().getUserCount(); int count = (this.userSource == WiredSourceUtil.SOURCE_TRIGGER)
? ctx.room().getUserCount()
: WiredSourceUtil.resolveUsers(ctx, this.userSource).size();
return count < this.lowerLimit || count > this.upperLimit; return count < this.lowerLimit || count > this.upperLimit;
} }
@@ -44,7 +48,8 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.lowerLimit, this.lowerLimit,
this.upperLimit this.upperLimit,
this.userSource
)); ));
} }
@@ -56,10 +61,12 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
WiredConditionHabboCount.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionHabboCount.JsonData.class); WiredConditionHabboCount.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionHabboCount.JsonData.class);
this.lowerLimit = data.lowerLimit; this.lowerLimit = data.lowerLimit;
this.upperLimit = data.upperLimit; this.upperLimit = data.upperLimit;
this.userSource = data.userSource;
} else { } else {
String[] data = wiredData.split(":"); String[] data = wiredData.split(":");
this.lowerLimit = Integer.parseInt(data[0]); this.lowerLimit = Integer.parseInt(data[0]);
this.upperLimit = Integer.parseInt(data[1]); this.upperLimit = Integer.parseInt(data[1]);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@@ -67,6 +74,7 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
public void onPickUp() { public void onPickUp() {
this.upperLimit = 0; this.upperLimit = 0;
this.lowerLimit = 20; this.lowerLimit = 20;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -82,9 +90,10 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(2); message.appendInt(3);
message.appendInt(this.lowerLimit); message.appendInt(this.lowerLimit);
message.appendInt(this.upperLimit); message.appendInt(this.upperLimit);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -96,6 +105,8 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
if(settings.getIntParams().length < 2) return false; if(settings.getIntParams().length < 2) return false;
this.lowerLimit = settings.getIntParams()[0]; this.lowerLimit = settings.getIntParams()[0];
this.upperLimit = settings.getIntParams()[1]; this.upperLimit = settings.getIntParams()[1];
int[] params = settings.getIntParams();
this.userSource = (params.length > 2) ? params[2] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
@@ -103,10 +114,12 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
static class JsonData { static class JsonData {
int lowerLimit; int lowerLimit;
int upperLimit; int upperLimit;
int userSource;
public JsonData(int lowerLimit, int upperLimit) { public JsonData(int lowerLimit, int upperLimit, int userSource) {
this.lowerLimit = lowerLimit; this.lowerLimit = lowerLimit;
this.upperLimit = upperLimit; this.upperLimit = upperLimit;
this.userSource = userSource;
} }
} }
} }
@@ -8,15 +8,18 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
private static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_EFFECT; private static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_EFFECT;
protected int effectId; protected int effectId;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionNotHabboHasEffect(ResultSet set, Item baseItem) throws SQLException { public WiredConditionNotHabboHasEffect(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -28,9 +31,15 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (roomUnit == null) return false; if (targets.isEmpty()) return false;
return roomUnit.getEffectId() != this.effectId; for (RoomUnit roomUnit : targets) {
if (roomUnit == null) return false;
if (roomUnit.getEffectId() == this.effectId) {
return false;
}
}
return true;
} }
@Deprecated @Deprecated
@@ -42,7 +51,8 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.effectId this.effectId,
this.userSource
)); ));
} }
@@ -53,14 +63,17 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.effectId = data.effectId; this.effectId = data.effectId;
this.userSource = data.userSource;
} else { } else {
this.effectId = Integer.parseInt(wiredData); this.effectId = Integer.parseInt(wiredData);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.effectId = 0; this.effectId = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -76,7 +89,9 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.effectId + ""); message.appendString(this.effectId + "");
message.appendInt(0); message.appendInt(2);
message.appendInt(this.effectId);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -87,15 +102,19 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
if(settings.getIntParams().length < 1) return false; if(settings.getIntParams().length < 1) return false;
this.effectId = settings.getIntParams()[0]; this.effectId = settings.getIntParams()[0];
int[] params = settings.getIntParams();
this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
static class JsonData { static class JsonData {
int effectId; int effectId;
int userSource;
public JsonData(int effectId) { public JsonData(int effectId, int userSource) {
this.effectId = effectId; this.effectId = effectId;
this.userSource = userSource;
} }
} }
} }
@@ -10,15 +10,18 @@ import com.eu.habbo.habbohotel.users.HabboBadge;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition { public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_BADGE; public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_BADGE;
protected String badge = ""; protected String badge = "";
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionNotHabboWearsBadge(ResultSet set, Item baseItem) throws SQLException { public WiredConditionNotHabboWearsBadge(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -30,20 +33,21 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null);
Room room = ctx.room(); Room room = ctx.room();
Habbo habbo = room.getHabbo(roomUnit); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (targets.isEmpty()) return true;
if (habbo != null) { for (RoomUnit roomUnit : targets) {
synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) { Habbo habbo = room.getHabbo(roomUnit);
for (HabboBadge b : habbo.getInventory().getBadgesComponent().getWearingBadges()) { if (habbo != null) {
if (b.getCode().equalsIgnoreCase(this.badge)) synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) {
return false; for (HabboBadge b : habbo.getInventory().getBadgesComponent().getWearingBadges()) {
if (b.getCode().equalsIgnoreCase(this.badge))
return false;
}
} }
} }
return true;
} }
return true; return true;
} }
@@ -56,7 +60,8 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.badge this.badge,
this.userSource
)); ));
} }
@@ -67,14 +72,17 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.badge = data.badge; this.badge = data.badge;
this.userSource = data.userSource;
} else { } else {
this.badge = wiredData; this.badge = wiredData;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.badge = ""; this.badge = "";
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -90,7 +98,8 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.badge); message.appendString(this.badge);
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -100,15 +109,19 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
@Override @Override
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
this.badge = settings.getStringParam(); this.badge = settings.getStringParam();
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
static class JsonData { static class JsonData {
String badge; String badge;
int userSource;
public JsonData(String badge) { public JsonData(String badge, int userSource) {
this.badge = badge; this.badge = badge;
this.userSource = userSource;
} }
} }
} }
@@ -8,13 +8,16 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionNotInGroup extends InteractionWiredCondition { public class WiredConditionNotInGroup extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_GROUP; public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_GROUP;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionNotInGroup(ResultSet set, Item baseItem) throws SQLException { public WiredConditionNotInGroup(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -26,14 +29,20 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null);
Room room = ctx.room(); Room room = ctx.room();
if (room.getGuildId() == 0) if (room.getGuildId() == 0)
return false; return false;
Habbo habbo = room.getHabbo(roomUnit); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (targets.isEmpty()) return true;
return habbo == null || !habbo.getHabboStats().hasGuild(room.getGuildId()); for (RoomUnit roomUnit : targets) {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null && habbo.getHabboStats().hasGuild(room.getGuildId())) {
return false;
}
}
return true;
} }
@Deprecated @Deprecated
@@ -44,17 +53,26 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition {
@Override @Override
public String getWiredData() { public String getWiredData() {
return ""; return String.valueOf(this.userSource);
} }
@Override @Override
public void loadWiredData(ResultSet set, Room room) throws SQLException { public void loadWiredData(ResultSet set, Room room) throws SQLException {
String wiredData = set.getString("wired_data");
if (wiredData != null && !wiredData.isEmpty()) {
try {
this.userSource = Integer.parseInt(wiredData);
} catch (NumberFormatException ignored) {
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
}
} else {
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
}
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -70,7 +88,8 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -79,6 +98,8 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition {
@Override @Override
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
} }
@@ -10,15 +10,18 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionNotInTeam extends InteractionWiredCondition { public class WiredConditionNotInTeam extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_TEAM; public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_TEAM;
private GameTeamColors teamColor = GameTeamColors.RED; private GameTeamColors teamColor = GameTeamColors.RED;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionNotInTeam(ResultSet set, Item baseItem) throws SQLException { public WiredConditionNotInTeam(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -30,14 +33,18 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null);
Room room = ctx.room(); Room room = ctx.room();
Habbo habbo = room.getHabbo(roomUnit); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (targets.isEmpty()) return true;
if (habbo != null) { for (RoomUnit roomUnit : targets) {
return habbo.getHabboInfo().getGamePlayer() == null || !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); // user is not part of any team Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null && habbo.getHabboInfo().getGamePlayer() != null) {
if (habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor)) {
return false;
}
}
} }
return true; return true;
} }
@@ -50,7 +57,8 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.teamColor this.teamColor,
this.userSource
)); ));
} }
@@ -62,18 +70,22 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.teamColor = data.teamColor; this.teamColor = data.teamColor;
this.userSource = data.userSource;
} else { } else {
if (!wiredData.equals("")) if (!wiredData.equals(""))
this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)]; this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)];
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} catch (Exception e) { } catch (Exception e) {
this.teamColor = GameTeamColors.RED; this.teamColor = GameTeamColors.RED;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.teamColor = GameTeamColors.RED; this.teamColor = GameTeamColors.RED;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -89,8 +101,9 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(1); message.appendInt(2);
message.appendInt(this.teamColor.type); message.appendInt(this.teamColor.type);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -101,15 +114,19 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
if(settings.getIntParams().length < 1) return false; if(settings.getIntParams().length < 1) return false;
this.teamColor = GameTeamColors.values()[settings.getIntParams()[0]]; this.teamColor = GameTeamColors.values()[settings.getIntParams()[0]];
int[] params = settings.getIntParams();
this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
static class JsonData { static class JsonData {
GameTeamColors teamColor; GameTeamColors teamColor;
int userSource;
public JsonData(GameTeamColors teamColor) { public JsonData(GameTeamColors teamColor, int userSource) {
this.teamColor = teamColor; this.teamColor = teamColor;
this.userSource = userSource;
} }
} }
} }
@@ -3,11 +3,14 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit; 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.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurni { public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurni {
public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_ON_FURNI; public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_ON_FURNI;
@@ -22,18 +25,19 @@ public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurn
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null);
Room room = ctx.room(); Room room = ctx.room();
if (roomUnit == null)
return false;
this.refresh(); this.refresh();
if (this.items.isEmpty()) List<RoomUnit> userTargets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (userTargets.isEmpty())
return false;
List<HabboItem> itemTargets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
if (itemTargets.isEmpty())
return true; return true;
return !triggerOnFurni(roomUnit, room); return !isAnyUserOnFurni(userTargets, itemTargets, room);
} }
@Deprecated @Deprecated
@@ -10,15 +10,18 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
public class WiredConditionTeamMember extends InteractionWiredCondition { public class WiredConditionTeamMember extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.ACTOR_IN_TEAM; public static final WiredConditionType type = WiredConditionType.ACTOR_IN_TEAM;
private GameTeamColors teamColor = GameTeamColors.RED; private GameTeamColors teamColor = GameTeamColors.RED;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionTeamMember(ResultSet set, Item baseItem) throws SQLException { public WiredConditionTeamMember(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -30,16 +33,18 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null);
Room room = ctx.room(); Room room = ctx.room();
Habbo habbo = room.getHabbo(roomUnit); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (targets.isEmpty()) return false;
if (habbo != null) { for (RoomUnit roomUnit : targets) {
if (habbo.getHabboInfo().getGamePlayer() != null) { Habbo habbo = room.getHabbo(roomUnit);
return habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); if (habbo != null && habbo.getHabboInfo().getGamePlayer() != null) {
if (habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor)) {
return true;
}
} }
} }
return false; return false;
} }
@@ -52,7 +57,8 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.teamColor this.teamColor,
this.userSource
)); ));
} }
@@ -64,18 +70,22 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.teamColor = data.teamColor; this.teamColor = data.teamColor;
this.userSource = data.userSource;
} else { } else {
if (!wiredData.equals("")) if (!wiredData.equals(""))
this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)]; this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)];
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} catch (Exception e) { } catch (Exception e) {
this.teamColor = GameTeamColors.RED; this.teamColor = GameTeamColors.RED;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.teamColor = GameTeamColors.RED; this.teamColor = GameTeamColors.RED;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -91,8 +101,9 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(1); message.appendInt(2);
message.appendInt(this.teamColor.type); message.appendInt(this.teamColor.type);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -103,15 +114,19 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
if(settings.getIntParams().length < 1) return false; if(settings.getIntParams().length < 1) return false;
this.teamColor = GameTeamColors.values()[settings.getIntParams()[0]]; this.teamColor = GameTeamColors.values()[settings.getIntParams()[0]];
int[] params = settings.getIntParams();
this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
return true; return true;
} }
static class JsonData { static class JsonData {
GameTeamColors teamColor; GameTeamColors teamColor;
int userSource;
public JsonData(GameTeamColors teamColor) { public JsonData(GameTeamColors teamColor, int userSource) {
this.teamColor = teamColor; this.teamColor = teamColor;
this.userSource = userSource;
} }
} }
} }
@@ -11,11 +11,13 @@ import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -23,6 +25,8 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI; public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI;
protected THashSet<HabboItem> items = new THashSet<>(); protected THashSet<HabboItem> items = new THashSet<>();
protected int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
protected int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException { public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -34,18 +38,19 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
@Override @Override
public boolean evaluate(WiredContext ctx) { public boolean evaluate(WiredContext ctx) {
RoomUnit roomUnit = ctx.actor().orElse(null);
Room room = ctx.room(); Room room = ctx.room();
if (roomUnit == null)
return false;
this.refresh(); this.refresh();
if (this.items.isEmpty()) List<RoomUnit> userTargets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (userTargets.isEmpty())
return false; return false;
return triggerOnFurni(roomUnit, room); List<HabboItem> itemTargets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
if (itemTargets.isEmpty())
return false;
return isAnyUserOnFurni(userTargets, itemTargets, room);
} }
@Deprecated @Deprecated
@@ -54,16 +59,24 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
return false; return false;
} }
protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) { protected boolean isAnyUserOnFurni(Collection<RoomUnit> users, Collection<HabboItem> items, Room room) {
THashSet<HabboItem> itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); for (RoomUnit roomUnit : users) {
return this.items.stream().anyMatch(itemsAtUser::contains); if (roomUnit == null) continue;
THashSet<HabboItem> itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation());
if (items.stream().anyMatch(itemsAtUser::contains)) {
return true;
}
}
return false;
} }
@Override @Override
public String getWiredData() { public String getWiredData() {
this.refresh(); this.refresh();
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) this.items.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource,
this.userSource
)); ));
} }
@@ -74,6 +87,8 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.furniSource = data.furniSource;
this.userSource = data.userSource;
for(int id : data.itemIds) { for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -92,12 +107,19 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
this.items.add(item); this.items.add(item);
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
}
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -119,7 +141,9 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(2);
message.appendInt(this.furniSource);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(0); message.appendInt(0);
@@ -131,16 +155,22 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
int count = settings.getFurniIds().length; int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
this.items.clear(); this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) { if (room != null) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); HabboItem item = room.getHabboItem(settings.getFurniIds()[i]);
if (item != null) { if (item != null) {
this.items.add(item); this.items.add(item);
}
} }
} }
} }
@@ -171,9 +201,13 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
static class JsonData { static class JsonData {
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
int userSource;
public JsonData(List<Integer> itemIds) { public JsonData(List<Integer> itemIds, int furniSource, int userSource) {
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
this.userSource = userSource;
} }
} }
} }
@@ -22,7 +22,7 @@ public class WiredEffectAlert extends WiredEffectWhisper {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
for (com.eu.habbo.habbohotel.rooms.RoomUnit unit : ctx.targets().users()) { for (com.eu.habbo.habbohotel.rooms.RoomUnit unit : resolveUsers(ctx)) {
Habbo habbo = room.getHabbo(unit); Habbo habbo = room.getHabbo(unit);
if (habbo == null) continue; if (habbo == null) continue;
@@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -27,6 +28,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
private String botName = ""; private String botName = "";
private int mode = 0; private int mode = 0;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectBotFollowHabbo(ResultSet set, Item baseItem) throws SQLException { public WiredEffectBotFollowHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -44,8 +46,9 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.botName); message.appendString(this.botName);
message.appendInt(1); message.appendInt(2);
message.appendInt(this.mode); message.appendInt(this.mode);
message.appendInt(this.userSource);
message.appendInt(1); message.appendInt(1);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -72,9 +75,10 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
if(settings.getIntParams().length < 1) throw new WiredSaveException("Mode is invalid"); if(settings.getIntParams().length < 2) throw new WiredSaveException("Mode is invalid");
int mode = settings.getIntParams()[0]; int mode = settings.getIntParams()[0];
this.userSource = settings.getIntParams()[1];
if(mode != 0 && mode != 1) if(mode != 0 && mode != 1)
throw new WiredSaveException("Mode is invalid"); throw new WiredSaveException("Mode is invalid");
@@ -102,8 +106,9 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
@Override @Override
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
RoomUnit roomUnit = ctx.actor().orElse(null); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (roomUnit == null) return; if (targets.isEmpty()) return;
RoomUnit roomUnit = targets.get(0);
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
List<Bot> bots = room.getBots(this.botName); List<Bot> bots = room.getBots(this.botName);
@@ -127,7 +132,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -139,6 +144,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
this.setDelay(data.delay); this.setDelay(data.delay);
this.mode = data.mode; this.mode = data.mode;
this.botName = data.bot_name; this.botName = data.bot_name;
this.userSource = data.userSource;
} }
else { else {
String[] data = wiredData.split(((char) 9) + ""); String[] data = wiredData.split(((char) 9) + "");
@@ -150,6 +156,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@@ -157,23 +164,26 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
public void onPickUp() { public void onPickUp() {
this.botName = ""; this.botName = "";
this.mode = 0; this.mode = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
String bot_name; String bot_name;
int mode; int mode;
int delay; int delay;
int userSource;
public JsonData(String bot_name, int mode, int delay) { public JsonData(String bot_name, int mode, int delay, int userSource) {
this.bot_name = bot_name; this.bot_name = bot_name;
this.mode = mode; this.mode = mode;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem; import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
@@ -30,6 +31,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
private String botName = ""; private String botName = "";
private int itemId; private int itemId;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectBotGiveHandItem(ResultSet set, Item baseItem) throws SQLException { public WiredEffectBotGiveHandItem(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -47,8 +49,9 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.botName); message.appendString(this.botName);
message.appendInt(1); message.appendInt(2);
message.appendInt(this.itemId); message.appendInt(this.itemId);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -75,9 +78,10 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
if(settings.getIntParams().length < 1) throw new WiredSaveException("Missing item id"); if(settings.getIntParams().length < 2) throw new WiredSaveException("Missing item id");
int itemId = settings.getIntParams()[0]; int itemId = settings.getIntParams()[0];
this.userSource = settings.getIntParams()[1];
if(itemId < 0) if(itemId < 0)
itemId = 0; itemId = 0;
@@ -104,8 +108,9 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
@Override @Override
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
RoomUnit roomUnit = ctx.actor().orElse(null); List<RoomUnit> targets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
if (roomUnit == null) return; if (targets.isEmpty()) return;
RoomUnit roomUnit = targets.get(0);
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
List<Bot> bots = room.getBots(this.botName); List<Bot> bots = room.getBots(this.botName);
@@ -141,7 +146,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.botName, this.itemId, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.botName, this.itemId, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -153,6 +158,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
this.setDelay(data.delay); this.setDelay(data.delay);
this.itemId = data.item_id; this.itemId = data.item_id;
this.botName = data.bot_name; this.botName = data.bot_name;
this.userSource = data.userSource;
} }
else { else {
String[] data = wiredData.split(((char) 9) + ""); String[] data = wiredData.split(((char) 9) + "");
@@ -164,6 +170,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@@ -171,23 +178,26 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
public void onPickUp() { public void onPickUp() {
this.botName = ""; this.botName = "";
this.itemId = 0; this.itemId = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
String bot_name; String bot_name;
int item_id; int item_id;
int delay; int delay;
int userSource;
public JsonData(String bot_name, int item_id, int delay) { public JsonData(String bot_name, int item_id, int delay, int userSource) {
this.bot_name = bot_name; this.bot_name = bot_name;
this.item_id = item_id; this.item_id = item_id;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -29,6 +30,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
private int mode; private int mode;
private String botName = ""; private String botName = "";
private String message = ""; private String message = "";
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectBotTalkToHabbo(ResultSet set, Item baseItem) throws SQLException { public WiredEffectBotTalkToHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -46,8 +48,9 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.botName + "" + ((char) 9) + "" + this.message); message.appendString(this.botName + "" + ((char) 9) + "" + this.message);
message.appendInt(1); message.appendInt(2);
message.appendInt(this.mode); message.appendInt(this.mode);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -74,8 +77,9 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
if(settings.getIntParams().length < 1) throw new WiredSaveException("Missing mode"); if(settings.getIntParams().length < 2) throw new WiredSaveException("Missing mode");
int mode = settings.getIntParams()[0]; int mode = settings.getIntParams()[0];
this.userSource = settings.getIntParams()[1];
if(mode != 0 && mode != 1) if(mode != 0 && mode != 1)
throw new WiredSaveException("Mode is invalid"); throw new WiredSaveException("Mode is invalid");
@@ -116,7 +120,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
if (bots.size() != 1) return; if (bots.size() != 1) return;
Bot bot = bots.get(0); Bot bot = bots.get(0);
for (RoomUnit roomUnit : ctx.targets().users()) { for (RoomUnit roomUnit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
if (habbo == null) continue; if (habbo == null) continue;
@@ -149,7 +153,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -162,6 +166,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
this.mode = data.mode; this.mode = data.mode;
this.botName = data.bot_name; this.botName = data.bot_name;
this.message = data.message; this.message = data.message;
this.userSource = data.userSource;
} }
else { else {
String[] data = wiredData.split(((char) 9) + ""); String[] data = wiredData.split(((char) 9) + "");
@@ -174,6 +179,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@@ -182,12 +188,13 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
this.botName = ""; this.botName = "";
this.message = ""; this.message = "";
this.mode = 0; this.mode = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return false; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
@@ -195,12 +202,14 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
int mode; int mode;
String message; String message;
int delay; int delay;
int userSource;
public JsonData(String bot_name, int mode, String message, int delay) { public JsonData(String bot_name, int mode, String message, int delay, int userSource) {
this.bot_name = bot_name; this.bot_name = bot_name;
this.mode = mode; this.mode = mode;
this.message = message; this.message = message;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer;
@@ -32,6 +33,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
private THashSet<HabboItem> items; private THashSet<HabboItem> items;
private String botName = ""; private String botName = "";
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectBotTeleport(ResultSet set, Item baseItem) throws SQLException { public WiredEffectBotTeleport(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -108,7 +110,8 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.botName); message.appendString(this.botName);
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -118,6 +121,8 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
String botName = settings.getStringParam(); String botName = settings.getStringParam();
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
int itemsCount = settings.getFurniIds().length; int itemsCount = settings.getFurniIds().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
@@ -126,14 +131,16 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
List<HabboItem> newItems = new ArrayList<>(); List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
int itemId = settings.getFurniIds()[i]; for (int i = 0; i < itemsCount; i++) {
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); int itemId = settings.getFurniIds()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null) if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId)); throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it); newItems.add(it);
}
} }
int delay = settings.getDelay(); int delay = settings.getDelay();
@@ -142,7 +149,9 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
throw new WiredSaveException("Delay too long"); throw new WiredSaveException("Delay too long");
this.items.clear(); this.items.clear();
this.items.addAll(newItems); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.addAll(newItems);
}
this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.setDelay(delay); this.setDelay(delay);
@@ -158,10 +167,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
Iterable<HabboItem> effectiveItems = ctx.targets().isItemsModifiedBySelector()
? ctx.targets().items()
: new ArrayList<>(this.items);
List<HabboItem> validItems = new ArrayList<>(); List<HabboItem> validItems = new ArrayList<>();
for (HabboItem item : effectiveItems) { for (HabboItem item : effectiveItems) {
@@ -208,7 +214,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
} }
} }
return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay(), this.furniSource));
} }
@Override @Override
@@ -221,6 +227,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.botName = data.bot_name; this.botName = data.bot_name;
this.furniSource = data.furniSource;
for(int itemId : data.items) { for(int itemId : data.items) {
HabboItem item = room.getHabboItem(itemId); HabboItem item = room.getHabboItem(itemId);
@@ -228,6 +235,9 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
if (item != null) if (item != null)
this.items.add(item); this.items.add(item);
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} }
else { else {
String[] wiredDataSplit = set.getString("wired_data").split("\t"); String[] wiredDataSplit = set.getString("wired_data").split("\t");
@@ -249,6 +259,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -256,6 +267,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
public void onPickUp() { public void onPickUp() {
this.botName = ""; this.botName = "";
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -263,11 +275,13 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
String bot_name; String bot_name;
List<Integer> items; List<Integer> items;
int delay; int delay;
int furniSource;
public JsonData(String bot_name, List<Integer> items, int delay) { public JsonData(String bot_name, List<Integer> items, int delay, int furniSource) {
this.bot_name = bot_name; this.bot_name = bot_name;
this.items = items; this.items = items;
this.delay = delay; this.delay = delay;
this.furniSource = furniSource;
} }
} }
} }
@@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
@@ -27,6 +28,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
private List<HabboItem> items; private List<HabboItem> items;
private String botName = ""; private String botName = "";
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectBotWalkToFurni(ResultSet set, Item baseItem) throws SQLException { public WiredEffectBotWalkToFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -60,7 +62,8 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.botName); message.appendString(this.botName);
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -70,6 +73,8 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
String botName = settings.getStringParam(); String botName = settings.getStringParam();
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
int itemsCount = settings.getFurniIds().length; int itemsCount = settings.getFurniIds().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
@@ -78,14 +83,16 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
List<HabboItem> newItems = new ArrayList<>(); List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
int itemId = settings.getFurniIds()[i]; for (int i = 0; i < itemsCount; i++) {
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); int itemId = settings.getFurniIds()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null) if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId)); throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it); newItems.add(it);
}
} }
int delay = settings.getDelay(); int delay = settings.getDelay();
@@ -94,7 +101,9 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
throw new WiredSaveException("Delay too long"); throw new WiredSaveException("Delay too long");
this.items.clear(); this.items.clear();
this.items.addAll(newItems); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.addAll(newItems);
}
this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.setDelay(delay); this.setDelay(delay);
@@ -111,15 +120,9 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
Room room = ctx.room(); Room room = ctx.room();
List<Bot> bots = room.getBots(this.botName); List<Bot> bots = room.getBots(this.botName);
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
boolean useSelector = ctx.targets().isItemsModifiedBySelector(); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
List<HabboItem> effectiveItems;
if (useSelector) {
effectiveItems = new ArrayList<>(ctx.targets().items());
} else {
this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
effectiveItems = this.items;
} }
if (effectiveItems.isEmpty() || bots.size() != 1) { if (effectiveItems.isEmpty() || bots.size() != 1) {
@@ -163,7 +166,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
} }
} }
return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay(), this.furniSource));
} }
@Override @Override
@@ -176,6 +179,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.botName = data.bot_name; this.botName = data.bot_name;
this.furniSource = data.furniSource;
for(int itemId : data.items) { for(int itemId : data.items) {
HabboItem item = room.getHabboItem(itemId); HabboItem item = room.getHabboItem(itemId);
@@ -183,6 +187,9 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
if (item != null) if (item != null)
this.items.add(item); this.items.add(item);
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} }
else { else {
String[] wiredDataSplit = set.getString("wired_data").split("\t"); String[] wiredDataSplit = set.getString("wired_data").split("\t");
@@ -204,6 +211,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -211,6 +219,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.botName = ""; this.botName = "";
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -218,11 +227,13 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
String bot_name; String bot_name;
List<Integer> items; List<Integer> items;
int delay; int delay;
int furniSource;
public JsonData(String bot_name, List<Integer> items, int delay) { public JsonData(String bot_name, List<Integer> items, int delay, int furniSource) {
this.bot_name = bot_name; this.bot_name = bot_name;
this.items = items; this.items = items;
this.delay = delay; this.delay = delay;
this.furniSource = furniSource;
} }
} }
} }
@@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.*; import com.eu.habbo.habbohotel.wired.*;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -36,6 +37,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
private final THashMap<HabboItem, WiredChangeDirectionSetting> items = new THashMap<>(0); private final THashMap<HabboItem, WiredChangeDirectionSetting> items = new THashMap<>(0);
private RoomUserRotation startRotation = RoomUserRotation.NORTH; private RoomUserRotation startRotation = RoomUserRotation.NORTH;
private int blockedAction = 0; private int blockedAction = 0;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectChangeFurniDirection(ResultSet set, Item baseItem) throws SQLException { public WiredEffectChangeFurniDirection(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -50,23 +52,10 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
Room room = ctx.room(); Room room = ctx.room();
if (room == null || room.getLayout() == null) return; if (room == null || room.getLayout() == null) return;
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> resolvedItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items.keySet());
boolean useSelector = ctx.targets().isItemsModifiedBySelector();
THashMap<HabboItem, WiredChangeDirectionSetting> effectiveItems; THashMap<HabboItem, WiredChangeDirectionSetting> effectiveItems;
if (useSelector) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
effectiveItems = new THashMap<>();
for (HabboItem item : ctx.targets().items()) {
if (item != null) {
// Check if we already have settings for this item, otherwise create defaults
WiredChangeDirectionSetting setting = this.items.get(item);
if (setting == null) {
setting = new WiredChangeDirectionSetting(item.getId(), item.getRotation(), this.startRotation);
}
effectiveItems.put(item, setting);
}
}
} else {
THashSet<HabboItem> toRemove = new THashSet<>(); THashSet<HabboItem> toRemove = new THashSet<>();
for (HabboItem item : this.items.keySet()) { for (HabboItem item : this.items.keySet()) {
if (item == null || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) if (item == null || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
@@ -76,6 +65,17 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
this.items.remove(item); this.items.remove(item);
} }
effectiveItems = this.items; effectiveItems = this.items;
} else {
effectiveItems = new THashMap<>();
for (HabboItem item : resolvedItems) {
if (item != null) {
WiredChangeDirectionSetting setting = this.items.get(item);
if (setting == null) {
setting = new WiredChangeDirectionSetting(item.getId(), item.getRotation(), this.startRotation);
}
effectiveItems.put(item, setting);
}
}
} }
if (effectiveItems.isEmpty()) return; if (effectiveItems.isEmpty()) return;
@@ -157,7 +157,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
ArrayList<WiredChangeDirectionSetting> settings = new ArrayList<>(this.items.values()); ArrayList<WiredChangeDirectionSetting> settings = new ArrayList<>(this.items.values());
return WiredManager.getGson().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getDelay(), this.furniSource));
} }
@Override @Override
@@ -172,6 +172,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
this.setDelay(data.delay); this.setDelay(data.delay);
this.startRotation = data.start_direction; this.startRotation = data.start_direction;
this.blockedAction = data.blocked_action; this.blockedAction = data.blocked_action;
this.furniSource = data.furniSource;
for(WiredChangeDirectionSetting setting : data.items) { for(WiredChangeDirectionSetting setting : data.items) {
HabboItem item = room.getHabboItem(setting.item_id); HabboItem item = room.getHabboItem(setting.item_id);
@@ -180,6 +181,9 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
this.items.put(item, setting); this.items.put(item, setting);
} }
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} }
else { else {
String[] data = wiredData.split("\t"); String[] data = wiredData.split("\t");
@@ -212,6 +216,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
this.needsUpdate(true); this.needsUpdate(true);
} }
} }
@@ -222,6 +227,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
this.items.clear(); this.items.clear();
this.blockedAction = 0; this.blockedAction = 0;
this.startRotation = RoomUserRotation.NORTH; this.startRotation = RoomUserRotation.NORTH;
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -240,9 +246,10 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(2); message.appendInt(3);
message.appendInt(this.startRotation != null ? this.startRotation.getValue() : 0); message.appendInt(this.startRotation != null ? this.startRotation.getValue() : 0);
message.appendInt(this.blockedAction); message.appendInt(this.blockedAction);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -251,7 +258,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
if(settings.getIntParams().length < 2) throw new WiredSaveException("Invalid data"); if(settings.getIntParams().length < 3) throw new WiredSaveException("Invalid data");
int startDirectionInt = settings.getIntParams()[0]; int startDirectionInt = settings.getIntParams()[0];
@@ -262,6 +269,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
RoomUserRotation startDirection = RoomUserRotation.fromValue(startDirectionInt); RoomUserRotation startDirection = RoomUserRotation.fromValue(startDirectionInt);
int blockedActionInt = settings.getIntParams()[1]; int blockedActionInt = settings.getIntParams()[1];
this.furniSource = settings.getIntParams()[2];
if(blockedActionInt < 0 || blockedActionInt > 6) { if(blockedActionInt < 0 || blockedActionInt > 6) {
throw new WiredSaveException("Blocked action is invalid"); throw new WiredSaveException("Blocked action is invalid");
@@ -291,7 +299,9 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
throw new WiredSaveException("Delay too long"); throw new WiredSaveException("Delay too long");
this.items.clear(); this.items.clear();
this.items.putAll(newItems); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.putAll(newItems);
}
this.startRotation = startDirection; this.startRotation = startDirection;
this.blockedAction = blockedActionInt; this.blockedAction = blockedActionInt;
this.setDelay(delay); this.setDelay(delay);
@@ -329,12 +339,14 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
int blocked_action; int blocked_action;
List<WiredChangeDirectionSetting> items; List<WiredChangeDirectionSetting> items;
int delay; int delay;
int furniSource;
public 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, int furniSource) {
this.start_direction = start_direction; this.start_direction = start_direction;
this.blocked_action = blocked_action; this.blocked_action = blocked_action;
this.items = items; this.items = items;
this.delay = delay; this.delay = delay;
this.furniSource = furniSource;
} }
} }
} }
@@ -30,7 +30,7 @@ public class WiredEffectGiveEffect extends WiredEffectWhisper {
Room room = ctx.room(); Room room = ctx.room();
if (effectId >= 0) { if (effectId >= 0) {
for (RoomUnit roomUnit : ctx.targets().users()) { for (RoomUnit roomUnit : resolveUsers(ctx)) {
room.giveEffect(roomUnit, effectId, Integer.MAX_VALUE); room.giveEffect(roomUnit, effectId, Integer.MAX_VALUE);
} }
} }
@@ -24,7 +24,7 @@ public class WiredEffectGiveHandItem extends WiredEffectWhisper {
Room room = ctx.room(); Room room = ctx.room();
for (com.eu.habbo.habbohotel.rooms.RoomUnit unit : ctx.targets().users()) { for (com.eu.habbo.habbohotel.rooms.RoomUnit unit : resolveUsers(ctx)) {
Habbo habbo = room.getHabbo(unit); Habbo habbo = room.getHabbo(unit);
if (habbo != null) { if (habbo != null) {
room.giveHandItem(habbo, itemId); room.giveHandItem(habbo, itemId);
@@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.hotelview.BonusRareComposer; import com.eu.habbo.messages.outgoing.hotelview.BonusRareComposer;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -25,6 +26,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
private int amount = 0; private int amount = 0;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectGiveHotelviewBonusRarePoints(ResultSet set, Item baseItem) throws SQLException { public WiredEffectGiveHotelviewBonusRarePoints(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -42,7 +44,8 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.amount + ""); message.appendString(this.amount + "");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(type.code); message.appendInt(type.code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -75,6 +78,9 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
return false; return false;
} }
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(settings.getDelay()); this.setDelay(settings.getDelay());
return true; return true;
@@ -87,12 +93,12 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
@Override @Override
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Habbo habbo = ctx.actor().map(unit -> ctx.room().getHabbo(unit)).orElse(null); if (this.amount <= 0) return;
if (habbo == null) for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
return; Habbo habbo = ctx.room().getHabbo(unit);
if (habbo == null) continue;
if (this.amount > 0) {
habbo.givePoints(Emulator.getConfig().getInt("hotelview.promotional.points.type"), this.amount); habbo.givePoints(Emulator.getConfig().getInt("hotelview.promotional.points.type"), this.amount);
habbo.getClient().sendResponse(new BonusRareComposer(habbo)); habbo.getClient().sendResponse(new BonusRareComposer(habbo));
} }
@@ -106,7 +112,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.getDelay(), this.amount)); return WiredManager.getGson().toJson(new JsonData(this.getDelay(), this.amount, this.userSource));
} }
@Override @Override
@@ -118,6 +124,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.amount = data.amount; this.amount = data.amount;
this.userSource = data.userSource;
} else { } else {
if (wiredData.split("\t").length >= 2) { if (wiredData.split("\t").length >= 2) {
super.setDelay(Integer.parseInt(wiredData.split("\t")[0])); super.setDelay(Integer.parseInt(wiredData.split("\t")[0]));
@@ -133,21 +140,24 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
@Override @Override
public void onPickUp() { public void onPickUp() {
this.amount = 0; this.amount = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
int delay; int delay;
int amount; int amount;
int userSource;
public JsonData(int delay, int amount) { public JsonData(int delay, int amount, int userSource) {
this.delay = delay; this.delay = delay;
this.amount = amount; this.amount = amount;
this.userSource = userSource;
} }
} }
} }
@@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -24,6 +25,7 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
private int amount = 0; private int amount = 0;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectGiveHotelviewHofPoints(ResultSet set, Item baseItem) throws SQLException { public WiredEffectGiveHotelviewHofPoints(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -41,7 +43,8 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.amount + ""); message.appendString(this.amount + "");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(type.code); message.appendInt(type.code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -74,6 +77,9 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
return false; return false;
} }
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(settings.getDelay()); this.setDelay(settings.getDelay());
return true; return true;
@@ -86,12 +92,12 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
@Override @Override
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Habbo habbo = ctx.actor().map(unit -> ctx.room().getHabbo(unit)).orElse(null); if (this.amount <= 0) return;
if (habbo == null) for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
return; Habbo habbo = ctx.room().getHabbo(unit);
if (habbo == null) continue;
if (this.amount > 0) {
habbo.getHabboStats().hofPoints += this.amount; habbo.getHabboStats().hofPoints += this.amount;
Emulator.getThreading().run(habbo.getHabboStats()); Emulator.getThreading().run(habbo.getHabboStats());
} }
@@ -105,7 +111,7 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.amount, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.amount, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -116,6 +122,7 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.amount = data.amount; this.amount = data.amount;
this.setDelay(data.delay); this.setDelay(data.delay);
this.userSource = data.userSource;
} }
else { else {
this.amount = 0; this.amount = 0;
@@ -130,27 +137,31 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.amount = 0; this.amount = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
int amount; int amount;
int delay; int delay;
int userSource;
public JsonData(int amount, int delay) { public JsonData(int amount, int delay, int userSource) {
this.amount = amount; this.amount = amount;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -25,6 +26,7 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
private int respects = 0; private int respects = 0;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectGiveRespect(ResultSet set, Item baseItem) throws SQLException { public WiredEffectGiveRespect(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -42,7 +44,8 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.respects + ""); message.appendString(this.respects + "");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(type.code); message.appendInt(type.code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -75,6 +78,9 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
return false; return false;
} }
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(settings.getDelay()); this.setDelay(settings.getDelay());
return true; return true;
@@ -89,7 +95,7 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
for (RoomUnit unit : ctx.targets().users()) { for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
Habbo habbo = room.getHabbo(unit); Habbo habbo = room.getHabbo(unit);
if (habbo == null) continue; if (habbo == null) continue;
@@ -106,7 +112,7 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.respects, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.respects, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -117,6 +123,7 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.respects = data.amount; this.respects = data.amount;
this.setDelay(data.delay); this.setDelay(data.delay);
this.userSource = data.userSource;
} }
else { else {
String[] data = wiredData.split("\t"); String[] data = wiredData.split("\t");
@@ -132,27 +139,31 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.respects = 0; this.respects = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
int amount; int amount;
int delay; int delay;
int userSource;
public JsonData(int amount, int delay) { public JsonData(int amount, int delay, int userSource) {
this.amount = amount; this.amount = amount;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -15,6 +15,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredGiveRewardItem; import com.eu.habbo.habbohotel.wired.WiredGiveRewardItem;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.generic.alerts.UpdateFailedComposer; import com.eu.habbo.messages.outgoing.generic.alerts.UpdateFailedComposer;
@@ -40,6 +41,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
public int rewardTime; public int rewardTime;
public boolean uniqueRewards; public boolean uniqueRewards;
public THashSet<WiredGiveRewardItem> rewardItems = new THashSet<>(); public THashSet<WiredGiveRewardItem> rewardItems = new THashSet<>();
public int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectGiveReward(ResultSet set, Item baseItem) throws SQLException { public WiredEffectGiveReward(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -53,7 +55,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
for (RoomUnit roomUnit : ctx.targets().users()) { for (RoomUnit roomUnit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) { if (habbo != null) {
WiredManager.getReward(habbo, this); WiredManager.getReward(habbo, this);
@@ -71,7 +73,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
public String getWiredData() { public String getWiredData() {
ArrayList<WiredGiveRewardItem> rewards = new ArrayList<>(this.rewardItems); ArrayList<WiredGiveRewardItem> rewards = new ArrayList<>(this.rewardItems);
return WiredManager.getGson().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -88,6 +90,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
this.limitationInterval = data.limit_interval; this.limitationInterval = data.limit_interval;
this.rewardItems.clear(); this.rewardItems.clear();
this.rewardItems.addAll(data.rewards); this.rewardItems.addAll(data.rewards);
this.userSource = data.userSource;
} }
else { else {
String[] data = wiredData.split(":"); String[] data = wiredData.split(":");
@@ -115,6 +118,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
} }
@@ -127,6 +131,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
this.rewardTime = 0; this.rewardTime = 0;
this.uniqueRewards = false; this.uniqueRewards = false;
this.rewardItems.clear(); this.rewardItems.clear();
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -157,11 +162,12 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
s.append(item.wiredString()).append(";"); s.append(item.wiredString()).append(";");
} }
message.appendString(s.toString()); message.appendString(s.toString());
message.appendInt(4); message.appendInt(5);
message.appendInt(this.rewardTime); message.appendInt(this.rewardTime);
message.appendInt(this.uniqueRewards); message.appendInt(this.uniqueRewards);
message.appendInt(this.limit); message.appendInt(this.limit);
message.appendInt(this.limitationInterval); message.appendInt(this.limitationInterval);
message.appendInt(this.userSource);
message.appendInt(this.limit > 0); message.appendInt(this.limit > 0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -189,11 +195,12 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
if (gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) { if (gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) {
if(settings.getIntParams().length < 4) throw new WiredSaveException("Invalid data"); if(settings.getIntParams().length < 5) throw new WiredSaveException("Invalid data");
this.rewardTime = settings.getIntParams()[0]; this.rewardTime = settings.getIntParams()[0];
this.uniqueRewards = settings.getIntParams()[1] == 1; this.uniqueRewards = settings.getIntParams()[1] == 1;
this.limit = settings.getIntParams()[2]; this.limit = settings.getIntParams()[2];
this.limitationInterval = settings.getIntParams()[3]; this.limitationInterval = settings.getIntParams()[3];
this.userSource = settings.getIntParams()[4];
this.given = 0; this.given = 0;
String data = settings.getStringParam(); String data = settings.getStringParam();
@@ -229,7 +236,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -245,8 +252,9 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
int limit_interval; int limit_interval;
List<WiredGiveRewardItem> rewards; List<WiredGiveRewardItem> rewards;
int delay; int delay;
int userSource;
public 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, int userSource) {
this.limit = limit; this.limit = limit;
this.given = given; this.given = given;
this.reward_time = reward_time; this.reward_time = reward_time;
@@ -254,6 +262,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
this.limit_interval = limit_interval; this.limit_interval = limit_interval;
this.rewards = rewards; this.rewards = rewards;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
@@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.iterator.TObjectIntIterator; import gnu.trove.iterator.TObjectIntIterator;
@@ -32,6 +33,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
private int score; private int score;
private int count; private int count;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
private TObjectIntMap<Map.Entry<Integer, Integer>> data = new TObjectIntHashMap<>(); private TObjectIntMap<Map.Entry<Integer, Integer>> data = new TObjectIntHashMap<>();
@@ -47,7 +49,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
for (RoomUnit unit : ctx.targets().users()) { for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
Habbo habbo = room.getHabbo(unit); Habbo habbo = room.getHabbo(unit);
if (habbo == null || habbo.getHabboInfo().getCurrentGame() == null) continue; if (habbo == null || habbo.getHabboInfo().getCurrentGame() == null) continue;
@@ -107,7 +109,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.score, this.count, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.score, this.count, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -119,6 +121,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
this.score = data.score; this.score = data.score;
this.count = data.count; this.count = data.count;
this.setDelay(data.delay); this.setDelay(data.delay);
this.userSource = data.userSource;
} }
else { else {
String[] data = wiredData.split(";"); String[] data = wiredData.split(";");
@@ -130,6 +133,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@@ -138,6 +142,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
this.score = 0; this.score = 0;
this.count = 0; this.count = 0;
this.setDelay(0); this.setDelay(0);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -153,9 +158,10 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(2); message.appendInt(3);
message.appendInt(this.score); message.appendInt(this.score);
message.appendInt(this.count); message.appendInt(this.count);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -182,7 +188,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
if(settings.getIntParams().length < 2) throw new WiredSaveException("Invalid data"); if(settings.getIntParams().length < 3) throw new WiredSaveException("Invalid data");
int score = settings.getIntParams()[0]; int score = settings.getIntParams()[0];
@@ -194,6 +200,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
if(timesPerGame < 1 || timesPerGame > 10) if(timesPerGame < 1 || timesPerGame > 10)
throw new WiredSaveException("Times per game is invalid"); throw new WiredSaveException("Times per game is invalid");
this.userSource = settings.getIntParams()[2];
int delay = settings.getDelay(); int delay = settings.getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
@@ -208,18 +215,20 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
int score; int score;
int count; int count;
int delay; int delay;
int userSource;
public JsonData(int score, int count, int delay) { public JsonData(int score, int count, int delay, int userSource) {
this.score = score; this.score = score;
this.count = count; this.count = count;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -15,6 +15,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -28,6 +29,7 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.JOIN_TEAM; public static final WiredEffectType type = WiredEffectType.JOIN_TEAM;
private GameTeamColors teamColor = GameTeamColors.RED; private GameTeamColors teamColor = GameTeamColors.RED;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectJoinTeam(ResultSet set, Item baseItem) throws SQLException { public WiredEffectJoinTeam(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -41,7 +43,7 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
for (RoomUnit unit : ctx.targets().users()) { for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
Habbo habbo = room.getHabbo(unit); Habbo habbo = room.getHabbo(unit);
if (habbo == null) continue; if (habbo == null) continue;
@@ -67,7 +69,7 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.teamColor, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.teamColor, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -78,6 +80,7 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.teamColor = data.team; this.teamColor = data.team;
this.userSource = data.userSource;
} }
else { else {
String[] data = set.getString("wired_data").split("\t"); String[] data = set.getString("wired_data").split("\t");
@@ -91,12 +94,14 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.teamColor = GameTeamColors.RED; this.teamColor = GameTeamColors.RED;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -113,8 +118,9 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(1); message.appendInt(2);
message.appendInt(this.teamColor.type); message.appendInt(this.teamColor.type);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -141,9 +147,10 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
if(settings.getIntParams().length < 1) throw new WiredSaveException("invalid data"); if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data");
int team = settings.getIntParams()[0]; int team = settings.getIntParams()[0];
this.userSource = settings.getIntParams()[1];
if(team < 1 || team > 4) if(team < 1 || team > 4)
throw new WiredSaveException("Team is invalid"); throw new WiredSaveException("Team is invalid");
@@ -161,16 +168,18 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
GameTeamColors team; GameTeamColors team;
int delay; int delay;
int userSource;
public JsonData(GameTeamColors team, int delay) { public JsonData(GameTeamColors team, int delay, int userSource) {
this.team = team; this.team = team;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -15,6 +15,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
@@ -34,6 +35,7 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.KICK_USER; public static final WiredEffectType type = WiredEffectType.KICK_USER;
private String message = ""; private String message = "";
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectKickHabbo(ResultSet set, Item baseItem) throws SQLException { public WiredEffectKickHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -50,7 +52,7 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
LOGGER.debug("[KickHabbo] targets.users().size={} usersModifiedBySelector={}", LOGGER.debug("[KickHabbo] targets.users().size={} usersModifiedBySelector={}",
ctx.targets().users().size(), ctx.targets().isUsersModifiedBySelector()); ctx.targets().users().size(), ctx.targets().isUsersModifiedBySelector());
for (RoomUnit unit : ctx.targets().users()) { for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
Habbo habbo = room.getHabbo(unit); Habbo habbo = room.getHabbo(unit);
LOGGER.debug("[KickHabbo] RoomUnit id={} type={} -> Habbo={}", unit.getId(), unit.getRoomUnitType(), LOGGER.debug("[KickHabbo] RoomUnit id={} type={} -> Habbo={}", unit.getId(), unit.getRoomUnitType(),
habbo != null ? habbo.getHabboInfo().getUsername() : "null"); habbo != null ? habbo.getHabboInfo().getUsername() : "null");
@@ -83,7 +85,7 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -94,6 +96,7 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.message = data.message; this.message = data.message;
this.userSource = data.userSource;
} }
else { else {
try { try {
@@ -112,12 +115,14 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
} }
this.needsUpdate(true); this.needsUpdate(true);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.message = ""; this.message = "";
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -134,7 +139,8 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.message); message.appendString(this.message);
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -162,6 +168,8 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
String message = settings.getStringParam(); String message = settings.getStringParam();
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
int delay = settings.getDelay(); int delay = settings.getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
@@ -175,16 +183,18 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
String message; String message;
int delay; int delay;
int userSource;
public JsonData(String message, int delay) { public JsonData(String message, int delay, int userSource) {
this.message = message; this.message = message;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -25,6 +26,7 @@ import java.util.List;
public class WiredEffectLeaveTeam extends InteractionWiredEffect { public class WiredEffectLeaveTeam extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.LEAVE_TEAM; public static final WiredEffectType type = WiredEffectType.LEAVE_TEAM;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectLeaveTeam(ResultSet set, Item baseItem) throws SQLException { public WiredEffectLeaveTeam(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -38,7 +40,7 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
for (RoomUnit unit : ctx.targets().users()) { for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
Habbo habbo = room.getHabbo(unit); Habbo habbo = room.getHabbo(unit);
if (habbo == null) continue; if (habbo == null) continue;
@@ -64,7 +66,7 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.getDelay(), this.userSource));
} }
@Override @Override
@@ -74,15 +76,18 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
if(wiredData.startsWith("{")) { if(wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.userSource = data.userSource;
} }
else { else {
this.setDelay(Integer.parseInt(wiredData)); this.setDelay(Integer.parseInt(wiredData));
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.setDelay(0); this.setDelay(0);
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -98,7 +103,8 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -125,6 +131,9 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
int delay = settings.getDelay(); int delay = settings.getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
@@ -134,11 +143,18 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
return true; return true;
} }
@Override
public boolean requiresTriggeringUser() {
return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
}
static class JsonData { static class JsonData {
int delay; int delay;
int userSource;
public JsonData(int delay) { public JsonData(int delay, int userSource) {
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -34,6 +35,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
private boolean state = false; private boolean state = false;
private boolean direction = false; private boolean direction = false;
private boolean position = false; private boolean position = false;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectMatchFurni(ResultSet set, Item baseItem) throws SQLException { public WiredEffectMatchFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -55,18 +57,21 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
if (room.getLayout() == null) if (room.getLayout() == null)
return; return;
// When a selector provides items, only apply matching to items in both the selector targets and settings java.util.Set<Integer> allowedItemIds = null;
boolean useSelector = ctx.targets().isItemsModifiedBySelector(); if (this.furniSource != WiredSourceUtil.SOURCE_SELECTED) {
java.util.Set<Integer> selectorItemIds = null; allowedItemIds = new java.util.HashSet<>();
if (useSelector) { for (HabboItem si : WiredSourceUtil.resolveItems(ctx, this.furniSource, null)) {
selectorItemIds = new java.util.HashSet<>(); if (si != null) {
for (HabboItem si : ctx.targets().items()) { allowedItemIds.add(si.getId());
selectorItemIds.add(si.getId()); }
}
if (allowedItemIds.isEmpty()) {
return;
} }
} }
for (WiredMatchFurniSetting setting : this.settings) { for (WiredMatchFurniSetting setting : this.settings) {
if (useSelector && !selectorItemIds.contains(setting.item_id)) continue; if (allowedItemIds != null && !allowedItemIds.contains(setting.item_id)) continue;
HabboItem item = room.getHabboItem(setting.item_id); HabboItem item = room.getHabboItem(setting.item_id);
if (item != null) { if (item != null) {
@@ -113,7 +118,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
@Override @Override
public String getWiredData() { public String getWiredData() {
this.refresh(); this.refresh();
return WiredManager.getGson().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList<WiredMatchFurniSetting>(this.settings), this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList<WiredMatchFurniSetting>(this.settings), this.getDelay(), this.furniSource));
} }
@Override @Override
@@ -128,6 +133,10 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
this.position = data.position; this.position = data.position;
this.settings.clear(); this.settings.clear();
this.settings.addAll(data.items); this.settings.addAll(data.items);
this.furniSource = data.furniSource;
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.settings.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} }
else { else {
String[] data = set.getString("wired_data").split(":"); String[] data = set.getString("wired_data").split(":");
@@ -154,6 +163,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
this.direction = data[3].equals("1"); this.direction = data[3].equals("1");
this.position = data[4].equals("1"); this.position = data[4].equals("1");
this.setDelay(Integer.parseInt(data[5])); this.setDelay(Integer.parseInt(data[5]));
this.furniSource = this.settings.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
this.needsUpdate(true); this.needsUpdate(true);
} }
} }
@@ -164,6 +174,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
this.state = false; this.state = false;
this.direction = false; this.direction = false;
this.position = false; this.position = false;
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -186,10 +197,11 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(3); message.appendInt(4);
message.appendInt(this.state ? 1 : 0); message.appendInt(this.state ? 1 : 0);
message.appendInt(this.direction ? 1 : 0); message.appendInt(this.direction ? 1 : 0);
message.appendInt(this.position ? 1 : 0); message.appendInt(this.position ? 1 : 0);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -198,32 +210,34 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
if(settings.getIntParams().length < 3) throw new WiredSaveException("Invalid data"); if(settings.getIntParams().length < 4) throw new WiredSaveException("Invalid data");
boolean setState = settings.getIntParams()[0] == 1; boolean setState = settings.getIntParams()[0] == 1;
boolean setDirection = settings.getIntParams()[1] == 1; boolean setDirection = settings.getIntParams()[1] == 1;
boolean setPosition = settings.getIntParams()[2] == 1; boolean setPosition = settings.getIntParams()[2] == 1;
this.furniSource = settings.getIntParams()[3];
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) if (room == null)
throw new WiredSaveException("Trying to save wired in unloaded room"); throw new WiredSaveException("Trying to save wired in unloaded room");
int itemsCount = settings.getFurniIds().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
throw new WiredSaveException("Too many furni selected");
}
List<WiredMatchFurniSetting> newSettings = new ArrayList<>(); List<WiredMatchFurniSetting> newSettings = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
int itemsCount = settings.getFurniIds().length;
for (int i = 0; i < itemsCount; i++) { if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
int itemId = settings.getFurniIds()[i]; throw new WiredSaveException("Too many furni selected");
HabboItem it = room.getHabboItem(itemId); }
if(it == null) for (int i = 0; i < itemsCount; i++) {
throw new WiredSaveException(String.format("Item %s not found", itemId)); int itemId = settings.getFurniIds()[i];
HabboItem it = room.getHabboItem(itemId);
newSettings.add(new WiredMatchFurniSetting(it.getId(), this.checkForWiredResetPermission && it.allowWiredResetState() ? it.getExtradata() : " ", it.getRotation(), it.getX(), it.getY())); 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 = settings.getDelay(); int delay = settings.getDelay();
@@ -235,7 +249,9 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
this.direction = setDirection; this.direction = setDirection;
this.position = setPosition; this.position = setPosition;
this.settings.clear(); this.settings.clear();
this.settings.addAll(newSettings); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.settings.addAll(newSettings);
}
this.setDelay(delay); this.setDelay(delay);
return true; return true;
@@ -276,13 +292,15 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int
boolean position; boolean position;
List<WiredMatchFurniSetting> items; List<WiredMatchFurniSetting> items;
int delay; int delay;
int furniSource;
public 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, int furniSource) {
this.state = state; this.state = state;
this.direction = direction; this.direction = direction;
this.position = position; this.position = position;
this.items = items; this.items = items;
this.delay = delay; this.delay = delay;
this.furniSource = furniSource;
} }
} }
} }
@@ -11,6 +11,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSimulation; import com.eu.habbo.habbohotel.wired.core.WiredSimulation;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -28,6 +29,7 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.FLEE; public static final WiredEffectType type = WiredEffectType.FLEE;
private THashSet<HabboItem> items = new THashSet<>(); private THashSet<HabboItem> items = new THashSet<>();
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectMoveFurniAway(ResultSet set, Item baseItem) throws SQLException { public WiredEffectMoveFurniAway(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -42,21 +44,15 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
Room room = ctx.room(); Room room = ctx.room();
if (room.getLayout() == null) return; if (room.getLayout() == null) return;
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
boolean useSelector = ctx.targets().isItemsModifiedBySelector(); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Iterable<HabboItem> effectiveItems;
if (useSelector) {
effectiveItems = ctx.targets().items();
} else {
THashSet<HabboItem> toRemove = new THashSet<>(); THashSet<HabboItem> toRemove = new THashSet<>();
List<HabboItem> itemsSnapshot = new ArrayList<>(this.items); for (HabboItem item : effectiveItems) {
for (HabboItem item : itemsSnapshot) { if (item != null && item.getRoomId() == 0) {
if (item.getRoomId() == 0)
toRemove.add(item); toRemove.add(item);
}
} }
this.items.removeAll(toRemove); this.items.removeAll(toRemove);
effectiveItems = new ArrayList<>(this.items);
} }
for (HabboItem item : effectiveItems) { for (HabboItem item : effectiveItems) {
@@ -124,7 +120,8 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
Room room = ctx.room(); Room room = ctx.room();
if (room.getLayout() == null) return true; if (room.getLayout() == null) return true;
for (HabboItem item : new ArrayList<>(this.items)) { List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
for (HabboItem item : effectiveItems) {
if (item == null) continue; if (item == null) continue;
WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item); WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item);
@@ -170,7 +167,8 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
List<HabboItem> itemsSnapshot = new ArrayList<>(this.items); List<HabboItem> itemsSnapshot = new ArrayList<>(this.items);
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.getDelay(), this.getDelay(),
itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -182,12 +180,16 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.furniSource = data.furniSource;
for (Integer id: data.itemIds) { for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
if (item != null) { if (item != null) {
this.items.add(item); this.items.add(item);
} }
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} else { } else {
String[] wiredDataOld = wiredData.split("\t"); String[] wiredDataOld = wiredData.split("\t");
@@ -204,12 +206,14 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
} }
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -241,7 +245,8 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -250,6 +255,9 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
int itemsCount = settings.getFurniIds().length; int itemsCount = settings.getFurniIds().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
@@ -258,14 +266,16 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
List<HabboItem> newItems = new ArrayList<>(); List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
int itemId = settings.getFurniIds()[i]; for (int i = 0; i < itemsCount; i++) {
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); int itemId = settings.getFurniIds()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null) if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId)); throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it); newItems.add(it);
}
} }
int delay = settings.getDelay(); int delay = settings.getDelay();
@@ -274,7 +284,9 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
throw new WiredSaveException("Delay too long"); throw new WiredSaveException("Delay too long");
this.items.clear(); this.items.clear();
this.items.addAll(newItems); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.addAll(newItems);
}
this.setDelay(delay); this.setDelay(delay);
return true; return true;
@@ -288,10 +300,12 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
static class JsonData { static class JsonData {
int delay; int delay;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(int delay, List<Integer> itemIds) { public JsonData(int delay, List<Integer> itemIds, int furniSource) {
this.delay = delay; this.delay = delay;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSimulation; import com.eu.habbo.habbohotel.wired.core.WiredSimulation;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -32,6 +33,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
private int direction; private int direction;
private int spacing = 1; private int spacing = 1;
private Map<Integer, Integer> indexOffset = new LinkedHashMap<>(); private Map<Integer, Integer> indexOffset = new LinkedHashMap<>();
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectMoveFurniTo(ResultSet set, Item baseItem) throws SQLException { public WiredEffectMoveFurniTo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -51,13 +53,16 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
this.items.clear(); this.items.clear();
this.indexOffset.clear(); this.indexOffset.clear();
if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data"); if(settings.getIntParams().length < 3) throw new WiredSaveException("invalid data");
this.direction = settings.getIntParams()[0]; this.direction = settings.getIntParams()[0];
this.spacing = settings.getIntParams()[1]; this.spacing = settings.getIntParams()[1];
this.furniSource = settings.getIntParams()[2];
int count = settings.getFurniIds().length; int count = settings.getFurniIds().length;
for (int i = 0; i < count; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.add(room.getHabboItem(settings.getFurniIds()[i])); for (int i = 0; i < count; i++) {
this.items.add(room.getHabboItem(settings.getFurniIds()[i]));
}
} }
this.setDelay(settings.getDelay()); this.setDelay(settings.getDelay());
@@ -75,23 +80,16 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
Room room = ctx.room(); Room room = ctx.room();
if (room == null || room.getLayout() == null) return; if (room == null || room.getLayout() == null) return;
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
boolean useSelector = ctx.targets().isItemsModifiedBySelector(); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
List<HabboItem> effectiveItems;
if (useSelector) {
effectiveItems = new ArrayList<>(ctx.targets().items());
} else {
List<HabboItem> toRemove = new ArrayList<>(); List<HabboItem> toRemove = new ArrayList<>();
List<HabboItem> itemsSnapshot = new ArrayList<>(this.items); for (HabboItem item : effectiveItems) {
for (HabboItem item : itemsSnapshot) {
if (item == null || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) if (item == null || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
toRemove.add(item); toRemove.add(item);
} }
for (HabboItem item : toRemove) { for (HabboItem item : toRemove) {
this.items.remove(item); this.items.remove(item);
} }
effectiveItems = new ArrayList<>(this.items);
} }
if (effectiveItems.isEmpty()) if (effectiveItems.isEmpty())
@@ -158,12 +156,13 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
Object[] stuff = ctx.legacySettings(); Object[] stuff = ctx.legacySettings();
if (stuff == null || stuff.length == 0) return true; if (stuff == null || stuff.length == 0) return true;
List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
for (Object object : stuff) { for (Object object : stuff) {
if (object instanceof HabboItem) { if (object instanceof HabboItem) {
HabboItem item = (HabboItem) object; HabboItem item = (HabboItem) object;
if (this.items.isEmpty()) continue; if (effectiveItems.isEmpty()) continue;
HabboItem targetItem = this.items.get(0); HabboItem targetItem = effectiveItems.get(0);
if (targetItem == null) continue; if (targetItem == null) continue;
WiredSimulation.SimulatedPosition targetPos = simulation.getItemPosition(targetItem); WiredSimulation.SimulatedPosition targetPos = simulation.getItemPosition(targetItem);
@@ -205,7 +204,8 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
this.direction, this.direction,
this.spacing, this.spacing,
this.getDelay(), this.getDelay(),
itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -232,9 +232,10 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(2); message.appendInt(3);
message.appendInt(this.direction); message.appendInt(this.direction);
message.appendInt(this.spacing); message.appendInt(this.spacing);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -251,6 +252,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
this.direction = data.direction; this.direction = data.direction;
this.spacing = data.spacing; this.spacing = data.spacing;
this.setDelay(data.delay); this.setDelay(data.delay);
this.furniSource = data.furniSource;
for (Integer id: data.itemIds) { for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -258,6 +260,9 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
this.items.add(item); this.items.add(item);
} }
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} else { } else {
String[] data = wiredData.split("\t"); String[] data = wiredData.split("\t");
@@ -276,6 +281,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
this.items.add(item); this.items.add(item);
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -286,6 +292,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
this.direction = 0; this.direction = 0;
this.spacing = 0; this.spacing = 0;
this.indexOffset.clear(); this.indexOffset.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -298,12 +305,14 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
int spacing; int spacing;
int delay; int delay;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(int direction, int spacing, int delay, List<Integer> itemIds) { public JsonData(int direction, int spacing, int delay, List<Integer> itemIds, int furniSource) {
this.direction = direction; this.direction = direction;
this.spacing = spacing; this.spacing = spacing;
this.delay = delay; this.delay = delay;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -11,6 +11,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSimulation; import com.eu.habbo.habbohotel.wired.core.WiredSimulation;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -37,6 +38,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
private THashSet<HabboItem> items; private THashSet<HabboItem> items;
private THashMap<Integer, RoomUserRotation> lastDirections; private THashMap<Integer, RoomUserRotation> lastDirections;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectMoveFurniTowards(ResultSet set, Item baseItem) throws SQLException { public WiredEffectMoveFurniTowards(ResultSet set, Item baseItem) throws SQLException {
@@ -90,23 +92,17 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
boolean useSelector = ctx.targets().isItemsModifiedBySelector(); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Iterable<HabboItem> effectiveItems;
if (useSelector) {
effectiveItems = ctx.targets().items();
} else {
THashSet<HabboItem> toRemove = new THashSet<>(); THashSet<HabboItem> toRemove = new THashSet<>();
List<HabboItem> itemsSnapshot = new ArrayList<>(this.items); for (HabboItem item : effectiveItems) {
for (HabboItem item : itemsSnapshot) { if (item != null && Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) {
if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
toRemove.add(item); toRemove.add(item);
}
} }
for (HabboItem item : toRemove) { for (HabboItem item : toRemove) {
this.items.remove(item); this.items.remove(item);
} }
effectiveItems = new ArrayList<>(this.items);
} }
for (HabboItem item : effectiveItems) { for (HabboItem item : effectiveItems) {
@@ -257,7 +253,8 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
RoomLayout layout = room.getLayout(); RoomLayout layout = room.getLayout();
if (layout == null) return true; if (layout == null) return true;
for (HabboItem item : new ArrayList<>(this.items)) { List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
for (HabboItem item : effectiveItems) {
if (item == null) continue; if (item == null) continue;
WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item); WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item);
@@ -322,7 +319,8 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
List<HabboItem> itemsSnapshot = new ArrayList<>(this.items); List<HabboItem> itemsSnapshot = new ArrayList<>(this.items);
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.getDelay(), this.getDelay(),
itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -334,6 +332,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.furniSource = data.furniSource;
for (Integer id: data.itemIds) { for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -341,6 +340,9 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
this.items.add(item); this.items.add(item);
} }
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} else { } else {
String[] wiredDataOld = wiredData.split("\t"); String[] wiredDataOld = wiredData.split("\t");
@@ -357,12 +359,14 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
} }
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -394,7 +398,8 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -403,6 +408,9 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
int itemsCount = settings.getFurniIds().length; int itemsCount = settings.getFurniIds().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
@@ -411,14 +419,16 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
List<HabboItem> newItems = new ArrayList<>(); List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
int itemId = settings.getFurniIds()[i]; for (int i = 0; i < itemsCount; i++) {
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); int itemId = settings.getFurniIds()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null) if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId)); throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it); newItems.add(it);
}
} }
int delay = settings.getDelay(); int delay = settings.getDelay();
@@ -427,7 +437,9 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
throw new WiredSaveException("Delay too long"); throw new WiredSaveException("Delay too long");
this.items.clear(); this.items.clear();
this.items.addAll(newItems); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.addAll(newItems);
}
this.setDelay(delay); this.setDelay(delay);
return true; return true;
@@ -441,10 +453,12 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
static class JsonData { static class JsonData {
int delay; int delay;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(int delay, List<Integer> itemIds) { public JsonData(int delay, List<Integer> itemIds, int furniSource) {
this.delay = delay; this.delay = delay;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSimulation; import com.eu.habbo.habbohotel.wired.core.WiredSimulation;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
@@ -30,6 +31,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
private final Set<HabboItem> items = new LinkedHashSet<>(WiredManager.MAXIMUM_FURNI_SELECTION / 2); private final Set<HabboItem> items = new LinkedHashSet<>(WiredManager.MAXIMUM_FURNI_SELECTION / 2);
private int direction; private int direction;
private int rotation; private int rotation;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
// Use thread-safe set for cooldowns since execute() can be called from async threads // Use thread-safe set for cooldowns since execute() can be called from async threads
private final Set<HabboItem> itemCooldowns = ConcurrentHashMap.newKeySet(); private final Set<HabboItem> itemCooldowns = ConcurrentHashMap.newKeySet();
// Pre-selected directions from simulation (itemId -> direction) // Pre-selected directions from simulation (itemId -> direction)
@@ -47,16 +49,9 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
boolean useSelector = ctx.targets().isItemsModifiedBySelector(); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
Iterable<HabboItem> effectiveItems;
if (useSelector) {
effectiveItems = ctx.targets().items();
} else {
// remove items that are no longer in the room
this.items.removeIf(item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); this.items.removeIf(item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
effectiveItems = this.items;
} }
for (HabboItem item : effectiveItems) { for (HabboItem item : effectiveItems) {
@@ -99,7 +94,8 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
// Clear any previous pre-selected directions // Clear any previous pre-selected directions
this.preSelectedDirections.clear(); this.preSelectedDirections.clear();
for (HabboItem item : this.items) { List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
for (HabboItem item : effectiveItems) {
if (item == null) continue; if (item == null) continue;
WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item); WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item);
@@ -156,7 +152,8 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
this.direction, this.direction,
this.rotation, this.rotation,
this.getDelay(), this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) this.items.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -170,12 +167,16 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
this.setDelay(data.delay); this.setDelay(data.delay);
this.direction = data.direction; this.direction = data.direction;
this.rotation = data.rotation; this.rotation = data.rotation;
this.furniSource = data.furniSource;
for (Integer id: data.itemIds) { for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
if (item != null) { if (item != null) {
this.items.add(item); this.items.add(item);
} }
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} else { } else {
String[] data = wiredData.split("\t"); String[] data = wiredData.split("\t");
@@ -195,6 +196,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
this.items.add(item); this.items.add(item);
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@@ -203,6 +205,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
this.direction = 0; this.direction = 0;
this.rotation = 0; this.rotation = 0;
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -232,9 +235,10 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(2); message.appendInt(3);
message.appendInt(this.direction); message.appendInt(this.direction);
message.appendInt(this.rotation); message.appendInt(this.rotation);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -248,19 +252,22 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
if (room == null) if (room == null)
return false; return false;
if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data"); if(settings.getIntParams().length < 3) throw new WiredSaveException("invalid data");
this.direction = settings.getIntParams()[0]; this.direction = settings.getIntParams()[0];
this.rotation = settings.getIntParams()[1]; this.rotation = settings.getIntParams()[1];
this.furniSource = settings.getIntParams()[2];
int count = settings.getFurniIds().length; int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count", 5)) return false; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count", 5)) return false;
this.items.clear(); this.items.clear();
for (int i = 0; i < count; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); for (int i = 0; i < count; i++) {
if (item != null) { HabboItem item = room.getHabboItem(settings.getFurniIds()[i]);
this.items.add(item); if (item != null) {
this.items.add(item);
}
} }
} }
@@ -384,12 +391,14 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
int rotation; int rotation;
int delay; int delay;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(int direction, int rotation, int delay, List<Integer> itemIds) { public JsonData(int direction, int rotation, int delay, List<Integer> itemIds, int furniSource) {
this.direction = direction; this.direction = direction;
this.rotation = rotation; this.rotation = rotation;
this.delay = delay; this.delay = delay;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
@@ -25,6 +26,7 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
private int length = 5; private int length = 5;
private String message = ""; private String message = "";
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectMuteHabbo(ResultSet set, Item baseItem) throws SQLException { public WiredEffectMuteHabbo(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -42,8 +44,9 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.message); message.appendString(this.message);
message.appendInt(1); message.appendInt(2);
message.appendInt(this.length); message.appendInt(this.length);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -52,9 +55,10 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
if(settings.getIntParams().length < 1) throw new WiredSaveException("invalid data"); if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data");
this.length = settings.getIntParams()[0]; this.length = settings.getIntParams()[0];
this.userSource = settings.getIntParams()[1];
this.message = settings.getStringParam(); this.message = settings.getStringParam();
this.setDelay(settings.getDelay()); this.setDelay(settings.getDelay());
@@ -66,7 +70,7 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
for (RoomUnit roomUnit : ctx.targets().users()) { for (RoomUnit roomUnit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
if (habbo == null) continue; if (habbo == null) continue;
@@ -89,7 +93,8 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.getDelay(), this.getDelay(),
this.length, this.length,
this.message this.message,
this.userSource
)); ));
} }
@@ -102,6 +107,7 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
this.setDelay(data.delay); this.setDelay(data.delay);
this.length = data.length; this.length = data.length;
this.message = data.message; this.message = data.message;
this.userSource = data.userSource;
} else { } else {
String[] data = wiredData.split("\t"); String[] data = wiredData.split("\t");
@@ -121,6 +127,7 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
this.setDelay(0); this.setDelay(0);
this.message = ""; this.message = "";
this.length = 0; this.length = 0;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -130,18 +137,20 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
int delay; int delay;
int length; int length;
String message; String message;
int userSource;
public JsonData(int delay, int length, String message) { public JsonData(int delay, int length, String message, int userSource) {
this.delay = delay; this.delay = delay;
this.length = length; this.length = length;
this.message = message; this.message = message;
this.userSource = userSource;
} }
} }
} }
@@ -18,6 +18,7 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer;
@@ -38,6 +39,8 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.TELEPORT; public static final WiredEffectType type = WiredEffectType.TELEPORT;
protected List<HabboItem> items; protected List<HabboItem> items;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
private int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectTeleport(ResultSet set, Item baseItem) throws SQLException { public WiredEffectTeleport(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -134,7 +137,9 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(2);
message.appendInt(this.furniSource);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -160,6 +165,10 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
int itemsCount = settings.getFurniIds().length; int itemsCount = settings.getFurniIds().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
@@ -168,14 +177,16 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
List<HabboItem> newItems = new ArrayList<>(); List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
int itemId = settings.getFurniIds()[i]; for (int i = 0; i < itemsCount; i++) {
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); int itemId = settings.getFurniIds()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null) if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId)); throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it); newItems.add(it);
}
} }
int delay = settings.getDelay(); int delay = settings.getDelay();
@@ -184,7 +195,9 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
throw new WiredSaveException("Delay too long"); throw new WiredSaveException("Delay too long");
this.items.clear(); this.items.clear();
this.items.addAll(newItems); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.addAll(newItems);
}
this.setDelay(delay); this.setDelay(delay);
return true; return true;
@@ -198,20 +211,15 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
return; return;
} }
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
List<HabboItem> effectiveItems; if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
if (ctx.targets().isItemsModifiedBySelector()) {
effectiveItems = new ArrayList<>(ctx.targets().items());
} else {
this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId()
|| Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
effectiveItems = new ArrayList<>(this.items);
} }
if (effectiveItems.isEmpty()) return; if (effectiveItems.isEmpty()) return;
for (RoomUnit roomUnit : ctx.targets().users()) { for (RoomUnit roomUnit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) {
int i = Emulator.getRandom().nextInt(effectiveItems.size()); int i = Emulator.getRandom().nextInt(effectiveItems.size());
HabboItem item = effectiveItems.get(i); HabboItem item = effectiveItems.get(i);
@@ -235,7 +243,9 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
List<HabboItem> itemsSnapshot = new ArrayList<>(this.items); List<HabboItem> itemsSnapshot = new ArrayList<>(this.items);
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.getDelay(), this.getDelay(),
itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource,
this.userSource
)); ));
} }
@@ -247,12 +257,17 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.furniSource = data.furniSource;
this.userSource = data.userSource;
for (Integer id: data.itemIds) { for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
if (item != null) { if (item != null) {
this.items.add(item); this.items.add(item);
} }
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} else { } else {
String[] wiredDataOld = wiredData.split("\t"); String[] wiredDataOld = wiredData.split("\t");
@@ -269,12 +284,16 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
} }
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -285,7 +304,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
@Override @Override
@@ -296,10 +315,14 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
static class JsonData { static class JsonData {
int delay; int delay;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
int userSource;
public JsonData(int delay, List<Integer> itemIds) { public JsonData(int delay, List<Integer> itemIds, int furniSource, int userSource) {
this.delay = delay; this.delay = delay;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
this.userSource = userSource;
} }
} }
} }
@@ -23,6 +23,7 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -42,6 +43,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.TOGGLE_STATE; public static final WiredEffectType type = WiredEffectType.TOGGLE_STATE;
private final THashSet<HabboItem> items; private final THashSet<HabboItem> items;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
private static final List<Class<? extends HabboItem>> FORBIDDEN_TYPES = new ArrayList<Class<? extends HabboItem>>() { private static final List<Class<? extends HabboItem>> FORBIDDEN_TYPES = new ArrayList<Class<? extends HabboItem>>() {
{ {
@@ -120,7 +122,8 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -147,6 +150,9 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
int itemsCount = settings.getFurniIds().length; int itemsCount = settings.getFurniIds().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
@@ -154,15 +160,16 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
} }
List<HabboItem> newItems = new ArrayList<>(); List<HabboItem> newItems = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
for (int i = 0; i < itemsCount; i++) {
int itemId = settings.getFurniIds()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
for (int i = 0; i < itemsCount; i++) { if(it == null)
int itemId = settings.getFurniIds()[i]; throw new WiredSaveException(String.format("Item %s not found", itemId));
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null) newItems.add(it);
throw new WiredSaveException(String.format("Item %s not found", itemId)); }
newItems.add(it);
} }
int delay = settings.getDelay(); int delay = settings.getDelay();
@@ -171,7 +178,9 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
throw new WiredSaveException("Delay too long"); throw new WiredSaveException("Delay too long");
this.items.clear(); this.items.clear();
this.items.addAll(newItems); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.addAll(newItems);
}
this.setDelay(delay); this.setDelay(delay);
return true; return true;
@@ -182,12 +191,9 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
Room room = ctx.room(); Room room = ctx.room();
Habbo habbo = ctx.actor().map(unit -> room.getHabbo(unit)).orElse(null); Habbo habbo = ctx.actor().map(unit -> room.getHabbo(unit)).orElse(null);
// Use selector targets if a selector has modified them, otherwise use manually picked items.
// Snapshot this.items into a new list to avoid undefined behavior from concurrent // Snapshot this.items into a new list to avoid undefined behavior from concurrent
// THashSet access (serializeWiredData can modify items from the network thread). // THashSet access (serializeWiredData can modify items from the network thread).
Iterable<HabboItem> effectiveItems = ctx.targets().isItemsModifiedBySelector() List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
? ctx.targets().items()
: new ArrayList<>(this.items);
THashSet<HabboItem> itemsToRemove = new THashSet<>(); THashSet<HabboItem> itemsToRemove = new THashSet<>();
for (HabboItem item : effectiveItems) { for (HabboItem item : effectiveItems) {
@@ -213,7 +219,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
} }
} }
if (!ctx.targets().isItemsModifiedBySelector()) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.removeAll(itemsToRemove); this.items.removeAll(itemsToRemove);
} }
} }
@@ -228,7 +234,8 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.getDelay(), this.getDelay(),
new ArrayList<>(this.items).stream().map(HabboItem::getId).collect(Collectors.toList()) new ArrayList<>(this.items).stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -240,6 +247,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.furniSource = data.furniSource;
for (Integer id: data.itemIds) { for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -251,6 +259,9 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
this.items.add(item); this.items.add(item);
} }
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} else { } else {
String[] wiredDataOld = wiredData.split("\t"); String[] wiredDataOld = wiredData.split("\t");
@@ -270,12 +281,14 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
} }
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -287,10 +300,12 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
static class JsonData { static class JsonData {
int delay; int delay;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(int delay, List<Integer> itemIds) { public JsonData(int delay, List<Integer> itemIds, int furniSource) {
this.delay = delay; this.delay = delay;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -22,6 +22,7 @@ import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -41,6 +42,7 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.TOGGLE_RANDOM; public static final WiredEffectType type = WiredEffectType.TOGGLE_RANDOM;
private final THashSet<HabboItem> items = new THashSet<>(); private final THashSet<HabboItem> items = new THashSet<>();
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
private static final List<Class<? extends HabboItem>> FORBIDDEN_TYPES = new ArrayList<Class<? extends HabboItem>>() { private static final List<Class<? extends HabboItem>> FORBIDDEN_TYPES = new ArrayList<Class<? extends HabboItem>>() {
{ {
@@ -114,7 +116,8 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -141,6 +144,9 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
int itemsCount = settings.getFurniIds().length; int itemsCount = settings.getFurniIds().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
@@ -149,14 +155,16 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
List<HabboItem> newItems = new ArrayList<>(); List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
int itemId = settings.getFurniIds()[i]; for (int i = 0; i < itemsCount; i++) {
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); int itemId = settings.getFurniIds()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null) if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId)); throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it); newItems.add(it);
}
} }
int delay = settings.getDelay(); int delay = settings.getDelay();
@@ -165,7 +173,9 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
throw new WiredSaveException("Delay too long"); throw new WiredSaveException("Delay too long");
this.items.clear(); this.items.clear();
this.items.addAll(newItems); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.addAll(newItems);
}
this.setDelay(delay); this.setDelay(delay);
return true; return true;
@@ -175,14 +185,11 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
Iterable<HabboItem> effectiveItems = ctx.targets().isItemsModifiedBySelector()
? ctx.targets().items()
: new ArrayList<>(this.items);
for (HabboItem item : effectiveItems) { for (HabboItem item : effectiveItems) {
if (item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) { if (item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) {
if (!ctx.targets().isItemsModifiedBySelector()) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.remove(item); this.items.remove(item);
} }
continue; continue;
@@ -208,7 +215,8 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
List<HabboItem> itemsSnapshot = new ArrayList<>(this.items); List<HabboItem> itemsSnapshot = new ArrayList<>(this.items);
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.getDelay(), this.getDelay(),
itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -220,6 +228,7 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.furniSource = data.furniSource;
for (Integer id: data.itemIds) { for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
@@ -229,6 +238,9 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
if (item != null) if (item != null)
this.items.add(item); this.items.add(item);
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} else { } else {
String[] wiredDataOld = wiredData.split("\t"); String[] wiredDataOld = wiredData.split("\t");
@@ -248,12 +260,14 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
} }
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -265,10 +279,12 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
static class JsonData { static class JsonData {
int delay; int delay;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(int delay, List<Integer> itemIds) { public JsonData(int delay, List<Integer> itemIds, int furniSource) {
this.delay = delay; this.delay = delay;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure; import gnu.trove.procedure.TObjectProcedure;
@@ -28,6 +29,7 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.CALL_STACKS; public static final WiredEffectType type = WiredEffectType.CALL_STACKS;
private THashSet<HabboItem> items; private THashSet<HabboItem> items;
private int furniSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectTriggerStacks(ResultSet set, Item baseItem) throws SQLException { public WiredEffectTriggerStacks(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -62,7 +64,8 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(""); message.appendString("");
message.appendInt(0); message.appendInt(1);
message.appendInt(this.furniSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(this.getType().code); message.appendInt(this.getType().code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -89,6 +92,9 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
int[] params = settings.getIntParams();
this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
int itemsCount = settings.getFurniIds().length; int itemsCount = settings.getFurniIds().length;
if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
@@ -97,14 +103,16 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
List<HabboItem> newItems = new ArrayList<>(); List<HabboItem> newItems = new ArrayList<>();
for (int i = 0; i < itemsCount; i++) { if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
int itemId = settings.getFurniIds()[i]; for (int i = 0; i < itemsCount; i++) {
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); int itemId = settings.getFurniIds()[i];
HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
if(it == null) if(it == null)
throw new WiredSaveException(String.format("Item %s not found", itemId)); throw new WiredSaveException(String.format("Item %s not found", itemId));
newItems.add(it); newItems.add(it);
}
} }
int delay = settings.getDelay(); int delay = settings.getDelay();
@@ -113,7 +121,9 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
throw new WiredSaveException("Delay too long"); throw new WiredSaveException("Delay too long");
this.items.clear(); this.items.clear();
this.items.addAll(newItems); if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
this.items.addAll(newItems);
}
this.setDelay(delay); this.setDelay(delay);
return true; return true;
@@ -137,10 +147,7 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
return; return;
} }
// Use selector targets if a selector has modified them, otherwise use manually picked items List<HabboItem> effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items);
Iterable<HabboItem> effectiveItems = ctx.targets().isItemsModifiedBySelector()
? ctx.targets().items()
: new ArrayList<>(this.items);
THashSet<RoomTile> usedTiles = new THashSet<>(); THashSet<RoomTile> usedTiles = new THashSet<>();
@@ -179,7 +186,8 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
List<HabboItem> itemsSnapshot = new ArrayList<>(this.items); List<HabboItem> itemsSnapshot = new ArrayList<>(this.items);
return WiredManager.getGson().toJson(new JsonData( return WiredManager.getGson().toJson(new JsonData(
this.getDelay(), this.getDelay(),
itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()),
this.furniSource
)); ));
} }
@@ -191,12 +199,16 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
if (wiredData.startsWith("{")) { if (wiredData.startsWith("{")) {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.furniSource = data.furniSource;
for (Integer id: data.itemIds) { for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id); HabboItem item = room.getHabboItem(id);
if (item != null) { if (item != null) {
this.items.add(item); this.items.add(item);
} }
} }
if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) {
this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
}
} else { } else {
String[] wiredDataOld = wiredData.split("\t"); String[] wiredDataOld = wiredData.split("\t");
@@ -213,12 +225,14 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
} }
} }
} }
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
} }
} }
@Override @Override
public void onPickUp() { public void onPickUp() {
this.items.clear(); this.items.clear();
this.furniSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -235,10 +249,12 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
static class JsonData { static class JsonData {
int delay; int delay;
List<Integer> itemIds; List<Integer> itemIds;
int furniSource;
public JsonData(int delay, List<Integer> itemIds) { public JsonData(int delay, List<Integer> itemIds, int furniSource) {
this.delay = delay; this.delay = delay;
this.itemIds = itemIds; this.itemIds = itemIds;
this.furniSource = furniSource;
} }
} }
} }
@@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
@@ -26,6 +27,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
protected String message = ""; protected String message = "";
protected int userSource = WiredSourceUtil.SOURCE_TRIGGER;
public WiredEffectWhisper(ResultSet set, Item baseItem) throws SQLException { public WiredEffectWhisper(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@@ -43,7 +45,8 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId()); message.appendInt(this.getId());
message.appendString(this.message); message.appendString(this.message);
message.appendInt(0); message.appendInt(1);
message.appendInt(this.userSource);
message.appendInt(0); message.appendInt(0);
message.appendInt(type.code); message.appendInt(type.code);
message.appendInt(this.getDelay()); message.appendInt(this.getDelay());
@@ -71,6 +74,8 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
@Override @Override
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
String message = settings.getStringParam(); String message = settings.getStringParam();
int[] params = settings.getIntParams();
this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER;
if(gameClient.getHabbo() == null || !gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) { if(gameClient.getHabbo() == null || !gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) {
message = Emulator.getGameEnvironment().getWordFilter().filter(message, null); message = Emulator.getGameEnvironment().getWordFilter().filter(message, null);
@@ -87,11 +92,15 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
return true; return true;
} }
protected List<RoomUnit> resolveUsers(WiredContext ctx) {
return WiredSourceUtil.resolveUsers(ctx, this.userSource);
}
@Override @Override
public void execute(WiredContext ctx) { public void execute(WiredContext ctx) {
Room room = ctx.room(); Room room = ctx.room();
if (this.message.length() > 0) { if (this.message.length() > 0) {
for (RoomUnit roomUnit : ctx.targets().users()) { for (RoomUnit roomUnit : resolveUsers(ctx)) {
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
if (habbo == null) continue; if (habbo == null) continue;
@@ -113,7 +122,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay())); return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay(), this.userSource));
} }
@Override @Override
@@ -124,6 +133,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay); this.setDelay(data.delay);
this.message = data.message; this.message = data.message;
this.userSource = data.userSource;
} }
else { else {
this.message = ""; this.message = "";
@@ -133,6 +143,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
this.message = wiredData.split("\t")[1]; this.message = wiredData.split("\t")[1];
} }
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.needsUpdate(true); this.needsUpdate(true);
} }
} }
@@ -140,6 +151,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
@Override @Override
public void onPickUp() { public void onPickUp() {
this.message = ""; this.message = "";
this.userSource = WiredSourceUtil.SOURCE_TRIGGER;
this.setDelay(0); this.setDelay(0);
} }
@@ -150,16 +162,18 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
@Override @Override
public boolean requiresTriggeringUser() { public boolean requiresTriggeringUser() {
return true; return this.userSource == WiredSourceUtil.SOURCE_TRIGGER;
} }
static class JsonData { static class JsonData {
String message; String message;
int delay; int delay;
int userSource;
public JsonData(String message, int delay) { public JsonData(String message, int delay, int userSource) {
this.message = message; this.message = message;
this.delay = delay; this.delay = delay;
this.userSource = userSource;
} }
} }
} }
@@ -229,6 +229,11 @@ public final class WiredEngine {
// Activate extras (for their animation) // Activate extras (for their animation)
activateExtras(room, stack.triggerItem(), event.getActor().orElse(null), currentTime); activateExtras(room, stack.triggerItem(), event.getActor().orElse(null), currentTime);
// Run selectors before conditions so targets are available
if (stack.hasEffects()) {
executeSelectors(stack, ctx, currentTime);
}
// Evaluate conditions // Evaluate conditions
if (stack.hasConditions()) { if (stack.hasConditions()) {
debug(room, "Evaluating {} conditions...", stack.conditions().size()); debug(room, "Evaluating {} conditions...", stack.conditions().size());
@@ -347,15 +352,11 @@ public final class WiredEngine {
if (effects.isEmpty()) { if (effects.isEmpty()) {
return; return;
} }
// Separate selectors from regular effects. // Selectors already executed before conditions; only run regular effects here
// Selectors must always run first so ctx.targets() is populated before
// regular effects consume it.
List<IWiredEffect> selectors = new ArrayList<>();
List<IWiredEffect> regulars = new ArrayList<>(); List<IWiredEffect> regulars = new ArrayList<>();
for (IWiredEffect e : effects) { for (IWiredEffect e : effects) {
if (e.isSelector()) selectors.add(e); if (!e.isSelector()) regulars.add(e);
else regulars.add(e);
} }
// Determine which (regular) effects to execute // Determine which (regular) effects to execute
@@ -385,12 +386,6 @@ public final class WiredEngine {
Collections.shuffle(toExecute); Collections.shuffle(toExecute);
} }
// Selectors always run first (in their natural tile order), then regular effects
List<IWiredEffect> ordered = new ArrayList<>(selectors.size() + toExecute.size());
ordered.addAll(selectors);
ordered.addAll(toExecute);
toExecute = ordered;
// Execute selected effects // Execute selected effects
for (IWiredEffect effect : toExecute) { for (IWiredEffect effect : toExecute) {
// Check if effect requires actor // Check if effect requires actor
@@ -421,6 +416,34 @@ public final class WiredEngine {
} }
} }
} }
/**
* Execute selector effects before conditions so ctx.targets() is populated.
*/
private void executeSelectors(WiredStack stack, WiredContext ctx, long currentTime) {
List<IWiredEffect> effects = stack.effects();
if (effects.isEmpty()) return;
for (IWiredEffect effect : effects) {
if (!effect.isSelector()) continue;
if (effect.requiresActor() && !ctx.hasActor()) {
continue;
}
ctx.state().step();
try {
effect.execute(ctx);
if (effect instanceof InteractionWiredEffect) {
InteractionWiredEffect wiredEffect = (InteractionWiredEffect) effect;
wiredEffect.setCooldown(currentTime);
wiredEffect.activateBox(ctx.room(), ctx.actor().orElse(null), currentTime);
}
} catch (Exception e) {
LOGGER.warn("Error executing selector: {}", e.getMessage());
}
}
}
/** /**
* Schedule a delayed effect execution. * Schedule a delayed effect execution.
@@ -0,0 +1,63 @@
package com.eu.habbo.habbohotel.wired.core;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public final class WiredSourceUtil {
public static final int SOURCE_TRIGGER = 0;
public static final int SOURCE_SELECTED = 100;
public static final int SOURCE_SELECTOR = 200;
public static final int SOURCE_SIGNAL = 201;
private WiredSourceUtil() {
}
public static List<HabboItem> resolveItems(WiredContext ctx, int sourceType, Collection<HabboItem> selectedItems) {
switch (sourceType) {
case SOURCE_TRIGGER:
return ctx.sourceItem().map(Collections::singletonList).orElse(Collections.emptyList());
case SOURCE_SELECTED:
return (selectedItems != null) ? new ArrayList<>(selectedItems) : Collections.emptyList();
case SOURCE_SELECTOR:
return ctx.targets().isItemsModifiedBySelector()
? new ArrayList<>(ctx.targets().items())
: Collections.emptyList();
case SOURCE_SIGNAL:
if (ctx.eventType() == WiredEvent.Type.SIGNAL_RECEIVED) {
return ctx.sourceItem().map(Collections::singletonList).orElse(Collections.emptyList());
}
return Collections.emptyList();
default:
return ctx.sourceItem().map(Collections::singletonList).orElse(Collections.emptyList());
}
}
public static List<RoomUnit> resolveUsers(WiredContext ctx, int sourceType) {
return resolveUsers(ctx, sourceType, null);
}
public static List<RoomUnit> resolveUsers(WiredContext ctx, int sourceType, Collection<RoomUnit> selectedUsers) {
switch (sourceType) {
case SOURCE_TRIGGER:
return ctx.actor().map(Collections::singletonList).orElse(Collections.emptyList());
case SOURCE_SELECTED:
return (selectedUsers != null) ? new ArrayList<>(selectedUsers) : Collections.emptyList();
case SOURCE_SELECTOR:
return ctx.targets().isUsersModifiedBySelector()
? new ArrayList<>(ctx.targets().users())
: Collections.emptyList();
case SOURCE_SIGNAL:
if (ctx.eventType() == WiredEvent.Type.SIGNAL_RECEIVED) {
return ctx.actor().map(Collections::singletonList).orElse(Collections.emptyList());
}
return Collections.emptyList();
default:
return ctx.actor().map(Collections::singletonList).orElse(Collections.emptyList());
}
}
}