Rules.h 7.8 KB

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