Rules.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 RULES_H_
  17. #define RULES_H_
  18. #include <string.h>
  19. #include <map>
  20. #include "../../common/Mutex.h"
  21. #include "../../common/types.h"
  22. using namespace std;
  23. enum RuleCategory {
  24. R_Client,
  25. R_Faction,
  26. R_Guild,
  27. R_Player,
  28. R_PVP,
  29. R_Combat,
  30. R_Spawn,
  31. R_UI,
  32. R_World,
  33. R_Zone,
  34. R_Loot,
  35. R_Spells,
  36. R_Expansion,
  37. R_Discord
  38. };
  39. enum RuleType {
  40. /* CLIENT */
  41. ShowWelcomeScreen,
  42. /* FACTION */
  43. AllowFactionBasedCombat,
  44. /* GUILD */
  45. /* PLAYER */
  46. MaxLevel,
  47. MaxLevelOverrideStatus,
  48. MaxPlayers,
  49. MaxPlayersOverrideStatus,
  50. VitalityAmount,
  51. VitalityFrequency,
  52. MaxAA,
  53. MaxClassAA,
  54. MaxSubclassAA,
  55. MaxShadowsAA,
  56. MaxHeroicAA,
  57. MaxTradeskillAA,
  58. MaxPrestigeAA,
  59. MaxTradeskillPrestigeAA,
  60. MaxDragonAA,
  61. MinLastNameLevel,
  62. MaxLastNameLength,
  63. MinLastNameLength,
  64. DisableHouseAlignmentRequirement,
  65. MentorItemDecayRate,
  66. TemporaryItemLogoutTime,
  67. HeirloomItemShareExpiration,
  68. SwimmingSkillMinSpeed,
  69. SwimmingSkillMaxSpeed,
  70. SwimmingSkillMinBreathLength,
  71. SwimmingSkillMaxBreathLength,
  72. AutoSkillUpBaseSkills,
  73. /* PVP */
  74. AllowPVP,
  75. LevelRange,
  76. InvisPlayerDiscoveryRange,
  77. PVPMitigationModByLevel,
  78. /* COMBAT */
  79. MaxCombatRange,
  80. DeathExperienceDebt,
  81. GroupExperienceDebt,
  82. PVPDeathExperienceDebt,
  83. ExperienceToDebt,
  84. ExperienceDebtRecoveryPercent,
  85. ExperienceDebtRecoveryPeriod,
  86. EnableSpiritShards,
  87. SpiritShardSpawnScript,
  88. ShardDebtRecoveryPercent,
  89. ShardRecoveryByRadius,
  90. ShardLifetime,
  91. EffectiveMitigationCapLevel,
  92. CalculatedMitigationCapLevel,
  93. MitigationLevelEffectivenessMax,
  94. MitigationLevelEffectivenessMin,
  95. MaxMitigationAllowed,
  96. MaxMitigationAllowedPVP,
  97. StrengthNPC,
  98. StrengthOther,
  99. MaxSkillBonusByLevel,
  100. LockedEncounterNoAttack,
  101. /* SPAWN */
  102. SpeedMultiplier,
  103. ClassicRegen,
  104. HailMovementPause,
  105. HailDistance,
  106. UseHardCodeWaterModelType,
  107. UseHardCodeFlyingModelType,
  108. //SpeedRatio,
  109. /* UI */
  110. MaxWhoResults,
  111. MaxWhoOverrideStatus,
  112. /* WORLD */
  113. DefaultStartingZoneID,
  114. EnablePOIDiscovery,
  115. GamblingTokenItemID,
  116. GuildAutoJoin,
  117. GuildAutoJoinID,
  118. GuildAutoJoinDefaultRankID,
  119. ServerLocked,
  120. ServerLockedOverrideStatus,
  121. SyncZonesWithLogin,
  122. SyncEquipWithLogin,
  123. UseBannedIPsTable,
  124. LinkDeadTimer,
  125. RemoveDisconnectedClientsTimer,
  126. PlayerCampTimer,
  127. GMCampTimer,
  128. AutoAdminPlayers,
  129. AutoAdminGMs,
  130. AutoAdminStatusValue,
  131. DuskTime,
  132. DawnTime,
  133. ThreadedLoad,
  134. TradeskillSuccessChance,
  135. TradeskillCritSuccessChance,
  136. TradeskillFailChance,
  137. TradeskillCritFailChance,
  138. TradeskillEventChance,
  139. EditorURL,
  140. EditorIncludeID,
  141. EditorOfficialServer,
  142. GroupSpellsTimer,
  143. QuestQueueTimer,
  144. SavePaperdollImage,
  145. SaveHeadshotImage,
  146. SendPaperdollImagesToLogin,
  147. TreasureChestDisabled,
  148. StartingZoneLanguages,
  149. StartingZoneRuleFlag,
  150. EnforceRacialAlignment,
  151. MemoryCacheZoneMaps,
  152. AutoLockEncounter,
  153. DisplayItemTiers,
  154. LoreAndLegendAccept,
  155. /* ZONE */
  156. MinZoneLevelOverrideStatus,
  157. MinZoneAccessOverrideStatus,
  158. XPMultiplier,
  159. TSXPMultiplier,
  160. WeatherEnabled,
  161. WeatherType,
  162. MinWeatherSeverity,
  163. MaxWeatherSeverity,
  164. WeatherChangeFrequency,
  165. WeatherChangePerInterval,
  166. WeatherDynamicMaxOffset,
  167. WeatherChangeChance,
  168. SpawnUpdateTimer,
  169. CheckAttackPlayer,
  170. CheckAttackNPC,
  171. HOTime,
  172. UseMapUnderworldCoords,
  173. MapUnderworldCoordOffset,
  174. /* LOOT */
  175. LootRadius,
  176. AutoDisarmChest, // if enabled disarm only works if you right click and disarm, clicking and opening chest won't attempt auto disarm
  177. ChestTriggerRadiusGroup,
  178. ChestUnlockedTimeDrop,
  179. AllowChestUnlockByDropTime,
  180. ChestUnlockedTimeTrap,
  181. AllowChestUnlockByTrapTime,
  182. /* SPELLS */
  183. NoInterruptBaseChance,
  184. EnableFizzleSpells,
  185. DefaultFizzleChance,
  186. FizzleMaxSkill,
  187. FizzleDefaultSkill,
  188. EnableCrossZoneGroupBuffs,
  189. EnableCrossZoneTargetBuffs,
  190. PlayerSpellSaveStateWaitInterval,
  191. PlayerSpellSaveStateCap,
  192. RequirePreviousTierScribe,
  193. CureSpellID,
  194. CureCurseSpellID,
  195. CureNoxiousSpellID,
  196. CureMagicSpellID,
  197. CureTraumaSpellID,
  198. CureArcaneSpellID,
  199. MinistrationSkillID,
  200. MinistrationPowerReductionMax,
  201. MinistrationPowerReductionSkill,
  202. MasterSkillReduceSpellResist,
  203. /* ZONE TIMERS */
  204. RegenTimer,
  205. ClientSaveTimer,
  206. ShutdownDelayTimer,
  207. WeatherTimer,
  208. SpawnDeleteTimer,
  209. GlobalExpansionFlag,
  210. GlobalHolidayFlag,
  211. DatabaseVersion,
  212. SkipLootGrayMob,
  213. LootDistributionTime,
  214. DiscordEnabled,
  215. DiscordWebhookURL,
  216. DiscordBotToken,
  217. DiscordChannel,
  218. DiscordListenChan
  219. };
  220. class Rule {
  221. public:
  222. Rule();
  223. Rule(int32 category, int32 type, const char *value, const char *combined);
  224. Rule (Rule *rule_in);
  225. virtual ~Rule();
  226. void SetValue(const char *value) {strncpy(this->value, value, sizeof(this->value));}
  227. int32 GetCategory() {return category;}
  228. int32 GetType() {return type;}
  229. const char * GetValue() {return value;}
  230. const char * GetCombined() {return combined;}
  231. int8 GetInt8() {return (int8)atoul(value);}
  232. int16 GetInt16() {return (int16)atoul(value);}
  233. int32 GetInt32() {return (int32)atoul(value);}
  234. int64 GetInt64() {return (int64)atoi64(value);}
  235. sint8 GetSInt8() {return (sint8)atoi(value);}
  236. sint16 GetSInt16() {return (sint16)atoi(value);}
  237. sint32 GetSInt32() {return (sint32)atoi(value);}
  238. sint64 GetSInt64() {return (sint64)atoi64(value);}
  239. bool GetBool() {return atoul(value) > 0 ? true : false;}
  240. float GetFloat() {return atof(value);}
  241. char GetChar() {return value[0];}
  242. const char * GetString() {return value;}
  243. private:
  244. int32 category;
  245. int32 type;
  246. char value[64];
  247. char combined[256];
  248. };
  249. class RuleSet {
  250. public:
  251. RuleSet();
  252. RuleSet(RuleSet *in_rule_set);
  253. virtual ~RuleSet();
  254. void CopyRulesInto(RuleSet *in_rule_set);
  255. void SetID(int32 id) {this->id = id;}
  256. void SetName(const char *name) {strncpy(this->name, name, sizeof(this->name));}
  257. int32 GetID() {return id;}
  258. const char *GetName() {return name;}
  259. void AddRule(Rule *rule);
  260. Rule * GetRule(int32 category, int32 type);
  261. Rule * GetRule(const char *category, const char *type);
  262. void ClearRules();
  263. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  264. private:
  265. int32 id;
  266. char name[64];
  267. Mutex m_rules;
  268. map<int32, map<int32, Rule *> > rules;
  269. };
  270. class RuleManager {
  271. public:
  272. RuleManager();
  273. virtual ~RuleManager();
  274. void Init();
  275. void Flush(bool reinit=false);
  276. void LoadCodedDefaultsIntoRuleSet(RuleSet *rule_set);
  277. bool AddRuleSet(RuleSet *rule_set);
  278. int32 GetNumRuleSets();
  279. void ClearRuleSets();
  280. Rule * GetBlankRule() {return &blank_rule;}
  281. bool SetGlobalRuleSet(int32 rule_set_id);
  282. Rule * GetGlobalRule(int32 category, int32 type);
  283. Rule * GetGlobalRule(const char* category, const char* type);
  284. bool SetZoneRuleSet(int32 zone_id, int32 rule_set_id);
  285. Rule * GetZoneRule(int32 zone_id, int32 category, int32 type);
  286. void ClearZoneRuleSets();
  287. RuleSet * GetGlobalRuleSet() {return &global_rule_set;}
  288. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  289. private:
  290. Mutex m_rule_sets;
  291. Mutex m_global_rule_set;
  292. Mutex m_zone_rule_sets;
  293. Rule blank_rule; /* READ ONLY */
  294. map<int32, map<int32, Rule *> > rules; /* all of the rules loaded with their defaults (FROM THE CODE). map<category, map<type, rule>> */
  295. map<int32, RuleSet *> rule_sets; /* all of the possible rule sets from the database. map<rule set id, rule set> */
  296. RuleSet global_rule_set; /* the global rule set, first fill it the defaults from the code, then over ride from the database */
  297. map<int32, RuleSet *> zone_rule_sets; /* references to a zone's rule set. map<zone id, rule set> */
  298. };
  299. #endif