mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Move ANOTHER_ELEMENTAL_SUMMONED problem check to SummonMechanics class
This commit is contained in:
parent
ef20c57f2c
commit
0cce1ef2f1
@ -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())
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user