Rules.h 8.0 KB

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