Rules.h 8.3 KB

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