1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00
This commit is contained in:
SoundSSGood
2025-05-16 22:01:07 +02:00
parent f614a8a7f5
commit 051381d4db
10 changed files with 75 additions and 22 deletions

View File

@@ -3931,6 +3931,9 @@ void CGameHandler::castSpell(const spells::Caster * caster, SpellID spellID, con
const CSpell * s = spellID.toSpell();
s->adventureCast(spellEnv, p);
if(const auto hero = caster->getHeroCaster())
verifyChargedArtifactUsed(hero->id, spellID);
}
bool CGameHandler::swapStacks(const StackLocation & sl1, const StackLocation & sl2)
@@ -4337,3 +4340,35 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
{
battles->startBattle(army1, army2);
}
void CGameHandler::verifyChargedArtifactUsed(const ObjectInstanceID & heroObjectID, const SpellID & spellID)
{
if(const auto hero = getHero(heroObjectID))
{
assert(hero->canCastThisSpell(spellID.toSpell()));
if(vstd::contains(hero->getSpellsInSpellbook(), spellID))
return;
std::vector<std::pair<ArtifactPosition, ArtifactInstanceID>> chargedArts;
for(const auto & [slot, slotInfo] : hero->artifactsWorn)
{
const auto artInst = slotInfo.getArt();
const auto artType = artInst->getType();
if(artType->getDischargeCondition() == DischargeArtifactCondition::SPELLCAST)
{
chargedArts.emplace_back(slot, artInst->getId());
}
else
{
if(const auto bonuses = artInst->getBonusesOfType(BonusType::SPELL, spellID); !bonuses->empty())
return;
}
}
assert(!chargedArts.empty());
DischargeArtifact msg(chargedArts.front().second, 1);
msg.artLoc.emplace(hero->id, chargedArts.front().first);
sendAndApply(msg);
}
}