diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index 0948c4a85..a32f58b8a 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -335,6 +335,11 @@ int CBattleInfoEssentials::battleCastSpells(ui8 side) const return getBattle()->sides[side].castSpellsCount; } +const IBonusBearer * CBattleInfoEssentials::getBattleNode() const +{ + return getBattle(); +} + ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(PlayerColor player, ECastingMode::ECastingMode mode) const { RETURN_IF_NOT_BATTLE(ESpellCastProblem::INVALID); @@ -1645,7 +1650,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell return ESpellCastProblem::NO_APPROPRIATE_TARGET; } - if(battleMaxSpellLevel() < spell->level) //effect like Recanter's Cloak or Orb of Inhibition + if(battleMaxSpellLevel(side) < spell->level) //effect like Recanter's Cloak or Orb of Inhibition return ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED; //checking if there exists an appropriate target @@ -2060,12 +2065,14 @@ int CBattleInfoCallback::battleGetSurrenderCost(PlayerColor Player) const return ret; } -si8 CBattleInfoCallback::battleMaxSpellLevel() const +si8 CBattleInfoCallback::battleMaxSpellLevel(ui8 side) const { - const CBonusSystemNode *node = nullptr; - if(const CGHeroInstance *h = battleGetFightingHero(battleGetMySide())) + const IBonusBearer *node = nullptr; + if(const CGHeroInstance * h = battleGetFightingHero(side)) node = h; - //TODO else use battle node + else + node = getBattleNode(); + if(!node) return GameConstants::SPELL_LEVELS; diff --git a/lib/CBattleCallback.h b/lib/CBattleCallback.h index 62e6eb160..73a6a5f12 100644 --- a/lib/CBattleCallback.h +++ b/lib/CBattleCallback.h @@ -158,6 +158,7 @@ class DLL_LINKAGE CBattleInfoEssentials : public virtual CCallbackBase { protected: bool battleDoWeKnowAbout(ui8 side) const; + const IBonusBearer * getBattleNode() const; public: enum EStackOwnership { @@ -276,7 +277,7 @@ public: std::vector getAttackableBattleHexes() const; //*** MAGIC - si8 battleMaxSpellLevel() const; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned + si8 battleMaxSpellLevel(ui8 side) const; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned ui32 battleGetSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //returns cost of given spell ESpellCastProblem::ESpellCastProblem battleCanCastSpell(PlayerColor player, ECastingMode::ECastingMode mode) const; //returns true if there are no general issues preventing from casting a spell ESpellCastProblem::ESpellCastProblem battleCanCastThisSpell(PlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode) const; //checks if given player can cast given spell diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 1cf7690b7..65dfc2707 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -4183,17 +4183,17 @@ void CGameHandler::stackTurnTrigger(const CStack * st) } if (st->hasBonusOfType(Bonus::MANA_DRAIN) && !vstd::contains(st->state, EBattleStackState::DRAINED_MANA)) { - const CGHeroInstance * enemy = gs->curB->getHero(gs->curB->theOtherPlayer(st->owner)); - //const CGHeroInstance * owner = gs->curB->getHero(st->owner); - if (enemy) + const PlayerColor opponent = gs->curB->theOtherPlayer(st->owner); + const CGHeroInstance * opponentHero = gs->curB->getHero(opponent); + if (opponentHero) { ui32 manaDrained = st->valOfBonuses(Bonus::MANA_DRAIN); - vstd::amin(manaDrained, gs->curB->battleGetFightingHero(0)->mana); + vstd::amin(manaDrained, opponentHero->mana); if (manaDrained) { bte.effect = Bonus::MANA_DRAIN; bte.val = manaDrained; - bte.additionalInfo = enemy->id.getNum(); //for sanity + bte.additionalInfo = opponentHero->id.getNum(); //for sanity sendAndApply(&bte); } }