Skip to content

Commit

Permalink
Finalized v1 of combat and camp code
Browse files Browse the repository at this point in the history
  • Loading branch information
DerpleMQ2 committed Dec 31, 2023
1 parent 6243f94 commit 9504746
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 37 deletions.
23 changes: 11 additions & 12 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ local function RGMercsGUI()
if ImGui.BeginTabItem("RGMercsMain") then
ImGui.Text("Current State: " .. curState)
ImGui.Text("Hater Count: " .. tostring(RGMercUtils.GetXTHaterCount()))
ImGui.Text("AutoTargetID: " .. tostring(RGMercConfig.Globals.AutoTargetID))
ImGui.Text("MA: " .. RGMercConfig:GetAssistSpawn().CleanName())
if ImGui.CollapsingHeader("Config Options") then
local newSettings = RGMercConfig:GetSettings()
newSettings, pressed, _ = RGMercUtils.RenderSettings(newSettings, RGMercConfig.DefaultConfig)
Expand Down Expand Up @@ -236,20 +238,18 @@ local function Main()

if mq.TLO.Me.Hovering() then RGMercUtils.HandleDeath() end

if RGMercUtils.GetXTHaterCount() > 0 then
curState = "Combat"
RGMercUtils.SetControlTool()

RGMercsLogger.log_verbose("Setting ControlToon()")
RGMercUtils.SetControlTool()
if RGMercUtils.FindTargetCheck() then
RGMercUtils.FindTarget()
end

RGMercsLogger.log_verbose("Checking FindTargetCheck()")
if RGMercUtils.FindTargetCheck() then
RGMercUtils.FindTarget()
end
if RGMercUtils.OkToEngage(mq.TLO.Target.ID()) then
RGMercUtils.EngageTarget(mq.TLO.Target.ID())
end

if RGMercUtils.OkToEngage(mq.TLO.Target.ID()) then
RGMercUtils.EngageTarget(mq.TLO.Target.ID())
end
if RGMercUtils.GetXTHaterCount() > 0 then
curState = "Combat"
end

-- TODO: Write Healing Module
Expand Down Expand Up @@ -308,7 +308,6 @@ local function Main()

if RGMercUtils.ShouldKillTargetReset() then
RGMercConfig.Globals.AutoTargetID = 0
RGMercConfig.Globals.KillTargetID = 0
end

-- TODO: Fix Curing
Expand Down
14 changes: 10 additions & 4 deletions modules/chase.lua → modules/movement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ local RGMercsLogger = require("rgmercs.utils.rgmercs_logger")
local RGMercUtils = require("rgmercs.utils.rgmercs_utils")
local ICONS = require('mq.Icons')

local Module = { _version = '0.1a', name = "Chase", author = 'Derple' }
local Module = { _version = '0.1a', name = "Movement", author = 'Derple' }
Module.__index = Module

Module.TempSettings = {}
Module.TempSettings.CampZoneId = 0

Module.DefaultConfig = {
['AutoCampRadius'] = { DisplayName = "Auto Camp Radius", Tooltip = "Return to camp after you get this far away", Default = 60, Min = 10, Max = 150 },
['ChaseOn'] = { DisplayName = "Chase On", Tooltip = "Chase your Chase Target.", Default = false },
['ChaseDistance'] = { DisplayName = "Chase Distance", Tooltip = "How Far your Chase Target can get before you Chase.", Default = 25, Min = 5, Max = 100 },
['ChaseTarget'] = { DisplayName = "Chase Target", Tooltip = "Character you are Chasing", Type = "Custom", Default = "" },
Expand Down Expand Up @@ -227,9 +228,14 @@ function Module:Render()
ImGui.Separator()

if self.settings.ReturnToCamp then
local me = mq.TLO.Me
local distanceToCamp = mq.TLO.Math.Distance(string.format("%d,%d:%d,%d", me.Y(), me.X(), self.TempSettings.AutoCampY or 0, self.TempSettings.AutoCampX or 0))()
ImGui.Text("Camp Location")
ImGui.Indent()
ImGui.Text(string.format("X: %d, Y: %d, Z: %d", self.TempSettings.AutoCampX, self.TempSettings.AutoCampY, self.TempSettings.AutoCampZ))
ImGui.Text(string.format("X: %d, Y: %d, Z: %d", self.TempSettings.AutoCampX or 0, self.TempSettings.AutoCampY or 0, self.TempSettings.AutoCampZ or 0))
if self.TempSettings.CampZoneId > 0 then
ImGui.Text(string.format("Distance to Camp: %d", distanceToCamp))
end
ImGui.Unindent()
if ImGui.SmallButton("Set New Camp Here") then
self:CampOn()
Expand Down Expand Up @@ -267,12 +273,12 @@ function Module:GiveTime(combat_state)
return
end

if not self:ShouldFollow() then return end

if RGMercUtils.DoCamp() then
RGMercUtils.AutoCampCheck(self.settings, self.TempSettings)
end

if not self:ShouldFollow() then return end

if self.settings.ChaseOn and not self.settings.ChaseTarget then
self.settings.ChaseOn = false
RGMercsLogger.log_warning("\awNOTICE:\ax \ayChase Target is invalid. Turning Chase Off!")
Expand Down
1 change: 0 additions & 1 deletion utils/rgmercs_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Config.settings = {}
Config.Globals = {}
Config.Globals.MainAssist = ""
Config.Globals.AutoTargetID = 0
Config.Globals.KillTargetID = 0
Config.Globals.BurnNow = false
Config.Globals.PauseMain = false
Config.Globals.LastMove = nil
Expand Down
2 changes: 1 addition & 1 deletion utils/rgmercs_modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Modules.load()
local newModules = setmetatable({
modules = {
--Basic = require("modules.basic").New(),
Chase = require("modules.chase").New(),
Movement = require("modules.movement").New(),
ShadowKnight = require("modules.shd").New(),
}
}, Modules)
Expand Down
60 changes: 41 additions & 19 deletions utils/rgmercs_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,9 @@ function Utils.NavInCombat(config, assistId, targetId, distance, bDontStick)
end

function Utils.ShouldKillTargetReset()
local killSpawn = mq.TLO.Spawn(string.format("targetable id %d", RGMercConfig.Globals.KillTargetID))
local killCorpse = mq.TLO.Spawn(string.format("corpse id %d", RGMercConfig.Globals.KillTargetID))
return ((not killSpawn()) or killCorpse()) and RGMercConfig.Globals.KillTargetID > 0
local killSpawn = mq.TLO.Spawn(string.format("targetable id %d", RGMercConfig.Globals.AutoTargetID))
local killCorpse = mq.TLO.Spawn(string.format("corpse id %d", RGMercConfig.Globals.AutoTargetID))
return ((not killSpawn()) or killCorpse()) and RGMercConfig.Globals.AutoTargetID > 0
end

function Utils.AutoMed()
Expand Down Expand Up @@ -755,7 +755,7 @@ function Utils.DoBuffCheck()

if mq.TLO.Me.Invis() then return false end

if Utils.GetXTHaterCount() > 0 or RGMercConfig.Globals.KillTargetID > 0 then return false end
if Utils.GetXTHaterCount() > 0 or RGMercConfig.Globals.AutoTargetID > 0 then return false end

if (mq.TLO.MoveTo.Moving() or mq.TLO.Me.Moving() or mq.TLO.AdvPath.Following() or mq.TLO.Nav.Active()) and mq.TLO.Me.Class.ShortName():lower() ~= "brd" then return false end

Expand All @@ -765,7 +765,7 @@ function Utils.DoBuffCheck()
end

function Utils.DoCamp()
return Utils.GetXTHaterCount() == 0 and RGMercConfig.KillTargetID == 0
return Utils.GetXTHaterCount() == 0 and RGMercConfig.Globals.AutoTargetID == 0
end

function Utils.AutoCampCheck(config, tempConfig)
Expand All @@ -781,11 +781,32 @@ function Utils.AutoCampCheck(config, tempConfig)

local me = mq.TLO.Me

if mq.TLO.Math.Distance(string.format("%d,%d,%d,%d", me.Y(), me.X(), tempConfig.AutoCampY, tempConfig.AutoCampX)) >= 400 then
local distanceToCamp = mq.TLO.Math.Distance(string.format("%d,%d:%d,%d", me.Y(), me.X(), tempConfig.AutoCampY, tempConfig.AutoCampX))()

if distanceToCamp >= 400 then
Utils.PrintGroupMessage("I'm over 400 units from camp, not returning!")
mq.cmdf("/rgl campoff")
return
end

if distanceToCamp < config.AutoCampRadius then return end

if distanceToCamp > 5 then
local navTo = string.format("locyxz %d %d %d", tempConfig.AutoCampY, tempConfig.AutoCampX, tempConfig.AutoCampZ)
if mq.TLO.Nav.PathExists(navTo)() then
mq.cmdf("/nav %s", navTo)
while mq.TLO.Nav.Active() do
mq.delay(10)
mq.doevents()
end
else
mq.cmdf("/moveto loc %d %d|on", tempConfig.AutoCampY, tempConfig.AutoCampX)
while mq.TLO.MoveTo.Moving() do
mq.delay(10)
mq.doevents()
end
end
end
end

function Utils.EngageTarget(autoTargetId, preEngageRoutine)
Expand Down Expand Up @@ -950,23 +971,23 @@ function Utils.MATargetScan(radius, zradius)
local xtSpawn = mq.TLO.Me.XTarget(i)

if xtSpawn() and xtSpawn.Type():lower() == "auto hater" and xtSpawn.ID() > 0 then
RGMercsLogger.log_debug("Found %s [%d] Distance: %d", xtSpawn.CleanName(), xtSpawn.ID(), xtSpawn.Distance())
RGMercsLogger.log_verbose("Found %s [%d] Distance: %d", xtSpawn.CleanName(), xtSpawn.ID(), xtSpawn.Distance())
if xtSpawn.Distance() <= radius then
-- Check for lack of aggro and make sure we get the ones we haven't aggro'd. We can't
-- get aggro data from the spawn data type.
if Utils.HaveExpansion("EXPANSION_LEVEL_ROF") then
if xtSpawn.PctAggro() < 100 and RGMercConfig.Globals.IsTanking then
-- Coarse check to determine if a mob is _not_ mezzed. No point in waking a mezzed mob if we don't need to.
if RGMercConfig.Constants.RGMezAnims:contains(xtSpawn.Animation()) then
RGMercsLogger.log_debug("Have not fully aggro'd %s -- returning %s [%d]", xtSpawn.CleanName(), xtSpawn.CleanName(), xtSpawn.ID())
RGMercsLogger.log_verbose("Have not fully aggro'd %s -- returning %s [%d]", xtSpawn.CleanName(), xtSpawn.CleanName(), xtSpawn.ID())
return xtSpawn.ID()
end
end
end

-- If a name has take priority.
if Utils.IsNamed(xtSpawn) then
RGMercsLogger.log_debug("Found Named: %s -- returning %d", xtSpawn.CleanName(), xtSpawn.ID())
RGMercsLogger.log_verbose("Found Named: %s -- returning %d", xtSpawn.CleanName(), xtSpawn.ID())
return xtSpawn.ID()
end

Expand All @@ -982,15 +1003,15 @@ function Utils.MATargetScan(radius, zradius)
end
end

RGMercsLogger.log_debug("We apparently didn't find anything on xtargets, doing a search for mezzed targets")
RGMercsLogger.log_verbose("We apparently didn't find anything on xtargets, doing a search for mezzed targets")

-- We didn't find anything to kill yet so spawn search
if killId == 0 then
RGMercsLogger.log_debug("Falling back on Spawn Searching")
RGMercsLogger.log_verbose("Falling back on Spawn Searching")
local aggroMobCount = mq.TLO.SpawnCount(aggroSearch)()
local aggroMobPetCount = mq.TLO.SpawnCount(aggroSearchPet)()
RGMercsLogger.log_debug("NPC Target Scan: %s ===> %d", aggroSearch, aggroMobCount)
RGMercsLogger.log_debug("NPCPET Target Scan: %s ===> %d", aggroSearchPet, aggroMobPetCount)
RGMercsLogger.log_verbose("NPC Target Scan: %s ===> %d", aggroSearch, aggroMobCount)
RGMercsLogger.log_verbose("NPCPET Target Scan: %s ===> %d", aggroSearchPet, aggroMobPetCount)

for i = 1, aggroMobCount do
local spawn = mq.TLO.NearestSpawn(i, aggroSearch)
Expand All @@ -1001,7 +1022,7 @@ function Utils.MATargetScan(radius, zradius)
-- take priority. Note: More mobs as of ToL are "named" even though they really aren't.

if Utils.IsNamed(spawn) then
RGMercsLogger.log_debug("DEBUG Found Named: %s -- returning %d", spawn.CleanName(), spawn.ID())
RGMercsLogger.log_verbose("DEBUG Found Named: %s -- returning %d", spawn.CleanName(), spawn.ID())
return spawn.ID()
end

Expand Down Expand Up @@ -1031,6 +1052,7 @@ function Utils.MATargetScan(radius, zradius)
end
end

RGMercsLogger.log_verbose("\agMATargetScan Returning: \at%d", killId)
return killId
end

Expand Down Expand Up @@ -1084,14 +1106,14 @@ function Utils.FindTarget()
if RGMercConfig.Globals.AutoTargetID == 0 then
-- If we currently don't have a target, we should see if there's anything nearby we should go after.
RGMercConfig.Globals.AutoTargetID = Utils.MATargetScan(RGMercConfig:GetSettings().AssistRange, RGMercConfig:GetSettings().MAScanZRange)
RGMercsLogger.log_debug("MATargetScan returned %d -- Current Target: %s [%d]", RGMercConfig.Globals.AutoTargetID, target.CleanName(), target.ID())
RGMercsLogger.log_verbose("MATargetScan returned %d -- Current Target: %s [%d]", RGMercConfig.Globals.AutoTargetID, target.CleanName(), target.ID())
else
-- If StayOnTarget is off, we're going to scan if we don't have full aggro. As this is a dev applied setting that defaults to on, it should
-- Only be turned off by tank modes.
if not RGMercConfig:GetSettings().StayOnTarget then
RGMercConfig.Globals.AutoTargetID = Utils.MATargetScan(RGMercConfig:GetSettings().AssistRange, RGMercConfig:GetSettings().MAScanZRange)
local autoTarget = mq.TLO.Spawn(RGMercConfig.Globals.AutoTargetID)
RGMercsLogger.log_debug("Re-Targeting: MATargetScan says we need to target %s [%d] -- Current Target: %s [%d]",
RGMercsLogger.log_verbose("Re-Targeting: MATargetScan says we need to target %s [%d] -- Current Target: %s [%d]",
autoTarget.CleanName() or "None", RGMercConfig.AutoTargetID or 0, target() and target.CleanName() or "None", target() and target.ID() or 0)
end
end
Expand All @@ -1104,11 +1126,11 @@ function Utils.FindTarget()
local assist = mq.TLO.Spawn(RGMercConfig:GetAssistId())
local assistTarget = mq.TLO.Spawn(assist.AssistName())

RGMercsLogger.log_debug("FindTarget Assisting %s [%d] -- Target Agressive: %s", RGMercConfig.Globals.MainAssist, assist.ID(),
RGMercsLogger.log_verbose("FindTarget Assisting %s [%d] -- Target Agressive: %s", RGMercConfig.Globals.MainAssist, assist.ID(),
assistTarget.Aggressive() and "True" or "False")

if assistTarget() and assistTarget.Aggressive() and (assistTarget.Type():lower() == "npc" or assistTarget.Type():lower() == "npcpet") then
RGMercsLogger.log_debug(" FindTarget Setting Target To %s [%d]", assistTarget.CleanName(), assistTarget.ID())
RGMercsLogger.log_verbose(" FindTarget Setting Target To %s [%d]", assistTarget.CleanName(), assistTarget.ID())
RGMercConfig.Globals.AutoTargetID = assistTarget.ID()
end
else
Expand Down Expand Up @@ -1192,7 +1214,7 @@ function Utils.OkToEngage(autoTargetId)
return false
end

if Utils.GetXTHaterCount() > 0 then -- TODO: or KillTargetID and !BackOffFlag
if Utils.GetXTHaterCount() > 0 then -- TODO: or AutoTargetID and !BackOffFlag
if target.Distance() < config.AssistRange and (target.PctHPs() < config.AutoAssistAt or RGMercConfig.Globals.IsTanking or assistId == mq.TLO.Me.ID()) then
if not mq.TLO.Me.Combat() then
RGMercsLogger.log_debug("\ay%d < %d and %d < %d or Tanking or %d == %d --> \agOK To Engage!",
Expand Down

0 comments on commit 9504746

Please sign in to comment.