mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Move isCastableBy logic back to CGHeroInstance - it is Hero-specific
* When and if canCastThisSpell will also be implmented for creatures common part may be moved to CSpell class.
This commit is contained in:
parent
dc8b05fbd8
commit
9e0fd70208
@ -905,7 +905,46 @@ ui32 CGHeroInstance::getSpellBonus(const CSpell * spell, ui32 base, const CStack
|
||||
|
||||
bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const
|
||||
{
|
||||
return spell->isCastableBy(this, nullptr !=getArt(ArtifactPosition::SPELLBOOK), spells);
|
||||
if(nullptr == getArt(ArtifactPosition::SPELLBOOK))
|
||||
return false;
|
||||
|
||||
const bool isAllowed = IObjectInterface::cb->isAllowed(0, spell->id);
|
||||
|
||||
const bool inSpellBook = vstd::contains(spells, spell->id);
|
||||
const bool specificBonus = hasBonusOfType(Bonus::SPELL, spell->id);
|
||||
|
||||
bool schoolBonus = false;
|
||||
|
||||
spell->forEachSchool([this, &schoolBonus](const SpellSchoolInfo & cnf, bool & stop)
|
||||
{
|
||||
if(hasBonusOfType(cnf.knoledgeBonus))
|
||||
{
|
||||
schoolBonus = stop = true;
|
||||
}
|
||||
});
|
||||
|
||||
const bool levelBonus = hasBonusOfType(Bonus::SPELLS_OF_LEVEL, spell->level);
|
||||
|
||||
if (spell->isSpecialSpell())
|
||||
{
|
||||
if (inSpellBook)
|
||||
{//hero has this spell in spellbook
|
||||
logGlobal->errorStream() << "Special spell " << spell->name << "in spellbook.";
|
||||
}
|
||||
return specificBonus;
|
||||
}
|
||||
else if(!isAllowed)
|
||||
{
|
||||
if (inSpellBook)
|
||||
{//hero has this spell in spellbook
|
||||
logGlobal->errorStream() << "Banned spell " << spell->name << " in spellbook.";
|
||||
}
|
||||
return specificBonus;
|
||||
}
|
||||
else
|
||||
{
|
||||
return inSpellBook || schoolBonus || specificBonus || levelBonus;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,50 +127,6 @@ void CSpell::battleCast(const SpellCastEnvironment * env, BattleSpellCastParamet
|
||||
mechanics->battleCast(env, parameters);
|
||||
}
|
||||
|
||||
bool CSpell::isCastableBy(const IBonusBearer * caster, bool hasSpellBook, const std::set<SpellID> & spellBook) const
|
||||
{
|
||||
if(!hasSpellBook)
|
||||
return false;
|
||||
|
||||
const bool isAllowed = IObjectInterface::cb->isAllowed(0, id);
|
||||
|
||||
const bool inSpellBook = vstd::contains(spellBook, id);
|
||||
const bool specificBonus = caster->hasBonusOfType(Bonus::SPELL, id);
|
||||
|
||||
bool schoolBonus = false;
|
||||
|
||||
forEachSchool([&](const SpellSchoolInfo & cnf, bool & stop)
|
||||
{
|
||||
if(caster->hasBonusOfType(cnf.knoledgeBonus))
|
||||
{
|
||||
schoolBonus = stop = true;
|
||||
}
|
||||
});
|
||||
|
||||
const bool levelBonus = caster->hasBonusOfType(Bonus::SPELLS_OF_LEVEL, level);
|
||||
|
||||
if (isSpecialSpell())
|
||||
{
|
||||
if (inSpellBook)
|
||||
{//hero has this spell in spellbook
|
||||
logGlobal->errorStream() << "Special spell " << name << "in spellbook.";
|
||||
}
|
||||
return specificBonus;
|
||||
}
|
||||
else if(!isAllowed)
|
||||
{
|
||||
if (inSpellBook)
|
||||
{//hero has this spell in spellbook
|
||||
logGlobal->errorStream() << "Banned spell " << name << " in spellbook.";
|
||||
}
|
||||
return specificBonus;
|
||||
}
|
||||
else
|
||||
{
|
||||
return inSpellBook || schoolBonus || specificBonus || levelBonus;
|
||||
}
|
||||
}
|
||||
|
||||
const CSpell::LevelInfo & CSpell::getLevelInfo(const int level) const
|
||||
{
|
||||
if(level < 0 || level >= GameConstants::SPELL_SCHOOL_LEVELS)
|
||||
|
@ -228,8 +228,6 @@ public:
|
||||
CSpell();
|
||||
~CSpell();
|
||||
|
||||
bool isCastableBy(const IBonusBearer * caster, bool hasSpellBook, const std::set<SpellID> & spellBook) const;
|
||||
|
||||
std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr ) const; //convert range to specific hexes; last optional out parameter is set to true, if spell would cover unavailable hexes (that are not included in ret)
|
||||
ETargetType getTargetType() const; //deprecated
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user