Guest User

Weapons.h

a guest
Mar 29th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 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 __WEAPONS__
  19. #define __WEAPONS__
  20. #include "otsystem.h"
  21.  
  22. #include "const.h"
  23. #include "combat.h"
  24.  
  25. #include "baseevents.h"
  26. #include "luascript.h"
  27.  
  28. #include "player.h"
  29. #include "item.h"
  30.  
  31. class Weapon;
  32. class WeaponMelee;
  33. class WeaponDistance;
  34. class WeaponWand;
  35.  
  36. class Weapons : public BaseEvents
  37. {
  38. public:
  39. Weapons();
  40. virtual ~Weapons() {clear();}
  41.  
  42. bool loadDefaults();
  43. const Weapon* getWeapon(const Item* item) const;
  44.  
  45. static int64_t getMaxMeleeDamage(int64_t attackSkill, int64_t attackValue);
  46. static int64_t getMaxWeaponDamage(int64_t level, int64_t attackSkill, int64_t attackValue, float attackFactor);
  47.  
  48. protected:
  49. virtual std::string getScriptBaseName() const {return "weapons";}
  50. virtual void clear();
  51.  
  52. virtual Event* getEvent(const std::string& nodeName);
  53. virtual bool registerEvent(Event* event, xmlNodePtr p, bool override);
  54.  
  55. virtual LuaInterface& getInterface() {return m_interface;}
  56. LuaInterface m_interface;
  57.  
  58. typedef std::map<uint32_t, Weapon*> WeaponMap;
  59. WeaponMap weapons;
  60. };
  61.  
  62. class Weapon : public Event
  63. {
  64. public:
  65. Weapon(LuaInterface* _interface);
  66. virtual ~Weapon() {}
  67.  
  68. static bool useFist(Player* player, Creature* target);
  69.  
  70. virtual bool loadFunction(const std::string& functionName);
  71. virtual bool configureEvent(xmlNodePtr p);
  72. virtual bool configureWeapon(const ItemType& it);
  73.  
  74. virtual int64_t playerWeaponCheck(Player* player, Creature* target) const;
  75.  
  76. uint16_t getID() const {return id;}
  77. virtual bool interruptSwing() const {return !swing;}
  78. CombatParams getCombatParam() const {return params;}
  79.  
  80. virtual bool useWeapon(Player* player, Item* item, Creature* target) const;
  81. virtual int64_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const = 0;
  82. virtual int64_t getWeaponElementDamage(const Player*, const Item*, bool = false) const {return 0;}
  83.  
  84. uint32_t getReqLevel() const {return level;}
  85. uint32_t getReqMagLv() const {return magLevel;}
  86. bool hasExhaustion() const {return exhaustion != 0;}
  87. bool isPremium() const {return premium;}
  88. bool isWieldedUnproperly() const {return wieldUnproperly;}
  89.  
  90. protected:
  91. virtual std::string getScriptEventName() const {return "onUseWeapon";}
  92. virtual std::string getScriptEventParams() const {return "cid, var";}
  93.  
  94. bool executeUseWeapon(Player* player, const LuaVariant& var) const;
  95.  
  96. bool internalUseWeapon(Player* player, Item* item, Creature* target, int64_t damageModifier) const;
  97. bool internalUseWeapon(Player* player, Item* item, Tile* tile) const;
  98.  
  99. virtual void onUsedWeapon(Player* player, Item* item, Tile* destTile) const;
  100. virtual void onUsedAmmo(Player* player, Item* item, Tile* destTile) const;
  101. virtual bool getSkillType(const Player*, const Item*, skills_t&, uint64_t&) const {return false;}
  102.  
  103. int64_t getManaCost(const Player* player) const;
  104.  
  105. uint16_t id;
  106. uint32_t exhaustion;
  107. bool enabled, premium, wieldUnproperly, swing;
  108. int64_t level, magLevel, mana, manaPercent, soul;
  109.  
  110. AmmoAction_t ammoAction;
  111. CombatParams params;
  112.  
  113. private:
  114. VocationMap vocWeaponMap;
  115. };
  116.  
  117. class WeaponMelee : public Weapon
  118. {
  119. public:
  120. WeaponMelee(LuaInterface* _interface);
  121. virtual ~WeaponMelee() {}
  122.  
  123. virtual bool useWeapon(Player* player, Item* item, Creature* target) const;
  124. virtual int64_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const;
  125. virtual int64_t getWeaponElementDamage(const Player* player, const Item* item, bool maxDamage = false) const;
  126.  
  127. protected:
  128. virtual bool getSkillType(const Player* player, const Item* item, skills_t& skill, uint64_t& skillPoint) const;
  129. };
  130.  
  131. class WeaponDistance : public Weapon
  132. {
  133. public:
  134. WeaponDistance(LuaInterface* _interface);
  135. virtual ~WeaponDistance() {}
  136.  
  137. virtual bool configureWeapon(const ItemType& it);
  138.  
  139. virtual int64_t playerWeaponCheck(Player* player, Creature* target) const;
  140.  
  141. virtual bool useWeapon(Player* player, Item* item, Creature* target) const;
  142. virtual int64_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const;
  143.  
  144. protected:
  145. virtual void onUsedAmmo(Player* player, Item* item, Tile* destTile) const;
  146. virtual bool getSkillType(const Player* player, const Item* item, skills_t& skill, uint64_t& skillPoint) const;
  147.  
  148. int64_t hitChance, maxHitChance, breakChance, attack;
  149. };
  150.  
  151. class WeaponWand : public Weapon
  152. {
  153. public:
  154. WeaponWand(LuaInterface* _interface);
  155. virtual ~WeaponWand() {}
  156.  
  157. virtual bool configureEvent(xmlNodePtr p);
  158. virtual bool configureWeapon(const ItemType& it);
  159.  
  160. virtual int64_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const;
  161.  
  162. protected:
  163. virtual bool getSkillType(const Player*, const Item*, skills_t&, uint64_t&) const {return false;}
  164.  
  165. int64_t minChange, maxChange;
  166. };
  167. #endif
Add Comment
Please, Sign In to add comment