瀏覽代碼

Bypass initial version of spell callback

nordsoft 2 年之前
父節點
當前提交
e440343921

+ 1 - 0
client/Client.h

@@ -231,6 +231,7 @@ public:
 	void changeObjPos(ObjectInstanceID objid, int3 newPos) override {};
 	void sendAndApply(CPackForClient * pack) override {};
 	void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override {};
+	void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos) override {};
 
 	void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) override {}
 	void changeFogOfWar(std::unordered_set<int3, ShashInt3> & tiles, PlayerColor player, bool hide) override {}

+ 2 - 0
lib/IGameCallback.h

@@ -132,6 +132,8 @@ public:
 	virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
 	virtual void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) = 0;
 	virtual void changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide) = 0;
+	
+	virtual void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos) = 0;
 };
 
 class DLL_LINKAGE CNonConstInfoCallback : public CPrivilegedInfoCallback

+ 1 - 0
lib/mapObjects/CRewardableConstructor.cpp

@@ -132,6 +132,7 @@ void CRandomRewardObjectInfo::configureReward(CRewardableObject * object, CRando
 	reward.artifacts = JsonRandom::loadArtifacts(source["artifacts"], rng);
 	reward.spells = JsonRandom::loadSpells(source["spells"], rng, spells);
 	reward.creatures = JsonRandom::loadCreatures(source["creatures"], rng);
+	reward.casts = JsonRandom::loadSpells(source["casts"], rng, spells);
 
 	for ( auto node : source["changeCreatures"].Struct() )
 	{

+ 10 - 0
lib/mapObjects/CRewardableObject.cpp

@@ -17,6 +17,8 @@
 #include "../IGameCallback.h"
 #include "../CGameState.h"
 #include "../CPlayerState.h"
+#include "../spells/CSpellHandler.h"
+#include "../spells/ISpellMechanics.h"
 
 #include "CObjectClassesHandler.h"
 
@@ -359,6 +361,14 @@ void CRewardableObject::grantRewardAfterLevelup(const CRewardVisitInfo & info, c
 
 		cb->giveCreatures(this, hero, creatures, false);
 	}
+	
+	if(!info.reward.casts.empty())
+	{
+		for(const auto & c : info.reward.casts)
+		{
+			cb->castSpell(hero, c, int3{-1, -1, -1});
+		}
+	}
 
 	if(info.reward.removeObject)
 		cb->removeObject(this);

+ 4 - 0
lib/mapObjects/CRewardableObject.h

@@ -169,6 +169,9 @@ public:
 	std::vector<ArtifactID> artifacts;
 	std::vector<SpellID> spells;
 	std::vector<CStackBasicDescriptor> creatures;
+	
+	/// actions that hero may execute
+	std::vector<SpellID> casts;
 
 	/// list of components that will be added to reward description. First entry in list will override displayed component
 	std::vector<Component> extraComponents;
@@ -213,6 +216,7 @@ public:
 		h & spells;
 		h & creatures;
 		h & creaturesChange;
+		h & casts;
 	}
 };
 

+ 14 - 1
server/CGameHandler.cpp

@@ -6282,6 +6282,19 @@ bool CGameHandler::moveStack(const StackLocation &src, const StackLocation &dst,
 	return true;
 }
 
+void CGameHandler::castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos)
+{
+	const CSpell * s = spellID.toSpell();
+	if(!s)
+		return;
+
+	AdventureSpellCastParameters p;
+	p.caster = hero;
+	p.pos = pos;
+
+	s->adventureCast(spellEnv, p);
+}
+
 bool CGameHandler::swapStacks(const StackLocation & sl1, const StackLocation & sl2)
 {
 	if(!sl1.army->hasStackAtSlot(sl1.slot))
@@ -7343,4 +7356,4 @@ const ObjectInstanceID CGameHandler::putNewObject(Obj ID, int subID, int3 pos)
 	no.pos = pos;
 	sendAndApply(&no);
 	return no.id; //id field will be filled during applying on gs
-}
+}

+ 1 - 0
server/CGameHandler.h

@@ -275,6 +275,7 @@ public:
 	void moveArmy(const CArmedInstance *src, const CArmedInstance *dst, bool allowMerging);
 	const ObjectInstanceID putNewObject(Obj ID, int subID, int3 pos);
 
+	void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos);
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{