Merge branch 'fix/wired-not-trigger-on-furni' into 'dev'

Fixed wired Condition: Trigger is NOT on furni

See merge request morningstar/Arcturus-Community!394
This commit is contained in:
Remco 2021-02-01 18:25:32 +00:00
commit c4495408b5
2 changed files with 14 additions and 131 deletions

View File

@ -1,27 +1,16 @@
package com.eu.habbo.habbohotel.items.interactions.wired.conditions; package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
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.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
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.List;
import java.util.stream.Collectors;
public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition { 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;
private THashSet<HabboItem> items = new THashSet<>();
public WiredConditionNotTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException { public WiredConditionNotTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
} }
@ -32,129 +21,19 @@ public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition {
@Override @Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (roomUnit == null) return false; if (roomUnit == null)
return false;
this.refresh(); this.refresh();
if (this.items.isEmpty()) if (this.items.isEmpty())
return true; return true;
THashSet<HabboItem> itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); return !triggerOnFurni(roomUnit, room);
return this.items.stream().noneMatch(itemsAtUser::contains);
}
@Override
public String getWiredData() {
this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
WiredConditionFurniTypeMatch.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class);
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(";");
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null) {
this.items.add(item);
}
}
}
}
@Override
public void onPickUp() {
this.items.clear();
} }
@Override @Override
public WiredConditionType getType() { public WiredConditionType getType() {
return type; return type;
} }
@Override
public void serializeWiredData(ServerMessage message, Room room) {
this.refresh();
message.appendBoolean(false);
message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
message.appendInt(item.getId());
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString("");
message.appendInt(0);
message.appendInt(0);
message.appendInt(this.getType().code);
message.appendInt(0);
message.appendInt(0);
}
@Override
public boolean saveData(ClientMessage packet) {
packet.readInt();
packet.readString();
int count = packet.readInt();
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(packet.readInt());
if (item != null) {
this.items.add(item);
}
}
}
return true;
}
private void refresh() {
THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
items.addAll(this.items);
} else {
for (HabboItem item : this.items) {
if (item.getRoomId() != room.getId())
items.add(item);
}
}
this.items.removeAll(items);
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
}
} }

View File

@ -22,7 +22,7 @@ import java.util.stream.Collectors;
public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI; public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI;
private THashSet<HabboItem> items = new THashSet<>(); protected THashSet<HabboItem> items = new THashSet<>();
public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException { public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
@ -42,10 +42,14 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
if (this.items.isEmpty()) if (this.items.isEmpty())
return false; return false;
return triggerOnFurni(roomUnit, room);
}
protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) {
/* /*
* 1. If a Habbo IS NOT walking we only have to check if the Habbo is on one of the selected tiles. * 1. If a Habbo IS NOT walking we only have to check if the Habbo is on one of the selected tiles.
* 2. If a Habbo IS walking we have to check if the next tile in the walking path is one of the selected items * 2. If a Habbo IS walking we have to check if the next tile in the walking path is one of the selected items
* */ * */
if (!roomUnit.isWalking()) { if (!roomUnit.isWalking()) {
THashSet<HabboItem> itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); THashSet<HabboItem> itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation());
return this.items.stream().anyMatch(itemsAtUser::contains); return this.items.stream().anyMatch(itemsAtUser::contains);
@ -158,7 +162,7 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
return true; return true;
} }
private void refresh() { protected void refresh() {
THashSet<HabboItem> items = new THashSet<>(); THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());