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
|
2015-09-26 20:35:30 +02:00
|
|
|
void AcidBreathDamageMechanics::applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2015-09-17 04:47:32 +02:00
|
|
|
//todo: this should be effectValue
|
2015-02-02 11:22:19 +02:00
|
|
|
//calculating dmg to display
|
2016-09-06 04:11:32 +02:00
|
|
|
ctx.setDamageToDisplay(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;
|
2015-09-17 04:47:32 +02:00
|
|
|
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
|
2015-09-26 20:35:30 +02:00
|
|
|
void DeathStareMechanics::applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
|
|
|
//calculating dmg to display
|
2016-09-06 04:11:32 +02:00
|
|
|
si32 dmgToDisplay = parameters.effectPower;
|
|
|
|
|
2015-02-02 11:22:19 +02:00
|
|
|
if(!ctx.attackedCres.empty())
|
2016-09-06 04:11:32 +02:00
|
|
|
vstd::amin(dmgToDisplay, (*ctx.attackedCres.begin())->count); //stack is already reduced after attack
|
|
|
|
|
|
|
|
ctx.setDamageToDisplay(dmgToDisplay);
|
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;
|
2016-02-15 12:34:37 +02:00
|
|
|
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);
|
2016-02-15 12:34:37 +02:00
|
|
|
|
|
|
|
doDispell(battle, packet, Selector::positiveSpellEffects);
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
2015-09-26 19:09:54 +02:00
|
|
|
ESpellCastProblem::ESpellCastProblem DispellHelpfulMechanics::isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const
|
2015-02-02 11:22:19 +02: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 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
|
|
|
}
|