Rules.h 8.0 KB

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