Rules.h 7.5 KB

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