ISpellMechanics.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "../battle/BattleHex.h"
  13. struct Query;
  14. ///callback to be provided by server
  15. class DLL_LINKAGE SpellCastEnvironment
  16. {
  17. public:
  18. virtual ~SpellCastEnvironment(){};
  19. virtual void sendAndApply(CPackForClient * info) const = 0;
  20. virtual CRandomGenerator & getRandomGenerator() const = 0;
  21. virtual void complain(const std::string & problem) const = 0;
  22. virtual const CMap * getMap() const = 0;
  23. virtual const CGameInfoCallback * getCb() const = 0;
  24. virtual bool moveHero(ObjectInstanceID hid, int3 dst, bool teleporting) const = 0; //TODO: remove
  25. virtual void genericQuery(Query * request, PlayerColor color, std::function<void(const JsonNode &)> callback) const = 0;//TODO: type safety on query, use generic query packet when implemented
  26. };
  27. ///all parameters of particular cast event
  28. struct DLL_LINKAGE BattleSpellCastParameters
  29. {
  30. public:
  31. ///Single spell destination.
  32. /// (assumes that anything but battle stack can share same hex)
  33. struct DLL_LINKAGE Destination
  34. {
  35. explicit Destination(const CStack * destination);
  36. explicit Destination(const BattleHex & destination);
  37. const CStack * stackValue;
  38. const BattleHex hexValue;
  39. };
  40. //normal constructor
  41. BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell_);
  42. //magic mirror constructor
  43. BattleSpellCastParameters(const BattleSpellCastParameters & orig, const ISpellCaster * caster);
  44. void aimToHex(const BattleHex & destination);
  45. void aimToStack(const CStack * destination);
  46. void cast(const SpellCastEnvironment * env);
  47. ///cast with silent check for permitted cast
  48. ///returns true if cast was permitted
  49. bool castIfPossible(const SpellCastEnvironment * env);
  50. BattleHex getFirstDestinationHex() const;
  51. int getEffectValue() const;
  52. const CSpell * spell;
  53. const BattleInfo * cb;
  54. const ISpellCaster * caster;
  55. const PlayerColor casterColor;
  56. const ui8 casterSide;
  57. std::vector<Destination> destinations;
  58. const CGHeroInstance * casterHero; //deprecated
  59. ECastingMode::ECastingMode mode;
  60. const CStack * casterStack; //deprecated
  61. ///spell school level
  62. int spellLvl;
  63. ///spell school level to use for effects
  64. int effectLevel;
  65. ///actual spell-power affecting effect values
  66. int effectPower;
  67. ///actual spell-power affecting effect duration
  68. int enchantPower;
  69. private:
  70. ///for Archangel-like casting
  71. int effectValue;
  72. };
  73. class DLL_LINKAGE ISpellMechanics
  74. {
  75. public:
  76. ISpellMechanics(const CSpell * s);
  77. virtual ~ISpellMechanics(){};
  78. virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0;
  79. virtual std::vector<const CStack *> getAffectedStacks(const CBattleInfoCallback * cb, const ECastingMode::ECastingMode mode, const ISpellCaster * caster, int spellLvl, BattleHex destination) const = 0;
  80. virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ECastingMode::ECastingMode mode, const ISpellCaster * caster) const = 0;
  81. virtual ESpellCastProblem::ESpellCastProblem canBeCastAt(const CBattleInfoCallback * cb, const ECastingMode::ECastingMode mode, const ISpellCaster * caster, BattleHex destination) const = 0;
  82. virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const = 0;
  83. virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const = 0;
  84. virtual void battleCast(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters) const = 0;
  85. //if true use generic algorithm for target existence check, see CSpell::canBeCast
  86. virtual bool requiresCreatureTarget() const = 0;
  87. static std::unique_ptr<ISpellMechanics> createMechanics(const CSpell * s);
  88. protected:
  89. const CSpell * owner;
  90. };
  91. struct DLL_LINKAGE AdventureSpellCastParameters
  92. {
  93. const CGHeroInstance * caster;
  94. int3 pos;
  95. };
  96. class DLL_LINKAGE IAdventureSpellMechanics
  97. {
  98. public:
  99. IAdventureSpellMechanics(const CSpell * s);
  100. virtual ~IAdventureSpellMechanics() = default;
  101. virtual bool adventureCast(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const = 0;
  102. static std::unique_ptr<IAdventureSpellMechanics> createMechanics(const CSpell * s);
  103. protected:
  104. const CSpell * owner;
  105. };