Rules.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. MaxWeightStrengthMultiplier,
  74. BaseWeight,
  75. WeightPercentImpact,
  76. WeightPercentCap,
  77. CoinWeightPerStone,
  78. WeightInflictsSpeed,
  79. LevelMasterySkillMultiplier,
  80. TraitTieringSelection,
  81. ClassicTraitLevelTable,
  82. TraitFocusSelectLevel,
  83. TraitTrainingSelectLevel,
  84. TraitRaceSelectLevel,
  85. TraitCharacterSelectLevel,
  86. /* PVP */
  87. AllowPVP,
  88. LevelRange,
  89. InvisPlayerDiscoveryRange,
  90. PVPMitigationModByLevel,
  91. /* COMBAT */
  92. MaxCombatRange,
  93. DeathExperienceDebt,
  94. GroupExperienceDebt,
  95. PVPDeathExperienceDebt,
  96. ExperienceToDebt,
  97. ExperienceDebtRecoveryPercent,
  98. ExperienceDebtRecoveryPeriod,
  99. EnableSpiritShards,
  100. SpiritShardSpawnScript,
  101. ShardDebtRecoveryPercent,
  102. ShardRecoveryByRadius,
  103. ShardLifetime,
  104. EffectiveMitigationCapLevel,
  105. CalculatedMitigationCapLevel,
  106. MitigationLevelEffectivenessMax,
  107. MitigationLevelEffectivenessMin,
  108. MaxMitigationAllowed,
  109. MaxMitigationAllowedPVP,
  110. StrengthNPC,
  111. StrengthOther,
  112. MaxSkillBonusByLevel,
  113. LockedEncounterNoAttack,
  114. /* SPAWN */
  115. SpeedMultiplier,
  116. ClassicRegen,
  117. HailMovementPause,
  118. HailDistance,
  119. UseHardCodeWaterModelType,
  120. UseHardCodeFlyingModelType,
  121. //SpeedRatio,
  122. /* UI */
  123. MaxWhoResults,
  124. MaxWhoOverrideStatus,
  125. /* WORLD */
  126. DefaultStartingZoneID,
  127. EnablePOIDiscovery,
  128. GamblingTokenItemID,
  129. GuildAutoJoin,
  130. GuildAutoJoinID,
  131. GuildAutoJoinDefaultRankID,
  132. ServerLocked,
  133. ServerLockedOverrideStatus,
  134. SyncZonesWithLogin,
  135. SyncEquipWithLogin,
  136. UseBannedIPsTable,
  137. LinkDeadTimer,
  138. RemoveDisconnectedClientsTimer,
  139. PlayerCampTimer,
  140. GMCampTimer,
  141. AutoAdminPlayers,
  142. AutoAdminGMs,
  143. AutoAdminStatusValue,
  144. DuskTime,
  145. DawnTime,
  146. ThreadedLoad,
  147. TradeskillSuccessChance,
  148. TradeskillCritSuccessChance,
  149. TradeskillFailChance,
  150. TradeskillCritFailChance,
  151. TradeskillEventChance,
  152. EditorURL,
  153. EditorIncludeID,
  154. EditorOfficialServer,
  155. GroupSpellsTimer,
  156. QuestQueueTimer,
  157. SavePaperdollImage,
  158. SaveHeadshotImage,
  159. SendPaperdollImagesToLogin,
  160. TreasureChestDisabled,
  161. StartingZoneLanguages,
  162. StartingZoneRuleFlag,
  163. EnforceRacialAlignment,
  164. MemoryCacheZoneMaps,
  165. AutoLockEncounter,
  166. DisplayItemTiers,
  167. LoreAndLegendAccept,
  168. /* ZONE */
  169. MinZoneLevelOverrideStatus,
  170. MinZoneAccessOverrideStatus,
  171. XPMultiplier,
  172. TSXPMultiplier,
  173. WeatherEnabled,
  174. WeatherType,
  175. MinWeatherSeverity,
  176. MaxWeatherSeverity,
  177. WeatherChangeFrequency,
  178. WeatherChangePerInterval,
  179. WeatherDynamicMaxOffset,
  180. WeatherChangeChance,
  181. SpawnUpdateTimer,
  182. CheckAttackPlayer,
  183. CheckAttackNPC,
  184. HOTime,
  185. UseMapUnderworldCoords,
  186. MapUnderworldCoordOffset,
  187. /* LOOT */
  188. LootRadius,
  189. AutoDisarmChest, // if enabled disarm only works if you right click and disarm, clicking and opening chest won't attempt auto disarm
  190. ChestTriggerRadiusGroup,
  191. ChestUnlockedTimeDrop,
  192. AllowChestUnlockByDropTime,
  193. ChestUnlockedTimeTrap,
  194. AllowChestUnlockByTrapTime,
  195. /* SPELLS */
  196. NoInterruptBaseChance,
  197. EnableFizzleSpells,
  198. DefaultFizzleChance,
  199. FizzleMaxSkill,
  200. FizzleDefaultSkill,
  201. EnableCrossZoneGroupBuffs,
  202. EnableCrossZoneTargetBuffs,
  203. PlayerSpellSaveStateWaitInterval,
  204. PlayerSpellSaveStateCap,
  205. RequirePreviousTierScribe,
  206. CureSpellID,
  207. CureCurseSpellID,
  208. CureNoxiousSpellID,
  209. CureMagicSpellID,
  210. CureTraumaSpellID,
  211. CureArcaneSpellID,
  212. MinistrationSkillID,
  213. MinistrationPowerReductionMax,
  214. MinistrationPowerReductionSkill,
  215. MasterSkillReduceSpellResist,
  216. /* ZONE TIMERS */
  217. RegenTimer,
  218. ClientSaveTimer,
  219. ShutdownDelayTimer,
  220. WeatherTimer,
  221. SpawnDeleteTimer,
  222. GlobalExpansionFlag,
  223. GlobalHolidayFlag,
  224. DatabaseVersion,
  225. SkipLootGrayMob,
  226. LootDistributionTime,
  227. DiscordEnabled,
  228. DiscordWebhookURL,
  229. DiscordBotToken,
  230. DiscordChannel,
  231. DiscordListenChan
  232. };
  233. class Rule {
  234. public:
  235. Rule();
  236. Rule(int32 category, int32 type, const char *value, const char *combined);
  237. Rule (Rule *rule_in);
  238. virtual ~Rule();
  239. void SetValue(const char *value) {strncpy(this->value, value, sizeof(this->value));}
  240. int32 GetCategory() {return category;}
  241. int32 GetType() {return type;}
  242. const char * GetValue() {return value;}
  243. const char * GetCombined() {return combined;}
  244. int8 GetInt8() {return (int8)atoul(value);}
  245. int16 GetInt16() {return (int16)atoul(value);}
  246. int32 GetInt32() {return (int32)atoul(value);}
  247. int64 GetInt64() {return (int64)atoi64(value);}
  248. sint8 GetSInt8() {return (sint8)atoi(value);}
  249. sint16 GetSInt16() {return (sint16)atoi(value);}
  250. sint32 GetSInt32() {return (sint32)atoi(value);}
  251. sint64 GetSInt64() {return (sint64)atoi64(value);}
  252. bool GetBool() {return atoul(value) > 0 ? true : false;}
  253. float GetFloat() {return atof(value);}
  254. char GetChar() {return value[0];}
  255. const char * GetString() {return value;}
  256. private:
  257. int32 category;
  258. int32 type;
  259. char value[1024];
  260. char combined[2048];
  261. };
  262. class RuleSet {
  263. public:
  264. RuleSet();
  265. RuleSet(RuleSet *in_rule_set);
  266. virtual ~RuleSet();
  267. void CopyRulesInto(RuleSet *in_rule_set);
  268. void SetID(int32 id) {this->id = id;}
  269. void SetName(const char *name) {strncpy(this->name, name, sizeof(this->name));}
  270. int32 GetID() {return id;}
  271. const char *GetName() {return name;}
  272. void AddRule(Rule *rule);
  273. Rule * GetRule(int32 category, int32 type);
  274. Rule * GetRule(const char *category, const char *type);
  275. void ClearRules();
  276. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  277. private:
  278. int32 id;
  279. char name[64];
  280. Mutex m_rules;
  281. map<int32, map<int32, Rule *> > rules;
  282. };
  283. class RuleManager {
  284. public:
  285. RuleManager();
  286. virtual ~RuleManager();
  287. void Init();
  288. void Flush(bool reinit=false);
  289. void LoadCodedDefaultsIntoRuleSet(RuleSet *rule_set);
  290. bool AddRuleSet(RuleSet *rule_set);
  291. int32 GetNumRuleSets();
  292. void ClearRuleSets();
  293. Rule * GetBlankRule() {return &blank_rule;}
  294. bool SetGlobalRuleSet(int32 rule_set_id);
  295. Rule * GetGlobalRule(int32 category, int32 type);
  296. Rule * GetGlobalRule(const char* category, const char* type);
  297. bool SetZoneRuleSet(int32 zone_id, int32 rule_set_id);
  298. Rule * GetZoneRule(int32 zone_id, int32 category, int32 type);
  299. void ClearZoneRuleSets();
  300. RuleSet * GetGlobalRuleSet() {return &global_rule_set;}
  301. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  302. private:
  303. Mutex m_rule_sets;
  304. Mutex m_global_rule_set;
  305. Mutex m_zone_rule_sets;
  306. Rule blank_rule; /* READ ONLY */
  307. map<int32, map<int32, Rule *> > rules; /* all of the rules loaded with their defaults (FROM THE CODE). map<category, map<type, rule>> */
  308. map<int32, RuleSet *> rule_sets; /* all of the possible rule sets from the database. map<rule set id, rule set> */
  309. RuleSet global_rule_set; /* the global rule set, first fill it the defaults from the code, then over ride from the database */
  310. map<int32, RuleSet *> zone_rule_sets; /* references to a zone's rule set. map<zone id, rule set> */
  311. };
  312. #endif