mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-11 11:31:52 +02:00
Rewrite CGHeroInstance::getSpellSchoolLevel using SPELL_SCHOOL_CONFIG
This commit is contained in:
parent
5d1077161c
commit
3fcb1254f7
@ -85,7 +85,7 @@ ui32 CSpell::calculateBonus(ui32 baseDamage, const CGHeroInstance* caster, const
|
||||
ret *= (100.0 + caster->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::SORCERY)) / 100.0;
|
||||
ret *= (100.0 + caster->valOfBonuses(Bonus::SPELL_DAMAGE) + caster->valOfBonuses(Bonus::SPECIFIC_SPELL_DAMAGE, id.toEnum())) / 100.0;
|
||||
|
||||
for(const SpellSchoolInfo & cnf : spellSchoolConfig)
|
||||
for(const SpellSchoolInfo & cnf : SPELL_SCHOOL_CONFIG)
|
||||
{
|
||||
if(school.at(cnf.id))
|
||||
{
|
||||
@ -116,7 +116,7 @@ ui32 CSpell::calculateDamage(const CGHeroInstance * caster, const CStack * affec
|
||||
{
|
||||
//applying protections - when spell has more then one elements, only one protection should be applied (I think)
|
||||
|
||||
for(const SpellSchoolInfo & cnf : spellSchoolConfig)
|
||||
for(const SpellSchoolInfo & cnf : SPELL_SCHOOL_CONFIG)
|
||||
{
|
||||
if(school.at(cnf.id) && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, (ui8)cnf.id))
|
||||
{
|
||||
@ -367,7 +367,7 @@ ESpellCastProblem::ESpellCastProblem CSpell::isImmuneBy(const IBonusBearer* obj)
|
||||
|
||||
//6. Check elemental immunities
|
||||
|
||||
for(const SpellSchoolInfo & cnf : spellSchoolConfig)
|
||||
for(const SpellSchoolInfo & cnf : SPELL_SCHOOL_CONFIG)
|
||||
{
|
||||
if(school.at(cnf.id))
|
||||
{
|
||||
@ -658,7 +658,7 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
|
||||
|
||||
const auto schoolNames = json["school"];
|
||||
|
||||
for(SpellSchoolInfo & info : spellSchoolConfig)
|
||||
for(const SpellSchoolInfo & info : SPELL_SCHOOL_CONFIG)
|
||||
{
|
||||
spell->school[info.id] = schoolNames[info.jsonName].Bool();
|
||||
}
|
||||
|
@ -35,34 +35,39 @@ struct SpellSchoolInfo
|
||||
ESpellSchool id; //backlink
|
||||
Bonus::BonusType damagePremyBonus;
|
||||
Bonus::BonusType immunityBonus;
|
||||
std::string jsonName;
|
||||
std::string jsonName;
|
||||
SecondarySkill::ESecondarySkill skill;
|
||||
};
|
||||
|
||||
static SpellSchoolInfo spellSchoolConfig[4] =
|
||||
static const SpellSchoolInfo SPELL_SCHOOL_CONFIG[4] =
|
||||
{
|
||||
{
|
||||
ESpellSchool::AIR,
|
||||
Bonus::AIR_SPELL_DMG_PREMY,
|
||||
Bonus::AIR_IMMUNITY,
|
||||
"air"
|
||||
"air",
|
||||
SecondarySkill::AIR_MAGIC
|
||||
},
|
||||
{
|
||||
ESpellSchool::FIRE,
|
||||
Bonus::FIRE_SPELL_DMG_PREMY,
|
||||
Bonus::FIRE_IMMUNITY,
|
||||
"fire"
|
||||
"fire",
|
||||
SecondarySkill::FIRE_MAGIC
|
||||
},
|
||||
{
|
||||
ESpellSchool::WATER,
|
||||
Bonus::WATER_SPELL_DMG_PREMY,
|
||||
Bonus::WATER_IMMUNITY,
|
||||
"water"
|
||||
"water",
|
||||
SecondarySkill::WATER_MAGIC
|
||||
},
|
||||
{
|
||||
ESpellSchool::EARTH,
|
||||
Bonus::EARTH_SPELL_DMG_PREMY,
|
||||
Bonus::EARTH_IMMUNITY,
|
||||
"earth"
|
||||
"earth",
|
||||
SecondarySkill::EARTH_MAGIC
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -863,27 +863,20 @@ TExpType CGHeroInstance::calculateXp(TExpType exp) const
|
||||
ui8 CGHeroInstance::getSpellSchoolLevel(const CSpell * spell, int *outSelectedSchool) const
|
||||
{
|
||||
si16 skill = -1; //skill level
|
||||
|
||||
#define TRY_SCHOOL(schoolName, schoolMechanicsId, schoolOutId) \
|
||||
if(spell-> schoolName) \
|
||||
{ \
|
||||
int thisSchool = std::max<int>(getSecSkillLevel( \
|
||||
SecondarySkill(14 + (schoolMechanicsId))), \
|
||||
valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 1 << (schoolMechanicsId))); \
|
||||
if(thisSchool > skill) \
|
||||
{ \
|
||||
skill = thisSchool; \
|
||||
if(outSelectedSchool) \
|
||||
*outSelectedSchool = schoolOutId; \
|
||||
} \
|
||||
|
||||
for(const SpellSchoolInfo & cnf : SPELL_SCHOOL_CONFIG)
|
||||
{
|
||||
if(spell->school.at(cnf.id))
|
||||
{
|
||||
int thisSchool = std::max<int>(getSecSkillLevel(cnf.skill), valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 1 << ((ui8)cnf.id)));
|
||||
if(thisSchool > skill)
|
||||
{
|
||||
skill = thisSchool;
|
||||
if(outSelectedSchool)
|
||||
*outSelectedSchool = (ui8)cnf.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
TRY_SCHOOL(fire, 0, 1)
|
||||
TRY_SCHOOL(air, 1, 0)
|
||||
TRY_SCHOOL(water, 2, 2)
|
||||
TRY_SCHOOL(earth, 3, 3)
|
||||
#undef TRY_SCHOOL
|
||||
|
||||
|
||||
|
||||
vstd::amax(skill, valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 0)); //any school bonus
|
||||
vstd::amax(skill, valOfBonuses(Bonus::SPELL, spell->id.toEnum())); //given by artifact or other effect
|
||||
|
Loading…
x
Reference in New Issue
Block a user