From f1425fc5e26f8b10593ebe66e8fafc4e0fe183af Mon Sep 17 00:00:00 2001 From: Karrz1 <127596890+Karrz1@users.noreply.github.com> Date: Fri, 13 Nov 2026 21:39:00 +0000 Subject: [PATCH] Combat-only enemy nameplates: the server hides the plate of mobs outside your fight With Enemy Unit Nameplates on and Always Show Nameplates off the client shows a health bar over every hostile mob in range. The client-side CVar switch of the first version could not fix that: once combat started every nearby enemy got a bar, also one that never joined the fight. The server now decides per viewer. A player who asks for it (Player::SetCombatPlateFilter, the ForeverBots add-on's PLATES request) gets UNIT_FLAG3_FORCE_HIDE_NAMEPLATE on every attackable NPC that is in no live fight with him, his pet or a member of his group on the map. It is checked when the NPC comes into view and four times a second after, so a mob that joins the fight gets its bar and the client draws the plate and the plain name itself. Script-forced plates and player- controlled units keep what they have. A UI reload clears it; the add-on asks again on every loading screen and when either setting changes. The add-on drops the CVar switch: the filter is on by default and only asks with those two settings; /fb plates on|off|status. --- .../Addon/ForeverBots/ForeverBots.lua | 103 ++++++++++-------- .../Addon/ForeverBots/ForeverBots_Net.lua | 2 +- .../Addon/ForeverBots/Locale_ruRU.lua | 8 +- .../PlayerbotV2/Addon/ForeverBots/README.md | 6 +- .../PlayerbotV2/Session/AddonControl.cpp | 23 ++++ 5 files changed, 95 insertions(+), 47 deletions(-) diff --git a/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.lua b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.lua index af7f7e77a7..add0454f79 100644 --- a/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.lua +++ b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.lua @@ -2062,55 +2062,61 @@ local function Toggle() UI.SetWindowShown(not open) end --- Enemy nameplates in combat only (/fb plates on|off). The client's own "only in combat" setting does not work on this build --- (always on or always off), so the add-on switches the CVar itself: on when combat starts, off when it ends. Off by default; --- turning it off puts back the setting the player had before. A CVar can be set at PLAYER_REGEN_DISABLED (a moment before the --- lockdown) and at PLAYER_REGEN_ENABLED (after it); a set refused during a lockdown is done on the next REGEN_ENABLED. -local PLATES_CVAR = "nameplateShowEnemies" -local function PlatesSet(on) - local v = on and "1" or "0" - if InCombatLockdown and InCombatLockdown() then - UI.platesPending = v - return false - end - UI.platesPending = nil - if C_CVar and C_CVar.SetCVar then C_CVar.SetCVar(PLATES_CVAR, v) elseif SetCVar then SetCVar(PLATES_CVAR, v) end - return true +-- Enemy nameplates in combat only. The client's own setting for it (Enemy Unit Nameplates on, Always Show Nameplates off) shows a +-- bar over every hostile mob in range, fighting you or not. With those two settings the add-on asks the server to filter +-- (PLATES|1, Player::SetCombatPlateFilter): a mob outside your, your pet's or your group's fight keeps its plain red name and one +-- that joins the fight gets its bar; the client draws both itself. Any other setting: no filter (PLATES|0). On by default; +-- /fb plates off leaves the client's own behaviour. The server forgets it on a UI reload, so it is asked again on every +-- loading screen and whenever one of the two settings changes. Up to three tries when no answer comes. +UI.plates = { asked = nil, confirmed = nil, tries = 0, gen = 0 } +local function CVarOn(name) + if C_CVar and C_CVar.GetCVarBool then return C_CVar.GetCVarBool(name) and true or false end + return GetCVar and GetCVar(name) == "1" or false end -local function PlatesGet() - local v = (C_CVar and C_CVar.GetCVar and C_CVar.GetCVar(PLATES_CVAR)) or (GetCVar and GetCVar(PLATES_CVAR)) - return v == "1" +local function PlatesWanted() + return ForeverBotsDB.combatPlates ~= false and CVarOn("nameplateShowEnemies") and not CVarOn("nameplateShowAll") +end +function UI.PlatesSync(force) + local Net = Cmd.ns.Net + if not Net then return end + local want = PlatesWanted() + local st = UI.plates + if not force and st.asked == want and st.confirmed == want then return end + st.asked, st.confirmed, st.tries = want, nil, 0 + st.gen = st.gen + 1 + local gen = st.gen + local function try() + if gen ~= st.gen then return end + st.tries = st.tries + 1 + Net.EnsureMode(function() + Net.Request("PLATES", { want and "1" or "0" }, function(fields) + if gen ~= st.gen then return end + if fields and fields[1] == (want and "1" or "0") then + st.confirmed = want + elseif st.tries < 3 and C_Timer and C_Timer.After then + C_Timer.After(st.tries * 3, try) + end + end) + end) + end + try() end function UI.CombatPlates(on) - if on and not ForeverBotsDB.combatPlates then - ForeverBotsDB.platesBefore = PlatesGet() -- what the player had, put back when this is turned off - ForeverBotsDB.combatPlates = true - PlatesSet(UnitAffectingCombat and UnitAffectingCombat("player") or false) - elseif not on and ForeverBotsDB.combatPlates then - ForeverBotsDB.combatPlates = false - PlatesSet(ForeverBotsDB.platesBefore and true or false) - ForeverBotsDB.platesBefore = nil - end + ForeverBotsDB.combatPlates = on and true or false + UI.PlatesSync(true) end local platesFrame = CreateFrame("Frame") -platesFrame:RegisterEvent("PLAYER_REGEN_DISABLED") -platesFrame:RegisterEvent("PLAYER_REGEN_ENABLED") platesFrame:RegisterEvent("PLAYER_ENTERING_WORLD") -platesFrame:SetScript("OnEvent", function(_, event) - if event == "PLAYER_REGEN_ENABLED" and UI.platesPending then - local pending = UI.platesPending - if ForeverBotsDB.combatPlates then pending = "0" end - PlatesSet(pending == "1") +platesFrame:RegisterEvent("CVAR_UPDATE") +platesFrame:SetScript("OnEvent", function(_, event, name) + if event == "CVAR_UPDATE" then + if issecretvalue and issecretvalue(name) then return end + name = type(name) == "string" and name:lower() or "" + if name ~= "nameplateshowenemies" and name ~= "nameplateshowall" then return end + UI.PlatesSync(false) return end - if not ForeverBotsDB.combatPlates then return end - if event == "PLAYER_REGEN_DISABLED" then - PlatesSet(true) - elseif event == "PLAYER_REGEN_ENABLED" then - PlatesSet(false) - else - PlatesSet(UnitAffectingCombat and UnitAffectingCombat("player") or false) - end + UI.PlatesSync(true) -- a new session or a UI reload: the server has forgotten end) local combatFrame = CreateFrame("Frame") @@ -2951,10 +2957,21 @@ SlashCmdList.FOREVERBOTS = function(msg) return end if verb == "plates" or verb == "nameplates" then + -- "/fb plates" alone shows the state (and asks the server again if it never answered) if class == "on" then UI.CombatPlates(true) elseif class == "off" then UI.CombatPlates(false) - elseif class == nil or class == "" then UI.CombatPlates(not ForeverBotsDB.combatPlates) end - Print(L["enemy nameplates only in combat: %s"]:format(ForeverBotsDB.combatPlates and L["on"] or L["off (your own setting)"]) .. " (/fb plates on|off)") + elseif UI.plates.confirmed == nil then UI.PlatesSync(true) end + local text + if ForeverBotsDB.combatPlates == false then + text = L["off: the client's own nameplate settings apply."] + elseif not PlatesWanted() then + text = L["on, but it needs Enemy Unit Nameplates on and Always Show Nameplates off (Esc > Options > Nameplates)."] + elseif UI.plates.confirmed == true then + text = L["on: a health bar only over mobs that fight you, your pet or your group; the others keep their name."] + else + text = L["on, waiting for the server to confirm (an older server does not have it)."] + end + Print(L["enemy nameplates only in combat: %s"]:format(text) .. " (/fb plates on|off)") return end if verb == "bots" or verb == "manage" or verb == "roster" then diff --git a/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots_Net.lua b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots_Net.lua index 4f72fc08c1..5c40c9d61d 100644 --- a/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots_Net.lua +++ b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots_Net.lua @@ -81,7 +81,7 @@ Net.Unescape = Unescape local ANSWERS = { ROSTER_RESP = true, BOT_DETAIL_RESP = true, STATS_RESP = true, PONG = true, ALTS_RESP = true, EVENT_PUSH = true, SUMMON_RESP = true, LOGIN_RESP = true, LOGOUT_RESP = true, SELF_RESP = true, GEAR_RESP = true, BAGS_RESP = true, QUESTS_RESP = true, SPEC_RESP = true, LFG_RESP = true, - ASSIGN_RESP = true } + ASSIGN_RESP = true, PLATES_RESP = true } Net.ANSWERS = ANSWERS Net.seq = math.random(1, 0x3fffffff) diff --git a/src/modules/PlayerbotV2/Addon/ForeverBots/Locale_ruRU.lua b/src/modules/PlayerbotV2/Addon/ForeverBots/Locale_ruRU.lua index 55861cc902..c9182e93bc 100644 --- a/src/modules/PlayerbotV2/Addon/ForeverBots/Locale_ruRU.lua +++ b/src/modules/PlayerbotV2/Addon/ForeverBots/Locale_ruRU.lua @@ -339,7 +339,13 @@ ForeverBotsLocale = { ["whisper to %s failed: %s"] = "шепот игроку %s не удался: %s", ["bot confirmations in chat: %s"] = "подтверждения ботов в чате: %s", ["enemy nameplates only in combat: %s"] = "индикаторы здоровья врагов только в бою: %s", - ["off (your own setting)"] = "выкл. (ваша настройка)", + ["off: the client's own nameplate settings apply."] = "выкл.: действуют настройки индикаторов здоровья самого клиента.", + ["on, but it needs Enemy Unit Nameplates on and Always Show Nameplates off (Esc > Options > Nameplates)."] = + "вкл., но нужно включить индикаторы здоровья противников и выключить «Всегда показывать индикаторы здоровья» (Esc > Настройки > Индикаторы здоровья).", -- check + ["on: a health bar only over mobs that fight you, your pet or your group; the others keep their name."] = + "вкл.: полоска здоровья только над мобами, которые сражаются с вами, вашим питомцем или вашей группой; у остальных только имя.", + ["on, waiting for the server to confirm (an older server does not have it)."] = + "вкл., ждем подтверждения сервера (на старом сервере этого нет).", ["shown"] = "включено", ["hidden (shown in the Bots panel status line)"] = "скрыто (отображается в строке состояния панели ботов)", ["minimap button: %s"] = "кнопка у миникарты: %s", diff --git a/src/modules/PlayerbotV2/Addon/ForeverBots/README.md b/src/modules/PlayerbotV2/Addon/ForeverBots/README.md index 7246db1850..d0e6ecbd54 100644 --- a/src/modules/PlayerbotV2/Addon/ForeverBots/README.md +++ b/src/modules/PlayerbotV2/Addon/ForeverBots/README.md @@ -155,8 +155,10 @@ Built on the client's own portrait window (the one its Raid and Looking For Grou - `/fb scale <0.7-1.5>` sets the window size (default 1.2, saved). - `/fb minimap on|off|reset` shows, hides or re-centres the minimap button. -- `/fb plates on|off`: enemy nameplates only in combat. The client's own "in combat only" setting does not work on this build, so the - add-on turns enemy nameplates on when a fight starts and off when it ends. Off by default; turning it off puts back your setting. +- Enemy nameplates only in combat: with Enemy Unit Nameplates on and Always Show Nameplates off, the client alone shows a health + bar over every hostile mob in range. The add-on has the server fix that: a mob fighting you, your pet or your group gets its + bar, every other one keeps its plain red name, and a mob that joins the fight gets its bar at once. It is on by default and + works only with those two settings; `/fb plates off` turns it off, `/fb plates` shows whether the server confirmed it. - `/fb quick` fills your group with bots: to five in the open world and 5-player dungeons, to the instance size in a bigger one (10 in Upper Blackrock Spire, 20 or 40 in a raid), with tanks, healers and damage dealers; `/fb resume` and `/fb flee` send those two orders. - Group finder tab (the fifth tab, after Marks): the bot dungeon finder without typing. Pick your role (Auto, Tank, Heal, DPS; remembered) and a dungeon with < and > (Any for my level, then the dungeons of your level, then the rest; Upper Blackrock Spire diff --git a/src/modules/PlayerbotV2/Session/AddonControl.cpp b/src/modules/PlayerbotV2/Session/AddonControl.cpp index 69f2d75e19..9f771b055d 100644 --- a/src/modules/PlayerbotV2/Session/AddonControl.cpp +++ b/src/modules/PlayerbotV2/Session/AddonControl.cpp @@ -1149,6 +1149,24 @@ void HandleAltsReq(uint32 client_seq, WorldSession* sess) SendFields(sess, client_seq, "ALTS_RESP", fields); } +// ---------------------------------------------------------------------------- +// PLATES — combat-only enemy nameplates for the sender's own client (Player::SetCombatPlateFilter): NPCs outside his, his pet's or +// his group's fight show their plain name, the ones fighting get their health bar. Any player may ask (no bot needed). +// +// Wire: PLATES|1 PLATES|0 +// Reply: PLATES_RESP|<1|0> (what will be in force from the player's next update) +// ---------------------------------------------------------------------------- +void HandlePlatesReq(uint32 client_seq, WorldSession* sess, std::vector const& fields) +{ + Player* me = sess ? sess->GetPlayer() : nullptr; + if (!me) + return; + bool const on = !fields.empty() && fields[0] == "1"; + me->SetCombatPlateFilter(on); + TC_LOG_DEBUG("playerbot.v2", "[combat_plates] {} turns combat-only nameplates {}", me->GetName(), on ? "on" : "off"); + SendFields(sess, client_seq, "PLATES_RESP", { on ? "1" : "0" }); +} + // ---------------------------------------------------------------------------- // SELF — addon counterpart to `.playerbot self on|off|status`. Attaches // or detaches the V2 bot logic to the issuing player's OWN character. Mirrors @@ -1659,6 +1677,10 @@ void DispatchAssembled(WorldSession* sess, uint32 seq, { HandleAltsReq(seq, sess); } + else if (mtype == "PLATES") + { + HandlePlatesReq(seq, sess, fields); + } else if (mtype == "SUMMON") { HandleSummon(seq, sess, fields); @@ -1826,6 +1848,7 @@ bool OnAddonWhisper(Player* sender, Player* /*receiver*/, && mtype != "LOGOUT_REQ" && mtype != "SELF" && mtype != "PING" + && mtype != "PLATES" && mtype != "LFG_REQ" && mtype != "POP_REQ" && mtype != "ASSIGN_REQ")