1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/lib/spells/CreatureSpellMechanics.cpp

87 lines
2.7 KiB
C++
Raw Normal View History

2015-02-02 10:40:06 +02:00
/*
* CreatureSpellMechanics.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "CreatureSpellMechanics.h"
2015-02-02 11:22:19 +02:00
#include "../NetPacks.h"
#include "../BattleState.h"
///AcidBreathDamageMechanics
void AcidBreathDamageMechanics::applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
{
//todo: this should be effectValue
2015-02-02 11:22:19 +02:00
//calculating dmg to display
ctx.sc.dmgToDisplay = parameters.effectPower;
2015-02-26 19:59:18 +02:00
2015-02-02 11:22:19 +02:00
for(auto & attackedCre : ctx.attackedCres) //no immunities
{
BattleStackAttacked bsa;
bsa.flags |= BattleStackAttacked::SPELL_EFFECT;
bsa.spellID = owner->id;
bsa.damageAmount = parameters.effectPower; //damage times the number of attackers
2015-02-02 11:22:19 +02:00
bsa.stackAttacked = (attackedCre)->ID;
bsa.attackerID = -1;
(attackedCre)->prepareAttacked(bsa, env->getRandomGenerator());
ctx.si.stacks.push_back(bsa);
2015-02-26 19:59:18 +02:00
}
2015-02-02 11:22:19 +02:00
}
///DeathStareMechanics
void DeathStareMechanics::applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
{
//calculating dmg to display
ctx.sc.dmgToDisplay = parameters.effectPower;
2015-02-02 11:22:19 +02:00
if(!ctx.attackedCres.empty())
2015-02-07 10:13:24 +02:00
vstd::amin(ctx.sc.dmgToDisplay, (*ctx.attackedCres.begin())->count); //stack is already reduced after attack
2015-02-26 19:59:18 +02:00
2015-02-02 11:22:19 +02:00
for(auto & attackedCre : ctx.attackedCres)
{
BattleStackAttacked bsa;
bsa.flags |= BattleStackAttacked::SPELL_EFFECT;
bsa.spellID = owner->id;
bsa.damageAmount = parameters.effectPower * (attackedCre)->valOfBonuses(Bonus::STACK_HEALTH);//todo: move here all DeathStare calculation
2015-02-02 11:22:19 +02:00
bsa.stackAttacked = (attackedCre)->ID;
bsa.attackerID = -1;
(attackedCre)->prepareAttacked(bsa, env->getRandomGenerator());
ctx.si.stacks.push_back(bsa);
2015-02-26 19:59:18 +02:00
}
2015-02-02 11:22:19 +02:00
}
///DispellHelpfulMechanics
void DispellHelpfulMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const
{
DefaultSpellMechanics::applyBattle(battle, packet);
2015-04-11 15:27:14 +02:00
doDispell(battle, packet, Selector::positiveSpellEffects);
2015-02-02 11:22:19 +02:00
}
ESpellCastProblem::ESpellCastProblem DispellHelpfulMechanics::isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const
{
TBonusListPtr spellBon = obj->getSpellBonuses();
bool hasPositiveSpell = false;
for(const Bonus * b : *spellBon)
{
if(SpellID(b->sid).toSpell()->isPositive())
{
hasPositiveSpell = true;
break;
}
}
if(!hasPositiveSpell)
{
return ESpellCastProblem::NO_SPELLS_TO_DISPEL;
}
2015-02-26 19:59:18 +02:00
//use default algorithm only if there is no mechanics-related problem
return DefaultSpellMechanics::isImmuneByStack(caster,obj);
2015-02-02 11:22:19 +02:00
}