From 695a94c3c89b9a5775c3c16b8ea55d4dcb5753ac Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 22 Jan 2023 18:17:26 +0200 Subject: [PATCH] Fixed all major bugs with newly converted objects --- config/objects/rewardable.json | 41 ++++++++++++++++----------------- lib/JsonNode.cpp | 15 ++++++++++++ lib/JsonNode.h | 3 +++ lib/mapObjects/JsonRandom.cpp | 42 ++++++++++++++++++++++++++++++++++ lib/mapObjects/JsonRandom.h | 2 ++ 5 files changed, 82 insertions(+), 21 deletions(-) diff --git a/config/objects/rewardable.json b/config/objects/rewardable.json index 11ef78f8f..212bc4b34 100644 --- a/config/objects/rewardable.json +++ b/config/objects/rewardable.json @@ -164,7 +164,7 @@ "campfire" :{ "index" : 12, - "handler": "pickable", + "handler": "configurable", "base" : { "sounds" : { "ambient" : ["LOOPCAMP"], @@ -181,14 +181,14 @@ "rarity" : 500 }, "visitMode" : "unlimited", - "selectMode" : "player", + "selectMode" : "selectFirst", "rewards" : [ { "message" : 23, "removeObject" : true, "resources" : [ { - "type" : [ "wood", "ore", "mercury", "gems", "sulfur", "crystal" ], + "list" : [ "wood", "ore", "mercury", "gems", "sulfur", "crystal" ], "min" : 4, "max" : 6 }, @@ -205,7 +205,7 @@ }, "flotsam" :{ "index" : 29, - "handler": "pickable", + "handler": "configurable", "base" : { "sounds" : { "visit" : ["GENIE"], @@ -221,7 +221,7 @@ "rarity" : 100 }, "visitMode" : "unlimited", - "selectMode" : "player", + "selectMode" : "selectFirst", "rewards" : [ { "message" : 51, @@ -260,7 +260,7 @@ }, "seaChest" :{ "index" : 82, - "handler": "pickable", + "handler": "configurable", "base" : { "sounds" : { "visit" : ["CHEST"], @@ -276,7 +276,7 @@ "rarity" : 500 }, "visitMode" : "unlimited", - "selectMode" : "player", + "selectMode" : "selectFirst", "rewards" : [ { "appearChance" : { "max" : 20 }, @@ -308,7 +308,7 @@ }, "shipwreckSurvivor" : { "index" : 86, - "handler": "pickable", + "handler": "configurable", "base" : { "sounds" : { "visit" : ["TREASURE"], @@ -317,7 +317,6 @@ }, "types" : { "shipwreckSurvivor" : { - //EXPERNCE.WAV "index" : 0, "aiValue" : 1500, "rmg" : { @@ -325,31 +324,31 @@ "rarity" : 50 }, "visitMode" : "unlimited", - "selectMode" : "player", + "selectMode" : "selectFirst", "rewards" : [ { "appearChance" : { "max" : 55 }, "message" : 125, //FIXME: this text contains placeholder for artifact name "removeObject" : true, - "artifacts" : [ "TREASURE"] + "artifacts" : [ { "class" : "TREASURE" } ] }, { "appearChance" : { "min" : 55, "max" : 75 }, "message" : 125, //FIXME: this text contains placeholder for artifact name "removeObject" : true, - "artifacts" : [ "MINOR"] + "artifacts" : [ { "class" : "MINOR" } ] }, { "appearChance" : { "min" : 75, "max" : 95 }, "message" : 125, //FIXME: this text contains placeholder for artifact name "removeObject" : true, - "artifacts" : [ "MAJOR"] + "artifacts" : [ { "class" : "MAJOR" } ] }, { "appearChance" : { "min" : 95 }, "message" : 125, //FIXME: this text contains placeholder for artifact name "removeObject" : true, - "artifacts" : [ "RELIC"] + "artifacts" : [ { "class" : "RELIC" } ] } ] } @@ -357,7 +356,7 @@ }, "treasureChest" : { "index" : 101, - "handler": "pickable", + "handler": "configurable", "base" : { "sounds" : { "visit" : ["CHEST"], @@ -365,7 +364,6 @@ } }, "types" : { - "onSelect" : 146, "treasureChest" : { "index" : 0, "aiValue" : 2000, @@ -373,8 +371,9 @@ "value" : 1500, "rarity" : 1000 }, + "onSelectMessage" : 146, "visitMode" : "unlimited", - "selectMode" : "player", + "selectMode" : "selectPlayer", "rewards" : [ { "appearChance" : { "max" : 33 }, @@ -383,7 +382,7 @@ }, { "appearChance" : { "max" : 33 }, - "experience" : 1500, + "gainedExp" : 1500, "removeObject" : true, }, { @@ -393,7 +392,7 @@ }, { "appearChance" : { "min" : 33, "max" : 65 }, - "experience" : 1000, + "gainedExp" : 1000, "removeObject" : true, }, { @@ -403,7 +402,7 @@ }, { "appearChance" : { "min" : 65, "max" : 95 }, - "experience" : 500, + "gainedExp" : 500, "removeObject" : true, }, { @@ -411,7 +410,7 @@ "appearChance" : { "min" : 95 }, "message" : 145, //FIXME: this text contains placeholder for artifact name "removeObject" : true, - "artifacts" : [ "TREASURE"] + "artifacts" : [ { "class" : "TREASURE" } ] } ] } diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index 97da86084..6682cf651 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -260,6 +260,21 @@ bool JsonNode::isNumber() const return type == JsonType::DATA_INTEGER || type == JsonType::DATA_FLOAT; } +bool JsonNode::isString() const +{ + return type == JsonType::DATA_STRING; +} + +bool JsonNode::isVector() const +{ + return type == JsonType::DATA_VECTOR; +} + +bool JsonNode::isStruct() const +{ + return type == JsonType::DATA_STRUCT; +} + bool JsonNode::containsBaseData() const { switch(type) diff --git a/lib/JsonNode.h b/lib/JsonNode.h index 0597af20b..5c888310a 100644 --- a/lib/JsonNode.h +++ b/lib/JsonNode.h @@ -83,6 +83,9 @@ public: bool isNull() const; bool isNumber() const; + bool isString() const; + bool isVector() const; + bool isStruct() const; /// true if node contains not-null data that cannot be extended via merging /// used for generating common base node from multiple nodes (e.g. bonuses) bool containsBaseData() const; diff --git a/lib/mapObjects/JsonRandom.cpp b/lib/mapObjects/JsonRandom.cpp index 7caf9b1e7..c9b9e2c88 100644 --- a/lib/mapObjects/JsonRandom.cpp +++ b/lib/mapObjects/JsonRandom.cpp @@ -38,9 +38,39 @@ namespace JsonRandom return rng.getIntRange(min, max)(); } + DLL_LINKAGE std::string loadKey(const JsonNode & value, CRandomGenerator & rng, std::string defaultValue) + { + if (value.isNull()) + return defaultValue; + if (value.isString()) + return value.String(); + if (!value["type"].isNull()) + return value["type"].String(); + + if (value["list"].isNull()) + return defaultValue; + + const auto & resourceList = value["list"].Vector(); + + if (resourceList.empty()) + return defaultValue; + + si32 index = rng.getIntRange(0, resourceList.size() - 1 )(); + + return resourceList[index].String(); + } + TResources loadResources(const JsonNode & value, CRandomGenerator & rng) { TResources ret; + + if (value.isVector()) + { + for (const auto & entry : value.Vector()) + ret += loadResource(entry, rng); + return ret; + } + for (size_t i=0; imodh->identifiers.getIdentifier(value.meta, "resource", resourceName).get()); + + TResources ret; + ret[resourceID] = resourceAmount; + return ret; + } + + std::vector loadPrimary(const JsonNode & value, CRandomGenerator & rng) { std::vector ret; diff --git a/lib/mapObjects/JsonRandom.h b/lib/mapObjects/JsonRandom.h index 0ed636aae..427ac739d 100644 --- a/lib/mapObjects/JsonRandom.h +++ b/lib/mapObjects/JsonRandom.h @@ -32,7 +32,9 @@ namespace JsonRandom }; DLL_LINKAGE si32 loadValue(const JsonNode & value, CRandomGenerator & rng, si32 defaultValue = 0); + DLL_LINKAGE std::string loadKey(const JsonNode & value, CRandomGenerator & rng, std::string defaultValue = ""); DLL_LINKAGE TResources loadResources(const JsonNode & value, CRandomGenerator & rng); + DLL_LINKAGE TResources loadResource(const JsonNode & value, CRandomGenerator & rng); DLL_LINKAGE std::vector loadPrimary(const JsonNode & value, CRandomGenerator & rng); DLL_LINKAGE std::map loadSecondary(const JsonNode & value, CRandomGenerator & rng);