diff --git a/client/battle/BattleActionsController.cpp b/client/battle/BattleActionsController.cpp index a6e4f5784..3484689c1 100644 --- a/client/battle/BattleActionsController.cpp +++ b/client/battle/BattleActionsController.cpp @@ -750,7 +750,7 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, B if (!spellcastingModeActive()) { - if (action.spell().toSpell()) + if (action.spell().hasValue()) { owner.giveCommand(EActionType::MONSTER_SPELL, targetHex, action.spell()); } @@ -887,17 +887,17 @@ void BattleActionsController::tryActivateStackSpellcasting(const CStack *casterS { // faerie dragon can cast only one, randomly selected spell until their next move //TODO: faerie dragon type spell should be selected by server - const auto * spellToCast = owner.getBattle()->getRandomCastedSpell(CRandomGenerator::getDefault(), casterStack).toSpell(); + const auto spellToCast = owner.getBattle()->getRandomCastedSpell(CRandomGenerator::getDefault(), casterStack); - if (spellToCast) - creatureSpells.push_back(spellToCast); + if (spellToCast.hasValue()) + creatureSpells.push_back(spellToCast.toSpell()); } TConstBonusListPtr bl = casterStack->getBonuses(Selector::type()(BonusType::SPELLCASTER)); for(const auto & bonus : *bl) { - if (bonus->additionalInfo[0] <= 0) + if (bonus->additionalInfo[0] <= 0 && bonus->subtype.as().hasValue()) creatureSpells.push_back(bonus->subtype.as().toSpell()); } } diff --git a/client/battle/BattleInterface.cpp b/client/battle/BattleInterface.cpp index c2255b6f5..d534f0556 100644 --- a/client/battle/BattleInterface.cpp +++ b/client/battle/BattleInterface.cpp @@ -352,13 +352,13 @@ void BattleInterface::spellCast(const BattleSpellCast * sc) CCS->curh->set(Cursor::Combat::BLOCKED); const SpellID spellID = sc->spellID; + + if(!spellID.hasValue()) + return; + const CSpell * spell = spellID.toSpell(); auto targetedTile = sc->tile; - assert(spell); - if(!spell) - return; - const AudioPath & castSoundPath = spell->getCastSound(); if (!castSoundPath.empty()) diff --git a/lib/battle/CBattleInfoCallback.cpp b/lib/battle/CBattleInfoCallback.cpp index 7db5cc7aa..14509999d 100644 --- a/lib/battle/CBattleInfoCallback.cpp +++ b/lib/battle/CBattleInfoCallback.cpp @@ -867,9 +867,10 @@ bool CBattleInfoCallback::handleObstacleTriggersForUnit(SpellCastEnvironment & s auto shouldReveal = !spellObstacle->hidden || !battleIsObstacleVisibleForSide(*obstacle, (BattlePerspective::BattlePerspective)side); const auto * hero = battleGetFightingHero(spellObstacle->casterSide); auto caster = spells::ObstacleCasterProxy(getBattle()->getSidePlayer(spellObstacle->casterSide), hero, *spellObstacle); - const auto * sp = obstacle->getTrigger().toSpell(); - if(obstacle->triggersEffects() && sp) + + if(obstacle->triggersEffects() && obstacle->getTrigger().hasValue()) { + const auto * sp = obstacle->getTrigger().toSpell(); auto cast = spells::BattleCast(this, &caster, spells::Mode::PASSIVE, sp); spells::detail::ProblemImpl ignored; auto target = spells::Target(1, spells::Destination(&unit)); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index ad9baed9e..dc9bcb999 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3955,14 +3955,14 @@ bool CGameHandler::moveStack(const StackLocation &src, const StackLocation &dst, void CGameHandler::castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) { - const CSpell * s = spellID.toSpell(); - if(!s) + if (!spellID.hasValue()) return; AdventureSpellCastParameters p; p.caster = caster; p.pos = pos; + const CSpell * s = spellID.toSpell(); s->adventureCast(spellEnv, p); } diff --git a/server/NetPacksServer.cpp b/server/NetPacksServer.cpp index a3d77db31..846ddcd42 100644 --- a/server/NetPacksServer.cpp +++ b/server/NetPacksServer.cpp @@ -327,9 +327,9 @@ void ApplyGhNetPackVisitor::visitCastAdvSpell(CastAdvSpell & pack) { gh.throwIfWrongOwner(&pack, pack.hid); - const CSpell * s = pack.sid.toSpell(); - if(!s) + if (!pack.sid.hasValue()) gh.throwNotAllowedAction(&pack); + const CGHeroInstance * h = gh.getHero(pack.hid); if(!h) gh.throwNotAllowedAction(&pack); @@ -338,6 +338,7 @@ void ApplyGhNetPackVisitor::visitCastAdvSpell(CastAdvSpell & pack) p.caster = h; p.pos = pack.pos; + const CSpell * s = pack.sid.toSpell(); result = s->adventureCast(gh.spellEnv, p); } diff --git a/server/battles/BattleActionProcessor.cpp b/server/battles/BattleActionProcessor.cpp index af8e88994..8a706a8c1 100644 --- a/server/battles/BattleActionProcessor.cpp +++ b/server/battles/BattleActionProcessor.cpp @@ -102,13 +102,13 @@ bool BattleActionProcessor::doHeroSpellAction(const CBattleInfoCallback & battle return false; } - const CSpell * s = ba.spell.toSpell(); - if (!s) + if (!ba.spell.hasValue()) { logGlobal->error("Wrong spell id (%d)!", ba.spell.getNum()); return false; } + const CSpell * s = ba.spell.toSpell(); spells::BattleCast parameters(&battle, h, spells::Mode::HERO, s); spells::detail::ProblemImpl problem;