Intial Commit
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
require "QMIA_State"
|
||||
require "TimedActions/QMIA_ArrangeAction"
|
||||
require "LootSorter_Core"
|
||||
require "LootSorter_Plan"
|
||||
require "LootSorter_DepositAction"
|
||||
require "LootSorter_ContextMenu"
|
||||
|
||||
local function feedback(playerNum, accepted, enabled)
|
||||
local player = getSpecificPlayer(playerNum)
|
||||
if not player then return end
|
||||
local message = "Could not update Item Arrange mode."
|
||||
if accepted then
|
||||
message = enabled and "Item Arrange enabled. Configure sorting to select items."
|
||||
or "Item Arrange disabled. Deliveries use container storage."
|
||||
end
|
||||
LootSorter.notify(player, message)
|
||||
end
|
||||
|
||||
function QMIA.setMark(obj, ci, enabled, playerNum)
|
||||
local player = getSpecificPlayer(playerNum)
|
||||
local square = obj and obj:getSquare()
|
||||
if not player or not QMIA.canAccess(square, player) then return end
|
||||
local args = { x = square:getX(), y = square:getY(), z = square:getZ(),
|
||||
oi = obj:getObjectIndex(), ci = ci, enabled = enabled, playerNum = playerNum }
|
||||
if isClient() then
|
||||
sendClientCommand(player, QMIA.MOD_ID, "setMark", args)
|
||||
else
|
||||
feedback(playerNum, QMIA.applyRequest(player, args), enabled)
|
||||
end
|
||||
end
|
||||
|
||||
-- Hook Quartermaster's common entry point: both world and inventory menus, every
|
||||
-- stacked object and every separate container index receive the toggle.
|
||||
if not QMIA.menuInstalled then
|
||||
QMIA.menuInstalled = true
|
||||
local original = LootSorter.addBoxOptions
|
||||
function LootSorter.addBoxOptions(menu, obj, ci, suffix, playerNum)
|
||||
original(menu, obj, ci, suffix, playerNum)
|
||||
local square = obj and obj:getSquare()
|
||||
if not QMIA.canAccess(square, getSpecificPlayer(playerNum)) then return end
|
||||
local marked = QMIA.isMarked(obj, ci)
|
||||
local label = (marked and "[x] Item Arrange" or "[ ] Item Arrange") .. (suffix or "")
|
||||
local option = menu:addOption(label, nil, function()
|
||||
QMIA.setMark(obj, ci, not marked, playerNum)
|
||||
end)
|
||||
option.onHighlightParams = { obj }
|
||||
option.onHighlight = LootSorter.onHighlightBox
|
||||
local tip = ISWorldObjectContextMenu.addToolTip()
|
||||
tip.description = "Deliver matching items to this container's tile using Item Arrange. "
|
||||
.. "Uses the same placement as Shift-dropping. No Shift key or mouse aim needed. "
|
||||
.. "Choose matching categories/items with Configure sorting."
|
||||
option.toolTip = tip
|
||||
end
|
||||
end
|
||||
|
||||
-- This changes the destination only. Quartermaster still loads bags, walks, plans
|
||||
-- trips and protects equipped/favorited/hotbar items using its own implementation.
|
||||
if not QMIA.depositInstalled then
|
||||
QMIA.depositInstalled = true
|
||||
local original = LootSorter.DepositAction.new
|
||||
function LootSorter.DepositAction:new(character, item, srcContainer, destContainer)
|
||||
local obj, ci = QMIA.containerTarget(destContainer)
|
||||
if obj and QMIA.isMarked(obj, ci) then
|
||||
return QMIArrangeAction:new(character, item, srcContainer, destContainer)
|
||||
end
|
||||
return original(self, character, item, srcContainer, destContainer)
|
||||
end
|
||||
end
|
||||
|
||||
-- A marked container represents display space, so its internal weight capacity
|
||||
-- must not prevent routing to it. IA.CheckSpace controls placement at execution.
|
||||
-- Copy records: no global ItemContainer methods or original planner data change.
|
||||
if not QMIA.plannerInstalled then
|
||||
QMIA.plannerInstalled = true
|
||||
local original = LootSorter.planTrips
|
||||
function LootSorter.planTrips(items, boxes, carriers, budget, accepts)
|
||||
local adjusted = {}
|
||||
for i, box in ipairs(boxes) do
|
||||
local obj, ci = QMIA.containerTarget(box.container)
|
||||
if obj and QMIA.isMarked(obj, ci) then
|
||||
local copy = {}
|
||||
for key, value in pairs(box) do copy[key] = value end
|
||||
copy.capacity, copy.used = math.huge, 0
|
||||
adjusted[i] = copy
|
||||
else
|
||||
adjusted[i] = box
|
||||
end
|
||||
end
|
||||
return original(items, adjusted, carriers, budget, accepts)
|
||||
end
|
||||
end
|
||||
|
||||
if not QMIA.resultsInstalled then
|
||||
QMIA.resultsInstalled = true
|
||||
Events.OnServerCommand.Add(function(module, command, args)
|
||||
if module ~= QMIA.MOD_ID or command ~= "markResult" or not args then return end
|
||||
feedback(tonumber(args.playerNum) or 0, args.accepted, args.enabled)
|
||||
end)
|
||||
end
|
||||
|
||||
print("[QuartermasterItemArrange] compatibility loaded")
|
||||
Reference in New Issue
Block a user