Advertisement
Guest User

Untitled

a guest
May 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.37 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. // OpenTibia - an opensource roleplaying game
  3. ////////////////////////////////////////////////////////////////////////
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ////////////////////////////////////////////////////////////////////////
  17.  
  18. #ifndef __SPELLS__
  19. #define __SPELLS__
  20. #include "otsystem.h"
  21.  
  22. #include "enums.h"
  23. #include "player.h"
  24. #include "luascript.h"
  25.  
  26. #include "baseevents.h"
  27. #include "actions.h"
  28. #include "talkaction.h"
  29.  
  30. class InstantSpell;
  31. class ConjureSpell;
  32. class RuneSpell;
  33. class Spell;
  34.  
  35. typedef std::map<uint32_t, RuneSpell*> RunesMap;
  36. typedef std::map<std::string, InstantSpell*> InstantsMap;
  37.  
  38. class Spells : public BaseEvents
  39. {
  40. public:
  41. Spells();
  42. virtual ~Spells() {clear();}
  43.  
  44. Spell* getSpellByName(const std::string& name);
  45.  
  46. RuneSpell* getRuneSpell(uint32_t id);
  47. RuneSpell* getRuneSpellByName(const std::string& name);
  48.  
  49. InstantSpell* getInstantSpell(const std::string words);
  50. InstantSpell* getInstantSpellByName(const std::string& name);
  51. InstantSpell* getInstantSpellByIndex(const Player* player, uint32_t index);
  52.  
  53. uint32_t getInstantSpellCount(const Player* player);
  54. ReturnValue onPlayerSay(Player* player, const std::string& words);
  55. virtual std::string getScriptBaseName() const {return "spells";}
  56. static Position getCasterPosition(Creature* creature, Direction dir);
  57.  
  58. protected:
  59. virtual void clear();
  60.  
  61. virtual Event* getEvent(const std::string& nodeName);
  62. virtual bool registerEvent(Event* event, xmlNodePtr p, bool override);
  63.  
  64. virtual LuaScriptInterface& getInterface() {return m_interface;}
  65. LuaScriptInterface m_interface;
  66.  
  67. RunesMap runes;
  68. InstantsMap instants;
  69.  
  70. friend class CombatSpell;
  71. };
  72.  
  73. typedef bool (InstantSpellFunction)(const InstantSpell* spell, Creature* creature, const std::string& param);
  74. typedef bool (ConjureSpellFunction)(const ConjureSpell* spell, Creature* creature, const std::string& param);
  75. typedef bool (RuneSpellFunction)(const RuneSpell* spell, Creature* creature, Item* item, const Position& posFrom, const Position& posTo);
  76.  
  77. class BaseSpell
  78. {
  79. public:
  80. BaseSpell() {}
  81. virtual ~BaseSpell() {}
  82.  
  83. virtual bool castSpell(Creature* creature);
  84. virtual bool castSpell(Creature* creature, Creature* target);
  85. };
  86.  
  87. class CombatSpell : public Event, public BaseSpell
  88. {
  89. public:
  90. CombatSpell(Combat* _combat, bool _needTarget, bool _needDirection);
  91. virtual ~CombatSpell();
  92.  
  93. virtual bool castSpell(Creature* creature);
  94. virtual bool castSpell(Creature* creature, Creature* target);
  95. virtual bool configureEvent(xmlNodePtr p) {return true;}
  96.  
  97. //scripting
  98. bool executeCastSpell(Creature* creature, const LuaVariant& var);
  99.  
  100. bool loadScriptCombat();
  101. Combat* getCombat() {return combat;}
  102.  
  103. protected:
  104. virtual std::string getScriptEventName() const {return "onCastSpell";}
  105. virtual std::string getScriptEventParams() const {return "cid, var";}
  106.  
  107. bool needDirection;
  108. bool needTarget;
  109. Combat* combat;
  110. };
  111.  
  112. class Spell : public BaseSpell
  113. {
  114. public:
  115. Spell();
  116. virtual ~Spell() {}
  117.  
  118. bool configureSpell(xmlNodePtr xmlspell);
  119. const std::string& getName() const {return name;}
  120.  
  121. void postCastSpell(Player* player, bool isFinished = true, bool payCost = true) const;
  122. void postCastSpell(Player* player, uint32_t manaCost, uint32_t soulCost) const;
  123.  
  124. int32_t getManaCost(const Player* player) const;
  125. int32_t getSoulCost() const {return soul;}
  126. uint32_t getLevel() const {return level;}
  127. int32_t getMagicLevel() const {return magLevel;}
  128. int32_t getMana() const {return mana;}
  129. int32_t getManaPercent() const {return manaPercent;}
  130. uint32_t getExhaustion(const Player*) const;
  131. const bool isEnabled() const {return enabled;}
  132. const bool isPremium() const {return premium;}
  133.  
  134. virtual bool isInstant() const = 0;
  135. bool isLearnable() const {return learnable;}
  136.  
  137. static ReturnValue CreateIllusion(Creature* creature, const Outfit_t outfit, int32_t time);
  138. static ReturnValue CreateIllusion(Creature* creature, const std::string& name, int32_t time);
  139. static ReturnValue CreateIllusion(Creature* creature, uint32_t itemId, int32_t time);
  140.  
  141. protected:
  142. bool playerSpellCheck(Player* player) const;
  143. bool playerInstantSpellCheck(Player* player, Creature* creature);
  144. bool playerInstantSpellCheck(Player* player, const Position& toPos);
  145. bool playerRuneSpellCheck(Player* player, const Position& toPos);
  146.  
  147. int32_t level;
  148. int32_t magLevel;
  149. bool premium;
  150. bool learnable;
  151. bool enabled;
  152.  
  153. int32_t mana;
  154. int32_t manaPercent;
  155. int32_t soul;
  156. int32_t range;
  157. int32_t cooldownGroup;
  158. int32_t storage;
  159. int32_t storageValue;
  160. uint32_t exhaustion;
  161.  
  162. bool needTarget;
  163. bool needWeapon;
  164. bool blockingSolid;
  165. bool blockingCreature;
  166. bool selfTarget;
  167. bool isAggressive;
  168.  
  169. VocationMap vocSpellMap;
  170. typedef std::vector<std::string> VocStringVec;
  171. std::string vocStringVec;
  172.  
  173. private:
  174. std::string name;
  175. };
  176.  
  177. class InstantSpell : public TalkAction, public Spell
  178. {
  179. public:
  180. InstantSpell(LuaScriptInterface* _interface);
  181. virtual ~InstantSpell() {}
  182.  
  183. virtual bool configureEvent(xmlNodePtr p);
  184. virtual bool loadFunction(const std::string& functionName);
  185.  
  186. virtual bool playerCastInstant(Player* player, const std::string& param);
  187.  
  188. virtual bool castSpell(Creature* creature);
  189. virtual bool castSpell(Creature* creature, Creature* target);
  190.  
  191. //scripting
  192. bool executeCastSpell(Creature* creature, const LuaVariant& var);
  193.  
  194. virtual bool isInstant() const {return true;}
  195. bool getHasParam() const {return hasParam;}
  196. bool canCast(const Player* player) const;
  197. bool canThrowSpell(const Creature* creature, const Creature* target) const;
  198.  
  199. protected:
  200. virtual std::string getScriptEventName() const {return "onCastSpell";}
  201. virtual std::string getScriptEventParams() const {return "cid, var";}
  202.  
  203. static InstantSpellFunction SearchPlayer;
  204. static InstantSpellFunction SummonMonster;
  205. static InstantSpellFunction Levitate;
  206. static InstantSpellFunction Illusion;
  207.  
  208. bool internalCastSpell(Creature* creature, const LuaVariant& var);
  209.  
  210. bool needDirection;
  211. bool hasParam;
  212. bool checkLineOfSight;
  213. bool casterTargetOrDirection;
  214. uint8_t limitRange;
  215.  
  216. InstantSpellFunction* function;
  217. };
  218.  
  219. class ConjureSpell : public InstantSpell
  220. {
  221. public:
  222. ConjureSpell(LuaScriptInterface* _interface);
  223. virtual ~ConjureSpell() {}
  224.  
  225. virtual bool configureEvent(xmlNodePtr p);
  226. virtual bool loadFunction(const std::string& functionName);
  227.  
  228. virtual bool playerCastInstant(Player* player, const std::string& param);
  229.  
  230. virtual bool castSpell(Creature* creature) {return false;}
  231. virtual bool castSpell(Creature* creature, Creature* target) {return false;}
  232.  
  233. uint32_t getConjureId() const {return conjureId;}
  234. uint32_t getConjureCount() const {return conjureCount;}
  235. uint32_t getReagentId() const {return conjureReagentId;}
  236.  
  237. protected:
  238. virtual std::string getScriptEventName() const {return "onCastSpell";}
  239. virtual std::string getScriptEventParams() const {return "cid, var";}
  240.  
  241. static ReturnValue internalConjureItem(Player* player, uint32_t conjureId, uint32_t conjureCount,
  242. bool transform = false, uint32_t reagentId = 0, slots_t slot = SLOT_WHEREEVER, bool test = false);
  243.  
  244. static ConjureSpellFunction ConjureItem;
  245. static ConjureSpellFunction ConjureFood;
  246.  
  247. bool internalCastSpell(Creature* creature, const LuaVariant& var);
  248. Position getCasterPosition(Creature* creature);
  249.  
  250. ConjureSpellFunction* function;
  251.  
  252. uint32_t conjureId;
  253. uint32_t conjureCount;
  254. uint32_t conjureReagentId;
  255. };
  256.  
  257. class RuneSpell : public Action, public Spell
  258. {
  259. public:
  260. RuneSpell(LuaScriptInterface* _interface);
  261. virtual ~RuneSpell() {}
  262.  
  263. virtual bool configureEvent(xmlNodePtr p);
  264. virtual bool loadFunction(const std::string& functionName);
  265.  
  266. virtual ReturnValue canExecuteAction(const Player* player, const Position& toPos);
  267. virtual bool hasOwnErrorHandler() {return true;}
  268.  
  269. virtual bool executeUse(Player* player, Item* item, const PositionEx& posFrom,
  270. const PositionEx& posTo, bool extendedUse, uint32_t creatureId);
  271.  
  272. virtual bool castSpell(Creature* creature);
  273. virtual bool castSpell(Creature* creature, Creature* target);
  274.  
  275. //scripting
  276. bool executeCastSpell(Creature* creature, const LuaVariant& var);
  277.  
  278. virtual bool isInstant() const {return false;}
  279. uint32_t getRuneItemId(){return runeId;}
  280.  
  281. protected:
  282. virtual std::string getScriptEventName() const {return "onCastSpell";}
  283. virtual std::string getScriptEventParams() const {return "cid, var";}
  284.  
  285. static RuneSpellFunction Illusion;
  286. static RuneSpellFunction Convince;
  287.  
  288. bool internalCastSpell(Creature* creature, const LuaVariant& var);
  289.  
  290. bool hasCharges;
  291. uint32_t runeId;
  292.  
  293. RuneSpellFunction* function;
  294. };
  295. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement