Rules.h 7.6 KB

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