2023-09-07 08:18:40 -04:00
|
|
|
-----------------------------------
|
2022-09-17 15:48:34 -04:00
|
|
|
-- func: !checkinteraction (handlerName)
|
2021-05-01 00:53:48 +02:00
|
|
|
-- desc:
|
2023-09-07 08:18:40 -04:00
|
|
|
-----------------------------------
|
2024-08-25 10:54:45 -04:00
|
|
|
---@type TCommand
|
2023-09-02 07:01:35 -04:00
|
|
|
local commandObj = {}
|
2021-05-01 00:53:48 +02:00
|
|
|
|
2023-09-02 07:01:35 -04:00
|
|
|
commandObj.cmdprops =
|
2021-05-01 00:53:48 +02:00
|
|
|
{
|
|
|
|
|
permission = 5,
|
2023-08-28 21:02:28 -04:00
|
|
|
parameters = 's'
|
2021-05-01 00:53:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local typeToName = {}
|
|
|
|
|
for name, typeVal in pairs(Action.Type) do
|
2022-11-04 08:36:20 -04:00
|
|
|
typeToName[typeVal] = name
|
2021-05-01 00:53:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function handlerToString(handler, player, containerVarCache, varCache)
|
|
|
|
|
local action = handler.handler
|
|
|
|
|
|
|
|
|
|
local message = type(action)
|
|
|
|
|
if message == 'table' then
|
2023-08-28 21:02:28 -04:00
|
|
|
message = string.format('Type: %s, ID: %s, Priority: %d', typeToName[action.type], action.id, action.priority)
|
2021-05-01 00:53:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if handler.container then
|
2023-08-28 21:02:28 -04:00
|
|
|
message = message .. ' [container: ' .. handler.container.id .. ']'
|
2021-05-01 00:53:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if handler.check then
|
|
|
|
|
local checkArgs = { }
|
|
|
|
|
if handler.container then
|
|
|
|
|
if handler.container.getCheckArgs then
|
|
|
|
|
checkArgs = handler.container:getCheckArgs(player)
|
|
|
|
|
end
|
2022-11-22 14:39:00 -05:00
|
|
|
|
2022-10-23 10:54:18 -04:00
|
|
|
checkArgs[#checkArgs + 1] = containerVarCache[handler.container]
|
|
|
|
|
checkArgs[#checkArgs + 1] = varCache
|
2021-05-01 00:53:48 +02:00
|
|
|
end
|
|
|
|
|
|
2023-08-28 21:02:28 -04:00
|
|
|
message = message .. ' [check: ' .. (handler.check(player, unpack(checkArgs)) and 'true' or 'false') .. ']'
|
2021-05-01 00:53:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return message
|
|
|
|
|
end
|
|
|
|
|
|
2023-09-02 07:01:35 -04:00
|
|
|
commandObj.onTrigger = function(player, handlerName)
|
2021-05-01 00:53:48 +02:00
|
|
|
local function cmdPrint(message, ...)
|
2023-12-09 23:54:00 +00:00
|
|
|
player:printToPlayer(string.format(message, unpack({ ... }) or nil), 17)
|
2021-05-01 00:53:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if handlerName == nil then
|
|
|
|
|
local target = player:getCursorTarget()
|
|
|
|
|
if target and target:isNPC() then
|
|
|
|
|
handlerName = target:getName()
|
|
|
|
|
else
|
2023-08-28 21:02:28 -04:00
|
|
|
cmdPrint('No valid handler targeted or handler name given.')
|
2021-05-01 00:53:48 +02:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local data = InteractionGlobal.lookup.data
|
|
|
|
|
if data == nil then
|
2023-08-28 21:02:28 -04:00
|
|
|
cmdPrint('No data in interaction global.')
|
2021-05-01 00:53:48 +02:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local zoneData = data[player:getZoneID()]
|
|
|
|
|
if zoneData == nil then
|
2023-08-28 21:02:28 -04:00
|
|
|
cmdPrint('No interactions in zone.')
|
2021-05-01 00:53:48 +02:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local handlerData = zoneData[handlerName]
|
|
|
|
|
if handlerData == nil then
|
2023-08-28 21:02:28 -04:00
|
|
|
cmdPrint('No interactions for "%s".', handlerName)
|
2021-05-01 00:53:48 +02:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-01 17:34:48 -05:00
|
|
|
local varCache = interactionUtil.makeTableCache(function(varname)
|
2024-08-25 12:01:53 -04:00
|
|
|
return player:getCharVar(varname)
|
2021-05-01 00:53:48 +02:00
|
|
|
end)
|
2022-11-22 14:39:00 -05:00
|
|
|
|
2021-05-01 00:53:48 +02:00
|
|
|
local containerVarCache = interactionUtil.makeContainerVarCache(player)
|
|
|
|
|
|
|
|
|
|
local function gatherHandlers(category)
|
|
|
|
|
local handlers = {}
|
|
|
|
|
if handlerData[category] then
|
|
|
|
|
for i = 1, #handlerData[category] do
|
|
|
|
|
table.insert(handlers, handlerToString(handlerData[category][i], player, containerVarCache, varCache))
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-11-22 14:39:00 -05:00
|
|
|
|
2021-05-01 00:53:48 +02:00
|
|
|
return handlers
|
|
|
|
|
end
|
|
|
|
|
|
2024-12-07 09:51:40 -06:00
|
|
|
local onSteals = gatherHandlers('onSteal')
|
2023-08-28 21:02:28 -04:00
|
|
|
local onTriggers = gatherHandlers('onTrigger')
|
|
|
|
|
local onTrades = gatherHandlers('onTrade')
|
2021-05-01 00:53:48 +02:00
|
|
|
|
|
|
|
|
if #onTriggers == 0 and #onTrades == 0 then
|
2023-08-28 21:02:28 -04:00
|
|
|
cmdPrint('No interactions for "%s".', handlerName)
|
2021-05-01 00:53:48 +02:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function printHandlers(category, handlers)
|
|
|
|
|
if #handlers > 0 then
|
2023-08-28 21:02:28 -04:00
|
|
|
cmdPrint(category .. ':')
|
2021-05-01 00:53:48 +02:00
|
|
|
for i = 1, #handlers do
|
2023-08-28 21:02:28 -04:00
|
|
|
cmdPrint(' ' .. handlers[i])
|
2021-05-01 00:53:48 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-28 21:02:28 -04:00
|
|
|
cmdPrint('Handlers for "%s":', handlerName)
|
2024-12-07 09:51:40 -06:00
|
|
|
printHandlers('Steal', onSteals)
|
2023-08-28 21:02:28 -04:00
|
|
|
printHandlers('Trigger', onTriggers)
|
|
|
|
|
printHandlers('Trade', onTrades)
|
2021-05-01 00:53:48 +02:00
|
|
|
end
|
2023-09-02 07:01:35 -04:00
|
|
|
|
|
|
|
|
return commandObj
|