mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-27 21:49:10 +02:00
get rid of CBattleInfoCallback::calculateSpellDmg
This commit is contained in:
parent
e4b726151d
commit
d7800b834e
@ -469,7 +469,7 @@ void CBattleAI::attemptCastingSpell()
|
|||||||
|
|
||||||
for(auto stack : stacksSuffering)
|
for(auto stack : stacksSuffering)
|
||||||
{
|
{
|
||||||
const int dmg = cb->calculateSpellDmg(ps.spell, hero, stack, skillLevel, spellPower);
|
const int dmg = ps.spell->calculateDamage(hero, stack, skillLevel, spellPower);
|
||||||
if(stack->owner == playerID)
|
if(stack->owner == playerID)
|
||||||
damageReceived += dmg;
|
damageReceived += dmg;
|
||||||
else
|
else
|
||||||
|
@ -1908,59 +1908,6 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell
|
|||||||
return battleIsImmune(nullptr, spell, mode, dest);
|
return battleIsImmune(nullptr, spell, mode, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui32 CBattleInfoCallback::calculateSpellDmg( const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature, int spellSchoolLevel, int usedSpellPower ) const
|
|
||||||
{
|
|
||||||
ui32 ret = 0; //value to return
|
|
||||||
|
|
||||||
//check if spell really does damage - if not, return 0
|
|
||||||
if(!sp->isDamageSpell())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
ret = usedSpellPower * sp->power;
|
|
||||||
ret += sp->getPower(spellSchoolLevel);
|
|
||||||
|
|
||||||
//affected creature-specific part
|
|
||||||
if(affectedCreature)
|
|
||||||
{
|
|
||||||
//applying protections - when spell has more then one elements, only one protection should be applied (I think)
|
|
||||||
if(sp->air && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, 0)) //air spell & protection from air
|
|
||||||
{
|
|
||||||
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, 0);
|
|
||||||
ret /= 100;
|
|
||||||
}
|
|
||||||
else if(sp->fire && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, 1)) //fire spell & protection from fire
|
|
||||||
{
|
|
||||||
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, 1);
|
|
||||||
ret /= 100;
|
|
||||||
}
|
|
||||||
else if(sp->water && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, 2)) //water spell & protection from water
|
|
||||||
{
|
|
||||||
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, 2);
|
|
||||||
ret /= 100;
|
|
||||||
}
|
|
||||||
else if (sp->earth && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, 3)) //earth spell & protection from earth
|
|
||||||
{
|
|
||||||
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, 3);
|
|
||||||
ret /= 100;
|
|
||||||
}
|
|
||||||
//general spell dmg reduction
|
|
||||||
//FIXME?
|
|
||||||
if(sp->air && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, -1))
|
|
||||||
{
|
|
||||||
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, -1);
|
|
||||||
ret /= 100;
|
|
||||||
}
|
|
||||||
//dmg increasing
|
|
||||||
if( affectedCreature->hasBonusOfType(Bonus::MORE_DAMAGE_FROM_SPELL, sp->id) )
|
|
||||||
{
|
|
||||||
ret *= 100 + affectedCreature->valOfBonuses(Bonus::MORE_DAMAGE_FROM_SPELL, sp->id.toEnum());
|
|
||||||
ret /= 100;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret = sp->calculateBonus(ret, caster, affectedCreature);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<const CStack*> CBattleInfoCallback::getAffectedCreatures(const CSpell * spell, int skillLevel, PlayerColor attackerOwner, BattleHex destinationTile)
|
std::set<const CStack*> CBattleInfoCallback::getAffectedCreatures(const CSpell * spell, int skillLevel, PlayerColor attackerOwner, BattleHex destinationTile)
|
||||||
{
|
{
|
||||||
std::set<const CStack*> attackedCres; //std::set to exclude multiple occurrences of two hex creatures
|
std::set<const CStack*> attackedCres; //std::set to exclude multiple occurrences of two hex creatures
|
||||||
|
@ -281,7 +281,6 @@ public:
|
|||||||
ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(PlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest) const; //checks if given player can cast given spell at given tile in given mode
|
ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(PlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest) const; //checks if given player can cast given spell at given tile in given mode
|
||||||
ESpellCastProblem::ESpellCastProblem battleCanCreatureCastThisSpell(const CSpell * spell, BattleHex destination) const; //determines if creature can cast a spell here
|
ESpellCastProblem::ESpellCastProblem battleCanCreatureCastThisSpell(const CSpell * spell, BattleHex destination) const; //determines if creature can cast a spell here
|
||||||
std::vector<BattleHex> battleGetPossibleTargets(PlayerColor player, const CSpell *spell) const;
|
std::vector<BattleHex> battleGetPossibleTargets(PlayerColor player, const CSpell *spell) const;
|
||||||
ui32 calculateSpellDmg(const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature, int spellSchoolLevel, int usedSpellPower) const; //calculates damage inflicted by spell
|
|
||||||
ui32 calculateHealedHP(int healedHealth, const CSpell * spell, const CStack * stack) const; //for Archangel
|
ui32 calculateHealedHP(int healedHealth, const CSpell * spell, const CStack * stack) const; //for Archangel
|
||||||
ui32 calculateHealedHP(const CSpell * spell, int usedSpellPower, int spellSchoolLevel, const CStack * stack) const; //healing spells casted by stacks
|
ui32 calculateHealedHP(const CSpell * spell, int usedSpellPower, int spellSchoolLevel, const CStack * stack) const; //healing spells casted by stacks
|
||||||
std::set<const CStack*> getAffectedCreatures(const CSpell * s, int skillLevel, PlayerColor attackerOwner, BattleHex destinationTile); //calculates stack affected by given spell
|
std::set<const CStack*> getAffectedCreatures(const CSpell * s, int skillLevel, PlayerColor attackerOwner, BattleHex destinationTile); //calculates stack affected by given spell
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "BattleState.h" // for BattleInfo
|
#include "BattleState.h" // for BattleInfo
|
||||||
#include "NetPacks.h" // for InfoWindow
|
#include "NetPacks.h" // for InfoWindow
|
||||||
#include "CModHandler.h"
|
#include "CModHandler.h"
|
||||||
|
#include "CSpellHandler.h"
|
||||||
|
|
||||||
//TODO make clean
|
//TODO make clean
|
||||||
#define ERROR_VERBOSE_OR_NOT_RET_VAL_IF(cond, verbose, txt, retVal) do {if(cond){if(verbose)logGlobal->errorStream() << BOOST_CURRENT_FUNCTION << ": " << txt; return retVal;}} while(0)
|
#define ERROR_VERBOSE_OR_NOT_RET_VAL_IF(cond, verbose, txt, retVal) do {if(cond){if(verbose)logGlobal->errorStream() << BOOST_CURRENT_FUNCTION << ": " << txt; return retVal;}} while(0)
|
||||||
@ -173,16 +174,14 @@ int CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroInstan
|
|||||||
if(!gs->curB) //no battle
|
if(!gs->curB) //no battle
|
||||||
{
|
{
|
||||||
if (hero) //but we see hero's spellbook
|
if (hero) //but we see hero's spellbook
|
||||||
return gs->curB->calculateSpellDmg(
|
return sp->calculateDamage(hero, nullptr, hero->getSpellSchoolLevel(sp), hero->getPrimSkillLevel(PrimarySkill::SPELL_POWER));
|
||||||
sp, hero, nullptr, hero->getSpellSchoolLevel(sp), hero->getPrimSkillLevel(PrimarySkill::SPELL_POWER));
|
|
||||||
else
|
else
|
||||||
return 0; //mage guild
|
return 0; //mage guild
|
||||||
}
|
}
|
||||||
//gs->getHero(gs->currentPlayer)
|
//gs->getHero(gs->currentPlayer)
|
||||||
//const CGHeroInstance * ourHero = gs->curB->heroes[0]->tempOwner == player ? gs->curB->heroes[0] : gs->curB->heroes[1];
|
//const CGHeroInstance * ourHero = gs->curB->heroes[0]->tempOwner == player ? gs->curB->heroes[0] : gs->curB->heroes[1];
|
||||||
const CGHeroInstance * ourHero = hero;
|
const CGHeroInstance * ourHero = hero;
|
||||||
return gs->curB->calculateSpellDmg(
|
return sp->calculateDamage(ourHero, nullptr, ourHero->getSpellSchoolLevel(sp), ourHero->getPrimSkillLevel(PrimarySkill::SPELL_POWER));
|
||||||
sp, ourHero, nullptr, ourHero->getSpellSchoolLevel(sp), ourHero->getPrimSkillLevel(PrimarySkill::SPELL_POWER));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj)
|
void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj)
|
||||||
|
@ -353,6 +353,60 @@ ui32 CSpell::calculateBonus(ui32 baseDamage, const CGHeroInstance* caster, const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui32 CSpell::calculateDamage(const CGHeroInstance * caster, const CStack * affectedCreature, int spellSchoolLevel, int usedSpellPower) const
|
||||||
|
{
|
||||||
|
ui32 ret = 0; //value to return
|
||||||
|
|
||||||
|
//check if spell really does damage - if not, return 0
|
||||||
|
if(!isDamageSpell())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ret = usedSpellPower * power;
|
||||||
|
ret += getPower(spellSchoolLevel);
|
||||||
|
|
||||||
|
//affected creature-specific part
|
||||||
|
if(nullptr != affectedCreature)
|
||||||
|
{
|
||||||
|
//applying protections - when spell has more then one elements, only one protection should be applied (I think)
|
||||||
|
if(air && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, 0)) //air spell & protection from air
|
||||||
|
{
|
||||||
|
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, 0);
|
||||||
|
ret /= 100;
|
||||||
|
}
|
||||||
|
else if(fire && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, 1)) //fire spell & protection from fire
|
||||||
|
{
|
||||||
|
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, 1);
|
||||||
|
ret /= 100;
|
||||||
|
}
|
||||||
|
else if(water && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, 2)) //water spell & protection from water
|
||||||
|
{
|
||||||
|
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, 2);
|
||||||
|
ret /= 100;
|
||||||
|
}
|
||||||
|
else if (earth && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, 3)) //earth spell & protection from earth
|
||||||
|
{
|
||||||
|
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, 3);
|
||||||
|
ret /= 100;
|
||||||
|
}
|
||||||
|
//general spell dmg reduction
|
||||||
|
//FIXME?
|
||||||
|
if(air && affectedCreature->hasBonusOfType(Bonus::SPELL_DAMAGE_REDUCTION, -1))
|
||||||
|
{
|
||||||
|
ret *= affectedCreature->valOfBonuses(Bonus::SPELL_DAMAGE_REDUCTION, -1);
|
||||||
|
ret /= 100;
|
||||||
|
}
|
||||||
|
//dmg increasing
|
||||||
|
if(affectedCreature->hasBonusOfType(Bonus::MORE_DAMAGE_FROM_SPELL, id))
|
||||||
|
{
|
||||||
|
ret *= 100 + affectedCreature->valOfBonuses(Bonus::MORE_DAMAGE_FROM_SPELL, id.toEnum());
|
||||||
|
ret /= 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret = calculateBonus(ret, caster, affectedCreature);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ui32 CSpell::calculateHealedHP(const CGHeroInstance* caster, const CStack* stack, const CStack* sacrificedStack) const
|
ui32 CSpell::calculateHealedHP(const CGHeroInstance* caster, const CStack* stack, const CStack* sacrificedStack) const
|
||||||
{
|
{
|
||||||
//todo: use Mechanics class
|
//todo: use Mechanics class
|
||||||
|
@ -129,11 +129,15 @@ public:
|
|||||||
//checks for creature immunity / anything that prevent casting *at given hex* - doesn't take into acount general problems such as not having spellbook or mana points etc.
|
//checks for creature immunity / anything that prevent casting *at given hex* - doesn't take into acount general problems such as not having spellbook or mana points etc.
|
||||||
ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, ECastingMode::ECastingMode mode, const CStack * obj) const;
|
ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, ECastingMode::ECastingMode mode, const CStack * obj) const;
|
||||||
|
|
||||||
//applying secondary skills
|
//internal, for use only by Mechanics classes. applying secondary skills
|
||||||
ui32 calculateBonus(ui32 baseDamage, const CGHeroInstance * caster, const CStack * affectedCreature) const;
|
ui32 calculateBonus(ui32 baseDamage, const CGHeroInstance * caster, const CStack * affectedCreature) const;
|
||||||
|
|
||||||
|
ui32 calculateDamage(const CGHeroInstance * caster, const CStack * affectedCreature, int spellSchoolLevel, int usedSpellPower) const;
|
||||||
|
|
||||||
///calculate healed HP for all spells casted by hero
|
///calculate healed HP for all spells casted by hero
|
||||||
ui32 calculateHealedHP(const CGHeroInstance * caster, const CStack * stack, const CStack * sacrificedStack = nullptr) const;
|
ui32 calculateHealedHP(const CGHeroInstance * caster, const CStack * stack, const CStack * sacrificedStack = nullptr) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
si32 getCost(const int skillLevel) const;
|
si32 getCost(const int skillLevel) const;
|
||||||
|
|
||||||
|
@ -4105,7 +4105,7 @@ void CGameHandler::handleSpellCasting( SpellID spellID, int spellLvl, BattleHex
|
|||||||
if (spellDamage)
|
if (spellDamage)
|
||||||
bsa.damageAmount = spellDamage >> chainLightningModifier;
|
bsa.damageAmount = spellDamage >> chainLightningModifier;
|
||||||
else
|
else
|
||||||
bsa.damageAmount = gs->curB->calculateSpellDmg(spell, caster, attackedCre, spellLvl, usedSpellPower) >> chainLightningModifier;
|
bsa.damageAmount = spell->calculateDamage(caster, attackedCre, spellLvl, usedSpellPower) >> chainLightningModifier;
|
||||||
|
|
||||||
sc.dmgToDisplay += bsa.damageAmount;
|
sc.dmgToDisplay += bsa.damageAmount;
|
||||||
|
|
||||||
@ -4710,14 +4710,14 @@ void CGameHandler::handleDamageFromObstacle(const CObstacleInstance &obstacle, c
|
|||||||
|
|
||||||
oneTimeObstacle = true;
|
oneTimeObstacle = true;
|
||||||
effect = 82; //makes
|
effect = 82; //makes
|
||||||
damage = gs->curB->calculateSpellDmg(SpellID(SpellID::LAND_MINE).toSpell(), hero, curStack,
|
damage = SpellID(SpellID::LAND_MINE).toSpell()->calculateDamage(hero, curStack,
|
||||||
spellObstacle->spellLevel, spellObstacle->casterSpellPower);
|
spellObstacle->spellLevel, spellObstacle->casterSpellPower);
|
||||||
//TODO even if obstacle wasn't created by hero (Tower "moat") it should deal dmg as if casted by hero,
|
//TODO even if obstacle wasn't created by hero (Tower "moat") it should deal dmg as if casted by hero,
|
||||||
//if it is bigger than default dmg. Or is it just irrelevant H3 implementation quirk
|
//if it is bigger than default dmg. Or is it just irrelevant H3 implementation quirk
|
||||||
}
|
}
|
||||||
else if(obstacle.obstacleType == CObstacleInstance::FIRE_WALL)
|
else if(obstacle.obstacleType == CObstacleInstance::FIRE_WALL)
|
||||||
{
|
{
|
||||||
damage = gs->curB->calculateSpellDmg(SpellID(SpellID::FIRE_WALL).toSpell(), hero, curStack,
|
damage = SpellID(SpellID::FIRE_WALL).toSpell()->calculateDamage(hero, curStack,
|
||||||
spellObstacle->spellLevel, spellObstacle->casterSpellPower);
|
spellObstacle->spellLevel, spellObstacle->casterSpellPower);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user