2014-11-12 10:36:34 +02:00
|
|
|
/*
|
2015-02-02 11:22:19 +02:00
|
|
|
* ISpellMechanics.h, part of VCMI engine
|
2014-11-12 10:36:34 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2014-11-12 10:36:34 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CSpellHandler.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "../BattleHex.h"
|
2015-09-17 07:42:30 +02:00
|
|
|
|
2014-11-12 10:36:34 +02:00
|
|
|
|
2015-09-16 09:50:33 +02:00
|
|
|
///callback to be provided by server
|
|
|
|
class DLL_LINKAGE SpellCastEnvironment
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~SpellCastEnvironment(){};
|
|
|
|
virtual void sendAndApply(CPackForClient * info) const = 0;
|
|
|
|
|
|
|
|
virtual CRandomGenerator & getRandomGenerator() const = 0;
|
|
|
|
virtual void complain(const std::string & problem) const = 0;
|
|
|
|
|
|
|
|
virtual const CMap * getMap() const = 0;
|
|
|
|
virtual const CGameInfoCallback * getCb() const = 0;
|
|
|
|
|
|
|
|
virtual bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, PlayerColor asker = PlayerColor::NEUTRAL) const =0; //TODO: remove
|
|
|
|
};
|
|
|
|
|
2015-09-29 20:47:04 +02:00
|
|
|
///all parameters of particular cast event
|
2015-09-16 09:50:33 +02:00
|
|
|
struct DLL_LINKAGE BattleSpellCastParameters
|
|
|
|
{
|
|
|
|
public:
|
2016-02-15 12:34:37 +02:00
|
|
|
///Single spell destination.
|
2015-09-29 20:47:04 +02:00
|
|
|
/// (assumes that anything but battle stack can share same hex)
|
|
|
|
struct DLL_LINKAGE Destination
|
|
|
|
{
|
2016-02-15 12:34:37 +02:00
|
|
|
explicit Destination(const CStack * destination);
|
2015-09-29 20:47:04 +02:00
|
|
|
explicit Destination(const BattleHex & destination);
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2015-09-29 20:47:04 +02:00
|
|
|
const CStack * stackValue;
|
|
|
|
const BattleHex hexValue;
|
|
|
|
};
|
|
|
|
|
2016-09-06 12:51:53 +02:00
|
|
|
//normal constructor
|
2016-09-06 12:33:11 +02:00
|
|
|
BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell_);
|
2016-09-06 12:51:53 +02:00
|
|
|
|
|
|
|
//magic mirror constructor
|
|
|
|
BattleSpellCastParameters(const BattleSpellCastParameters & orig, const ISpellCaster * caster);
|
|
|
|
|
2015-09-29 20:47:04 +02:00
|
|
|
void aimToHex(const BattleHex & destination);
|
|
|
|
void aimToStack(const CStack * destination);
|
2016-09-06 12:33:11 +02:00
|
|
|
|
|
|
|
void cast(const SpellCastEnvironment * env);
|
|
|
|
|
2015-09-29 20:47:04 +02:00
|
|
|
BattleHex getFirstDestinationHex() const;
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2016-09-18 14:27:22 +02:00
|
|
|
int getEffectValue() const;
|
|
|
|
|
2016-09-06 12:33:11 +02:00
|
|
|
const CSpell * spell;
|
2015-09-17 07:42:30 +02:00
|
|
|
const BattleInfo * cb;
|
|
|
|
const ISpellCaster * caster;
|
2016-02-15 12:34:37 +02:00
|
|
|
const PlayerColor casterColor;
|
2015-09-17 08:29:57 +02:00
|
|
|
const ui8 casterSide;
|
|
|
|
|
2015-09-29 20:47:04 +02:00
|
|
|
std::vector<Destination> destinations;
|
|
|
|
|
2015-09-16 09:50:33 +02:00
|
|
|
const CGHeroInstance * casterHero; //deprecated
|
|
|
|
ECastingMode::ECastingMode mode;
|
2015-09-17 07:42:30 +02:00
|
|
|
const CStack * casterStack; //deprecated
|
|
|
|
|
2015-09-17 08:29:57 +02:00
|
|
|
///spell school level
|
2016-02-15 12:34:37 +02:00
|
|
|
int spellLvl;
|
2015-09-17 07:42:30 +02:00
|
|
|
///spell school level to use for effects
|
2015-09-17 04:47:32 +02:00
|
|
|
int effectLevel;
|
2015-09-17 07:42:30 +02:00
|
|
|
///actual spell-power affecting effect values
|
2015-09-17 04:47:32 +02:00
|
|
|
int effectPower;
|
2015-09-17 07:42:30 +02:00
|
|
|
///actual spell-power affecting effect duration
|
2015-09-17 04:47:32 +02:00
|
|
|
int enchantPower;
|
2016-09-18 14:27:22 +02:00
|
|
|
|
|
|
|
private:
|
2015-09-17 07:42:30 +02:00
|
|
|
///for Archangel-like casting
|
|
|
|
int effectValue;
|
2015-09-16 09:50:33 +02:00
|
|
|
};
|
|
|
|
|
2016-09-04 04:15:37 +02:00
|
|
|
struct DLL_LINKAGE SpellTargetingContext
|
2014-11-13 06:34:20 +02:00
|
|
|
{
|
2016-09-04 04:15:37 +02:00
|
|
|
CSpell::TargetInfo ti;
|
|
|
|
ECastingMode::ECastingMode mode;
|
|
|
|
BattleHex destination;
|
|
|
|
const ISpellCaster * caster;
|
|
|
|
int schoolLvl;
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2016-09-04 04:15:37 +02:00
|
|
|
SpellTargetingContext(const CSpell * s, ECastingMode::ECastingMode mode_, const ISpellCaster * caster_, int schoolLvl_, BattleHex destination_)
|
|
|
|
: ti(s,schoolLvl_, mode_), mode(mode_), destination(destination_), caster(caster_), schoolLvl(schoolLvl_)
|
|
|
|
{};
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2016-09-04 04:15:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE ISpellMechanics
|
|
|
|
{
|
2014-11-13 06:34:20 +02:00
|
|
|
public:
|
|
|
|
ISpellMechanics(CSpell * s);
|
2015-02-26 19:59:18 +02:00
|
|
|
virtual ~ISpellMechanics(){};
|
|
|
|
|
|
|
|
virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0;
|
2016-09-06 05:40:23 +02:00
|
|
|
virtual std::vector<const CStack *> getAffectedStacks(const CBattleInfoCallback * cb, SpellTargetingContext & ctx) const = 0;
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2016-09-18 15:30:03 +02:00
|
|
|
virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ECastingMode::ECastingMode mode, const ISpellCaster * caster) const = 0;
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2016-09-04 04:15:37 +02:00
|
|
|
virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const = 0;
|
2016-03-01 08:50:04 +02:00
|
|
|
|
2015-09-26 19:09:54 +02:00
|
|
|
virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const = 0;
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2015-03-09 21:07:28 +02:00
|
|
|
virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const = 0;
|
2016-09-06 05:40:23 +02:00
|
|
|
virtual void battleCast(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters) const = 0;
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2016-09-05 10:36:25 +02:00
|
|
|
//if true use generic algorithm for target existence check, see CSpell::canBeCast
|
|
|
|
virtual bool requiresCreatureTarget() const = 0;
|
|
|
|
|
2016-09-04 07:19:28 +02:00
|
|
|
static std::unique_ptr<ISpellMechanics> createMechanics(CSpell * s);
|
|
|
|
protected:
|
|
|
|
CSpell * owner;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DLL_LINKAGE AdventureSpellCastParameters
|
|
|
|
{
|
|
|
|
const CGHeroInstance * caster;
|
|
|
|
int3 pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE IAdventureSpellMechanics
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IAdventureSpellMechanics(CSpell * s);
|
|
|
|
virtual ~IAdventureSpellMechanics() = default;
|
|
|
|
|
|
|
|
virtual bool adventureCast(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const = 0;
|
|
|
|
|
|
|
|
static std::unique_ptr<IAdventureSpellMechanics> createMechanics(CSpell * s);
|
2014-11-13 06:34:20 +02:00
|
|
|
protected:
|
2015-02-26 19:59:18 +02:00
|
|
|
CSpell * owner;
|
2014-11-13 06:34:20 +02:00
|
|
|
};
|