ISpellMechanics.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell);
  39. void aimToHex(const BattleHex & destination);
  40. void aimToStack(const CStack * destination);
  41. BattleHex getFirstDestinationHex() const;
  42. const BattleInfo * cb;
  43. const ISpellCaster * caster;
  44. const PlayerColor casterColor;
  45. const ui8 casterSide;
  46. std::vector<Destination> destinations;
  47. const CGHeroInstance * casterHero; //deprecated
  48. ECastingMode::ECastingMode mode;
  49. const CStack * casterStack; //deprecated
  50. const CStack * selectedStack;//deprecated
  51. ///spell school level
  52. int spellLvl;
  53. ///spell school level to use for effects
  54. int effectLevel;
  55. ///actual spell-power affecting effect values
  56. int effectPower;
  57. ///actual spell-power affecting effect duration
  58. int enchantPower;
  59. ///for Archangel-like casting
  60. int effectValue;
  61. private:
  62. void prepare(const CSpell * spell);
  63. };
  64. struct DLL_LINKAGE SpellTargetingContext
  65. {
  66. CSpell::TargetInfo ti;
  67. ECastingMode::ECastingMode mode;
  68. BattleHex destination;
  69. const ISpellCaster * caster;
  70. int schoolLvl;
  71. SpellTargetingContext(const CSpell * s, ECastingMode::ECastingMode mode_, const ISpellCaster * caster_, int schoolLvl_, BattleHex destination_)
  72. : ti(s,schoolLvl_, mode_), mode(mode_), destination(destination_), caster(caster_), schoolLvl(schoolLvl_)
  73. {};
  74. };
  75. class DLL_LINKAGE ISpellMechanics
  76. {
  77. public:
  78. ISpellMechanics(CSpell * s);
  79. virtual ~ISpellMechanics(){};
  80. virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0;
  81. virtual std::set<const CStack *> getAffectedStacks(const CBattleInfoCallback * cb, SpellTargetingContext & ctx) const = 0;
  82. virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ISpellCaster * caster) const = 0;
  83. virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const = 0;
  84. virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const = 0;
  85. virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const = 0;
  86. virtual void battleCast(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters) const = 0;
  87. virtual void battleLogSingleTarget(std::vector<std::string> & logLines, const BattleSpellCast * packet,
  88. const std::string & casterName, const CStack * attackedStack, bool & displayDamage) const = 0;
  89. static std::unique_ptr<ISpellMechanics> createMechanics(CSpell * s);
  90. protected:
  91. CSpell * owner;
  92. };
  93. struct DLL_LINKAGE AdventureSpellCastParameters
  94. {
  95. const CGHeroInstance * caster;
  96. int3 pos;
  97. };
  98. class DLL_LINKAGE IAdventureSpellMechanics
  99. {
  100. public:
  101. IAdventureSpellMechanics(CSpell * s);
  102. virtual ~IAdventureSpellMechanics() = default;
  103. virtual bool adventureCast(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const = 0;
  104. static std::unique_ptr<IAdventureSpellMechanics> createMechanics(CSpell * s);
  105. protected:
  106. CSpell * owner;
  107. };