9
3

Skills.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator 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. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __EQ2_SKILLS_H__
  17. #define __EQ2_SKILLS_H__
  18. #include <map>
  19. #include <mutex>
  20. #include <shared_mutex>
  21. #include "../common/ConfigReader.h"
  22. #include "../common/types.h"
  23. #include "MutexMap.h"
  24. #define SKILL_TYPE_WEAPONRY 1
  25. #define SKILL_TYPE_SPELLCASTING 2
  26. #define SKILL_TYPE_AVOIDANCE 3
  27. #define SKILL_TYPE_ARMOR 4
  28. #define SKILL_TYPE_SHIELD 5
  29. #define SKILL_TYPE_HARVESTING 6
  30. #define SKILL_TYPE_ARTISAN 7
  31. #define SKILL_TYPE_CRAFTSMAN 8
  32. #define SKILL_TYPE_OUTFITTER 9
  33. #define SKILL_TYPE_SCHOLAR 10
  34. #define SKILL_TYPE_GENERAL 13
  35. #define SKILL_TYPE_LANGUAGE 14
  36. #define SKILL_TYPE_CLASS 15
  37. #define SKILL_TYPE_COMBAT 16
  38. #define SKILL_TYPE_WEAPON 17
  39. #define SKILL_TYPE_TSKNOWLEDGE 18
  40. #define SKILL_TYPE_GENERAL_DOF 11
  41. #define SKILL_TYPE_LANGUAGE_DOF 12
  42. #define SKILL_TYPE_CLASS_DOF 13
  43. #define SKILL_TYPE_COMBAT_DOF 14
  44. #define SKILL_TYPE_WEAPON_DOF 15
  45. #define SKILL_TYPE_TSKNOWLEDGE_DOF 16
  46. #define SKILL_ID_SCULPTING 1039865549
  47. #define SKILL_ID_FLETCHING 3076004370
  48. #define SKILL_ID_ARTISTRY 3881305672
  49. #define SKILL_ID_TAILORING 2082133324
  50. #define SKILL_ID_METALSHAPING 3108933728
  51. #define SKILL_ID_METALWORKING 4032608519
  52. #define SKILL_ID_SCRIBING 773137566
  53. #define SKILL_ID_CHEMISTRY 2557647574
  54. #define SKILL_ID_ARTIFICING 3330500131
  55. #define SKILL_ID_ARTIFICING 3330500131
  56. //the following update the current_value to the max_value as soon as the max_value is updated
  57. #define SKILL_ID_DUALWIELD 1852383242
  58. #define SKILL_ID_FISTS 3177806075
  59. #define SKILL_ID_DESTROYING 3429135390
  60. #define SKILL_ID_MAGIC_AFFINITY 2072844078
  61. #define SKILL_ID_GREATSWORD 2292577688 // aka 2h slashing
  62. #define SKILL_ID_GREATSPEAR 2380184628 // aka 2h piercing
  63. #define SKILL_ID_STAFF 3180399725 // aka 2h crushing
  64. /* Each SkillBonus is comprised of multiple possible skill bonus values. This is so one spell can modify
  65. more than one skill */
  66. struct SkillBonusValue {
  67. int32 skill_id;
  68. float value;
  69. };
  70. struct SkillBonus {
  71. int32 spell_id;
  72. map<int32, SkillBonusValue*> skills;
  73. };
  74. class Skill{
  75. public:
  76. Skill();
  77. Skill(Skill* skill);
  78. int32 skill_id;
  79. int16 current_val;
  80. int16 previous_val;
  81. int16 max_val;
  82. int32 skill_type;
  83. int8 display;
  84. EQ2_16BitString short_name;
  85. EQ2_16BitString name;
  86. EQ2_16BitString description;
  87. bool save_needed;
  88. bool active_skill;
  89. int CheckDisarmSkill(int16 targetLevel, int8 chest_difficulty=0);
  90. };
  91. class MasterSkillList{
  92. public:
  93. MasterSkillList();
  94. ~MasterSkillList();
  95. void AddSkill(Skill* skill);
  96. int16 GetSkillCount();
  97. EQ2Packet* GetPopulateSkillsPacket(int16 version);
  98. map<int32, Skill*>* GetAllSkills();
  99. Skill* GetSkill(int32 skill_id);
  100. Skill* GetSkillByName(const char* skill_name);
  101. private:
  102. map<int32, Skill*> skills;
  103. map<int16, EQ2Packet*> populate_packets;
  104. };
  105. class PlayerSkillList{
  106. public:
  107. PlayerSkillList();
  108. ~PlayerSkillList();
  109. void RemoveSkill(Skill* skill);
  110. void AddSkill(Skill* new_skill);
  111. bool CheckSkillIncrease(Skill* skill);
  112. Skill* GetSkillByName(const char* name);
  113. bool HasSkill(int32 skill_id);
  114. Skill* GetSkill(int32 skill_id);
  115. void IncreaseSkill(Skill* skill, int16 amount);
  116. void IncreaseSkill(int32 skill_id, int16 amount);
  117. void DecreaseSkill(Skill* skill, int16 amount);
  118. void DecreaseSkill(int32 skill_id, int16 amount);
  119. void SetSkill(Skill* skill, int16 value, bool send_update = true);
  120. void SetSkill(int32 skill_id, int16 value, bool send_update = true);
  121. void IncreaseSkillCap(Skill* skill, int16 amount);
  122. void IncreaseSkillCap(int32 skill_id, int16 amount);
  123. void DecreaseSkillCap(Skill* skill, int16 amount);
  124. void DecreaseSkillCap(int32 skill_id, int16 amount);
  125. void SetSkillCap(Skill* skill, int16 value);
  126. void SetSkillCap(int32 skill_id, int16 value);
  127. void IncreaseAllSkillCaps(int16 value);
  128. void IncreaseSkillCapsByType(int8 type, int16 value);
  129. void SetSkillCapsByType(int8 type, int16 value);
  130. void SetSkillValuesByType(int8 type, int16 value, bool send_update = true);
  131. void AddSkillUpdateNeeded(Skill* skill);
  132. void AddSkillBonus(int32 spell_id, int32 skill_id, float value);
  133. SkillBonus* GetSkillBonus(int32 spell_id);
  134. void RemoveSkillBonus(int32 spell_id);
  135. int16 CalculateSkillValue(int32 skill_id, int16 current_val);
  136. int16 CalculateSkillMaxValue(int32 skill_id, int16 max_val);
  137. EQ2Packet* GetSkillPacket(int16 version);
  138. vector<Skill*>* GetSaveNeededSkills();
  139. vector<Skill*>* GetSkillUpdates();
  140. map<int32, Skill*>* GetAllSkills();
  141. bool HasSkillUpdates();
  142. void ResetPackets();
  143. private:
  144. volatile bool has_updates;
  145. mutable std::shared_mutex MPlayerSkills;
  146. Mutex MSkillUpdates;
  147. int16 packet_count;
  148. uchar* orig_packet;
  149. int16 orig_packet_size;
  150. uchar* xor_packet;
  151. map<int32, Skill*> skills;
  152. map<string, Skill*> name_skill_map;
  153. vector<Skill*> skill_updates;
  154. MutexMap<int32, SkillBonus*> skill_bonus_list;
  155. };
  156. #endif