mirror of
https://codeberg.org/Duvelcorp/MetaHunt.git
synced 2026-10-08 09:46:32 +00:00
v1.4.0 Twow 1.18.1
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
local MTH_AutoBuy = {
|
||||
name = "autobuy",
|
||||
enabled = false,
|
||||
version = "1.3.0",
|
||||
version = "1.4.0",
|
||||
events = {
|
||||
"VARIABLES_LOADED",
|
||||
"MERCHANT_SHOW",
|
||||
@@ -24,9 +24,6 @@ end
|
||||
|
||||
local AB_Engine
|
||||
|
||||
local function AB_Trace(message)
|
||||
return
|
||||
end
|
||||
|
||||
local function AB_EnsureBridgeFrame(moduleRef)
|
||||
if MTH_AutoBuy._bridgeFrame then
|
||||
@@ -46,15 +43,12 @@ local function AB_EnsureBridgeFrame(moduleRef)
|
||||
local eventName = event
|
||||
local engine = AB_Engine()
|
||||
if not engine then
|
||||
AB_Trace("bridge event=" .. tostring(eventName) .. " engine missing")
|
||||
return
|
||||
end
|
||||
|
||||
if eventName == "MERCHANT_SHOW" or eventName == "MERCHANT_UPDATE" then
|
||||
AB_Trace("bridge " .. tostring(eventName) .. " -> engine")
|
||||
engine:OnMerchantEvent(eventName)
|
||||
elseif eventName == "MERCHANT_CLOSED" then
|
||||
AB_Trace("bridge MERCHANT_CLOSED -> engine")
|
||||
if engine.OnMerchantClosed then
|
||||
engine:OnMerchantClosed()
|
||||
end
|
||||
@@ -77,10 +71,8 @@ local function AB_SetBridgeActive(active)
|
||||
frame:RegisterEvent("MERCHANT_UPDATE")
|
||||
frame:RegisterEvent("MERCHANT_CLOSED")
|
||||
MTH_AutoBuy._bridgeActive = true
|
||||
AB_Trace("bridge active=true")
|
||||
else
|
||||
MTH_AutoBuy._bridgeActive = false
|
||||
AB_Trace("bridge active=false (frame missing)")
|
||||
end
|
||||
return
|
||||
end
|
||||
@@ -91,7 +83,6 @@ local function AB_SetBridgeActive(active)
|
||||
frame:UnregisterEvent("MERCHANT_CLOSED")
|
||||
end
|
||||
MTH_AutoBuy._bridgeActive = false
|
||||
AB_Trace("bridge active=false")
|
||||
end
|
||||
|
||||
AB_Engine = function()
|
||||
@@ -102,15 +93,12 @@ function MTH_AutoBuy:init()
|
||||
local engine = AB_Engine()
|
||||
if not engine then
|
||||
AB_Log("init failed: engine missing", "error")
|
||||
AB_Trace("init failed: engine missing")
|
||||
return
|
||||
end
|
||||
engine:Init()
|
||||
self.initialized = true
|
||||
AB_SetBridgeActive(self.enabled and true or false)
|
||||
AB_Trace("init done")
|
||||
if self.enabled then
|
||||
AB_Log("module initialized", "debug")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -120,20 +108,16 @@ function MTH_AutoBuy:setEnabled(enabled)
|
||||
end
|
||||
local engine = AB_Engine()
|
||||
if not engine then
|
||||
AB_Trace("setEnabled ignored: engine missing")
|
||||
return
|
||||
end
|
||||
local store = engine:EnsureDefaults()
|
||||
store.enabled = enabled and true or false
|
||||
AB_SetBridgeActive(store.enabled and true or false)
|
||||
AB_Trace("setEnabled store.enabled=" .. tostring(store.enabled))
|
||||
end
|
||||
|
||||
function MTH_AutoBuy:onEvent(event)
|
||||
local engine = AB_Engine()
|
||||
if not engine then
|
||||
AB_Log("onEvent ignored: engine missing, event=" .. tostring(event), "debug")
|
||||
AB_Trace("engine missing, event=" .. tostring(event))
|
||||
return
|
||||
end
|
||||
if self._bridgeActive and (event == "MERCHANT_SHOW" or event == "MERCHANT_UPDATE" or event == "MERCHANT_CLOSED") then
|
||||
@@ -143,27 +127,19 @@ function MTH_AutoBuy:onEvent(event)
|
||||
if event == "VARIABLES_LOADED" then
|
||||
engine:Init()
|
||||
AB_SetBridgeActive(self.enabled and true or false)
|
||||
local store = engine:EnsureDefaults()
|
||||
AB_Trace("VARIABLES_LOADED module.enabled=" .. tostring(self.enabled)
|
||||
.. " store.enabled=" .. tostring(store and store.enabled)
|
||||
.. " projectiles.enabled=" .. tostring(store and store.projectiles and store.projectiles.enabled))
|
||||
engine:EnsureDefaults()
|
||||
return
|
||||
end
|
||||
|
||||
if not self.enabled then
|
||||
AB_Log("onEvent ignored: module disabled", "debug")
|
||||
if event == "MERCHANT_SHOW" or event == "MERCHANT_UPDATE" then
|
||||
AB_Trace(tostring(event) .. " ignored: module disabled")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if event == "MERCHANT_SHOW" or event == "MERCHANT_UPDATE" then
|
||||
AB_Log("onEvent merchant event forwarded: " .. tostring(event), "debug")
|
||||
AB_Trace("forwarding " .. tostring(event) .. " to engine")
|
||||
engine:OnMerchantEvent(event)
|
||||
elseif event == "MERCHANT_CLOSED" then
|
||||
AB_Trace("forwarding MERCHANT_CLOSED to engine")
|
||||
if engine.OnMerchantClosed then
|
||||
engine:OnMerchantClosed()
|
||||
end
|
||||
@@ -171,7 +147,6 @@ function MTH_AutoBuy:onEvent(event)
|
||||
end
|
||||
|
||||
function MTH_AutoBuy:cleanup()
|
||||
AB_Log("module cleanup", "debug")
|
||||
end
|
||||
|
||||
MTH:RegisterModule("autobuy", MTH_AutoBuy)
|
||||
|
||||
Reference in New Issue
Block a user