mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-05 00:49:09 +02:00
rewrite CGHeroInstance::canCastThisSpell
This commit is contained in:
@ -65,6 +65,39 @@ CSpell::~CSpell()
|
|||||||
delete mechanics;
|
delete mechanics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSpell::isCastableBy(const IBonusBearer * caster, bool hasSpellBook, const std::set<SpellID> & spellBook) const
|
||||||
|
{
|
||||||
|
if(!hasSpellBook)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const bool inSpellBook = vstd::contains(spellBook, id);
|
||||||
|
const bool isBonus = caster->hasBonusOfType(Bonus::SPELL, id);
|
||||||
|
|
||||||
|
bool inTome = false;
|
||||||
|
|
||||||
|
for(const SpellSchoolInfo & cnf : SPELL_SCHOOL_CONFIG)
|
||||||
|
{
|
||||||
|
if(school.at(cnf.id) && caster->hasBonusOfType(cnf.knoledgeBonus))
|
||||||
|
{
|
||||||
|
inTome = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSpecialSpell())
|
||||||
|
{
|
||||||
|
if (inSpellBook)
|
||||||
|
{//hero has this spell in spellbook
|
||||||
|
logGlobal->errorStream() << "Special spell in spellbook "<<name;
|
||||||
|
}
|
||||||
|
return isBonus;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return inSpellBook || inTome || isBonus || caster->hasBonusOfType(Bonus::SPELLS_OF_LEVEL, level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const CSpell::LevelInfo & CSpell::getLevelInfo(const int level) const
|
const CSpell::LevelInfo & CSpell::getLevelInfo(const int level) const
|
||||||
{
|
{
|
||||||
if(level < 0 || level >= GameConstants::SPELL_SCHOOL_LEVELS)
|
if(level < 0 || level >= GameConstants::SPELL_SCHOOL_LEVELS)
|
||||||
|
@ -37,6 +37,7 @@ struct SpellSchoolInfo
|
|||||||
Bonus::BonusType immunityBonus;
|
Bonus::BonusType immunityBonus;
|
||||||
std::string jsonName;
|
std::string jsonName;
|
||||||
SecondarySkill::ESecondarySkill skill;
|
SecondarySkill::ESecondarySkill skill;
|
||||||
|
Bonus::BonusType knoledgeBonus;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const SpellSchoolInfo SPELL_SCHOOL_CONFIG[4] =
|
static const SpellSchoolInfo SPELL_SCHOOL_CONFIG[4] =
|
||||||
@ -46,28 +47,32 @@ static const SpellSchoolInfo SPELL_SCHOOL_CONFIG[4] =
|
|||||||
Bonus::AIR_SPELL_DMG_PREMY,
|
Bonus::AIR_SPELL_DMG_PREMY,
|
||||||
Bonus::AIR_IMMUNITY,
|
Bonus::AIR_IMMUNITY,
|
||||||
"air",
|
"air",
|
||||||
SecondarySkill::AIR_MAGIC
|
SecondarySkill::AIR_MAGIC,
|
||||||
|
Bonus::AIR_SPELLS
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ESpellSchool::FIRE,
|
ESpellSchool::FIRE,
|
||||||
Bonus::FIRE_SPELL_DMG_PREMY,
|
Bonus::FIRE_SPELL_DMG_PREMY,
|
||||||
Bonus::FIRE_IMMUNITY,
|
Bonus::FIRE_IMMUNITY,
|
||||||
"fire",
|
"fire",
|
||||||
SecondarySkill::FIRE_MAGIC
|
SecondarySkill::FIRE_MAGIC,
|
||||||
|
Bonus::FIRE_SPELLS
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ESpellSchool::WATER,
|
ESpellSchool::WATER,
|
||||||
Bonus::WATER_SPELL_DMG_PREMY,
|
Bonus::WATER_SPELL_DMG_PREMY,
|
||||||
Bonus::WATER_IMMUNITY,
|
Bonus::WATER_IMMUNITY,
|
||||||
"water",
|
"water",
|
||||||
SecondarySkill::WATER_MAGIC
|
SecondarySkill::WATER_MAGIC,
|
||||||
|
Bonus::WATER_SPELLS
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ESpellSchool::EARTH,
|
ESpellSchool::EARTH,
|
||||||
Bonus::EARTH_SPELL_DMG_PREMY,
|
Bonus::EARTH_SPELL_DMG_PREMY,
|
||||||
Bonus::EARTH_IMMUNITY,
|
Bonus::EARTH_IMMUNITY,
|
||||||
"earth",
|
"earth",
|
||||||
SecondarySkill::EARTH_MAGIC
|
SecondarySkill::EARTH_MAGIC,
|
||||||
|
Bonus::EARTH_SPELLS
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -179,6 +184,8 @@ public:
|
|||||||
CSpell();
|
CSpell();
|
||||||
~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)
|
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)
|
||||||
si16 mainEffectAnim; //main spell effect animation, in AC format (or -1 when none)
|
si16 mainEffectAnim; //main spell effect animation, in AC format (or -1 when none)
|
||||||
ETargetType getTargetType() const; //deprecated
|
ETargetType getTargetType() const; //deprecated
|
||||||
|
@ -888,35 +888,7 @@ ui8 CGHeroInstance::getSpellSchoolLevel(const CSpell * spell, int *outSelectedSc
|
|||||||
|
|
||||||
bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const
|
bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const
|
||||||
{
|
{
|
||||||
if(!getArt(ArtifactPosition::SPELLBOOK)) //if hero has no spellbook
|
return spell->isCastableBy(this, nullptr !=getArt(ArtifactPosition::SPELLBOOK), spells);
|
||||||
return false;
|
|
||||||
|
|
||||||
if (spell->isSpecialSpell())
|
|
||||||
{
|
|
||||||
if (vstd::contains(spells, spell->id))
|
|
||||||
{//hero has this spell in spellbook
|
|
||||||
logGlobal->errorStream() << "Special spell in spellbook "<<spell->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasBonusOfType(Bonus::SPELL, spell->id))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(vstd::contains(spells, spell->id) //hero has this spell in spellbook
|
|
||||||
|| (spell->air && hasBonusOfType(Bonus::AIR_SPELLS)) // this is air spell and hero can cast all air spells
|
|
||||||
|| (spell->fire && hasBonusOfType(Bonus::FIRE_SPELLS)) // this is fire spell and hero can cast all fire spells
|
|
||||||
|| (spell->water && hasBonusOfType(Bonus::WATER_SPELLS)) // this is water spell and hero can cast all water spells
|
|
||||||
|| (spell->earth && hasBonusOfType(Bonus::EARTH_SPELLS)) // this is earth spell and hero can cast all earth spells
|
|
||||||
|| hasBonusOfType(Bonus::SPELL, spell->id)
|
|
||||||
|| hasBonusOfType(Bonus::SPELLS_OF_LEVEL, spell->level)
|
|
||||||
)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user