Skip to content

Commit

Permalink
Compatibility measure & wired move packet
Browse files Browse the repository at this point in the history
  • Loading branch information
sirjonasxx committed Apr 22, 2023
1 parent f0f12a4 commit 25df958
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -33,8 +34,13 @@ public PresetWireds(JSONObject object) {
triggers = object.getJSONArray("triggers").toList().stream()
.map(o -> new PresetWiredTrigger(new JSONObject((Map)o))).collect(Collectors.toList());

addons = object.getJSONArray("addons").toList().stream()
.map(o -> new PresetWiredAddon(new JSONObject((Map)o))).collect(Collectors.toList());
if (object.has("addons")) {
addons = object.getJSONArray("addons").toList().stream()
.map(o -> new PresetWiredAddon(new JSONObject((Map)o))).collect(Collectors.toList());
}
else {
addons = new ArrayList<>();
}
}


Expand Down
31 changes: 28 additions & 3 deletions src/main/java/game/FloorState.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import gearth.extensions.parsers.HStuff;
import gearth.protocol.HMessage;
import gearth.protocol.HPacket;
import javafx.beans.InvalidationListener;
import utils.Callback;

import java.util.*;
Expand Down Expand Up @@ -44,7 +43,8 @@ public FloorState(IExtension extension, Logger logger, Callback onFloorItemsChan
extension.intercept(HMessage.Direction.TOCLIENT, "ObjectAdd", this::onObjectAdd);
extension.intercept(HMessage.Direction.TOCLIENT, "ObjectRemove", this::onObjectRemove);
extension.intercept(HMessage.Direction.TOCLIENT, "ObjectUpdate", this::onObjectUpdate);
extension.intercept(HMessage.Direction.TOCLIENT, "SlideObjectBundle", this::onObjectMove);
extension.intercept(HMessage.Direction.TOCLIENT, "SlideObjectBundle", this::onSlide);
extension.intercept(HMessage.Direction.TOCLIENT, "WiredFurniMove", this::onFurniMove);

extension.intercept(HMessage.Direction.TOCLIENT, "ObjectDataUpdate", this::onDataUpdate);
extension.intercept(HMessage.Direction.TOCLIENT, "ObjectsDataUpdate", this::onDataUpdates);
Expand Down Expand Up @@ -229,7 +229,7 @@ private void onObjectUpdate(HMessage hMessage) {
addObject(hMessage.getPacket(), owner);
}
}
private void onObjectMove(HMessage hMessage) {
private void onSlide(HMessage hMessage) {
if (inRoom()) {
HPacket packet = hMessage.getPacket();
int oldx = packet.readInteger();
Expand Down Expand Up @@ -258,6 +258,31 @@ private void onObjectMove(HMessage hMessage) {
}
}

private void onFurniMove(HMessage hMessage) {
if (inRoom()) {
HPacket packet = hMessage.getPacket();
synchronized (lock) {
int oldX = packet.readInteger();
int oldY = packet.readInteger();
int newX = packet.readInteger();
int newY = packet.readInteger();

String oldZ = packet.readString();
String newZ = packet.readString();

int furniId = packet.readInteger();

HFloorItem item = furniIdToItem.get(furniId);
if (item != null) {
furnimap.get(item.getTile().getX()).get(item.getTile().getY()).remove(item.getId());
item.setTile(new HPoint(newX, newY, Double.parseDouble(newZ)));
furnimap.get(newX).get(newY).put(item.getId(), item);
}
}
}
}


private void onDataUpdate(HPacket hPacket, int id) {
// int id = Integer.parseInt(hPacket.readString());
int category = hPacket.readInteger();
Expand Down

0 comments on commit 25df958

Please sign in to comment.