소스 검색

Move ANOTHER_ELEMENTAL_SUMMONED problem check to SummonMechanics class

AlexVinS 10 년 전
부모
커밋
0cce1ef2f1
3개의 변경된 파일24개의 추가작업 그리고 17개의 파일을 삭제
  1. 0 17
      lib/CBattleCallback.cpp
  2. 22 0
      lib/spells/BattleSpellMechanics.cpp
  3. 2 0
      lib/spells/BattleSpellMechanics.h

+ 0 - 17
lib/CBattleCallback.cpp

@@ -1623,26 +1623,9 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell
 			return ESpellCastProblem::NO_APPROPRIATE_TARGET;
 	}
 
-
 	if(battleMaxSpellLevel() < spell->level) //effect like Recanter's Cloak or Orb of Inhibition
 		return ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED;
 
-	//IDs of summon elemental spells (fire, earth, water, air)
-	int spellIDs[] = {	SpellID::SUMMON_FIRE_ELEMENTAL, SpellID::SUMMON_EARTH_ELEMENTAL,
-						SpellID::SUMMON_WATER_ELEMENTAL, SpellID::SUMMON_AIR_ELEMENTAL };
-	//(fire, earth, water, air) elementals
-	int creIDs[] = {CreatureID::FIRE_ELEMENTAL,  CreatureID::EARTH_ELEMENTAL,
-					CreatureID::WATER_ELEMENTAL, CreatureID::AIR_ELEMENTAL};
-
-	int arpos = vstd::find_pos(spellIDs, spell->id);
-	if(arpos < ARRAY_COUNT(spellIDs))
-	{
-		//check if there are summoned elementals of other type
-		for(const CStack * st : battleAliveStacks(side))
-			if(vstd::contains(st->state, EBattleStackState::SUMMONED) && st->getCreature()->idNumber != creIDs[arpos])
-				return ESpellCastProblem::ANOTHER_ELEMENTAL_SUMMONED;
-	}
-
 	//checking if there exists an appropriate target
 	switch(spell->getTargetType())
 	{

+ 22 - 0
lib/spells/BattleSpellMechanics.cpp

@@ -469,6 +469,28 @@ ESpellCastProblem::ESpellCastProblem SpecialRisingSpellMechanics::isImmuneByStac
 }
 
 ///SummonMechanics
+ESpellCastProblem::ESpellCastProblem SummonMechanics::canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const
+{
+	const ui8 side = cb->playerToSide(player);
+	//IDs of summon elemental spells (fire, earth, water, air)
+	int spellIDs[] = {	SpellID::SUMMON_FIRE_ELEMENTAL, SpellID::SUMMON_EARTH_ELEMENTAL,
+						SpellID::SUMMON_WATER_ELEMENTAL, SpellID::SUMMON_AIR_ELEMENTAL };
+	//(fire, earth, water, air) elementals
+	int creIDs[] = {CreatureID::FIRE_ELEMENTAL,  CreatureID::EARTH_ELEMENTAL,
+					CreatureID::WATER_ELEMENTAL, CreatureID::AIR_ELEMENTAL};
+
+	int arpos = vstd::find_pos(spellIDs, owner->id);
+	if(arpos < ARRAY_COUNT(spellIDs))
+	{
+		//check if there are summoned elementals of other type
+		for(const CStack * st : cb->battleAliveStacks(side))
+			if(vstd::contains(st->state, EBattleStackState::SUMMONED) && st->getCreature()->idNumber != creIDs[arpos])
+				return ESpellCastProblem::ANOTHER_ELEMENTAL_SUMMONED;
+	}
+
+	return ESpellCastProblem::OK;
+}
+
 void SummonMechanics::applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
 {
 	//todo: make configurable

+ 2 - 0
lib/spells/BattleSpellMechanics.h

@@ -112,6 +112,8 @@ class DLL_LINKAGE SummonMechanics : public DefaultSpellMechanics
 {
 public:
 	SummonMechanics(CSpell * s): DefaultSpellMechanics(s){};
+	
+	ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const override;	
 protected:
 	void applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override;
 };