瀏覽代碼

Implement behavior

nordsoft 2 年之前
父節點
當前提交
464ad63749
共有 3 個文件被更改,包括 9 次插入4 次删除
  1. 2 1
      lib/mapObjects/CRewardableObject.cpp
  2. 5 1
      lib/mapObjects/CRewardableObject.h
  3. 2 2
      server/CGameHandler.h

+ 2 - 1
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});
 		}
 	}
 

+ 5 - 1
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;

+ 2 - 2
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;