Rules.h 8.3 KB

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