1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-09 13:14:02 +02:00
vcmi/lib/spells/CreatureSpellMechanics.cpp

95 lines
2.9 KiB
C++
Raw Normal View History

2015-02-02 11:40:06 +03: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 12:22:19 +03:00
#include "../NetPacks.h"
#include "../BattleState.h"
///AcidBreathDamageMechanics
2015-09-26 21:35:30 +03:00
void AcidBreathDamageMechanics::applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
2015-02-02 12:22:19 +03:00
{
//todo: this should be effectValue
2015-02-02 12:22:19 +03:00
//calculating dmg to display
2016-09-06 05:11:32 +03:00
ctx.setDamageToDisplay(parameters.effectPower);
2015-02-26 20:59:18 +03:00
2015-02-02 12:22:19 +03: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 12:22:19 +03:00
bsa.stackAttacked = (attackedCre)->ID;
bsa.attackerID = -1;
(attackedCre)->prepareAttacked(bsa, env->getRandomGenerator());
ctx.si.stacks.push_back(bsa);
2015-02-26 20:59:18 +03:00
}
2015-02-02 12:22:19 +03:00
}
2016-09-06 07:16:32 +03:00
void AcidBreathDamageMechanics::handleImmunities(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx, std::vector<const CStack*> & stacks) const
{
//no immunities
}
2015-02-02 12:22:19 +03:00
///DeathStareMechanics
2015-09-26 21:35:30 +03:00
void DeathStareMechanics::applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
2015-02-02 12:22:19 +03:00
{
//calculating dmg to display
2016-09-06 05:11:32 +03:00
si32 dmgToDisplay = parameters.effectPower;
2015-02-02 12:22:19 +03:00
if(!ctx.attackedCres.empty())
2016-09-06 05:11:32 +03:00
vstd::amin(dmgToDisplay, (*ctx.attackedCres.begin())->count); //stack is already reduced after attack
ctx.setDamageToDisplay(dmgToDisplay);
2015-02-26 20:59:18 +03:00
2015-02-02 12:22:19 +03:00
for(auto & attackedCre : ctx.attackedCres)
{
BattleStackAttacked bsa;
bsa.flags |= BattleStackAttacked::SPELL_EFFECT;
bsa.spellID = owner->id;
2016-02-15 13:34:37 +03:00
bsa.damageAmount = parameters.effectPower * (attackedCre)->valOfBonuses(Bonus::STACK_HEALTH);//todo: move here all DeathStare calculation
2015-02-02 12:22:19 +03:00
bsa.stackAttacked = (attackedCre)->ID;
bsa.attackerID = -1;
(attackedCre)->prepareAttacked(bsa, env->getRandomGenerator());
ctx.si.stacks.push_back(bsa);
2015-02-26 20:59:18 +03:00
}
2015-02-02 12:22:19 +03:00
}
///DispellHelpfulMechanics
void DispellHelpfulMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const
{
DefaultSpellMechanics::applyBattle(battle, packet);
2016-02-15 13:34:37 +03:00
doDispell(battle, packet, Selector::positiveSpellEffects);
2015-02-02 12:22:19 +03:00
}
2015-09-26 20:09:54 +03:00
ESpellCastProblem::ESpellCastProblem DispellHelpfulMechanics::isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const
2015-02-02 12:22:19 +03:00
{
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 20:59:18 +03:00
//use default algorithm only if there is no mechanics-related problem
return DefaultSpellMechanics::isImmuneByStack(caster,obj);
2015-02-02 12:22:19 +03:00
}