Skip to content

Commit

Permalink
0.6.2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Qowyn committed Sep 15, 2017
1 parent acedb45 commit a84838c
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 138 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>qowyn.ark</groupId>
<artifactId>ark-tools</artifactId>
<version>0.6.1</version>
<version>0.6.2</version>
<packaging>jar</packaging>

<name>ark-tools</name>
Expand All @@ -13,7 +13,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<launch4j.version>0.6.1.0</launch4j.version>
<launch4j.version>0.6.2.0</launch4j.version>
</properties>

<dependencies>
Expand Down
136 changes: 87 additions & 49 deletions src/main/java/qowyn/ark/tools/PlayerListCommands.java

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/main/java/qowyn/ark/tools/TribeBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import qowyn.ark.GameObject;
import qowyn.ark.tools.data.DroppedItem;
import qowyn.ark.tools.data.Item;
import qowyn.ark.types.LocationData;

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

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

private final List<DroppedItem> droppedItems = new ArrayList<>();

public TribeBase(String name, float x, float y, float z, float size) {
this.name = name;
this.x = x;
Expand Down Expand Up @@ -71,6 +74,10 @@ public List<Item> getBlueprints() {
return blueprints;
}

public List<DroppedItem> getDroppedItems() {
return droppedItems;
}

@Override
public int hashCode() {
return (name == null) ? 0 : name.hashCode();
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/qowyn/ark/tools/data/Creature.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class Creature {
public Creature(GameObject creature, GameObjectContainer saveFile) {
className = creature.getClassName();
CreatureData creatureData = DataManager.getCreature(creature.getClassString());
type = creatureData != null ? creatureData.getName() : creature.getClassString();
type = creatureData != null ? creatureData.getName() : creature.getClassString();

location = creature.getLocation();

Expand Down Expand Up @@ -272,6 +272,13 @@ public static class AncestorLineEntry {
}
}
});
PROPERTIES.put("myInventoryComponent", (creature, generator, context, writeEmpty) -> {
if (creature.inventory != null) {
generator.writeNumberField("myInventoryComponent", creature.inventory.getId());
} else if (writeEmpty) {
generator.writeNullField("myInventoryComponent");
}
});
PROPERTIES.put("id", (creature, generator, context, writeEmpty) -> {
if (writeEmpty || creature.dinoId != 0) {
generator.writeNumberField("id", creature.dinoId);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/qowyn/ark/tools/data/DataCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class DataCollector implements DataContext {

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

public final SortedMap<Integer, DroppedItem> droppedItemMap = new TreeMap<>();

public final SortedMap<Integer, Inventory> inventoryMap = new TreeMap<>();

public final SortedMap<Integer, Creature> creatureMap = new TreeMap<>();
Expand Down Expand Up @@ -97,6 +99,9 @@ public void loadSavegame(Path path) throws IOException {
// Skip players, weapons and items on the ground
// is (probably) a structure
structureMap.put(obj.getId(), new Structure(obj, savegame));
} else if (obj.hasAnyProperty("MyItem")) {
// dropped Item
droppedItemMap.put(obj.getId(), new DroppedItem(obj, savegame));
}
}
}
Expand Down
153 changes: 153 additions & 0 deletions src/main/java/qowyn/ark/tools/data/DroppedItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package qowyn.ark.tools.data;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;

import com.fasterxml.jackson.core.JsonGenerator;

import qowyn.ark.GameObject;
import qowyn.ark.GameObjectContainer;
import qowyn.ark.tools.CreatureData;
import qowyn.ark.tools.DataManager;
import qowyn.ark.types.ArkName;
import qowyn.ark.types.LocationData;
import qowyn.ark.types.ObjectReference;

public class DroppedItem {

public ArkName className;

public String type;

public LocationData location;

public GameObject myItem;

public String droppedByName;

public int targetingTeam;

public double originalCreationTime;

public float initialLifeSpan;

public DroppedItem() {}

public DroppedItem(GameObject droppedItem, GameObjectContainer saveFile) {
className = droppedItem.getClassName();
CreatureData structureData = DataManager.getStructure(droppedItem.getClassString());
type = structureData != null ? structureData.getName() : droppedItem.getClassString();

location = droppedItem.getLocation();

myItem = droppedItem.findPropertyValue("MyItem", ObjectReference.class).map(saveFile::getObject).orElse(null);
droppedByName = droppedItem.findPropertyValue("DroppedByName", String.class).orElse("");
targetingTeam = droppedItem.findPropertyValue("TargetingTeam", Integer.class).orElse(0);
originalCreationTime = droppedItem.findPropertyValue("OriginalCreationTime", Double.class).orElse(0.0);
initialLifeSpan = droppedItem.findPropertyValue("InitialLifeSpan", Float.class).orElse(Float.POSITIVE_INFINITY);
}

public static final SortedMap<String, WriterFunction<DroppedItem>> PROPERTIES = new TreeMap<>();

static {
/**
* Creature Properties
*/
PROPERTIES.put("type", (droppedItem, generator, context, writeEmpty) -> {
if (context instanceof DataCollector) {
generator.writeStringField("type", droppedItem.className.toString());
} else {
generator.writeStringField("type", droppedItem.type);
}
});
PROPERTIES.put("location", (droppedItem, generator, context, writeEmpty) -> {
if (writeEmpty || droppedItem.location != null) {
if (droppedItem.location == null) {
generator.writeNullField("location");
} else {
generator.writeObjectFieldStart("location");
generator.writeNumberField("x", droppedItem.location.getX());
generator.writeNumberField("y", droppedItem.location.getY());
generator.writeNumberField("z", droppedItem.location.getZ());
if (context.getLatLonCalculator() != null) {
generator.writeNumberField("lat", context.getLatLonCalculator().calculateLat(droppedItem.location.getY()));
generator.writeNumberField("lon", context.getLatLonCalculator().calculateLon(droppedItem.location.getX()));
}
generator.writeEndObject();
}
}
});
PROPERTIES.put("myItem", (droppedItem, generator, context, writeEmpty) -> {
if (droppedItem.myItem != null) {
generator.writeNumberField("myItem", droppedItem.myItem.getId());
} else if (writeEmpty) {
generator.writeNullField("myItem");
}
});
PROPERTIES.put("droppedByName", (droppedItem, generator, context, writeEmpty) -> {
if (writeEmpty || !droppedItem.droppedByName.isEmpty()) {
generator.writeStringField("droppedByName", droppedItem.droppedByName);
}
});
PROPERTIES.put("targetingTeam", (droppedItem, generator, context, writeEmpty) -> {
if (writeEmpty || droppedItem.targetingTeam != 0) {
generator.writeNumberField("targetingTeam", droppedItem.targetingTeam);
}
});
PROPERTIES.put("originalCreationTime", (droppedItem, generator, context, writeEmpty) -> {
if (writeEmpty || droppedItem.originalCreationTime != 0.0) {
generator.writeNumberField("originalCreationTime", droppedItem.originalCreationTime);
}
});
PROPERTIES.put("initialLifeSpan", (droppedItem, generator, context, writeEmpty) -> {
if (writeEmpty || droppedItem.initialLifeSpan != Float.POSITIVE_INFINITY) {
generator.writeNumberField("initialLifeSpan", droppedItem.initialLifeSpan);
}
});
PROPERTIES.put("lifeSpanLeft", (droppedItem, generator, context, writeEmpty) -> {
if (context.getSavegame() != null && droppedItem.initialLifeSpan != Float.POSITIVE_INFINITY) {
generator.writeNumberField("lifeSpanLeft", droppedItem.initialLifeSpan - (context.getSavegame().getGameTime() - droppedItem.originalCreationTime));
} else if (writeEmpty) {
if (droppedItem.initialLifeSpan != Float.POSITIVE_INFINITY) {
generator.writeNumberField("lifeSpanLeft", Float.NaN);
} else {
generator.writeNumberField("lifeSpanLeft", Float.POSITIVE_INFINITY);
}
}
});
}

public static final List<WriterFunction<DroppedItem>> PROPERTIES_LIST = new ArrayList<>(PROPERTIES.values());

public void writeAllProperties(JsonGenerator generator, DataContext context, boolean writeEmpty) throws IOException {
for (WriterFunction<DroppedItem> writer: PROPERTIES_LIST) {
writer.accept(this, generator, context, writeEmpty);
}
}

public void writeInventory(JsonGenerator generator, DataContext context, boolean writeEmpty, boolean inventorySummary) throws IOException {
if (this.myItem != null) {
Item item = new Item(myItem);

generator.writeFieldName("item");
if (inventorySummary) {
generator.writeStartObject();

generator.writeStringField("name", item.type);
generator.writeNumberField("count", item.quantity);

generator.writeEndObject();
} else {
generator.writeStartObject();

item.writeAllProperties(generator, context, writeEmpty);

generator.writeEndObject();
}
}
}

}
80 changes: 0 additions & 80 deletions src/main/java/qowyn/ark/tools/data/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,86 +201,6 @@ public static void writeInventoryLong(JsonGenerator generator, DataContext conte

item.writeAllProperties(generator, context, writeEmpty);

/*
String name = item.className.toString();
if (DataManager.hasItem(name)) {
name = DataManager.getItem(name).getName();
}
generator.writeStringField("name", name);
if (blueprintStatus) {
generator.writeBooleanField("isBlueprint", item.isBlueprint);
}
if (item.quantity > 1) {
generator.writeNumberField("quantity", item.quantity);
}
if (!item.customName.isEmpty()) {
generator.writeStringField("customName", item.customName);
}
if (!item.customDescription.isEmpty()) {
generator.writeStringField("customDescription", item.customDescription);
}
if (!item.isBlueprint && item.durability > 0.0f) {
generator.writeNumberField("durability", item.durability);
}
if (item.rating > 0.0f) {
generator.writeNumberField("rating", item.rating);
}
if (item.quality > 0) {
generator.writeNumberField("quality", item.quality);
}
if (item.itemStatValues[1] != 0) {
generator.writeNumberField("armorMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[1])) * 0.2f * 0.001f);
}
if (item.itemStatValues[2] != 0) {
generator.writeNumberField("durabilityMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[2])) * 0.25f * 0.001f);
}
if (item.itemStatValues[3] != 0) {
generator.writeNumberField("damageMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[3])) * 0.1f * 0.001f);
}
if (item.itemStatValues[5] != 0) {
generator.writeNumberField("hypoMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[5])) * 0.2f * 0.001f);
}
if (item.itemStatValues[7] != 0) {
generator.writeNumberField("hyperMultiplier", 1.0f + ((float) Short.toUnsignedInt(item.itemStatValues[7])) * 0.2f * 0.001f);
}
if (item.className.toString().contains("_Fertilized_")) {
generator.writeObjectFieldStart("eggAttributes");
for (int i = 0; i < item.eggLevelups.length; i++) {
byte value = item.eggLevelups[i];
if (value != 0) {
generator.writeNumberField(AttributeNames.get(i), Byte.toUnsignedInt(value));
}
}
generator.writeEndObject();
generator.writeObjectFieldStart("eggColors");
for (int i = 0; i < item.eggColors.length; i++) {
byte value = item.eggColors[i];
if (value != 0) {
generator.writeNumberField(Integer.toString(i), Byte.toUnsignedInt(value));
}
}
generator.writeEndObject();
}*/

generator.writeEndObject();
}
generator.writeEndArray();
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/qowyn/ark/tools/data/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ public class Player {

public GameObject inventory;

public int inventoryId = -1;

public LocationData location;

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

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

if (playerCharacterStatus != null) {
Expand Down Expand Up @@ -392,9 +389,11 @@ public Player(Path path, DataContext context, ReadingOptions ro) throws IOExcept
generator.writeNumberField("percentageOfFacialHairGrowth", player.percentageOfFacialHairGrowth);
}
});
PROPERTIES.put("inventoryId", (player, generator, context, writeEmpty) -> {
if (writeEmpty || player.inventoryId != -1) {
generator.writeNumberField("inventoryId", player.inventoryId);
PROPERTIES.put("myInventoryComponent", (player, generator, context, writeEmpty) -> {
if (player.inventory != null) {
generator.writeNumberField("myInventoryComponent", player.inventory.getId());
} else if (writeEmpty) {
generator.writeNullField("myInventoryComponent");
}
});
PROPERTIES.put("location", (player, generator, context, writeEmpty) -> {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/qowyn/ark/tools/data/TeamType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package qowyn.ark.tools.data;

public enum TeamType {

NON_PLAYER, PLAYER, TRIBE, BREEDING, UNKNOWN;

public static final int PLAYER_START = 50000;

public static final int TRIBE_START = 1000000000;

public static final int BREEDING_ID = 2000000000;

public static TeamType forTargetingTeam(int teamId) {
if (teamId < PLAYER_START) {
return NON_PLAYER;
}

if (teamId < TRIBE_START) {
return PLAYER;
}

if (teamId < BREEDING_ID) {
return TRIBE;
}

return teamId == 2000000000 ? BREEDING : UNKNOWN;
}

}
Loading

0 comments on commit a84838c

Please sign in to comment.