1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Merge pull request #5720 from SoundSSGood/artifact-charges

Charged artifacts
This commit is contained in:
Ivan Savenko
2025-05-21 13:49:14 +03:00
committed by GitHub
28 changed files with 480 additions and 57 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())
useChargedArtifactUsed(hero->id, spellID);
}
bool CGameHandler::swapStacks(const StackLocation & sl1, const StackLocation & sl2)
@@ -4331,3 +4334,34 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
{
battles->startBattle(army1, army2);
}
void CGameHandler::useChargedArtifactUsed(const ObjectInstanceID & heroObjectID, const SpellID & spellID)
{
const auto hero = getHero(heroObjectID);
assert(hero);
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);
}