Skip to content

Commit a84838c

Browse files
committed
0.6.2
Added support for dropped items, making --non-player actually useful Renamed --non-player to --non-players (the old name will still work) Id of main inventory is now myInventoryComponent for all object types
1 parent acedb45 commit a84838c

File tree

10 files changed

+315
-138
lines changed

10 files changed

+315
-138
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>qowyn.ark</groupId>
66
<artifactId>ark-tools</artifactId>
7-
<version>0.6.1</version>
7+
<version>0.6.2</version>
88
<packaging>jar</packaging>
99

1010
<name>ark-tools</name>
@@ -13,7 +13,7 @@
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<maven.compiler.target>1.8</maven.compiler.target>
1515
<maven.compiler.source>1.8</maven.compiler.source>
16-
<launch4j.version>0.6.1.0</launch4j.version>
16+
<launch4j.version>0.6.2.0</launch4j.version>
1717
</properties>
1818

1919
<dependencies>

src/main/java/qowyn/ark/tools/PlayerListCommands.java

+87-49
Large diffs are not rendered by default.

src/main/java/qowyn/ark/tools/TribeBase.java

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55

66
import qowyn.ark.GameObject;
7+
import qowyn.ark.tools.data.DroppedItem;
78
import qowyn.ark.tools.data.Item;
89
import qowyn.ark.types.LocationData;
910

@@ -27,6 +28,8 @@ public class TribeBase {
2728

2829
private final List<Item> blueprints = new ArrayList<>();
2930

31+
private final List<DroppedItem> droppedItems = new ArrayList<>();
32+
3033
public TribeBase(String name, float x, float y, float z, float size) {
3134
this.name = name;
3235
this.x = x;
@@ -71,6 +74,10 @@ public List<Item> getBlueprints() {
7174
return blueprints;
7275
}
7376

77+
public List<DroppedItem> getDroppedItems() {
78+
return droppedItems;
79+
}
80+
7481
@Override
7582
public int hashCode() {
7683
return (name == null) ? 0 : name.hashCode();

src/main/java/qowyn/ark/tools/data/Creature.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public class Creature {
104104
public Creature(GameObject creature, GameObjectContainer saveFile) {
105105
className = creature.getClassName();
106106
CreatureData creatureData = DataManager.getCreature(creature.getClassString());
107-
type = creatureData != null ? creatureData.getName() : creature.getClassString();
107+
type = creatureData != null ? creatureData.getName() : creature.getClassString();
108108

109109
location = creature.getLocation();
110110

@@ -272,6 +272,13 @@ public static class AncestorLineEntry {
272272
}
273273
}
274274
});
275+
PROPERTIES.put("myInventoryComponent", (creature, generator, context, writeEmpty) -> {
276+
if (creature.inventory != null) {
277+
generator.writeNumberField("myInventoryComponent", creature.inventory.getId());
278+
} else if (writeEmpty) {
279+
generator.writeNullField("myInventoryComponent");
280+
}
281+
});
275282
PROPERTIES.put("id", (creature, generator, context, writeEmpty) -> {
276283
if (writeEmpty || creature.dinoId != 0) {
277284
generator.writeNumberField("id", creature.dinoId);

src/main/java/qowyn/ark/tools/data/DataCollector.java

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class DataCollector implements DataContext {
3636

3737
public final SortedMap<Integer, Item> itemMap = new TreeMap<>();
3838

39+
public final SortedMap<Integer, DroppedItem> droppedItemMap = new TreeMap<>();
40+
3941
public final SortedMap<Integer, Inventory> inventoryMap = new TreeMap<>();
4042

4143
public final SortedMap<Integer, Creature> creatureMap = new TreeMap<>();
@@ -97,6 +99,9 @@ public void loadSavegame(Path path) throws IOException {
9799
// Skip players, weapons and items on the ground
98100
// is (probably) a structure
99101
structureMap.put(obj.getId(), new Structure(obj, savegame));
102+
} else if (obj.hasAnyProperty("MyItem")) {
103+
// dropped Item
104+
droppedItemMap.put(obj.getId(), new DroppedItem(obj, savegame));
100105
}
101106
}
102107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package qowyn.ark.tools.data;
2+
3+
import java.io.IOException;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.SortedMap;
7+
import java.util.TreeMap;
8+
9+
import com.fasterxml.jackson.core.JsonGenerator;
10+
11+
import qowyn.ark.GameObject;
12+
import qowyn.ark.GameObjectContainer;
13+
import qowyn.ark.tools.CreatureData;
14+
import qowyn.ark.tools.DataManager;
15+
import qowyn.ark.types.ArkName;
16+
import qowyn.ark.types.LocationData;
17+
import qowyn.ark.types.ObjectReference;
18+
19+
public class DroppedItem {
20+
21+
public ArkName className;
22+
23+
public String type;
24+
25+
public LocationData location;
26+
27+
public GameObject myItem;
28+
29+
public String droppedByName;
30+
31+
public int targetingTeam;
32+
33+
public double originalCreationTime;
34+
35+
public float initialLifeSpan;
36+
37+
public DroppedItem() {}
38+
39+
public DroppedItem(GameObject droppedItem, GameObjectContainer saveFile) {
40+
className = droppedItem.getClassName();
41+
CreatureData structureData = DataManager.getStructure(droppedItem.getClassString());
42+
type = structureData != null ? structureData.getName() : droppedItem.getClassString();
43+
44+
location = droppedItem.getLocation();
45+
46+
myItem = droppedItem.findPropertyValue("MyItem", ObjectReference.class).map(saveFile::getObject).orElse(null);
47+
droppedByName = droppedItem.findPropertyValue("DroppedByName", String.class).orElse("");
48+
targetingTeam = droppedItem.findPropertyValue("TargetingTeam", Integer.class).orElse(0);
49+
originalCreationTime = droppedItem.findPropertyValue("OriginalCreationTime", Double.class).orElse(0.0);
50+
initialLifeSpan = droppedItem.findPropertyValue("InitialLifeSpan", Float.class).orElse(Float.POSITIVE_INFINITY);
51+
}
52+
53+
public static final SortedMap<String, WriterFunction<DroppedItem>> PROPERTIES = new TreeMap<>();
54+
55+
static {
56+
/**
57+
* Creature Properties
58+
*/
59+
PROPERTIES.put("type", (droppedItem, generator, context, writeEmpty) -> {
60+
if (context instanceof DataCollector) {
61+
generator.writeStringField("type", droppedItem.className.toString());
62+
} else {
63+
generator.writeStringField("type", droppedItem.type);
64+
}
65+
});
66+
PROPERTIES.put("location", (droppedItem, generator, context, writeEmpty) -> {
67+
if (writeEmpty || droppedItem.location != null) {
68+
if (droppedItem.location == null) {
69+
generator.writeNullField("location");
70+
} else {
71+
generator.writeObjectFieldStart("location");
72+
generator.writeNumberField("x", droppedItem.location.getX());
73+
generator.writeNumberField("y", droppedItem.location.getY());
74+
generator.writeNumberField("z", droppedItem.location.getZ());
75+
if (context.getLatLonCalculator() != null) {
76+
generator.writeNumberField("lat", context.getLatLonCalculator().calculateLat(droppedItem.location.getY()));
77+
generator.writeNumberField("lon", context.getLatLonCalculator().calculateLon(droppedItem.location.getX()));
78+
}
79+
generator.writeEndObject();
80+
}
81+
}
82+
});
83+
PROPERTIES.put("myItem", (droppedItem, generator, context, writeEmpty) -> {
84+
if (droppedItem.myItem != null) {
85+
generator.writeNumberField("myItem", droppedItem.myItem.getId());
86+
} else if (writeEmpty) {
87+
generator.writeNullField("myItem");
88+
}
89+
});
90+
PROPERTIES.put("droppedByName", (droppedItem, generator, context, writeEmpty) -> {
91+
if (writeEmpty || !droppedItem.droppedByName.isEmpty()) {
92+
generator.writeStringField("droppedByName", droppedItem.droppedByName);
93+
}
94+
});
95+
PROPERTIES.put("targetingTeam", (droppedItem, generator, context, writeEmpty) -> {
96+
if (writeEmpty || droppedItem.targetingTeam != 0) {
97+
generator.writeNumberField("targetingTeam", droppedItem.targetingTeam);
98+
}
99+
});
100+
PROPERTIES.put("originalCreationTime", (droppedItem, generator, context, writeEmpty) -> {
101+
if (writeEmpty || droppedItem.originalCreationTime != 0.0) {
102+
generator.writeNumberField("originalCreationTime", droppedItem.originalCreationTime);
103+
}
104+
});
105+
PROPERTIES.put("initialLifeSpan", (droppedItem, generator, context, writeEmpty) -> {
106+
if (writeEmpty || droppedItem.initialLifeSpan != Float.POSITIVE_INFINITY) {
107+
generator.writeNumberField("initialLifeSpan", droppedItem.initialLifeSpan);
108+
}
109+
});
110+
PROPERTIES.put("lifeSpanLeft", (droppedItem, generator, context, writeEmpty) -> {
111+
if (context.getSavegame() != null && droppedItem.initialLifeSpan != Float.POSITIVE_INFINITY) {
112+
generator.writeNumberField("lifeSpanLeft", droppedItem.initialLifeSpan - (context.getSavegame().getGameTime() - droppedItem.originalCreationTime));
113+
} else if (writeEmpty) {
114+
if (droppedItem.initialLifeSpan != Float.POSITIVE_INFINITY) {
115+
generator.writeNumberField("lifeSpanLeft", Float.NaN);
116+
} else {
117+
generator.writeNumberField("lifeSpanLeft", Float.POSITIVE_INFINITY);
118+
}
119+
}
120+
});
121+
}
122+
123+
public static final List<WriterFunction<DroppedItem>> PROPERTIES_LIST = new ArrayList<>(PROPERTIES.values());
124+
125+
public void writeAllProperties(JsonGenerator generator, DataContext context, boolean writeEmpty) throws IOException {
126+
for (WriterFunction<DroppedItem> writer: PROPERTIES_LIST) {
127+
writer.accept(this, generator, context, writeEmpty);
128+
}
129+
}
130+
131+
public void writeInventory(JsonGenerator generator, DataContext context, boolean writeEmpty, boolean inventorySummary) throws IOException {
132+
if (this.myItem != null) {
133+
Item item = new Item(myItem);
134+
135+
generator.writeFieldName("item");
136+
if (inventorySummary) {
137+
generator.writeStartObject();
138+
139+
generator.writeStringField("name", item.type);
140+
generator.writeNumberField("count", item.quantity);
141+
142+
generator.writeEndObject();
143+
} else {
144+
generator.writeStartObject();
145+
146+
item.writeAllProperties(generator, context, writeEmpty);
147+
148+
generator.writeEndObject();
149+
}
150+
}
151+
}
152+
153+
}

src/main/java/qowyn/ark/tools/data/Inventory.java

-80
Original file line numberDiff line numberDiff line change
@@ -201,86 +201,6 @@ public static void writeInventoryLong(JsonGenerator generator, DataContext conte
201201

202202
item.writeAllProperties(generator, context, writeEmpty);
203203

204-
/*
205-
String name = item.className.toString();
206-
if (DataManager.hasItem(name)) {
207-
name = DataManager.getItem(name).getName();
208-
}
209-
210-
generator.writeStringField("name", name);
211-
212-
if (blueprintStatus) {
213-
generator.writeBooleanField("isBlueprint", item.isBlueprint);
214-
}
215-
216-
if (item.quantity > 1) {
217-
generator.writeNumberField("quantity", item.quantity);
218-
}
219-
220-
if (!item.customName.isEmpty()) {
221-
generator.writeStringField("customName", item.customName);
222-
}
223-
224-
if (!item.customDescription.isEmpty()) {
225-
generator.writeStringField("customDescription", item.customDescription);
226-
}
227-
228-
if (!item.isBlueprint && item.durability > 0.0f) {
229-
generator.writeNumberField("durability", item.durability);
230-
}
231-
232-
if (item.rating > 0.0f) {
233-
generator.writeNumberField("rating", item.rating);
234-
}
235-
236-
if (item.quality > 0) {
237-
generator.writeNumberField("quality", item.quality);
238-
}
239-
240-
if (item.itemStatValues[1] != 0) {
241-
generator.writeNumberField("armorMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[1])) * 0.2f * 0.001f);
242-
}
243-
244-
if (item.itemStatValues[2] != 0) {
245-
generator.writeNumberField("durabilityMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[2])) * 0.25f * 0.001f);
246-
}
247-
248-
if (item.itemStatValues[3] != 0) {
249-
generator.writeNumberField("damageMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[3])) * 0.1f * 0.001f);
250-
}
251-
252-
if (item.itemStatValues[5] != 0) {
253-
generator.writeNumberField("hypoMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[5])) * 0.2f * 0.001f);
254-
}
255-
256-
if (item.itemStatValues[7] != 0) {
257-
generator.writeNumberField("hyperMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[7])) * 0.2f * 0.001f);
258-
}
259-
260-
if (item.className.toString().contains("_Fertilized_")) {
261-
generator.writeObjectFieldStart("eggAttributes");
262-
263-
for (int i = 0; i < item.eggLevelups.length; i++) {
264-
byte value = item.eggLevelups[i];
265-
if (value != 0) {
266-
generator.writeNumberField(AttributeNames.get(i), Byte.toUnsignedInt(value));
267-
}
268-
}
269-
270-
generator.writeEndObject();
271-
272-
generator.writeObjectFieldStart("eggColors");
273-
274-
for (int i = 0; i < item.eggColors.length; i++) {
275-
byte value = item.eggColors[i];
276-
if (value != 0) {
277-
generator.writeNumberField(Integer.toString(i), Byte.toUnsignedInt(value));
278-
}
279-
}
280-
281-
generator.writeEndObject();
282-
}*/
283-
284204
generator.writeEndObject();
285205
}
286206
generator.writeEndArray();

src/main/java/qowyn/ark/tools/data/Player.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ public class Player {
7979

8080
public GameObject inventory;
8181

82-
public int inventoryId = -1;
83-
8482
public LocationData location;
8583

8684
public int characterLevel;
@@ -178,7 +176,6 @@ public Player(Path path, DataContext context, ReadingOptions ro) throws IOExcept
178176
}
179177

180178
inventory = player.findPropertyValue("MyInventoryComponent", ObjectReference.class).map(context.getObjectContainer()::getObject).orElse(null);
181-
inventoryId = inventory != null ? inventory.getId() : -1;
182179
location = player.getLocation();
183180

184181
if (playerCharacterStatus != null) {
@@ -392,9 +389,11 @@ public Player(Path path, DataContext context, ReadingOptions ro) throws IOExcept
392389
generator.writeNumberField("percentageOfFacialHairGrowth", player.percentageOfFacialHairGrowth);
393390
}
394391
});
395-
PROPERTIES.put("inventoryId", (player, generator, context, writeEmpty) -> {
396-
if (writeEmpty || player.inventoryId != -1) {
397-
generator.writeNumberField("inventoryId", player.inventoryId);
392+
PROPERTIES.put("myInventoryComponent", (player, generator, context, writeEmpty) -> {
393+
if (player.inventory != null) {
394+
generator.writeNumberField("myInventoryComponent", player.inventory.getId());
395+
} else if (writeEmpty) {
396+
generator.writeNullField("myInventoryComponent");
398397
}
399398
});
400399
PROPERTIES.put("location", (player, generator, context, writeEmpty) -> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package qowyn.ark.tools.data;
2+
3+
public enum TeamType {
4+
5+
NON_PLAYER, PLAYER, TRIBE, BREEDING, UNKNOWN;
6+
7+
public static final int PLAYER_START = 50000;
8+
9+
public static final int TRIBE_START = 1000000000;
10+
11+
public static final int BREEDING_ID = 2000000000;
12+
13+
public static TeamType forTargetingTeam(int teamId) {
14+
if (teamId < PLAYER_START) {
15+
return NON_PLAYER;
16+
}
17+
18+
if (teamId < TRIBE_START) {
19+
return PLAYER;
20+
}
21+
22+
if (teamId < BREEDING_ID) {
23+
return TRIBE;
24+
}
25+
26+
return teamId == 2000000000 ? BREEDING : UNKNOWN;
27+
}
28+
29+
}

0 commit comments

Comments
 (0)