ISpellMechanics.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. ///helper struct
  26. struct DLL_LINKAGE BattleSpellCastParameters
  27. {
  28. public:
  29. BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell);
  30. const BattleInfo * cb;
  31. const ISpellCaster * caster;
  32. const PlayerColor casterColor;
  33. const ui8 casterSide;
  34. BattleHex destination;
  35. const CGHeroInstance * casterHero; //deprecated
  36. ECastingMode::ECastingMode mode;
  37. const CStack * casterStack; //deprecated
  38. const CStack * selectedStack;
  39. ///spell school level
  40. int spellLvl;
  41. ///spell school level to use for effects
  42. int effectLevel;
  43. ///actual spell-power affecting effect values
  44. int effectPower;
  45. ///actual spell-power affecting effect duration
  46. int enchantPower;
  47. ///for Archangel-like casting
  48. int effectValue;
  49. private:
  50. void prepare(const CSpell * spell);
  51. };
  52. struct DLL_LINKAGE AdventureSpellCastParameters
  53. {
  54. const CGHeroInstance * caster;
  55. int3 pos;
  56. };
  57. class DLL_LINKAGE ISpellMechanics
  58. {
  59. public:
  60. struct DLL_LINKAGE SpellTargetingContext
  61. {
  62. const CBattleInfoCallback * cb;
  63. CSpell::TargetInfo ti;
  64. ECastingMode::ECastingMode mode;
  65. BattleHex destination;
  66. PlayerColor casterColor;
  67. int schoolLvl;
  68. SpellTargetingContext(const CSpell * s, const CBattleInfoCallback * c, ECastingMode::ECastingMode m, PlayerColor cc, int lvl, BattleHex dest)
  69. : cb(c), ti(s,lvl, m), mode(m), destination(dest), casterColor(cc), schoolLvl(lvl)
  70. {};
  71. };
  72. public:
  73. ISpellMechanics(CSpell * s);
  74. virtual ~ISpellMechanics(){};
  75. virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0;
  76. virtual std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const = 0;
  77. virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, PlayerColor player) const = 0;
  78. virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const = 0;
  79. virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const = 0;
  80. virtual bool adventureCast(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const = 0;
  81. virtual void battleCast(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters) const = 0;
  82. virtual void battleLogSingleTarget(std::vector<std::string> & logLines, const BattleSpellCast * packet,
  83. const std::string & casterName, const CStack * attackedStack, bool & displayDamage) const = 0;
  84. static ISpellMechanics * createMechanics(CSpell * s);
  85. protected:
  86. CSpell * owner;
  87. };