Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Core/MultiBotComm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Comm.version = "1"
local STATE_FRAMING_CAPABILITY = "STATE_FRAMING_V1"
local STRATEGY_MUTATION_CAPABILITY = "STRATEGY_MUTATION_V1"
local OUTFIT_CAPABILITY = "OUTFIT_V1"
local INVENTORY_CAPABILITY = "INVENTORY_V1"
local STATE_TIMEOUT_SECONDS = 5.0
local STATES_TIMEOUT_SECONDS = 15.0
local STRATEGY_MUTATION_TIMEOUT_SECONDS = 5.0
Expand Down Expand Up @@ -211,6 +212,7 @@ local function ensureBridgeState()
state.stateFramingCapable = state.stateFramingCapable or false
state.strategyMutationCapable = state.strategyMutationCapable or false
state.outfitCapable = state.outfitCapable or false
state.inventoryCapable = state.inventoryCapable or false
state.strategyMutationSeq = state.strategyMutationSeq or 0
state.strategyMutationCommands = state.strategyMutationCommands or {}
state.weaponEnchantDebugSeq = state.weaponEnchantDebugSeq or 0
Expand Down Expand Up @@ -1280,7 +1282,7 @@ end
function Comm.RequestInventory(name)
local state = ensureBridgeState()
name = trim(name)
if name == "" or not state.connected then
if name == "" or not state.connected or state.inventoryCapable ~= true then
return false
end

Expand All @@ -1291,6 +1293,7 @@ function Comm.RequestInventory(name)
botNameKey = string.lower(name),
token = token,
startedAt = safeNow(),
begun = false,
}

if not Comm.Send("GET", "INVENTORY~" .. name .. "~" .. token) then
Expand Down Expand Up @@ -1562,6 +1565,7 @@ function Comm.MarkDisconnected(reason)
state.formationQueryActive = nil
state.strategyMutationCapable = false
state.outfitCapable = false
state.inventoryCapable = false
state.stateFramingCapable = false

local pendingTokens = {}
Expand Down Expand Up @@ -3234,6 +3238,7 @@ function Comm.HandleAddonMessage(prefix, message, distribution, sender)
state.stateFramingCapable = false
state.strategyMutationCapable = false
state.outfitCapable = false
state.inventoryCapable = false
for capability in string.gmatch(payload or "", "([^,]+)") do
capability = trim(capability)
if capability == STATE_FRAMING_CAPABILITY then
Expand All @@ -3242,6 +3247,8 @@ function Comm.HandleAddonMessage(prefix, message, distribution, sender)
state.strategyMutationCapable = true
elseif capability == OUTFIT_CAPABILITY then
state.outfitCapable = true
elseif capability == INVENTORY_CAPABILITY then
state.inventoryCapable = true
end
end
debugPrint("ADDON:RX", "CAPS", payload or "")
Expand Down Expand Up @@ -3564,7 +3571,9 @@ function Comm.HandleAddonMessage(prefix, message, distribution, sender)
state.connected = true
state.lastError = nil

if getActiveInventoryRequest(botName, token) then
local active = getActiveInventoryRequest(botName, token)
if active then
active.begun = true
local inventory = getInventoryFrame()
if inventory and inventory.beginPayload then
inventory:beginPayload(trim(botName))
Expand Down Expand Up @@ -4443,6 +4452,7 @@ function Comm.OnPlayerEnteringWorld()
state.stateFramingCapable = false
state.strategyMutationCapable = false
state.outfitCapable = false
state.inventoryCapable = false
state.strategyMutationCommands = {}
state.details = {}
state.stats = {}
Expand Down
76 changes: 64 additions & 12 deletions Core/MultiBotEngine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2425,9 +2425,11 @@ local function scheduleInventoryRefresh(delay, callback)
end

-- MULTIBOT:INVENTORY REFRESH --
-- Rafraîchit l’inventaire d’un bot en bridge-first.
-- Le fallback chat legacy est désactivé par défaut ; l’activer explicitement avec
-- MultiBot.allowLegacyChatFallback = true pendant un diagnostic legacy.
-- P2B policy:
-- bridge capable + send success -> BRIDGE only
-- bridge capable + send failure -> BLOCKED, never chat
-- capability unavailable + legacy fallback enabled -> LEGACY
-- capability unavailable + fallback disabled -> BLOCKED
MultiBot.RequestInventoryRefresh = function(botName, delay, options)
botName = botName or (MultiBot.inventory and MultiBot.inventory.name) or ""
if not botName or botName == "" then
Expand All @@ -2436,33 +2438,81 @@ MultiBot.RequestInventoryRefresh = function(botName, delay, options)

options = options or {}

local function clearWaitState(waitButton)
if waitButton and (waitButton.waitFor == "INVENTORY" or waitButton.waitFor == "ITEM" or waitButton.waitFor == "LOOT") then
waitButton.waitFor = ""
end
end

local function neutralizeCurrentInventoryView()
local inventory = MultiBot.inventory
if inventory and inventory.name == botName and type(inventory.beginPayload) == "function" then
inventory:beginPayload(botName)
end
end

local function doRefresh()
local waitButton = getInventoryUnitButton(botName)
local bridge = MultiBot.bridge or nil
local comm = MultiBot.Comm or nil
local bridgeConnected = bridge and bridge.connected
local bridgeConnected = bridge and bridge.connected == true
local bridgeInventoryCapable = bridgeConnected and bridge.inventoryCapable == true

if bridgeInventoryCapable then
if comm and type(comm.RequestInventory) == "function" and comm.RequestInventory(botName) then
if bridge then
bridge.lastError = nil
end

-- P2B review fix v2: INV_* can be processed reentrantly before
-- RequestInventory returns. Neutralize stale data only while the
-- same request is still active and INV_BEGIN has not already run.
local activeInventoryRequest = bridge and bridge.inventoryActive or nil
if activeInventoryRequest
and activeInventoryRequest.botNameKey == string.lower(botName)
and activeInventoryRequest.begun ~= true then
neutralizeCurrentInventoryView()
end

if bridgeConnected and comm and comm.RequestInventory and comm.RequestInventory(botName) then
if waitButton and (waitButton.waitFor == "INVENTORY" or waitButton.waitFor == "ITEM" or waitButton.waitFor == "LOOT") then
waitButton.waitFor = ""
clearWaitState(waitButton)
return true
end
return true
end

if bridgeConnected and options.noChatFallbackWhenBridgeConnected then
if bridge then
bridge.lastError = "INVENTORY_SEND_FAILED"
end
neutralizeCurrentInventoryView()
clearWaitState(waitButton)
return false
end

if options.bridgeOnly or MultiBot.allowLegacyChatFallback ~= true then
if bridge then
bridge.lastError = "INVENTORY_CAPABILITY_UNAVAILABLE"
end
neutralizeCurrentInventoryView()
clearWaitState(waitButton)
return false
Comment thread
Wishmaster117 marked this conversation as resolved.
end

if not waitButton then
if bridge then
bridge.lastError = "INVENTORY_LEGACY_NO_BUTTON"
end
neutralizeCurrentInventoryView()
return false
end

local inventory = MultiBot.inventory
if inventory and inventory.beginPayload then
inventory:beginPayload(botName)
end

waitButton.waitFor = "INVENTORY"
SendChatMessage("items", "WHISPER", nil, botName)
if bridge then
bridge.lastError = nil
end
return true
end

Expand All @@ -2480,10 +2530,12 @@ MultiBot.RequestInventoryPostActionRefresh = function(botName, firstDelay, secon
end

options = options or {}
local bridgeConnected = MultiBot.bridge and MultiBot.bridge.connected
local bridgeInventoryCapable = MultiBot.bridge
and MultiBot.bridge.connected == true
and MultiBot.bridge.inventoryCapable == true
local requested = MultiBot.RequestInventoryRefresh(botName, firstDelay or 0.45, options)

if requested and bridgeConnected and type(secondDelay) == "number" and secondDelay > 0 then
if requested and bridgeInventoryCapable and type(secondDelay) == "number" and secondDelay > 0 then
MultiBot.RequestInventoryRefresh(botName, secondDelay, options)
end

Expand Down
45 changes: 4 additions & 41 deletions Core/MultiBotHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2222,18 +2222,7 @@ function MultiBot.HandleMultiBotEvent(event, ...)
return
end

if LegacyChatFallbackEnabled() then
tButton.waitFor = "INVENTORY"
if(MultiBot.TimerAfter) then
MultiBot.TimerAfter(0.45, function()
SendChatMessage("items", "WHISPER", nil, tButton.name)
end)
else
SendChatMessage("items", "WHISPER", nil, tButton.name)
end
else
tButton.waitFor = ""
end
tButton.waitFor = ""
return
end

Expand All @@ -2246,18 +2235,7 @@ function MultiBot.HandleMultiBotEvent(event, ...)
return
end

if LegacyChatFallbackEnabled() then
tButton.waitFor = "INVENTORY"
if(MultiBot.TimerAfter) then
MultiBot.TimerAfter(0.45, function()
SendChatMessage("items", "WHISPER", nil, tButton.name)
end)
else
SendChatMessage("items", "WHISPER", nil, tButton.name)
end
else
tButton.waitFor = ""
end
tButton.waitFor = ""
return
end

Expand Down Expand Up @@ -2300,12 +2278,7 @@ function MultiBot.HandleMultiBotEvent(event, ...)
return
end

if LegacyChatFallbackEnabled() then
tButton.waitFor = "INVENTORY"
SendChatMessage("items", "WHISPER", nil, tButton.name)
else
tButton.waitFor = ""
end
tButton.waitFor = ""
return
end
end
Expand All @@ -2318,21 +2291,11 @@ function MultiBot.HandleMultiBotEvent(event, ...)
local botName = inventory and inventory.name or ""

if inventory and inventory:IsVisible() and botName ~= "" then
local bridgeConnected = MultiBot.bridge and MultiBot.bridge.connected

if MultiBot.RequestInventoryPostActionRefresh
and MultiBot.RequestInventoryPostActionRefresh(botName, 0.45, 1.20, { noChatFallbackWhenBridgeConnected = true }) then
and MultiBot.RequestInventoryPostActionRefresh(botName, 0.45, 1.20) then
return
end

if bridgeConnected then
return
end

if MultiBot.RefreshInventory then
MultiBot.RefreshInventory(0.45)
return
end
return
end

Expand Down
51 changes: 28 additions & 23 deletions UI/MultiBotInventoryFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -818,25 +818,11 @@ local function resetInventoryViewState()
end

local function requestInventoryForBot(botName)
if botName and botName ~= "" and MultiBot.RequestInventoryRefresh and MultiBot.RequestInventoryRefresh(botName) then
return true
end

if MultiBot.allowLegacyChatFallback ~= true then
if not botName or botName == "" or not MultiBot.RequestInventoryRefresh then
return false
end

local waitButton = getInventoryWaitButton(botName)
if waitButton then
waitButton.waitFor = "INVENTORY"
end

if botName and botName ~= "" then
SendChatMessage("items", "WHISPER", nil, botName)
return true
end

return false
return MultiBot.RequestInventoryRefresh(botName)
end

MultiBot.RequestBotInventory = function(botName)
Expand All @@ -853,8 +839,7 @@ MultiBot.RequestBotInventory = function(botName)
return inventory:requestBotInventory(botName)
end

requestInventoryForBot(botName)
return true
return requestInventoryForBot(botName)
end

local function closeInventoryWindow()
Expand Down Expand Up @@ -911,23 +896,43 @@ local function prepareInventoryForBot(botName)
return false
end

local inventory = MultiBot and MultiBot.inventory or nil
local previousBotName = inventory and inventory.name or ""

disableOtherInventoryButtons(botName)
setInventoryBotName(botName)
openInventoryWindow()
openInspectForInventoryBot(botName)

local inventory = MultiBot and MultiBot.inventory or nil
if inventory and inventory.beginPayload then
inventory:beginPayload(botName)
if inventory and previousBotName ~= botName then
inventory.pendingLootBot = nil
if inventory.resetItems then
inventory:resetItems()
Comment thread
Wishmaster117 marked this conversation as resolved.
end
inventory.summary = {
bagUsed = nil,
bagTotal = nil,
gold = 0,
silver = 0,
copper = 0,
}
updateInventorySummaryLabels(inventory)
end

local sourceButton = getInventorySourceButton(botName)
if sourceButton and sourceButton.setEnable then
sourceButton.setEnable()
end

requestInventoryForBot(botName)
return true
local requested = requestInventoryForBot(botName)
if not requested then
local waitButton = getInventoryWaitButton(botName)
if waitButton and (waitButton.waitFor == "INVENTORY" or waitButton.waitFor == "ITEM" or waitButton.waitFor == "LOOT") then
waitButton.waitFor = ""
end
end

return requested
end

local function setInventoryActionState(buttonKey, options)
Expand Down
Loading