Rules.h 7.4 KB

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