9
3

Rules.h 8.4 KB

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