Rules.h 7.3 KB

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