9
3

Rules.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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. #include <assert.h>
  17. #include "../../common/debug.h"
  18. #include "../../common/Log.h"
  19. #include "../../common/database.h"
  20. #include "Rules.h"
  21. extern RuleManager rule_manager;
  22. Rule::Rule() {
  23. category = 0;
  24. type = 0;
  25. strncpy(value, "", sizeof(value));
  26. strncpy(combined, "NONE", sizeof(combined));
  27. }
  28. Rule::Rule(int32 category, int32 type, const char *value, const char *combined) {
  29. this->category = category;
  30. this->type = type;
  31. strncpy(this->value, value, sizeof(this->value));
  32. strncpy(this->combined, combined, sizeof(this->combined));
  33. }
  34. Rule::Rule (Rule *rule_in) {
  35. category = rule_in->GetCategory();
  36. type = rule_in->GetType();
  37. strncpy(value, rule_in->GetValue(), sizeof(value));
  38. strncpy(combined, rule_in->GetCombined(), sizeof(combined));
  39. }
  40. Rule::~Rule() {
  41. }
  42. RuleSet::RuleSet() {
  43. id = 0;
  44. memset(name, 0, sizeof(name));
  45. m_rules.SetName("RuleSet::rules");
  46. }
  47. RuleSet::RuleSet(RuleSet *in_rule_set) {
  48. assert(in_rule_set);
  49. map<int32, map<int32, Rule *> > * in_rules = in_rule_set->GetRules();
  50. map<int32, map<int32, Rule *> >::iterator itr;
  51. map<int32, Rule *>::iterator itr2;
  52. Rule * rule;
  53. m_rules.SetName("RuleSet::rules");
  54. id = in_rule_set->GetID();
  55. strncpy(name, in_rule_set->GetName(), sizeof(name));
  56. for (itr = in_rules->begin(); itr != in_rules->end(); itr++) {
  57. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  58. rule = itr2->second;
  59. rules[rule->GetCategory()][rule->GetType()] = new Rule(rule);
  60. }
  61. }
  62. }
  63. RuleSet::~RuleSet() {
  64. ClearRules();
  65. }
  66. void RuleSet::CopyRulesInto(RuleSet *in_rule_set) {
  67. assert(in_rule_set);
  68. map<int32, map<int32, Rule *> > * in_rules = in_rule_set->GetRules();
  69. map<int32, map<int32, Rule *> >::iterator itr;
  70. map<int32, Rule *>::iterator itr2;
  71. Rule * rule;
  72. ClearRules();
  73. m_rules.writelock(__FUNCTION__, __LINE__);
  74. for (itr = in_rules->begin(); itr != in_rules->end(); itr++) {
  75. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  76. rule = itr2->second;
  77. rules[rule->GetCategory()][rule->GetType()] = new Rule(rule);
  78. }
  79. }
  80. m_rules.releasewritelock(__FUNCTION__, __LINE__);
  81. }
  82. void RuleSet::AddRule(Rule *rule) {
  83. int32 category, type;
  84. assert(rule);
  85. category = rule->GetCategory();
  86. type = rule->GetType();
  87. m_rules.writelock(__FUNCTION__, __LINE__);
  88. if (rules[category].count(type) == 0)
  89. rules[category][type] = rule;
  90. else
  91. rules[category][type]->SetValue(rule->GetValue());
  92. m_rules.releasewritelock(__FUNCTION__, __LINE__);
  93. }
  94. Rule * RuleSet::GetRule(int32 category, int32 type) {
  95. Rule *ret = 0;
  96. m_rules.readlock(__FUNCTION__, __LINE__);
  97. if (rules[category].count(type) > 0)
  98. ret = rules[category][type];
  99. m_rules.releasereadlock(__FUNCTION__, __LINE__);
  100. if (!ret)
  101. ret = rule_manager.GetBlankRule();
  102. LogWrite(RULESYS__DEBUG, 5, "Rules", "Rule: %s, Value: %s", ret->GetCombined(), ret->GetValue());
  103. return ret;
  104. }
  105. Rule * RuleSet::GetRule(const char *category, const char *type) {
  106. map<int32, map<int32, Rule *> >::iterator itr;
  107. map<int32, Rule *>::iterator itr2;
  108. char combined[256];
  109. Rule *ret = 0;
  110. snprintf(combined, sizeof(combined), "%s:%s", category, type);
  111. // Zero terminate ([max - 1] = 0) to prevent a warning/error
  112. combined[255] = 0;
  113. m_rules.readlock(__FUNCTION__, __LINE__);
  114. for (itr = rules.begin(); itr != rules.end(); itr++) {
  115. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  116. if (!strcmp(itr2->second->GetCombined(), combined)) {
  117. ret = itr2->second;
  118. break;
  119. }
  120. }
  121. }
  122. m_rules.releasereadlock(__FUNCTION__, __LINE__);
  123. return ret;
  124. }
  125. void RuleSet::ClearRules() {
  126. map<int32, map<int32, Rule *> >::iterator itr;
  127. map<int32, Rule *>::iterator itr2;
  128. m_rules.writelock(__FUNCTION__, __LINE__);
  129. for (itr = rules.begin(); itr != rules.end(); itr++) {
  130. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++)
  131. safe_delete(itr2->second);
  132. }
  133. rules.clear();
  134. m_rules.releasewritelock(__FUNCTION__, __LINE__);
  135. }
  136. RuleManager::RuleManager() {
  137. m_rule_sets.SetName("RuleManager::rule_sets");
  138. m_global_rule_set.SetName("RuleManager::global_rule_set");
  139. m_zone_rule_sets.SetName("RuleManager::zone_rule_sets");
  140. Init();
  141. }
  142. RuleManager::~RuleManager() {
  143. Flush();
  144. }
  145. void RuleManager::Init()
  146. {
  147. #define RULE_INIT(category, type, value) rules[category][type] = new Rule(category, type, value, #category ":" #type)
  148. /* CLIENT */
  149. RULE_INIT(R_Client, ShowWelcomeScreen, "0");
  150. RULE_INIT(R_Client, GroupSpellsTimer, "1000");
  151. RULE_INIT(R_Client, QuestQueueTimer, "50"); // in milliseconds
  152. /* FACTION */
  153. RULE_INIT(R_Faction, AllowFactionBasedCombat, "1");
  154. /* GUILD */
  155. RULE_INIT(R_Guild, MaxLevel, "50");
  156. RULE_INIT(R_Guild, MaxPlayers, "-1");
  157. /* PLAYER */
  158. RULE_INIT(R_Player, MaxLevel, "50");
  159. RULE_INIT(R_Player, MaxLevelOverrideStatus, "100");
  160. RULE_INIT(R_Player, VitalityAmount, ".5");
  161. RULE_INIT(R_Player, VitalityFrequency, "3600");
  162. RULE_INIT(R_Player, XPMultiplier, "1.0");
  163. RULE_INIT(R_Player, TSXPMultiplier, "1.0");
  164. RULE_INIT(R_Player, MaxAA, "320");
  165. RULE_INIT(R_Player, MaxClassAA, "100");
  166. RULE_INIT(R_Player, MaxSubclassAA, "100");
  167. RULE_INIT(R_Player, MaxShadowsAA, "70");
  168. RULE_INIT(R_Player, MaxHeroicAA, "50");
  169. RULE_INIT(R_Player, MaxTradeskillAA, "40");
  170. RULE_INIT(R_Player, MaxPrestigeAA, "25");
  171. RULE_INIT(R_Player, MaxTradeskillPrestigeAA, "25");
  172. RULE_INIT(R_Player, MinLastNameLevel, "20");
  173. RULE_INIT(R_Player, MaxLastNameLength, "20");
  174. RULE_INIT(R_Player, MinLastNameLength, "4");
  175. RULE_INIT(R_Player, DisableHouseAlignmentRequirement, "1");
  176. RULE_INIT(R_Player, MentorItemDecayRate, ".05"); // 5% per level lost when mentoring
  177. RULE_INIT(R_Player, TemporaryItemLogoutTime, "1800.0"); // time in seconds (double) for temporary item to decay after being logged out for a period of time, 30 min is the default
  178. RULE_INIT(R_Player, HeirloomItemShareExpiration, "172800.0"); // 2 days ('48 hours') in seconds
  179. RULE_INIT(R_Player, SwimmingSkillMinSpeed, "20");
  180. RULE_INIT(R_Player, SwimmingSkillMaxSpeed, "200");
  181. RULE_INIT(R_Player, SwimmingSkillMinBreathLength, "30");
  182. RULE_INIT(R_Player, SwimmingSkillMaxBreathLength, "1000");
  183. RULE_INIT(R_Player, AutoSkillUpBaseSkills, "0"); // when set to 1 we auto skill to max value on levelling up for armor,shield,class,weapon skills
  184. RULE_INIT(R_Player, MaxWeightStrengthMultiplier, "2.0"); // multiplier for strength to add to max weight, eg 25 str * 2.0 = 50 max weight + base weight
  185. RULE_INIT(R_Player, BaseWeight, "50"); // base weight per class, added to max weight with the strength multiplier
  186. RULE_INIT(R_Player, WeightPercentImpact, "0.01"); // overweight in stone speed impact (.01 = 1% per 1 stone)
  187. RULE_INIT(R_Player, WeightPercentCap, "0.95"); // cap total impact for being overweight (.95 = 95%)
  188. RULE_INIT(R_Player, CoinWeightPerStone, "40.0"); // coin weight per stone, 40.0 = 40 coins per 1 stone (per DoF client hover over)
  189. RULE_INIT(R_Player, WeightInflictsSpeed, "1"); // whether weight will inflict speed, 1 = on, 0 = off
  190. RULE_INIT(R_Player, LevelMasterySkillMultiplier, "5"); // multiplier for adventure level / recommended level when applying mastery damage to determine if they are in mastery range
  191. RULE_INIT(R_Player, TraitTieringSelection, "1"); // when set to true limited to single trait per group, otherwise you can freely select from any group
  192. RULE_INIT(R_Player, ClassicTraitLevelTable, "1"); // uses built in table based on Prima Guide, see Traits.cpp for more, otherwise uses the levels below
  193. RULE_INIT(R_Player, TraitFocusSelectLevel, "9"); // x levels to receive new trait of focus, eg level/rule, level 10, rule value 5, 10/5 = 2 focus traits available at level 10
  194. RULE_INIT(R_Player, TraitTrainingSelectLevel, "10"); // x levels to receive new trait of focus
  195. RULE_INIT(R_Player, TraitRaceSelectLevel, "10"); // x levels to receive new trait of focus
  196. RULE_INIT(R_Player, TraitCharacterSelectLevel, "10"); // x levels to receive new trait of focus
  197. RULE_INIT(R_Player, StartHPBase, "40");
  198. RULE_INIT(R_Player, StartPowerBase, "45");
  199. RULE_INIT(R_Player, StartHPLevelMod, "2.0");
  200. RULE_INIT(R_Player, StartPowerLevelMod, "2.1");
  201. RULE_INIT(R_Player, AllowPlayerEquipCombat, "1");
  202. RULE_INIT(R_Player, MaxTargetCommandDistance, "50.0"); // max distance allowed for /target command when target name is not in group
  203. RULE_INIT(R_Player, MinSkillMultiplierValue, "30"); // min skill we use as a multiplier to note the max skill allowed by the node
  204. RULE_INIT(R_Player, HarvestSkillUpMultiplier, "2.0"); /* multiplier for node to take the "min skill" max and use a multiplier to offset the max skill allowed to skill up on node.
  205. ** Eg. 50 min skill on node, 50*1.5=75, no one with higher than 75 skill gets a skill up
  206. */
  207. /* PVP */
  208. RULE_INIT(R_PVP, AllowPVP, "0");
  209. RULE_INIT(R_PVP, LevelRange, "4");
  210. RULE_INIT(R_PVP, InvisPlayerDiscoveryRange, "20"); // value > 0 sets radius inner to see, = 0 means always seen, -1 = never seen
  211. RULE_INIT(R_PVP, PVPMitigationModByLevel, "25"); // gives a bonus to mitigation for PVP combat to offset the percentage level * mod (default 25)
  212. /* COMBAT */
  213. RULE_INIT(R_Combat, MaxCombatRange, "4.0");
  214. RULE_INIT(R_Combat, DeathExperienceDebt, "50.00"); // divide by 100, 50/100 = .5% debt per pve death
  215. RULE_INIT(R_Combat, PVPDeathExperienceDebt, "25.00"); // divide by 100, 25/100 = .25% debt per pvp death
  216. RULE_INIT(R_Combat, GroupExperienceDebt, "0"); // set to 1 means we will share debt between the group
  217. RULE_INIT(R_Combat, ExperienceToDebt, "50.00"); // percentage of xp earned to debt vs obtained xp 50/100 = 50% to debt
  218. RULE_INIT(R_Combat, ExperienceDebtRecoveryPercent, "5.00"); // recovery percentage per period of time, 5/100 = 5% recovered (so if .5% debt, .5*.05 = .025, .5-.025=.475% debt left)
  219. RULE_INIT(R_Combat, ExperienceDebtRecoveryPeriod, "600"); // every 10 minutes (x*60 seconds) recover ExperienceDebtRecoveryPercent
  220. RULE_INIT(R_Combat, EnableSpiritShards, "1");
  221. RULE_INIT(R_Combat, SpiritShardSpawnScript, "SpawnScripts/Generic/SpiritShard.lua");
  222. RULE_INIT(R_Combat, ShardDebtRecoveryPercent, "25.00"); // recovered percentage of debt upon obtainig shard, 25/100 means 25%. If there is .5 DeathExperienceDebt, .5*25% = .125, .5 - .125 = .375
  223. RULE_INIT(R_Combat, ShardRecoveryByRadius, "1"); // allow shards to auto pick up by radius, not requiring to click/right click the shard
  224. RULE_INIT(R_Combat, ShardLifetime, "86400"); // default: 86400 seconds (one day)
  225. RULE_INIT(R_Combat, EffectiveMitigationCapLevel, "80"); // level multiplier for max effective cap, level * 80 (default)
  226. RULE_INIT(R_Combat, CalculatedMitigationCapLevel, "100"); // The cap to calculate your mitigation from is [level*100].
  227. RULE_INIT(R_Combat, MitigationLevelEffectivenessMax, "1.5"); // ratio victim level / attacker level for max effectiveness, when victim is higher level cap can reach 1.5
  228. RULE_INIT(R_Combat, MitigationLevelEffectivenessMin, ".5"); // ratio victim level / attacker level for min effectiveness
  229. RULE_INIT(R_Combat, MaxMitigationAllowed, ".75"); // percentage max mitigation allowed, eg. 75% of damage can be mitigated max in PVE
  230. RULE_INIT(R_Combat, MaxMitigationAllowedPVP, ".75"); // percentage max mitigation allowed, eg. 75% of damage can be mitigated max in PVP
  231. RULE_INIT(R_Combat, StrengthNPC, "10"); // divider for strength NPC only str/x = additional dmg to low/high dmg
  232. RULE_INIT(R_Combat, StrengthOther, "25"); // divider for strength other than NPC str/x = additional dmg to low/high dmg
  233. RULE_INIT(R_Combat, MaxSkillBonusByLevel, "1.5"); // Level * 1.5 = max bonus skill allowed
  234. RULE_INIT(R_Combat, LockedEncounterNoAttack, "1"); // when set to 1, players/group members not part of the encounter cannot attack until /yell
  235. /* SPAWN */
  236. RULE_INIT(R_Spawn, SpeedMultiplier, "300"); // note: this value was 1280 until 6/1/2009, then was 600 til Sep 2009, when it became 300...?
  237. RULE_INIT(R_Spawn, ClassicRegen, "0");
  238. RULE_INIT(R_Spawn, HailMovementPause, "5000"); // time in milliseconds the spawn is paused on hail
  239. RULE_INIT(R_Spawn, HailDistance, "5"); // max distance to hail a spawn/npc
  240. RULE_INIT(R_Spawn, UseHardCodeWaterModelType, "1"); // uses alternate method of setting water type by model type (hardcoded) versus relying on just DB
  241. RULE_INIT(R_Spawn, UseHardCodeFlyingModelType, "1"); // uses alternate method of setting flying type by model type (hardcoded) versus relying on just DB
  242. /* TIMER */
  243. /* UI */
  244. RULE_INIT(R_UI, MaxWhoResults, "20");
  245. RULE_INIT(R_UI, MaxWhoOverrideStatus, "200");
  246. /* WORLD */
  247. RULE_INIT(R_World, DefaultStartingZoneID, "1");
  248. RULE_INIT(R_World, EnablePOIDiscovery, "0");
  249. RULE_INIT(R_World, GamblingTokenItemID, "2");
  250. RULE_INIT(R_World, GuildAutoJoin, "0");
  251. RULE_INIT(R_World, GuildAutoJoinID, "1");
  252. RULE_INIT(R_World, GuildAutoJoinDefaultRankID, "7");
  253. RULE_INIT(R_World, MaxPlayers, "-1");
  254. RULE_INIT(R_World, MaxPlayersOverrideStatus, "100");
  255. RULE_INIT(R_World, ServerLocked, "0");
  256. RULE_INIT(R_World, ServerLockedOverrideStatus, "10");
  257. RULE_INIT(R_World, SyncZonesWithLogin, "1");
  258. RULE_INIT(R_World, SyncEquipWithLogin, "1");
  259. RULE_INIT(R_World, UseBannedIPsTable, "0");
  260. RULE_INIT(R_World, LinkDeadTimer, "120000"); // default: 2 minutes
  261. RULE_INIT(R_World, RemoveDisconnectedClientsTimer, "30000"); // default: 30 seconds
  262. RULE_INIT(R_World, PlayerCampTimer, "20"); // default: 20 seconds
  263. RULE_INIT(R_World, GMCampTimer, "1"); // default: 1 second
  264. RULE_INIT(R_World, AutoAdminPlayers, "0"); // default: No
  265. RULE_INIT(R_World, AutoAdminGMs, "0"); // default: No
  266. RULE_INIT(R_World, AutoAdminStatusValue, "10"); // default: 10 (CSR)
  267. RULE_INIT(R_World, DuskTime, "20:00"); // default: 8pm
  268. RULE_INIT(R_World, DawnTime, "8:00"); // default: 8am
  269. RULE_INIT(R_World, ThreadedLoad, "0"); // default: no threaded loading
  270. RULE_INIT(R_World, TradeskillSuccessChance, "87.0"); // default: 87% chance of success while crafting
  271. RULE_INIT(R_World, TradeskillCritSuccessChance, "2.0"); // default: 2% chance of critical success while crafting
  272. RULE_INIT(R_World, TradeskillFailChance, "10.0"); // default: 10% chance of failure while crafting
  273. RULE_INIT(R_World, TradeskillCritFailChance, "1.0"); // default: 1% chance of critical failure while crafting
  274. RULE_INIT(R_World, TradeskillEventChance, "15.0"); // default: 15% chance of a tradeskill event while crafting
  275. RULE_INIT(R_World, EditorURL, "www.eq2emulator.net"); // default: www.eq2emulator.net
  276. RULE_INIT(R_World, EditorIncludeID, "0"); // default: 0 (0 = disabled, 1 = enabled)
  277. RULE_INIT(R_World, EditorOfficialServer, "0"); // default: 0 (0 = disabled, 1 = enabled)
  278. RULE_INIT(R_World, SavePaperdollImage, "1"); // default: true
  279. RULE_INIT(R_World, SaveHeadshotImage, "1"); // default: true
  280. RULE_INIT(R_World, SendPaperdollImagesToLogin, "1"); // default: true
  281. RULE_INIT(R_World, TreasureChestDisabled, "0"); // default: false
  282. RULE_INIT(R_World, StartingZoneLanguages, "0"); // default: 0 (0 = Live Like, 1 = Starting City Based)
  283. RULE_INIT(R_World, StartingZoneRuleFlag, "0"); // default: 0 - match any options available, just based on version/other fields (will not force qc/outpost)
  284. // 1 - force split zones on alignment/deity despite client selection (queens colony/overlord outpost)
  285. // 4 - send to 'new' starting zones, won't support old clients
  286. // 8 - (isle of refuge)
  287. RULE_INIT(R_World, EnforceRacialAlignment, "1");
  288. RULE_INIT(R_World, MemoryCacheZoneMaps, "0"); // 0 disables caching the zone maps in memory, too many individual/unique zones entered may cause a lot of memory build up
  289. RULE_INIT(R_World, AutoLockEncounter, "0"); // When set to 0 we require player to attack to lock the encounter, otherwise if 1 then npc can auto lock encounter
  290. RULE_INIT(R_World, DisplayItemTiers, "1"); // Display item tiers when set to 1, otherwise do not
  291. RULE_INIT(R_World, LoreAndLegendAccept, "0"); // default: 0 - L&L quests accepted only through starter books. 1 - L&L quests can be started by examining bodyparts.
  292. //INSERT INTO `ruleset_details`(`id`, `ruleset_id`, `rule_category`, `rule_type`, `rule_value`, `description`) VALUES (NULL, '1', 'R_World', '', '', '')
  293. /* ZONE */
  294. RULE_INIT(R_Zone, MaxPlayers, "100");
  295. RULE_INIT(R_Zone, MinZoneLevelOverrideStatus, "1");
  296. RULE_INIT(R_Zone, MinZoneAccessOverrideStatus, "100");
  297. RULE_INIT(R_Zone, WeatherEnabled, "1"); // default: 1 (0 = disabled, 1 = enabled)
  298. RULE_INIT(R_Zone, WeatherType, "0"); // default: 1 (0 = normal, 1 = dynamic, 2 = random, 3 = chaotic)
  299. RULE_INIT(R_Zone, MinWeatherSeverity, "0.0"); // default: 0.0 or no weather
  300. RULE_INIT(R_Zone, MaxWeatherSeverity, "1.0"); // default: 1.0 or hard rain (range 0.0 - 1.0, rain starts at 0.75)
  301. RULE_INIT(R_Zone, WeatherChangeFrequency, "300"); // default: 5 minutes
  302. RULE_INIT(R_Zone, WeatherChangePerInterval, "0.02"); // default: 0.02 (slight changes)
  303. RULE_INIT(R_Zone, WeatherChangeChance, "20"); // default: 20% (in whole percents)
  304. RULE_INIT(R_Zone, WeatherDynamicMaxOffset, "0.08"); // default: 0.08 - dynamic weather changes can only change this max amount
  305. RULE_INIT(R_Zone, SpawnUpdateTimer, "50"); // default: 50ms - how often to check for spawn update sends
  306. RULE_INIT(R_Zone, CheckAttackNPC, "2000"); // default: 2 seconds, how often to for NPCs to attack eachother
  307. RULE_INIT(R_Zone, CheckAttackPlayer, "2000"); // default: 2 seconds, how often to check for NPCs to attack players
  308. RULE_INIT(R_Zone, HOTime, "10.0"); // default: 10 seconds, time to complete the HO wheel before it expires
  309. /* ZONE TIMERS */
  310. RULE_INIT(R_Zone, RegenTimer, "6000");
  311. RULE_INIT(R_Zone, ClientSaveTimer, "60000");
  312. RULE_INIT(R_Zone, ShutdownDelayTimer, "120000");
  313. RULE_INIT(R_Zone, WeatherTimer, "60000"); // default: 1 minute
  314. RULE_INIT(R_Zone, SpawnDeleteTimer, "30000"); // default: 30 seconds, how long a spawn pointer is held onto after being removed from the world before deleting it
  315. RULE_INIT(R_Zone, UseMapUnderworldCoords, "1"); // use maps lowest Y coordinate to establish underworld markers
  316. RULE_INIT(R_Zone, MapUnderworldCoordOffset, "-200.0"); // adds (or in the case of negative value subtracts) so that the underworld marker is lower when map is using its lowest Y coordinate
  317. RULE_INIT(R_Loot, LootRadius, "5.0");
  318. RULE_INIT(R_Loot, AutoDisarmChest, "1");
  319. RULE_INIT(R_Loot, ChestTriggerRadiusGroup, "10.0"); // radius at which chest will trigger against group members
  320. RULE_INIT(R_Loot, ChestUnlockedTimeDrop, "1200"); // time in seconds, 20 minutes by default, triggers only if AllowChestUnlockByDropTime is 1
  321. RULE_INIT(R_Loot, AllowChestUnlockByDropTime, "1"); // when set to 1 we will start a countdown timer to allow anyone to loot once ChestUnlockedTimeDrop elapsed
  322. RULE_INIT(R_Loot, ChestUnlockedTimeTrap, "600"); // time in seconds, 10 minutes by default
  323. RULE_INIT(R_Loot, AllowChestUnlockByTrapTime, "1"); // when set to 1 we will allow unlocking the chest to all players after the trap is triggered (or chest is open) and period ChestUnlockedTimeTrap elapsed
  324. RULE_INIT(R_Loot, SkipLootGrayMob, "1");
  325. RULE_INIT(R_Loot, LootDistributionTime, "120"); // time in seconds that we allow the group to determine their loot decision (lotto/need/greed/decline).
  326. RULE_INIT(R_Spells, NoInterruptBaseChance, "50");
  327. RULE_INIT(R_Spells, EnableFizzleSpells, "1"); // enables/disables the 'fizzling' of spells based on can_fizzle in the spells table. This also enables increasing specialized skills for classes based on spells/abilities.
  328. RULE_INIT(R_Spells, DefaultFizzleChance, "10.0"); // default percentage x / 100, eg 10% is 10.0
  329. RULE_INIT(R_Spells, FizzleMaxSkill, "1.2"); // 1.0 is 100%, 1.2 is 120%, so you get 120% your max skill against a spell, no fizzle
  330. RULE_INIT(R_Spells, FizzleDefaultSkill, ".2"); // offset against MaxSkill to average out to 100%, default of .2f so we don't go over the threshold if no skill
  331. RULE_INIT(R_Spells, EnableCrossZoneGroupBuffs, "0"); // enables/disables allowing cross zone group buffs
  332. RULE_INIT(R_Spells, EnableCrossZoneTargetBuffs, "0"); // enables/disables allowing cross zone target buffs
  333. RULE_INIT(R_Spells, PlayerSpellSaveStateWaitInterval, "100"); // time in milliseconds we wait before performing a save when the spell save trigger is activated, allows additional actions to take place until the cap is hit
  334. RULE_INIT(R_Spells, PlayerSpellSaveStateCap, "1000"); // sets a maximum wait time before we queue a spell state save to the DB, given a lot can go on in a short period with players especially in combat, maybe good to have this at a higher interval.
  335. RULE_INIT(R_Spells, RequirePreviousTierScribe, "0"); // requires step up apprentice -> apprentice (handcrafted?) -> journeyman (handcrafted?) -> adept -> expert -> master
  336. RULE_INIT(R_Spells, CureSpellID, "110003"); // Base Cure spell that was used after they removed cure types
  337. RULE_INIT(R_Spells, CureCurseSpellID, "110004"); // Curse Spell ID in the spells database
  338. RULE_INIT(R_Spells, CureNoxiousSpellID, "110005"); // Noxious/Poison Spell ID in the spells database
  339. RULE_INIT(R_Spells, CureMagicSpellID, "210006"); // Magic/Elemental Spell ID in the spells database
  340. RULE_INIT(R_Spells, CureTraumaSpellID, "0"); // Trauma/Mental Spell ID in the spells database
  341. RULE_INIT(R_Spells, CureArcaneSpellID, "0"); // Arcane/Heat Spell ID in the spells database
  342. RULE_INIT(R_Spells, MinistrationSkillID, "366253016"); // ministration skill id used to map power reduction rule MinistrationPowerReductionMax
  343. RULE_INIT(R_Spells, MinistrationPowerReductionMax, "15.0"); // max percentage of power reduction for spells with ministration mastery skill (default is 15.0 for 15%)
  344. RULE_INIT(R_Spells, MinistrationPowerReductionSkill, "25"); // divides by integer value to establish how much skill req for higher power reduction
  345. RULE_INIT(R_Spells, MasterSkillReduceSpellResist, "25"); // divides by integer value to establish how much skill bonus for reducing spell resistance on target
  346. RULE_INIT(R_Expansion, GlobalExpansionFlag, "0");
  347. RULE_INIT(R_Expansion, GlobalHolidayFlag, "0");
  348. RULE_INIT(R_World, DatabaseVersion, "0");
  349. //devn00b
  350. RULE_INIT(R_Discord, DiscordEnabled, "0"); //Enable/Disable built in discord bot.
  351. RULE_INIT(R_Discord, DiscordWebhookURL, "None"); //Webhook url used for server -> discord messages.
  352. RULE_INIT(R_Discord, DiscordBotToken, "None"); //Bot token used to connect to discord and provides discord -> server messages.
  353. RULE_INIT(R_Discord, DiscordChannel, "Discord"); // in-game channel used for server -> discord messages.
  354. RULE_INIT(R_Discord, DiscordListenChan, "0"); // Discord ChannelID used for discord->server messages.
  355. #undef RULE_INIT
  356. }
  357. void RuleManager::Flush(bool reinit)
  358. {
  359. map<int32, map<int32, Rule*> >::iterator itr;
  360. map<int32, Rule*>::iterator itr2;
  361. for (itr = rules.begin(); itr != rules.end(); itr++) {
  362. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++)
  363. safe_delete(itr2->second);
  364. }
  365. rules.clear();
  366. ClearRuleSets();
  367. ClearZoneRuleSets();
  368. if (reinit)
  369. Init();
  370. }
  371. void RuleManager::LoadCodedDefaultsIntoRuleSet(RuleSet *rule_set) {
  372. map<int32, map<int32, Rule *> >::iterator itr;
  373. map<int32, Rule *>::iterator itr2;
  374. assert(rule_set);
  375. for (itr = rules.begin(); itr != rules.end(); itr++) {
  376. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++)
  377. rule_set->AddRule(new Rule(itr2->second));
  378. }
  379. }
  380. bool RuleManager::AddRuleSet(RuleSet *rule_set) {
  381. bool ret = false;
  382. int32 id;
  383. assert(rule_set);
  384. id = rule_set->GetID();
  385. m_rule_sets.writelock(__FUNCTION__, __LINE__);
  386. if (rule_sets.count(id) == 0) {
  387. rule_sets[id] = rule_set;
  388. ret = true;
  389. }
  390. m_rule_sets.releasewritelock(__FUNCTION__, __LINE__);
  391. return ret;
  392. }
  393. int32 RuleManager::GetNumRuleSets() {
  394. int32 ret;
  395. m_rule_sets.readlock(__FUNCTION__, __LINE__);
  396. ret = rule_sets.size();
  397. m_rule_sets.releasereadlock(__FUNCTION__, __LINE__);
  398. return ret;
  399. }
  400. void RuleManager::ClearRuleSets() {
  401. map<int32, RuleSet *>::iterator itr;
  402. m_rule_sets.writelock(__FUNCTION__, __LINE__);
  403. for (itr = rule_sets.begin(); itr != rule_sets.end(); itr++)
  404. safe_delete(itr->second);
  405. rule_sets.clear();
  406. m_rule_sets.releasewritelock(__FUNCTION__, __LINE__);
  407. }
  408. bool RuleManager::SetGlobalRuleSet(int32 rule_set_id) {
  409. if (rule_sets.count(rule_set_id) == 0)
  410. return false;
  411. global_rule_set.CopyRulesInto(rule_sets[rule_set_id]);
  412. return true;
  413. }
  414. Rule * RuleManager::GetGlobalRule(int32 category, int32 type) {
  415. return global_rule_set.GetRule(category, type);
  416. }
  417. Rule * RuleManager::GetGlobalRule(const char* category, const char* type) {
  418. return global_rule_set.GetRule(category, type);
  419. }
  420. bool RuleManager::SetZoneRuleSet(int32 zone_id, int32 rule_set_id) {
  421. bool ret = true;
  422. RuleSet *rule_set;
  423. m_rule_sets.readlock(__FUNCTION__, __LINE__);
  424. if (rule_sets.count(rule_set_id) == 0)
  425. ret = false;
  426. rule_set = rule_sets[rule_set_id];
  427. if (ret) {
  428. m_zone_rule_sets.writelock(__FUNCTION__, __LINE__);
  429. zone_rule_sets[zone_id] = rule_set;
  430. m_zone_rule_sets.releasewritelock(__FUNCTION__, __LINE__);
  431. }
  432. m_rule_sets.releasereadlock(__FUNCTION__, __LINE__);
  433. return ret;
  434. }
  435. Rule * RuleManager::GetZoneRule(int32 zone_id, int32 category, int32 type) {
  436. Rule *ret = 0;
  437. /* first try to get the zone rule */
  438. if(zone_id) {
  439. m_zone_rule_sets.readlock(__FUNCTION__, __LINE__);
  440. if (zone_rule_sets.count(zone_id) > 0)
  441. ret = zone_rule_sets[zone_id]->GetRule(category, type);
  442. m_zone_rule_sets.releasereadlock(__FUNCTION__, __LINE__);
  443. }
  444. if(!ret) {
  445. ret = GetGlobalRule(category, type);
  446. }
  447. return ret;
  448. }
  449. void RuleManager::ClearZoneRuleSets() {
  450. m_zone_rule_sets.writelock(__FUNCTION__, __LINE__);
  451. zone_rule_sets.clear();
  452. m_zone_rule_sets.releasewritelock(__FUNCTION__, __LINE__);
  453. }