9
3

Rules.h 8.3 KB

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