Rules.h 7.7 KB

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