From a204c827b5476398f29ee9f4a48578666ed0f124 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 18 May 2021 13:33:55 -0400 Subject: [PATCH] Scripts/Commands: New command: .debug threatinfo Port From (https://github.com/TrinityCore/TrinityCore/commit/e090c9a00eab7af40ba1b4090d5b5a456a3e4b33) --- Source/Framework/Constants/AccountConst.cs | 2 +- Source/Game/Chat/Commands/DebugCommands.cs | 79 ++++++++++++++++++- Source/Game/Combat/ThreatManager.cs | 8 +- sql/base/auth_database.sql | 3 + .../20061_2020_08_14/2018_01_09_00_auth.sql | 8 ++ ...021_05_16_11_world_2018_01_09_00_world.sql | 6 ++ 6 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 sql/old/8.x/auth/20061_2020_08_14/2018_01_09_00_auth.sql create mode 100644 sql/updates/world/master/2021_05_16_11_world_2018_01_09_00_world.sql diff --git a/Source/Framework/Constants/AccountConst.cs b/Source/Framework/Constants/AccountConst.cs index dccd715a5..e0bcbb4d5 100644 --- a/Source/Framework/Constants/AccountConst.cs +++ b/Source/Framework/Constants/AccountConst.cs @@ -775,7 +775,7 @@ namespace Framework.Constants CommandReloadQuestGreetingLocale = 867, // Reserved CommandModifyPower = 868, CommandDebugSendPlayerChoice = 869, - CommandDebugThreatinfo = 870, // reserved + CommandDebugThreatinfo = 870, CommandDebugInstancespawn = 871, // reserved CommandServerDebug = 872, CommandReloadCreatureMovementOverride = 873, diff --git a/Source/Game/Chat/Commands/DebugCommands.cs b/Source/Game/Chat/Commands/DebugCommands.cs index eaeb9beff..983a467a5 100644 --- a/Source/Game/Chat/Commands/DebugCommands.cs +++ b/Source/Game/Chat/Commands/DebugCommands.cs @@ -24,6 +24,7 @@ using Game.DataStorage; using Game.Entities; using Game.Maps; using Game.Networking.Packets; +using Game.Spells; using System; using System.Collections.Generic; using System.Text; @@ -495,7 +496,7 @@ namespace Game.Chat if (unit) { Player player = handler.GetSession().GetPlayer(); - handler.SendSysMessage($"Checking LoS {player.GetName()} -> {unit.GetName()}:"); + handler.SendSysMessage($"Checking LoS {player.GetName()} . {unit.GetName()}:"); handler.SendSysMessage($" VMAP LoS: {(player.IsWithinLOSInMap(unit, LineOfSightChecks.Vmap) ? "clear" : "obstructed")}"); handler.SendSysMessage($" GObj LoS: {(player.IsWithinLOSInMap(unit, LineOfSightChecks.Gobject) ? "clear" : "obstructed")}"); handler.SendSysMessage($"{unit.GetName()} is {(player.IsWithinLOSInMap(unit) ? "" : "not ")}in line of sight of {player.GetName()}."); @@ -832,6 +833,82 @@ namespace Game.Chat return true; } + [Command("threatinfo", RBACPermissions.CommandDebugThreatinfo)] + static bool HandleDebugThreatInfoCommand(StringArguments args, CommandHandler handler) + { + Unit target = handler.GetSelectedUnit(); + if (target == null) + { + handler.SendSysMessage(CypherStrings.SelectCharOrCreature); + return false; + } + + handler.SendSysMessage($"Threat info for {target.GetName()} ({target.GetGUID()}):"); + + ThreatManager mgr = target.GetThreatManager(); + + // _singleSchoolModifiers + { + var mods = mgr._singleSchoolModifiers; + handler.SendSysMessage(" - Single-school threat modifiers:"); + handler.SendSysMessage($" |-- Physical: {mods[(int)SpellSchools.Normal] * 100.0f:0.##}"); + handler.SendSysMessage($" |-- Holy : {mods[(int)SpellSchools.Holy] * 100.0f:0.##}"); + handler.SendSysMessage($" |-- Fire : {mods[(int)SpellSchools.Fire] * 100.0f:0.##}"); + handler.SendSysMessage($" |-- Nature : {mods[(int)SpellSchools.Nature] * 100.0f:0.##}"); + handler.SendSysMessage($" |-- Frost : {mods[(int)SpellSchools.Frost] * 100.0f:0.##}"); + handler.SendSysMessage($" |-- Shadow : {mods[(int)SpellSchools.Shadow] * 100.0f:0.##}"); + handler.SendSysMessage($" |-- Arcane : {mods[(int)SpellSchools.Arcane] * 100.0f:0.##}"); + } + + // _multiSchoolModifiers + { + var mods = mgr._multiSchoolModifiers; + handler.SendSysMessage($"- Multi-school threat modifiers ({mods.Count} entries):"); + + foreach (var pair in mods) + handler.SendSysMessage($" |-- Mask {pair.Key:X}: {pair.Value:0.XX}"); + } + + // _redirectInfo + { + var redirectInfo = mgr._redirectInfo; + if (redirectInfo.Empty()) + handler.SendSysMessage(" - No redirects being applied"); + else + { + handler.SendSysMessage($" - {redirectInfo.Count} redirects being applied:"); + foreach (var pair in redirectInfo) + { + Unit unit = Global.ObjAccessor.GetUnit(target, pair.Item1); + handler.SendSysMessage($" |-- {pair.Item2:D2} to {(unit != null ? unit.GetName() : pair.Item1)}"); + } + } + } + + // _redirectRegistry + { + var redirectRegistry = mgr._redirectRegistry; + if (redirectRegistry.Empty()) + handler.SendSysMessage(" - No redirects are registered"); + else + { + handler.SendSysMessage($" - {redirectRegistry.Count} spells may have redirects registered"); + foreach (var outerPair in redirectRegistry) // (spellId, (guid, pct)) + { + SpellInfo spell = Global.SpellMgr.GetSpellInfo(outerPair.Key, Difficulty.None); + handler.SendSysMessage($" |-- #{outerPair.Key} {(spell != null ? spell.SpellName[Global.WorldMgr.GetDefaultDbcLocale()] : "")} ({outerPair.Value.Count} entries):"); + foreach (var innerPair in outerPair.Value) // (guid, pct) + { + Unit unit = Global.ObjAccessor.GetUnit(target, innerPair.Key); + handler.SendSysMessage($" |-- {innerPair.Value} to {(unit != null ? unit.GetName() : innerPair.Key)}"); + } + } + } + } + + return true; + } + [Command("transport", RBACPermissions.CommandDebugTransport)] static bool HandleDebugTransportCommand(StringArguments args, CommandHandler handler) { diff --git a/Source/Game/Combat/ThreatManager.cs b/Source/Game/Combat/ThreatManager.cs index 98d81756c..4bed1dd06 100644 --- a/Source/Game/Combat/ThreatManager.cs +++ b/Source/Game/Combat/ThreatManager.cs @@ -40,11 +40,11 @@ namespace Game.Combat ThreatReference _currentVictimRef; Dictionary _threatenedByMe = new(); // these refs are entries for myself on other units' threat lists - float[] _singleSchoolModifiers = new float[(int)SpellSchools.Max]; // most spells are single school - we pre-calculate these and store them - volatile Dictionary _multiSchoolModifiers = new(); // these are calculated on demand + public float[] _singleSchoolModifiers = new float[(int)SpellSchools.Max]; // most spells are single school - we pre-calculate these and store them + public volatile Dictionary _multiSchoolModifiers = new(); // these are calculated on demand - List> _redirectInfo = new(); // current redirection targets and percentages (updated from registry in ThreatManager::UpdateRedirectInfo) - Dictionary> _redirectRegistry = new(); // spellid . (victim . pct); all redirection effects on us (removal individually managed by spell scripts because blizzard is dumb) + public List> _redirectInfo = new(); // current redirection targets and percentages (updated from registry in ThreatManager::UpdateRedirectInfo) + public Dictionary> _redirectRegistry = new(); // spellid . (victim . pct); all redirection effects on us (removal individually managed by spell scripts because blizzard is dumb) public static bool CanHaveThreatList(Unit who) { diff --git a/sql/base/auth_database.sql b/sql/base/auth_database.sql index bc508852c..7da5fa1a7 100644 --- a/sql/base/auth_database.sql +++ b/sql/base/auth_database.sql @@ -1195,6 +1195,7 @@ INSERT INTO `rbac_linked_permissions` VALUES (196,869), (196,872), (196,881), +(196,870), (197,232), (197,236), (197,237), @@ -2123,6 +2124,7 @@ INSERT INTO `rbac_permissions` VALUES (866,'Command: list spawnpoints'), (868,'Command: modify power'), (869,'Command: debug send playerchoice'), +(870,'Command: debug threatinfo'), (872,'Command: server debug'), (881,'Command: reload vehicle_template'); /*!40000 ALTER TABLE `rbac_permissions` ENABLE KEYS */; @@ -2336,6 +2338,7 @@ INSERT INTO `updates` VALUES ('2017_12_30_01_auth.sql','1E11C78BA6D1D8E8CED7423DF92D1D197D6061EE','ARCHIVED','2017-12-30 23:00:00',0), ('2017_12_31_00_auth.sql','1721ACBD35EB95FAE33B9E95F8C4E4B1FB70A5E4','ARCHIVED','2017-12-31 20:15:23',0), ('2018_01_02_00_auth.sql','CD9B826B9D95697DC412DEF780E814FA3991D6CD','ARCHIVED','2018-01-02 20:40:37',0), +('2018_01_09_00_auth.sql','A5D4EC8FCFAB4F2DCE70EDCAD1ACBFB484FD68D5','RELEASED','2018-01-09 00:00:00',0), ('2018_02_18_00_auth.sql','8489DD3EFFE14A7486B593435F0BA2BC69B6EABF','ARCHIVED','2018-02-18 16:35:55',0), ('2018_02_19_00_auth.sql','07CE658C5EF88693D3C047EF8E724F94ADA74C15','ARCHIVED','2018-02-19 22:33:32',0), ('2018_02_28_00_auth.sql','E92EF4ABF7FA0C66649E1633DD0459F44C09EB83','ARCHIVED','2018-02-28 23:07:59',0), diff --git a/sql/old/8.x/auth/20061_2020_08_14/2018_01_09_00_auth.sql b/sql/old/8.x/auth/20061_2020_08_14/2018_01_09_00_auth.sql new file mode 100644 index 000000000..aac66eaaa --- /dev/null +++ b/sql/old/8.x/auth/20061_2020_08_14/2018_01_09_00_auth.sql @@ -0,0 +1,8 @@ +-- +DELETE FROM `rbac_permissions` WHERE `id`=870; +INSERT INTO `rbac_permissions` (`id`,`name`) VALUES +(870, 'Command: debug threatinfo'); + +DELETE FROM `rbac_linked_permissions` WHERE `linkedId`=870; +INSERT INTO `rbac_linked_permissions` (`id`,`linkedId`) VALUES +(196,870); diff --git a/sql/updates/world/master/2021_05_16_11_world_2018_01_09_00_world.sql b/sql/updates/world/master/2021_05_16_11_world_2018_01_09_00_world.sql new file mode 100644 index 000000000..3e524284d --- /dev/null +++ b/sql/updates/world/master/2021_05_16_11_world_2018_01_09_00_world.sql @@ -0,0 +1,6 @@ +-- +DELETE FROM `command` WHERE `name`="debug threatinfo"; +INSERT INTO `command` (`name`,`permission`,`help`) VALUES +('debug threatinfo', 870, 'Syntax: .debug threatinfo + +Displays various debug information about the target\'s threat state, modifiers, redirects and similar.');