diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index 3a99aa47b..0c88118c9 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -365,9 +365,10 @@ void CRewardableObject::grantRewardAfterLevelup(const CRewardVisitInfo & info, c if(!info.reward.casts.empty()) { + caster = std::make_unique<spells::OuterCaster>(hero, 3); for(const auto & c : info.reward.casts) { - cb->castSpell(hero, c, int3{-1, -1, -1}); + cb->castSpell(caster.get(), c, int3{-1, -1, -1}); } } diff --git a/lib/mapObjects/CRewardableObject.h b/lib/mapObjects/CRewardableObject.h index f7270d475..1d8e37251 100644 --- a/lib/mapObjects/CRewardableObject.h +++ b/lib/mapObjects/CRewardableObject.h @@ -14,6 +14,7 @@ #include "../NetPacksBase.h" #include "../ResourceSet.h" +#include "../spells/OuterCaster.h" VCMI_LIB_NAMESPACE_BEGIN @@ -170,7 +171,7 @@ public: std::vector<SpellID> spells; std::vector<CStackBasicDescriptor> creatures; - /// actions that hero may execute + /// actions that hero may execute and object caster std::vector<SpellID> casts; /// list of components that will be added to reward description. First entry in list will override displayed component @@ -321,6 +322,9 @@ protected: bool wasVisitedBefore(const CGHeroInstance * contextHero) const; bool onceVisitableObjectCleared; + + /// caster to cast adveture spells + mutable std::unique_ptr<spells::OuterCaster> caster; public: EVisitMode getVisitMode() const; diff --git a/server/CGameHandler.h b/server/CGameHandler.h index bd4d7ca92..0a483a888 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -199,6 +199,8 @@ public: void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) override; void changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide) override; + + void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override; bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero) override; void setObjProperty(ObjectInstanceID objid, int prop, si64 val) override; @@ -275,8 +277,6 @@ public: void moveArmy(const CArmedInstance *src, const CArmedInstance *dst, bool allowMerging); const ObjectInstanceID putNewObject(Obj ID, int subID, int3 pos); - void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos); - template <typename Handler> void serialize(Handler &h, const int version) { h & QID;