2015-03-10 18:32:05 +01:00
|
|
|
/*
|
|
|
|
* CDefaultSpellMechanics.h, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ISpellMechanics.h"
|
2016-09-06 04:11:30 +03:00
|
|
|
#include "../NetPacks.h"
|
2015-03-10 18:32:05 +01:00
|
|
|
|
2016-09-06 04:11:30 +03:00
|
|
|
class DefaultSpellMechanics;
|
2015-03-10 18:32:05 +01:00
|
|
|
|
2016-09-06 08:20:17 +03:00
|
|
|
class DLL_LINKAGE SpellCastContext
|
2015-03-10 18:32:05 +01:00
|
|
|
{
|
2016-09-06 04:11:30 +03:00
|
|
|
public:
|
|
|
|
const DefaultSpellMechanics * mechanics;
|
2016-09-06 13:05:33 +03:00
|
|
|
const SpellCastEnvironment * env;
|
2016-09-06 04:11:30 +03:00
|
|
|
std::vector<const CStack *> attackedCres;//must be vector, as in Chain Lightning order matters
|
2016-09-06 05:11:32 +03:00
|
|
|
BattleSpellCast sc;//todo: make private
|
2016-09-06 04:11:30 +03:00
|
|
|
StacksInjured si;
|
2016-09-06 13:05:33 +03:00
|
|
|
const BattleSpellCastParameters & parameters;
|
2016-09-06 04:11:30 +03:00
|
|
|
|
2016-09-06 13:05:33 +03:00
|
|
|
SpellCastContext(const DefaultSpellMechanics * mechanics_, const SpellCastEnvironment * env_, const BattleSpellCastParameters & parameters_);
|
2016-09-06 06:40:23 +03:00
|
|
|
virtual ~SpellCastContext();
|
2016-09-06 05:11:32 +03:00
|
|
|
|
|
|
|
void addDamageToDisplay(const si32 value);
|
|
|
|
void setDamageToDisplay(const si32 value);
|
|
|
|
|
2016-09-06 13:05:33 +03:00
|
|
|
void beforeCast();
|
|
|
|
void afterCast();
|
2016-09-06 04:11:30 +03:00
|
|
|
private:
|
2016-09-06 13:05:33 +03:00
|
|
|
const CGHeroInstance * otherHero;
|
|
|
|
int spellCost;
|
2016-09-10 18:23:55 +03:00
|
|
|
si32 damageToDisplay;
|
2016-09-06 13:05:33 +03:00
|
|
|
|
2016-09-10 18:23:55 +03:00
|
|
|
void prepareBattleLog();
|
2015-03-10 18:32:05 +01:00
|
|
|
};
|
|
|
|
|
2016-09-06 04:11:30 +03:00
|
|
|
///all combat spells
|
2015-03-10 18:32:05 +01:00
|
|
|
class DLL_LINKAGE DefaultSpellMechanics : public ISpellMechanics
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DefaultSpellMechanics(CSpell * s): ISpellMechanics(s){};
|
|
|
|
|
|
|
|
std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const override;
|
2016-10-02 01:32:28 +03:00
|
|
|
std::vector<const CStack *> getAffectedStacks(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override final;
|
2015-03-10 18:32:05 +01:00
|
|
|
|
2016-09-18 16:30:03 +03:00
|
|
|
ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ECastingMode::ECastingMode mode, const ISpellCaster * caster) const override;
|
2016-09-04 05:15:37 +03:00
|
|
|
ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override;
|
2016-02-15 13:34:37 +03:00
|
|
|
|
2015-09-26 20:09:54 +03:00
|
|
|
ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const override;
|
2015-03-10 18:32:05 +01:00
|
|
|
|
|
|
|
virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const override;
|
2016-09-04 08:19:28 +03:00
|
|
|
|
2016-09-06 06:40:23 +03:00
|
|
|
void battleCast(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters) const override final;
|
2015-03-10 18:32:05 +01:00
|
|
|
|
2016-09-17 23:04:23 +03:00
|
|
|
void battleLog(std::vector<MetaString> & logLines, const BattleSpellCastParameters & parameters,
|
|
|
|
const std::vector<const CStack *> & attacked, const si32 damageToDisplay, bool & displayDamage) const;
|
|
|
|
|
|
|
|
void battleLogDefault(std::vector<MetaString> & logLines, const BattleSpellCastParameters & parameters,
|
|
|
|
const std::vector<const CStack *> & attacked) const;
|
2016-09-05 11:36:25 +03:00
|
|
|
|
|
|
|
bool requiresCreatureTarget() const override;
|
2016-10-02 16:38:30 +03:00
|
|
|
|
2015-03-10 18:32:05 +01:00
|
|
|
protected:
|
2015-09-26 21:35:30 +03:00
|
|
|
virtual void applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const;
|
2015-03-10 18:32:05 +01:00
|
|
|
|
2016-09-06 07:05:55 +03:00
|
|
|
virtual std::vector<const CStack *> calculateAffectedStacks(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const;
|
|
|
|
|
|
|
|
protected:
|
2015-09-16 17:00:58 +03:00
|
|
|
void doDispell(BattleInfo * battle, const BattleSpellCast * packet, const CSelector & selector) const;
|
2016-10-01 10:31:59 +03:00
|
|
|
bool canDispell(const IBonusBearer * obj, const CSelector & selector, const std::string &cachingStr = "") const;
|
2015-09-16 17:00:58 +03:00
|
|
|
private:
|
2016-09-06 13:05:33 +03:00
|
|
|
void cast(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, std::vector <const CStack*> & reflected) const;
|
2016-09-06 11:03:36 +03:00
|
|
|
|
2016-09-06 10:52:54 +03:00
|
|
|
void handleImmunities(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx, std::vector<const CStack *> & stacks) const;
|
2016-09-06 11:03:36 +03:00
|
|
|
void handleMagicMirror(const SpellCastEnvironment * env, SpellCastContext & ctx, std::vector <const CStack*> & reflected) const;
|
2016-09-06 12:26:01 +03:00
|
|
|
void handleResistance(const SpellCastEnvironment * env, SpellCastContext & ctx) const;
|
2016-09-06 04:11:30 +03:00
|
|
|
|
2016-10-01 10:31:59 +03:00
|
|
|
static bool dispellSelector(const Bonus * bonus);
|
|
|
|
|
2016-09-06 04:11:30 +03:00
|
|
|
friend class SpellCastContext;
|
2015-03-10 18:32:05 +01:00
|
|
|
};
|
2016-09-06 08:20:17 +03:00
|
|
|
|
|
|
|
///not affecting creatures directly
|
|
|
|
class DLL_LINKAGE SpecialSpellMechanics : public DefaultSpellMechanics
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SpecialSpellMechanics(CSpell * s): DefaultSpellMechanics(s){};
|
2016-10-02 01:32:28 +03:00
|
|
|
|
|
|
|
ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override;
|
2016-09-06 08:20:17 +03:00
|
|
|
protected:
|
|
|
|
std::vector<const CStack *> calculateAffectedStacks(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override;
|
|
|
|
};
|