Skip to content

Commit

Permalink
- Camp Hard Support Added
Browse files Browse the repository at this point in the history
- Cleaned up how /rgl set was handled to make it much more reliable
  • Loading branch information
DerpleMQ2 committed Feb 25, 2024
1 parent 18c91cf commit 5c70527
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 82 deletions.
2 changes: 1 addition & 1 deletion extras/version.lua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return { commitId = 'c2024f7 2024-02-25' }
return { commitId = '18c91cf 2024-02-25' }
84 changes: 8 additions & 76 deletions utils/rgmercs_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,81 +297,13 @@ function Config:UpdateCommandHandlers()
local handled, usageString = self:GetUsageText(config, true, moduleData.defaults)

if handled then
if type(configData.Default) == 'number' then
self.CommandHandlers[config:lower()] = {
name = config,
usage = usageString,
subModule = moduleName,
category = configData.Category,
about = configData.Tooltip,
handler = function(self, value)
value = tonumber(value)
if value > (moduleData.defaults[config].Max or 999) or value < (moduleData.defaults[config].Min or 0) then
RGMercsLogger.log_info("\ayError: %s is not a valid setting for %s.", value, config)
local _, update = self:GetUsageText(config, true, moduleData.defaults)
RGMercsLogger.log_info(update)
return
end
local _, update = self:GetUsageText(config, false, moduleData.defaults)
RGMercsLogger.log_info("\a-y%s :: Before :: %s", config, update)
moduleData.settings[config] = value
_, update = self:GetUsageText(config, false, moduleData.defaults)
RGMercsLogger.log_info("\ag%s :: After :: %s", config, update)
if moduleName == "Core" then
self:SaveSettings(true)
else
RGMercModules:ExecModule(moduleName, "SaveSettings", true)
end
end,
}
end
if type(configData.Default) == 'boolean' then
self.CommandHandlers[config:lower()] = {
name = config,
usage = usageString,
subModule = moduleName,
category = configData.Category,
about = configData.Tooltip,
handler = function(self, value)
local boolValue = false
if value == "true" or value == "on" or (tonumber(value) or 0) >= 1 then
boolValue = true
end

local _, update = self:GetUsageText(config, false, moduleData.defaults)
RGMercsLogger.log_info("\a-y%s :: Before :: %-5s", config, update)
moduleData.settings[config] = boolValue
_, update = self:GetUsageText(config, false, moduleData.defaults)
RGMercsLogger.log_info("\ag%s :: After :: %-5ss", config, update)
if moduleName == "Core" then
self:SaveSettings(true)
else
RGMercModules:ExecModule(moduleName, "SaveSettings", true)
end
end,
}
end
if type(configData.Default) == 'string' then
self.CommandHandlers[config:lower()] = {
name = config,
usage = usageString,
subModule = moduleName,
category = configData.Category,
about = configData.Tooltip,
handler = function(self, value)
local _, update = self:GetUsageText(config, false, moduleData.defaults)
RGMercsLogger.log_info("\a-y%s :: Before :: \"%s\"", config, update)
moduleData.settings[config] = value
_, update = self:GetUsageText(config, false, moduleData.defaults)
RGMercsLogger.log_info("\ag%s :: After :: \"%s\"", config, update)
if moduleName == "Core" then
self:SaveSettings(true)
else
RGMercModules:ExecModule(moduleName, "SaveSettings", true)
end
end,
}
end
self.CommandHandlers[config:lower()] = {
name = config,
usage = usageString,
subModule = moduleName,
category = configData.Category,
about = configData.Tooltip,
}
end
end
end
Expand Down Expand Up @@ -495,7 +427,7 @@ function Config:HandleBind(config, value)
end

if self.CommandHandlers[config:lower()] ~= nil then
self.CommandHandlers[config:lower()].handler(self, value)
RGMercUtils.SetSetting(config, value)
handled = true
else
RGMercsLogger.log_error("\at%s\aw - \arNot a valid config setting!\ax", config)
Expand Down
11 changes: 11 additions & 0 deletions utils/rgmercs_events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,17 @@ end)

-- [ END MEZ HANDLERS ] --

-- [ SUMMONED HANDLERS ] --

mq.event('Summoned', "You have been summoned!", function(_)
if RGMercUtils.GetSetting('DoAutoEngage') and not RGMercUtils.GetSetting('DoMelee') and not RGMercUtils.IAmMA() and RGMercUtils.GetSetting('ReturnToCamp') then
RGMercUtils.PrintGroupMessage("%s was just summoned -- returning to camp!", mq.TLO.Me.DisplayName())
RGMercModules:ExecModule("Movement", "DoAutoCampCheck")
end
end)

-- [ END SUMMONED HANDLERS ] --

-- [ GAME EVENT HANDLERS ] --

mq.event('Camping', "It will take you about #1# seconds to prepare your camp.", function(_, seconds)
Expand Down
99 changes: 94 additions & 5 deletions utils/rgmercs_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,94 @@ function Utils.GetSetting(setting)
return ret.value
end

---@param module string
---@param setting string
---@param value any
---@return boolean|string|number|nil
function Utils.MakeValidSetting(module, setting, value)
local defaultConfig = RGMercConfig.DefaultConfig

if module ~= "Core" then
defaultConfig = RGMercConfig.SubModuleSettings[module].defaults
end

if type(defaultConfig[setting].Default) == 'number' then
value = tonumber(value)
if value > (defaultConfig[setting].Max or 999) or value < (defaultConfig[setting].Min or 0) then
RGMercsLogger.log_info("\ayError: %s is not a valid setting for %s.", value, setting)
local _, update = RGMercConfig:GetUsageText(setting, true, defaultConfig[setting])
RGMercsLogger.log_info(update)
return nil
end

return value
elseif type(defaultConfig[setting].Default) == 'boolean' then
local boolValue = false
if value == "true" or value == "on" or (tonumber(value) or 0) >= 1 then
boolValue = true
end

return boolValue
elseif type(defaultConfig[setting].Default) == 'string' then
return value
end

return nil
end

---@param setting string
---@return string, string
function Utils.MakeValidSettingName(setting)
for s, _ in pairs(RGMercConfig:GetSettings()) do
if s:lower() == setting:lower() then return "Core", s end
end

for moduleName, data in pairs(RGMercConfig.SubModuleSettings) do
for s, _ in pairs(data.settings) do
if s:lower() == setting:lower() then return moduleName, s end
end
end
return "None", "None"
end

---Sets a setting from either in global or a module setting table.
---@param setting string #name of setting to get
---@param value string|boolean|number
function Utils.SetSetting(setting, value)
local defaultConfig = RGMercConfig.DefaultConfig
local settingModuleName = "Core"
local beforeUpdate = ""

settingModuleName, setting = Utils.MakeValidSettingName(setting)

if settingModuleName == "Core" then
local cleanValue = Utils.MakeValidSetting("Core", setting, value)
_, beforeUpdate = RGMercConfig:GetUsageText(setting, false, defaultConfig)
if cleanValue ~= nil then
RGMercConfig:GetSettings()[setting] = cleanValue
RGMercConfig:SaveSettings(true)
end
elseif settingModuleName ~= "None" then
local data = RGMercConfig.SubModuleSettings[settingModuleName]
if data.settings[setting] ~= nil then
defaultConfig = data.defaults
_, beforeUpdate = RGMercConfig:GetUsageText(setting, false, defaultConfig)
local cleanValue = Utils.MakeValidSetting(settingModuleName, setting, value)
if cleanValue ~= nil then
data.settings[setting] = cleanValue
RGMercModules:ExecModule(settingModuleName, "SaveSettings", true)
end
end
else
RGMercsLogger.log_error("Setting %s was not found!", setting)
return
end

local _, afterUpdate = RGMercConfig:GetUsageText(setting, false, defaultConfig)
RGMercsLogger.log_info("[%s] \ag%s :: Before :: %-5s", settingModuleName, setting, beforeUpdate)
RGMercsLogger.log_info("[%s] \ag%s :: After :: %-5s", settingModuleName, setting, afterUpdate)
end

---@param aaName string
---@return boolean
function Utils.SelfBuffAACheck(aaName)
Expand Down Expand Up @@ -1943,15 +2031,14 @@ function Utils.DoCamp()
return Utils.GetXTHaterCount() == 0 and RGMercConfig.Globals.AutoTargetID == 0
end

---@param config table
---@param tempConfig table
function Utils.AutoCampCheck(config, tempConfig)
if not config.ReturnToCamp then return end
function Utils.AutoCampCheck(tempConfig)
if not Utils.GetSetting('ReturnToCamp') then return end

if mq.TLO.Me.Casting.ID() and not Utils.MyClassIs("brd") then return end

-- chasing a toon dont use camnp.
if config.ChaseOn then return end
if Utils.GetSetting('ChaseOn') then return end

-- camped in a different zone.
if tempConfig.CampZoneId ~= mq.TLO.Zone.ID() then return end
Expand All @@ -1969,7 +2056,9 @@ function Utils.AutoCampCheck(config, tempConfig)
return
end

if distanceToCamp < config.AutoCampRadius then return end
if not Utils.GetSetting('CampHard') then
if distanceToCamp < Utils.GetSetting('AutoCampRadius') then return end
end

if distanceToCamp > 5 then
local navTo = string.format("locyxz %d %d %d", tempConfig.AutoCampY, tempConfig.AutoCampX, tempConfig.AutoCampZ)
Expand Down

0 comments on commit 5c70527

Please sign in to comment.