1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Remove artifact from slot as reward

This commit is contained in:
Ivan Savenko
2025-05-01 21:02:56 +03:00
parent 6688d28198
commit 0212b6e37d
9 changed files with 72 additions and 2 deletions

View File

@@ -164,6 +164,8 @@ void Rewardable::Info::configureReward(Rewardable::Configuration & object, vstd:
reward.resources = randomizer.loadResources(source["resources"], rng, variables);
reward.heroExperience = randomizer.loadValue(source["heroExperience"], rng, variables);
reward.unitExperience = randomizer.loadValue(source["unitExperience"], rng, variables);
reward.commanderExperience = randomizer.loadValue(source["commanderExperience"], rng, variables);
reward.heroLevel = randomizer.loadValue(source["heroLevel"], rng, variables);
reward.manaDiff = randomizer.loadValue(source["manaPoints"], rng, variables);
@@ -184,6 +186,7 @@ void Rewardable::Info::configureReward(Rewardable::Configuration & object, vstd:
reward.grantedArtifacts = randomizer.loadArtifacts(source["artifacts"], rng, variables);
reward.takenArtifacts = randomizer.loadArtifacts(source["takenArtifacts"], rng, variables);
reward.takenArtifactSlots = randomizer.loadArtifactSlots(source["takenArtifactsSlots"], 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);

View File

@@ -184,6 +184,16 @@ void Rewardable::Interface::grantRewardAfterLevelup(const Rewardable::VisitInfo
cb->removeArtifact(ArtifactLocation(hero->id, hero->getArtPos(art, false)));
}
for(const ArtifactPosition & slot : info.reward.takenArtifactSlots)
{
const auto & slotContent = hero->getSlot(slot);
if (!slotContent->locked && slotContent->artifactID.hasValue())
cb->removeArtifact(ArtifactLocation(hero->id, slot));
// TODO: handle locked slots?
}
for(const SpellID & spell : info.reward.scrolls)
cb->giveHeroNewScroll(hero, spell, ArtifactPosition::FIRST_AVAILABLE);

View File

@@ -77,6 +77,12 @@ struct DLL_LINKAGE Limiter final : public Serializeable
/// creatures that hero needs to have
std::vector<CStackBasicDescriptor> creatures;
/// creatures that hero needs to have
std::vector<CStackBasicDescriptor> canLoseCreatures;
/// creatures that hero needs to have
std::vector<CStackBasicDescriptor> canReceiveCreatures;
/// only heroes/hero classes from list could pass limiter
std::vector<HeroTypeID> heroes;
std::vector<HeroClassID> heroClasses;

View File

@@ -117,6 +117,16 @@ void Rewardable::Reward::loadComponents(std::vector<Component> & comps, const CG
for(const auto & entry : takenArtifacts)
comps.emplace_back(ComponentType::ARTIFACT, entry);
for(const auto & entry : takenArtifactSlots)
{
if (h)
{
const auto & slotContent = h->getSlot(entry);
if (slotContent->artifactID.hasValue())
comps.emplace_back(ComponentType::ARTIFACT, slotContent->getArt()->getTypeId());
}
}
for(const SpellID & spell : scrolls)
comps.emplace_back(ComponentType::SPELL, spell);
@@ -149,6 +159,7 @@ void Rewardable::Reward::serializeJson(JsonSerializeFormat & handler)
handler.serializeInt("movePoints", movePoints);
handler.serializeIdArray("artifacts", grantedArtifacts);
handler.serializeIdArray("takenArtifacts", takenArtifacts);
handler.serializeIdArray("takenArtifactSlots", takenArtifactSlots);
handler.serializeIdArray("scrolls", scrolls);
handler.serializeIdArray("spells", spells);
handler.enterArray("creatures").serializeStruct(creatures);

View File

@@ -66,7 +66,7 @@ struct DLL_LINKAGE Reward final
/// received experience
si32 heroExperience;
si32 commanderExperience;
si32 unitsExperience;
si32 unitExperience;
/// received levels (converted into XP during grant)
si32 heroLevel;
@@ -105,6 +105,7 @@ struct DLL_LINKAGE Reward final
std::vector<SpellID> scrolls;
std::vector<SpellID> spells;
std::vector<CStackBasicDescriptor> creatures;
std::vector<CStackBasicDescriptor> takenCreatures;
/// actions that hero may execute and object caster. Pair of spellID and school level
std::pair<SpellID, int> spellCast;
@@ -140,7 +141,7 @@ struct DLL_LINKAGE Reward final
if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS)
{
h & commanderExperience;
h & unitsExperience;
h & unitExperience;
}
h & heroLevel;
h & manaDiff;
@@ -162,6 +163,8 @@ struct DLL_LINKAGE Reward final
}
h & spells;
h & creatures;
if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS)
h & takenCreatures;
h & creaturesChange;
h & revealTiles;
h & spellCast;