ISpellMechanics.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * ISpellMechanics.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "CSpellHandler.h"
  12. #include "../BattleHex.h"
  13. ///callback to be provided by server
  14. class DLL_LINKAGE SpellCastEnvironment
  15. {
  16. public:
  17. virtual ~SpellCastEnvironment(){};
  18. virtual void sendAndApply(CPackForClient * info) const = 0;
  19. virtual CRandomGenerator & getRandomGenerator() const = 0;
  20. virtual void complain(const std::string & problem) const = 0;
  21. virtual const CMap * getMap() const = 0;
  22. virtual const CGameInfoCallback * getCb() const = 0;
  23. virtual bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, PlayerColor asker = PlayerColor::NEUTRAL) const =0; //TODO: remove
  24. };
  25. ///all parameters of particular cast event
  26. struct DLL_LINKAGE BattleSpellCastParameters
  27. {
  28. public:
  29. ///Single spell destination.
  30. /// (assumes that anything but battle stack can share same hex)
  31. struct DLL_LINKAGE Destination
  32. {
  33. explicit Destination(const CStack * destination);
  34. explicit Destination(const BattleHex & destination);
  35. const CStack * stackValue;
  36. const BattleHex hexValue;
  37. };
  38. //normal constructor
  39. BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell_);
  40. //magic mirror constructor
  41. BattleSpellCastParameters(const BattleSpellCastParameters & orig, const ISpellCaster * caster);
  42. void aimToHex(const BattleHex & destination);
  43. void aimToStack(const CStack * destination);
  44. void cast(const SpellCastEnvironment * env);
  45. BattleHex getFirstDestinationHex() const;
  46. int getEffectValue() const;
  47. const CSpell * spell;
  48. const BattleInfo * cb;
  49. const ISpellCaster * caster;
  50. const PlayerColor casterColor;
  51. const ui8 casterSide;
  52. std::vector<Destination> destinations;
  53. const CGHeroInstance * casterHero; //deprecated
  54. ECastingMode::ECastingMode mode;
  55. const CStack * casterStack; //deprecated
  56. ///spell school level
  57. int spellLvl;
  58. ///spell school level to use for effects
  59. int effectLevel;
  60. ///actual spell-power affecting effect values
  61. int effectPower;
  62. ///actual spell-power affecting effect duration
  63. int enchantPower;
  64. private:
  65. ///for Archangel-like casting
  66. int effectValue;
  67. };
  68. struct DLL_LINKAGE SpellTargetingContext
  69. {
  70. CSpell::TargetInfo ti;
  71. ECastingMode::ECastingMode mode;
  72. BattleHex destination;
  73. const ISpellCaster * caster;
  74. int schoolLvl;
  75. SpellTargetingContext(const CSpell * s, ECastingMode::ECastingMode mode_, const ISpellCaster * caster_, int schoolLvl_, BattleHex destination_)
  76. : ti(s,schoolLvl_, mode_), mode(mode_), destination(destination_), caster(caster_), schoolLvl(schoolLvl_)
  77. {};
  78. };
  79. class DLL_LINKAGE ISpellMechanics
  80. {
  81. public:
  82. ISpellMechanics(CSpell * s);
  83. virtual ~ISpellMechanics(){};
  84. virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0;
  85. virtual std::vector<const CStack *> getAffectedStacks(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const = 0;
  86. virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ECastingMode::ECastingMode mode, const ISpellCaster * caster) const = 0;
  87. virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const = 0;
  88. virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const = 0;
  89. virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const = 0;
  90. virtual void battleCast(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters) const = 0;
  91. //if true use generic algorithm for target existence check, see CSpell::canBeCast
  92. virtual bool requiresCreatureTarget() const = 0;
  93. static std::unique_ptr<ISpellMechanics> createMechanics(CSpell * s);
  94. protected:
  95. CSpell * owner;
  96. };
  97. struct DLL_LINKAGE AdventureSpellCastParameters
  98. {
  99. const CGHeroInstance * caster;
  100. int3 pos;
  101. };
  102. class DLL_LINKAGE IAdventureSpellMechanics
  103. {
  104. public:
  105. IAdventureSpellMechanics(CSpell * s);
  106. virtual ~IAdventureSpellMechanics() = default;
  107. virtual bool adventureCast(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const = 0;
  108. static std::unique_ptr<IAdventureSpellMechanics> createMechanics(CSpell * s);
  109. protected:
  110. CSpell * owner;
  111. };