diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/HEntity.java b/G-Earth/src/main/java/gearth/extensions/parsers/HEntity.java index 95f277e..4966c07 100644 --- a/G-Earth/src/main/java/gearth/extensions/parsers/HEntity.java +++ b/G-Earth/src/main/java/gearth/extensions/parsers/HEntity.java @@ -18,6 +18,8 @@ public class HEntity { private HEntityUpdate lastUpdate = null; private Object[] stuff = new Object[0]; + private int unknown1; + public HEntity(HPacket packet) { id = packet.readInteger(); name = packet.readString(); @@ -27,7 +29,7 @@ public class HEntity { tile = new HPoint(packet.readInteger(), packet.readInteger(), Double.parseDouble(packet.readString())); - packet.readInteger(); + unknown1 = packet.readInteger(); int entityTypeId = packet.readInteger(); entityType = HEntityType.valueOf(entityTypeId); @@ -43,7 +45,7 @@ public class HEntity { stuff[4] = packet.readBoolean(); break; case 2: - stuff = new Object[20]; + stuff = new Object[12]; stuff[0] = packet.readInteger(); stuff[1] = packet.readInteger(); stuff[2] = packet.readString(); @@ -72,6 +74,48 @@ public class HEntity { } } + public void appendToPacket(HPacket packet) { + packet.appendInt(id); + packet.appendString(name); + packet.appendString(motto); + packet.appendString(figureId); + packet.appendInt(index); + packet.appendInt(tile.getX()); + packet.appendInt(tile.getY()); + packet.appendString(tile.getZ() + ""); + packet.appendInt(unknown1); + packet.appendInt(entityType.getId()); +// + switch (entityType.getId()) { + case 1: + packet.appendObjects(gender.toString(), stuff[0], stuff[1], + favoriteGroup, stuff[2], stuff[3], stuff[4]); + break; + case 2: + packet.appendObjects(stuff); + break; + case 4: + packet.appendObjects(stuff[0], stuff[1], stuff[2]); + List list = (List) stuff[3]; + packet.appendInt(list.size()); + for(short s : list) { + packet.appendShort(s); + } + + break; + } + } + + public static HPacket constructPacket(HEntity[] entities, int headerId) { + HPacket packet = new HPacket(headerId); + packet.appendInt(entities.length); + for (HEntity entity : entities) { + entity.appendToPacket(packet); + } + + return packet; + } + public static HEntity[] parse(HPacket packet) { HEntity[] entities = new HEntity[packet.readInteger()]; @@ -132,4 +176,44 @@ public class HEntity { public Object[] getStuff() { return stuff; } + + public void setId(int id) { + this.id = id; + } + + public void setIndex(int index) { + this.index = index; + } + + public void setTile(HPoint tile) { + this.tile = tile; + } + + public void setName(String name) { + this.name = name; + } + + public void setMotto(String motto) { + this.motto = motto; + } + + public void setGender(HGender gender) { + this.gender = gender; + } + + public void setFigureId(String figureId) { + this.figureId = figureId; + } + + public void setFavoriteGroup(String favoriteGroup) { + this.favoriteGroup = favoriteGroup; + } + + public void setLastUpdate(HEntityUpdate lastUpdate) { + this.lastUpdate = lastUpdate; + } + + public void setStuff(Object[] stuff) { + this.stuff = stuff; + } }