1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fixed all major bugs with newly converted objects

This commit is contained in:
Ivan Savenko 2023-01-22 18:17:26 +02:00
parent 9f3f9cc563
commit 695a94c3c8
5 changed files with 82 additions and 21 deletions

View File

@ -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" } ]
}
]
}

View File

@ -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)

View File

@ -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;

View File

@ -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; i<GameConstants::RESOURCE_QUANTITY; i++)
{
ret[i] = loadValue(value[GameConstants::RESOURCE_NAMES[i]], rng);
@ -48,6 +78,18 @@ namespace JsonRandom
return ret;
}
TResources loadResource(const JsonNode & value, CRandomGenerator & rng)
{
std::string resourceName = loadKey(value, rng, "");
si32 resourceAmount = loadValue(value, rng, 0);
si32 resourceID(VLC->modh->identifiers.getIdentifier(value.meta, "resource", resourceName).get());
TResources ret;
ret[resourceID] = resourceAmount;
return ret;
}
std::vector<si32> loadPrimary(const JsonNode & value, CRandomGenerator & rng)
{
std::vector<si32> ret;

View File

@ -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<si32> loadPrimary(const JsonNode & value, CRandomGenerator & rng);
DLL_LINKAGE std::map<SecondarySkill, si32> loadSecondary(const JsonNode & value, CRandomGenerator & rng);