Rules.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. /* ZONE */
  154. MinZoneLevelOverrideStatus,
  155. MinZoneAccessOverrideStatus,
  156. XPMultiplier,
  157. TSXPMultiplier,
  158. WeatherEnabled,
  159. WeatherType,
  160. MinWeatherSeverity,
  161. MaxWeatherSeverity,
  162. WeatherChangeFrequency,
  163. WeatherChangePerInterval,
  164. WeatherDynamicMaxOffset,
  165. WeatherChangeChance,
  166. SpawnUpdateTimer,
  167. CheckAttackPlayer,
  168. CheckAttackNPC,
  169. HOTime,
  170. UseMapUnderworldCoords,
  171. MapUnderworldCoordOffset,
  172. /* LOOT */
  173. LootRadius,
  174. AutoDisarmChest, // if enabled disarm only works if you right click and disarm, clicking and opening chest won't attempt auto disarm
  175. ChestTriggerRadiusGroup,
  176. ChestUnlockedTimeDrop,
  177. AllowChestUnlockByDropTime,
  178. ChestUnlockedTimeTrap,
  179. AllowChestUnlockByTrapTime,
  180. /* SPELLS */
  181. NoInterruptBaseChance,
  182. EnableFizzleSpells,
  183. DefaultFizzleChance,
  184. FizzleMaxSkill,
  185. FizzleDefaultSkill,
  186. EnableCrossZoneGroupBuffs,
  187. EnableCrossZoneTargetBuffs,
  188. PlayerSpellSaveStateWaitInterval,
  189. PlayerSpellSaveStateCap,
  190. RequirePreviousTierScribe,
  191. CureSpellID,
  192. CureCurseSpellID,
  193. CureNoxiousSpellID,
  194. CureMagicSpellID,
  195. CureTraumaSpellID,
  196. CureArcaneSpellID,
  197. MinistrationSkillID,
  198. MinistrationPowerReductionMax,
  199. MinistrationPowerReductionSkill,
  200. MasterSkillReduceSpellResist,
  201. /* ZONE TIMERS */
  202. RegenTimer,
  203. ClientSaveTimer,
  204. ShutdownDelayTimer,
  205. WeatherTimer,
  206. SpawnDeleteTimer,
  207. GlobalExpansionFlag,
  208. GlobalHolidayFlag,
  209. DatabaseVersion,
  210. SkipLootGrayMob
  211. };
  212. class Rule {
  213. public:
  214. Rule();
  215. Rule(int32 category, int32 type, const char *value, const char *combined);
  216. Rule (Rule *rule_in);
  217. virtual ~Rule();
  218. void SetValue(const char *value) {strncpy(this->value, value, sizeof(this->value));}
  219. int32 GetCategory() {return category;}
  220. int32 GetType() {return type;}
  221. const char * GetValue() {return value;}
  222. const char * GetCombined() {return combined;}
  223. int8 GetInt8() {return (int8)atoul(value);}
  224. int16 GetInt16() {return (int16)atoul(value);}
  225. int32 GetInt32() {return (int32)atoul(value);}
  226. int64 GetInt64() {return (int64)atoi64(value);}
  227. sint8 GetSInt8() {return (sint8)atoi(value);}
  228. sint16 GetSInt16() {return (sint16)atoi(value);}
  229. sint32 GetSInt32() {return (sint32)atoi(value);}
  230. sint64 GetSInt64() {return (sint64)atoi64(value);}
  231. bool GetBool() {return atoul(value) > 0 ? true : false;}
  232. float GetFloat() {return atof(value);}
  233. char GetChar() {return value[0];}
  234. const char * GetString() {return value;}
  235. private:
  236. int32 category;
  237. int32 type;
  238. char value[64];
  239. char combined[256];
  240. };
  241. class RuleSet {
  242. public:
  243. RuleSet();
  244. RuleSet(RuleSet *in_rule_set);
  245. virtual ~RuleSet();
  246. void CopyRulesInto(RuleSet *in_rule_set);
  247. void SetID(int32 id) {this->id = id;}
  248. void SetName(const char *name) {strncpy(this->name, name, sizeof(this->name));}
  249. int32 GetID() {return id;}
  250. const char *GetName() {return name;}
  251. void AddRule(Rule *rule);
  252. Rule * GetRule(int32 category, int32 type);
  253. Rule * GetRule(const char *category, const char *type);
  254. void ClearRules();
  255. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  256. private:
  257. int32 id;
  258. char name[64];
  259. Mutex m_rules;
  260. map<int32, map<int32, Rule *> > rules;
  261. };
  262. class RuleManager {
  263. public:
  264. RuleManager();
  265. virtual ~RuleManager();
  266. void Init();
  267. void Flush(bool reinit=false);
  268. void LoadCodedDefaultsIntoRuleSet(RuleSet *rule_set);
  269. bool AddRuleSet(RuleSet *rule_set);
  270. int32 GetNumRuleSets();
  271. void ClearRuleSets();
  272. Rule * GetBlankRule() {return &blank_rule;}
  273. bool SetGlobalRuleSet(int32 rule_set_id);
  274. Rule * GetGlobalRule(int32 category, int32 type);
  275. Rule * GetGlobalRule(const char* category, const char* type);
  276. bool SetZoneRuleSet(int32 zone_id, int32 rule_set_id);
  277. Rule * GetZoneRule(int32 zone_id, int32 category, int32 type);
  278. void ClearZoneRuleSets();
  279. RuleSet * GetGlobalRuleSet() {return &global_rule_set;}
  280. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  281. private:
  282. Mutex m_rule_sets;
  283. Mutex m_global_rule_set;
  284. Mutex m_zone_rule_sets;
  285. Rule blank_rule; /* READ ONLY */
  286. map<int32, map<int32, Rule *> > rules; /* all of the rules loaded with their defaults (FROM THE CODE). map<category, map<type, rule>> */
  287. map<int32, RuleSet *> rule_sets; /* all of the possible rule sets from the database. map<rule set id, rule set> */
  288. RuleSet global_rule_set; /* the global rule set, first fill it the defaults from the code, then over ride from the database */
  289. map<int32, RuleSet *> zone_rule_sets; /* references to a zone's rule set. map<zone id, rule set> */
  290. };
  291. #endif