Преглед на файлове

Cleanup & consistency changes

Ivan Savenko преди 2 години
родител
ревизия
7a9e5e4e30

+ 5 - 5
config/objects/rewardableOncePerHero.json

@@ -119,10 +119,10 @@
 					{
 						"limiter" : {
 							"anyOf" : [
-								{ "minLevel" : 10 },
-								{ "minLevel" :  8, "secondary" : { "diplomacy" : 1 } },
-								{ "minLevel" :  6, "secondary" : { "diplomacy" : 2 } },
-								{ "minLevel" :  4, "secondary" : { "diplomacy" : 3 } }
+								{ "heroLevel" : 10 },
+								{ "heroLevel" :  8, "secondary" : { "diplomacy" : 1 } },
+								{ "heroLevel" :  6, "secondary" : { "diplomacy" : 2 } },
+								{ "heroLevel" :  4, "secondary" : { "diplomacy" : 3 } }
 							]
 						},
 						"message" : 59,
@@ -355,7 +355,7 @@
 				"rewards" : [
 					{
 						"message" : 143,
-						"gainedExp" : 1000
+						"heroExperience" : 1000
 					}
 				]
 			}

+ 8 - 0
config/objects/rewardableOnceVisitable.json

@@ -67,6 +67,10 @@
 						"appearChance" : { "min" : 10, "max" : 20 },
 						"message" : 37,
 						"artifacts" : [ { "class" : "MINOR" } ]
+					},
+					{
+						"appearChance" : { "min" : 20, "max" : 100 },
+						"message" : 38,
 					}
 				]
 			}
@@ -113,6 +117,10 @@
 								"max" : 5
 							},
 						]
+					},
+					{
+						"appearChance" : { "min" : 90, "max" : 100 },
+						"message" : 156,
 					}
 				]
 			}

+ 16 - 4
lib/mapObjects/CRewardableConstructor.cpp

@@ -63,9 +63,17 @@ TRewardLimitersList CRandomRewardObjectInfo::configureSublimiters(CRewardableObj
 
 void CRandomRewardObjectInfo::configureLimiter(CRewardableObject * object, CRandomGenerator & rng, CRewardLimiter & limiter, const JsonNode & source) const
 {
+	std::vector<SpellID> spells;
+	for (size_t i=0; i<6; i++)
+		IObjectInterface::cb->getAllowedSpells(spells, static_cast<ui16>(i));
+
+
 	limiter.dayOfWeek = JsonRandom::loadValue(source["dayOfWeek"], rng);
 	limiter.daysPassed = JsonRandom::loadValue(source["daysPassed"], rng);
-	limiter.minLevel = JsonRandom::loadValue(source["minLevel"], rng);
+	limiter.heroExperience = JsonRandom::loadValue(source["heroExperience"], rng);
+	limiter.heroLevel = JsonRandom::loadValue(source["heroLevel"], rng)
+					 + JsonRandom::loadValue(source["minLevel"], rng); // VCMI 1.1 compatibilty
+
 	limiter.manaPercentage = JsonRandom::loadValue(source["manaPercentage"], rng);
 	limiter.manaPoints = JsonRandom::loadValue(source["manaPoints"], rng);
 
@@ -73,7 +81,8 @@ void CRandomRewardObjectInfo::configureLimiter(CRewardableObject * object, CRand
 
 	limiter.primary = JsonRandom::loadPrimary(source["primary"], rng);
 	limiter.secondary = JsonRandom::loadSecondary(source["secondary"], rng);
-	limiter.artifacts = JsonRandom::loadArtifacts(source["artifacts"], rng);
+	limiter.artifacts = JsonRandom::loadArtifacts(source["spells"], rng);
+	limiter.spells  = JsonRandom::loadSpells(source["artifacts"], rng, spells);
 	limiter.creatures = JsonRandom::loadCreatures(source["creatures"], rng);
 
 	limiter.allOf  = configureSublimiters(object, rng, source["allOf"] );
@@ -85,8 +94,11 @@ void CRandomRewardObjectInfo::configureReward(CRewardableObject * object, CRando
 {
 	reward.resources = JsonRandom::loadResources(source["resources"], rng);
 
-	reward.gainedExp = JsonRandom::loadValue(source["gainedExp"], rng);
-	reward.gainedLevels = JsonRandom::loadValue(source["gainedLevels"], rng);
+	reward.heroExperience = JsonRandom::loadValue(source["heroExperience"], rng)
+						  + JsonRandom::loadValue(source["gainedExp"], rng); // VCMI 1.1 compatibilty
+
+	reward.heroLevel = JsonRandom::loadValue(source["heroLevel"], rng)
+						+ JsonRandom::loadValue(source["gainedLevels"], rng); // VCMI 1.1 compatibilty
 
 	reward.manaDiff = JsonRandom::loadValue(source["manaPoints"], rng);
 	reward.manaOverflowFactor = JsonRandom::loadValue(source["manaOverflowFactor"], rng);

+ 22 - 9
lib/mapObjects/CRewardableObject.cpp

@@ -52,7 +52,10 @@ bool CRewardLimiter::heroAllowed(const CGHeroInstance * hero) const
 	if(!IObjectInterface::cb->getPlayerState(hero->tempOwner)->resources.canAfford(resources))
 		return false;
 
-	if(minLevel > (si32)hero->level)
+	if(heroLevel > (si32)hero->level)
+		return false;
+
+	if((TExpType)heroExperience > hero->exp)
 		return false;
 
 	if(manaPoints > hero->mana)
@@ -73,6 +76,12 @@ bool CRewardLimiter::heroAllowed(const CGHeroInstance * hero) const
 			return false;
 	}
 
+	for(auto & spell : spells)
+	{
+		if (!hero->spellbookContainsSpell(spell))
+			return false;
+	}
+
 	for(auto & art : artifacts)
 	{
 		if (!hero->hasArt(art))
@@ -265,12 +274,16 @@ void CRewardableObject::grantRewardBeforeLevelup(const CRewardVisitInfo & info,
 	}
 
 	for(int i=0; i< info.reward.primary.size(); i++)
-		if(info.reward.primary[i] > 0)
-			cb->changePrimSkill(hero, static_cast<PrimarySkill::PrimarySkill>(i), info.reward.primary[i], false);
+		cb->changePrimSkill(hero, static_cast<PrimarySkill::PrimarySkill>(i), info.reward.primary[i], false);
 
 	si64 expToGive = 0;
-	expToGive += VLC->heroh->reqExp(hero->level+info.reward.gainedLevels) - VLC->heroh->reqExp(hero->level);
-	expToGive += hero->calculateXp(info.reward.gainedExp);
+
+	if (info.reward.heroLevel > 0)
+		expToGive += VLC->heroh->reqExp(hero->level+info.reward.heroLevel) - VLC->heroh->reqExp(hero->level);
+
+	if (info.reward.heroExperience > 0)
+		expToGive += hero->calculateXp(info.reward.heroExperience);
+
 	if(expToGive)
 		cb->changePrimSkill(hero, PrimarySkill::EXPERIENCE, expToGive);
 
@@ -427,13 +440,13 @@ void CRewardInfo::loadComponents(std::vector<Component> & comps,
 	for (auto comp : extraComponents)
 		comps.push_back(comp);
 
-	if (gainedExp)
+	if (heroExperience)
 	{
 		comps.push_back(Component(
-			Component::EXPERIENCE, 0, (si32)h->calculateXp(gainedExp), 0));
+			Component::EXPERIENCE, 0, (si32)h->calculateXp(heroExperience), 0));
 	}
-	if (gainedLevels)
-		comps.push_back(Component(Component::EXPERIENCE, 1, gainedLevels, 0));
+	if (heroLevel)
+		comps.push_back(Component(Component::EXPERIENCE, 1, heroLevel, 0));
 
 	if (manaDiff || manaPercentage >= 0)
 		comps.push_back(Component(Component::PRIM_SKILL, 5, manaDiff, 0));

+ 16 - 9
lib/mapObjects/CRewardableObject.h

@@ -32,8 +32,11 @@ public:
 	si32 dayOfWeek;
 	si32 daysPassed;
 
+	/// total experience that hero needs to have
+	si32 heroExperience;
+
 	/// level that hero needs to have
-	si32 minLevel;
+	si32 heroLevel;
 
 	/// mana points that hero needs to have
 	si32 manaPoints;
@@ -52,6 +55,9 @@ public:
 	/// Note: does not checks for multiple copies of the same arts
 	std::vector<ArtifactID> artifacts;
 
+	/// Spells that hero must have in the spellbook
+	std::vector<SpellID> spells;
+
 	/// creatures that hero needs to have
 	std::vector<CStackBasicDescriptor> creatures;
 
@@ -67,7 +73,7 @@ public:
 	CRewardLimiter():
 		dayOfWeek(0),
 		daysPassed(0),
-		minLevel(0),
+		heroLevel(0),
 		primary(4, 0)
 	{}
 
@@ -77,7 +83,8 @@ public:
 	{
 		h & dayOfWeek;
 		h & daysPassed;
-		h & minLevel;
+		h & heroExperience;
+		h & heroLevel;
 		h & manaPoints;
 		h & manaPercentage;
 		h & resources;
@@ -127,9 +134,9 @@ public:
 	TResources resources;
 
 	/// received experience
-	ui32 gainedExp;
+	si32 heroExperience;
 	/// received levels (converted into XP during grant)
-	ui32 gainedLevels;
+	si32 heroLevel;
 
 	/// mana given to/taken from hero, fixed value
 	si32 manaDiff;
@@ -172,8 +179,8 @@ public:
 	Component getDisplayedComponent(const CGHeroInstance * h) const;
 
 	CRewardInfo() :
-		gainedExp(0),
-		gainedLevels(0),
+		heroExperience(0),
+		heroLevel(0),
 		manaDiff(0),
 		manaPercentage(-1),
 		movePoints(0),
@@ -189,8 +196,8 @@ public:
 		h & removeObject;
 		h & manaPercentage;
 		h & movePercentage;
-		h & gainedExp;
-		h & gainedLevels;
+		h & heroExperience;
+		h & heroLevel;
 		h & manaDiff;
 		h & manaOverflowFactor;
 		h & movePoints;