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
|
|
|
|
2016-09-06 09:52:54 +02:00
|
|
|
for(auto & attackedCre : ctx.attackedCres)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-09-06 09:52:54 +02:00
|
|
|
ESpellCastProblem::ESpellCastProblem AcidBreathDamageMechanics::isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const
|
2016-09-06 06:16:32 +02:00
|
|
|
{
|
2016-09-06 09:52:54 +02:00
|
|
|
//just in case
|
|
|
|
if(!obj->alive())
|
|
|
|
return ESpellCastProblem::WRONG_SPELL_TARGET;
|
|
|
|
|
|
|
|
//there should be no immunities by design
|
|
|
|
//but make it a bit configurable
|
|
|
|
//ignore all immunities, except specific absolute immunity
|
|
|
|
{
|
|
|
|
//SPELL_IMMUNITY absolute case
|
|
|
|
std::stringstream cachingStr;
|
|
|
|
cachingStr << "type_" << Bonus::SPELL_IMMUNITY << "subtype_" << owner->id.toEnum() << "addInfo_1";
|
|
|
|
if(obj->hasBonus(Selector::typeSubtypeInfo(Bonus::SPELL_IMMUNITY, owner->id.toEnum(), 1), cachingStr.str()))
|
|
|
|
return ESpellCastProblem::STACK_IMMUNE_TO_SPELL;
|
|
|
|
}
|
|
|
|
return ESpellCastProblem::OK;
|
2016-09-06 06:16:32 +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-10 17:23:55 +02:00
|
|
|
si32 damageToDisplay = parameters.effectPower;
|
2016-09-06 04:11:32 +02:00
|
|
|
|
2015-02-02 11:22:19 +02:00
|
|
|
if(!ctx.attackedCres.empty())
|
2016-09-10 17:23:55 +02:00
|
|
|
vstd::amin(damageToDisplay, (*ctx.attackedCres.begin())->count); //stack is already reduced after attack
|
2016-09-06 04:11:32 +02:00
|
|
|
|
2016-09-10 17:23:55 +02:00
|
|
|
ctx.setDamageToDisplay(damageToDisplay);
|
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
|
|
|
|
2016-10-01 09:31:59 +02:00
|
|
|
doDispell(battle, packet, 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
|
|
|
{
|
2016-10-01 09:31:59 +02:00
|
|
|
if(!canDispell(obj, positiveSpellEffects, "DispellHelpfulMechanics::positiveSpellEffects"))
|
2015-02-02 11:22:19 +02:00
|
|
|
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
|
|
|
}
|
2016-10-01 09:31:59 +02:00
|
|
|
|
|
|
|
bool DispellHelpfulMechanics::positiveSpellEffects(const Bonus *b)
|
|
|
|
{
|
|
|
|
if(b->source == Bonus::SPELL_EFFECT)
|
|
|
|
{
|
2016-10-02 14:22:55 +02:00
|
|
|
const CSpell * sp = SpellID(b->sid).toSpell();
|
|
|
|
return sp && sp->isPositive();
|
2016-10-01 09:31:59 +02:00
|
|
|
}
|
|
|
|
return false; //not a spell effect
|
|
|
|
}
|