ISpellMechanics.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #include "../BattleState.h"
  14. #include "../NetPacks.h"
  15. ///callback to be provided by server
  16. class DLL_LINKAGE SpellCastEnvironment
  17. {
  18. public:
  19. virtual ~SpellCastEnvironment(){};
  20. virtual void sendAndApply(CPackForClient * info) const = 0;
  21. virtual CRandomGenerator & getRandomGenerator() const = 0;
  22. virtual void complain(const std::string & problem) const = 0;
  23. virtual const CMap * getMap() const = 0;
  24. virtual const CGameInfoCallback * getCb() const = 0;
  25. virtual bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, PlayerColor asker = PlayerColor::NEUTRAL) const =0; //TODO: remove
  26. };
  27. ///helper struct
  28. struct DLL_LINKAGE BattleSpellCastParameters
  29. {
  30. public:
  31. BattleSpellCastParameters(const BattleInfo * cb);
  32. int spellLvl;
  33. BattleHex destination;
  34. ui8 casterSide;
  35. PlayerColor casterColor;
  36. const CGHeroInstance * casterHero; //deprecated
  37. const CGHeroInstance * secHero;
  38. int usedSpellPower;
  39. ECastingMode::ECastingMode mode;
  40. const CStack * casterStack;
  41. const CStack * selectedStack;
  42. const BattleInfo * cb;
  43. };
  44. struct DLL_LINKAGE AdventureSpellCastParameters
  45. {
  46. const CGHeroInstance * caster;
  47. int3 pos;
  48. };
  49. class DLL_LINKAGE ISpellMechanics
  50. {
  51. public:
  52. struct DLL_LINKAGE SpellTargetingContext
  53. {
  54. const CBattleInfoCallback * cb;
  55. CSpell::TargetInfo ti;
  56. ECastingMode::ECastingMode mode;
  57. BattleHex destination;
  58. PlayerColor casterColor;
  59. int schoolLvl;
  60. SpellTargetingContext(const CSpell * s, const CBattleInfoCallback * c, ECastingMode::ECastingMode m, PlayerColor cc, int lvl, BattleHex dest)
  61. : cb(c), ti(s,lvl, m), mode(m), destination(dest), casterColor(cc), schoolLvl(lvl)
  62. {};
  63. };
  64. public:
  65. ISpellMechanics(CSpell * s);
  66. virtual ~ISpellMechanics(){};
  67. virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0;
  68. virtual std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const = 0;
  69. virtual ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const = 0;
  70. virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const = 0;
  71. virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const = 0;
  72. virtual bool adventureCast(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const = 0;
  73. virtual void battleCast(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters) const = 0;
  74. virtual void battleLogSingleTarget(std::vector<std::string> & logLines, const BattleSpellCast * packet,
  75. const std::string & casterName, const CStack * attackedStack, bool & displayDamage) const = 0;
  76. static ISpellMechanics * createMechanics(CSpell * s);
  77. protected:
  78. CSpell * owner;
  79. };