Skip to content

Commit

Permalink
Moved Binds and Events into their own files.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerpleMQ2 committed Jan 8, 2024
1 parent 908376f commit 30c2d5e
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 71 deletions.
2 changes: 1 addition & 1 deletion extras/version.lua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return { commitId = '97c43ef 2024-01-08' }
return { commitId = '908376f 2024-01-08' }
71 changes: 2 additions & 69 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local ImGui = require('ImGui')
local GitCommit = require('extras.version')

RGMercsBinds = require('utils.rgmercs_binds')
RGMercsEvents = require('utils.rgmercs_events')
RGMercConfig = require('utils.rgmercs_config')
RGMercConfig:LoadSettings()

Expand Down Expand Up @@ -279,9 +280,6 @@ local function RGMercsGUI()
end

mq.imgui.init('RGMercsUI', RGMercsGUI)
mq.bind('/rgmercsui', function()
openGUI = not openGUI
end)

-- End UI --
local unloadedPlugins = {}
Expand Down Expand Up @@ -541,73 +539,8 @@ local script_actor = RGMercUtils.Actors.register(function(message)
end)

-- Binds
local function bindHandler(cmd, ...)
if RGMercsBinds.Handlers[cmd] then
return RGMercsBinds.Handlers[cmd].handler(...)
end

local results = RGMercModules:ExecAll("HandleBind", cmd, ...)

local processed = false

for _, r in pairs(results) do processed = processed or r end

if not processed then
RGMercsLogger.log_warning("\ayWarning:\ay '\at%s\ay' is not a valid command", cmd)
end
end

mq.bind("/rglua", bindHandler)

-- [ EVENTS ] --
mq.event("CantSee", "You cannot see your target.", function()
if RGMercConfig.Globals.BackOffFlag then return end

if mq.TLO.Stick.Active() then
RGMercUtils.DoCmd("/stick off")
end

if RGMercModules:ExecModule("Pull", "IsPullState", "PULL_PULLING") then
RGMercsLogger.log_info("\ayWe are in Pull_State PULLING and Cannot see our target!")
RGMercUtils.DoCmd("/nav id %d distance=%d lineofsight=on log=off", mq.TLO.Target.ID() or 0, (mq.TLO.Target.Distance() or 0) * 0.5)
mq.delay("2s", function() return mq.TLO.Navigation.Active() end)

-- TODO: Do we need this?
--while (${Navigation.Active} && ${XAssist.XTFullHaterCount} == 0) {
--CALLTRACE In while loop :: Navigation.Active ${Navigation.Active} :: XAssist ${XAssist.XTFullHaterCount}
--/doevents
--/delay 1 ${XAssist.XTFullHaterCount} > 0
--}
else
RGMercsLogger.log_info("\ayWe are in COMBAT and Cannot see our target!")
if RGMercConfig:GetSettings().DoAutoEngage then
if RGMercUtils.OkToEngage(mq.TLO.Target.ID() or 0) then
RGMercUtils.DoCmd("/squelch /face fast")
if RGMercConfig:GetSettings().DoMelee then
RGMercsLogger.log_debug("Can't See target (%s [%d]). Naving to %d away.", mq.TLO.Target.CleanName() or "", mq.TLO.Target.ID() or 0,
(mq.TLO.Target.MaxRangeTo() or 0) * 0.9)
RGMercUtils.NavInCombat(RGMercConfig:GetSettings(), mq.TLO.Target.ID(), (mq.TLO.Target.MaxRangeTo() or 0) * 0.9, false)
end
end
end
end
mq.flushevents("CantSee")
end)

mq.event("TooFar1", "#*#Your target is too far away, get closer!", function()
RGMercUtils.TooFarHandler()
mq.flushevents("TooFar1")
end)
mq.event("TooFar2", "#*#You can't hit them from here.", function()
RGMercUtils.TooFarHandler()
mq.flushevents("TooFar2")
end)
mq.event("TooFar3", "#*#You are too far away#*#", function()
RGMercUtils.TooFarHandler()
mq.flushevents("TooFar3")
end)

-- [ END EVENTS ] --
mq.bind("/rglua", RGMercsBinds.MainHandler)

RGInit(...)

Expand Down
17 changes: 16 additions & 1 deletion utils/rgmercs_binds.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
local mq = require('mq')
local RGMercUtils = require("utils.rgmercs_utils")
local RGMercsLogger = require("utils.rgmercs_logger")
local Set = require("mq.Set")

local Bind = { _version = '0.1a', _name = "RGMercsBinds", _author = 'Derple', }

Bind.MainHandler = function(cmd, ...)
if RGMercsBinds.Handlers[cmd] then
return RGMercsBinds.Handlers[cmd].handler(...)
end

local results = RGMercModules:ExecAll("HandleBind", cmd, ...)

local processed = false

for _, r in pairs(results) do processed = processed or r end

if not processed then
RGMercsLogger.log_warning("\ayWarning:\ay '\at%s\ay' is not a valid command", cmd)
end
end

Bind.Handlers = {
['qsay'] = {
usage = "/rgl qsay <text>",
Expand Down
89 changes: 89 additions & 0 deletions utils/rgmercs_events.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
local mq = require('mq')
local RGMercUtils = require("utils.rgmercs_utils")
local RGMercsLogger = require("utils.rgmercs_logger")
local Set = require("mq.Set")

mq.event("CantSee", "You cannot see your target.", function()
if RGMercConfig.Globals.BackOffFlag then return end

if mq.TLO.Stick.Active() then
RGMercUtils.DoCmd("/stick off")
end

if RGMercModules:ExecModule("Pull", "IsPullState", "PULL_PULLING") then
RGMercsLogger.log_info("\ayWe are in Pull_State PULLING and Cannot see our target!")
RGMercUtils.DoCmd("/nav id %d distance=%d lineofsight=on log=off", mq.TLO.Target.ID() or 0, (mq.TLO.Target.Distance() or 0) * 0.5)
mq.delay("2s", function() return mq.TLO.Navigation.Active() end)

-- TODO: Do we need this?
--while (${Navigation.Active} && ${XAssist.XTFullHaterCount} == 0) {
--CALLTRACE In while loop :: Navigation.Active ${Navigation.Active} :: XAssist ${XAssist.XTFullHaterCount}
--/doevents
--/delay 1 ${XAssist.XTFullHaterCount} > 0
--}
else
RGMercsLogger.log_info("\ayWe are in COMBAT and Cannot see our target!")
if RGMercConfig:GetSettings().DoAutoEngage then
if RGMercUtils.OkToEngage(mq.TLO.Target.ID() or 0) then
RGMercUtils.DoCmd("/squelch /face fast")
if RGMercConfig:GetSettings().DoMelee then
RGMercsLogger.log_debug("Can't See target (%s [%d]). Naving to %d away.", mq.TLO.Target.CleanName() or "", mq.TLO.Target.ID() or 0,
(mq.TLO.Target.MaxRangeTo() or 0) * 0.9)
RGMercUtils.NavInCombat(RGMercConfig:GetSettings(), mq.TLO.Target.ID(), (mq.TLO.Target.MaxRangeTo() or 0) * 0.9, false)
end
end
end
end
mq.flushevents("CantSee")
end)

local function tooFarHandler()
RGMercsLogger.log_debug("tooFarHandler()")
if RGMercConfig.Globals.BackOffFlag then return end
if mq.TLO.Stick.Active() then
RGMercUtils.DoCmd("/stick off")
end

if RGMercModules:ExecModule("Pull", "IsPullState", "PULL_PULLING") then
RGMercsLogger.log_info("\ayWe are in Pull_State PULLING and too far from our target!")
RGMercUtils.DoCmd("/nav id %d distance=%d lineofsight=on log=off", mq.TLO.Target.ID() or 0, (mq.TLO.Target.Distance() or 0) * 0.75)
mq.delay("2s", function() return mq.TLO.Navigation.Active() end)
else
RGMercsLogger.log_info("\ayWe are in COMBAT and too far from our target!")
if RGMercConfig:GetSettings().DoAutoEngage then
if RGMercUtils.OkToEngage(mq.TLO.Target.ID() or 0) then
RGMercUtils.DoCmd("/squelch /face fast")
if RGMercConfig:GetSettings().DoMelee then
RGMercsLogger.log_debug("Too Far from Target (%s [%d]). Naving to %d away.", mq.TLO.Target.CleanName() or "", mq.TLO.Target.ID() or 0,
(mq.TLO.Target.MaxRangeTo() or 0) * 0.9)
RGMercUtils.NavInCombat(RGMercConfig:GetSettings(), mq.TLO.Target.ID(), (mq.TLO.Target.MaxRangeTo() or 0) * 0.9, false)
end
end
end
end
end

mq.event('Being Memo', "Beginning to memorize #1#...", function(spell)
RGMercUtils.Memorizing = true
end)

mq.event('End Memo', "You have finished memorizing #1#", function(spell)
RGMercUtils.Memorizing = false
end)

mq.event('Abort Memo', "Aborting memorization of spell.", function()
RGMercUtils.Memorizing = false
end)

mq.event("TooFar1", "#*#Your target is too far away, get closer!", function()
tooFarHandler()
mq.flushevents("TooFar1")
end)
mq.event("TooFar2", "#*#You can't hit them from here.", function()
tooFarHandler()
mq.flushevents("TooFar2")
end)
mq.event("TooFar3", "#*#You are too far away#*#", function()
tooFarHandler()
mq.flushevents("TooFar3")
end)

0 comments on commit 30c2d5e

Please sign in to comment.