Bläddra i källkod

Taking artifacts as a reward

Ivan Savenko 5 månader sedan
förälder
incheckning
6688d28198
3 ändrade filer med 23 tillägg och 0 borttagningar
  1. 1 0
      lib/rewardable/Info.cpp
  2. 18 0
      lib/rewardable/Interface.cpp
  3. 4 0
      lib/rewardable/Reward.cpp

+ 1 - 0
lib/rewardable/Info.cpp

@@ -183,6 +183,7 @@ void Rewardable::Info::configureReward(Rewardable::Configuration & object, vstd:
 	reward.secondary = randomizer.loadSecondaries(source["secondary"], rng, variables);
 
 	reward.grantedArtifacts = randomizer.loadArtifacts(source["artifacts"], rng, variables);
+	reward.takenArtifacts = randomizer.loadArtifacts(source["takenArtifacts"], rng, variables);
 	reward.scrolls = randomizer.loadSpells(source["scrolls"], rng, variables);
 	reward.spells = randomizer.loadSpells(source["spells"], rng, variables);
 	reward.creatures = randomizer.loadCreatures(source["creatures"], rng, variables);

+ 18 - 0
lib/rewardable/Interface.cpp

@@ -166,6 +166,24 @@ void Rewardable::Interface::grantRewardAfterLevelup(const Rewardable::VisitInfo
 	for(const ArtifactID & art : info.reward.grantedArtifacts)
 		cb->giveHeroNewArtifact(hero, art, ArtifactPosition::FIRST_AVAILABLE);
 
+	for(const ArtifactID & art : info.reward.takenArtifacts)
+	{
+		// hero does not have such artifact alone, but he might have it as part of assembled artifact
+		if(!hero->hasArt(art))
+		{
+			const auto * assembly = hero->getCombinedArtWithPart(art);
+			if (assembly)
+			{
+				DisassembledArtifact da;
+				da.al = ArtifactLocation(hero->id, hero->getArtPos(assembly));
+				cb->sendAndApply(da);
+			}
+		}
+
+		if(hero->hasArt(art))
+			cb->removeArtifact(ArtifactLocation(hero->id, hero->getArtPos(art, false)));
+	}
+
 	for(const SpellID & spell : info.reward.scrolls)
 		cb->giveHeroNewScroll(hero, spell, ArtifactPosition::FIRST_AVAILABLE);
 

+ 4 - 0
lib/rewardable/Reward.cpp

@@ -114,6 +114,9 @@ void Rewardable::Reward::loadComponents(std::vector<Component> & comps, const CG
 	for(const auto & entry : grantedArtifacts)
 		comps.emplace_back(ComponentType::ARTIFACT, entry);
 
+	for(const auto & entry : takenArtifacts)
+		comps.emplace_back(ComponentType::ARTIFACT, entry);
+
 	for(const SpellID & spell : scrolls)
 		comps.emplace_back(ComponentType::SPELL, spell);
 
@@ -145,6 +148,7 @@ void Rewardable::Reward::serializeJson(JsonSerializeFormat & handler)
 	handler.serializeInt("manaOverflowFactor", manaOverflowFactor);
 	handler.serializeInt("movePoints", movePoints);
 	handler.serializeIdArray("artifacts", grantedArtifacts);
+	handler.serializeIdArray("takenArtifacts", takenArtifacts);
 	handler.serializeIdArray("scrolls", scrolls);
 	handler.serializeIdArray("spells", spells);
 	handler.enterArray("creatures").serializeStruct(creatures);