Skip to content

Commit

Permalink
Main loop for combat is now complete
Browse files Browse the repository at this point in the history
  • Loading branch information
DerpleMQ2 committed Dec 31, 2023
1 parent 7183bb3 commit 5a65d08
Show file tree
Hide file tree
Showing 9 changed files with 5,458 additions and 150 deletions.
10 changes: 5 additions & 5 deletions class_configs/shd_class_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ local _ClassConfig = {
tooltip = Tooltips.ExplosionOfHatred,
cond = function(self)
return mq.TLO.SpawnCount("NPC radius 50 zradius 50")() >= self.settings.AeTauntCnt and
mq.TLO.XAssist.XTFullHaterCount() >= self.settings.AeTauntCnt
RGMercUtils.GetXTHaterCount() >= self.settings.AeTauntCnt
end
},
[5] = {
Expand All @@ -779,7 +779,7 @@ local _ClassConfig = {
tooltip = Tooltips.ExplosionOfSpite,
cond = function(self)
return mq.TLO.SpawnCount("NPC radius 50 zradius 50")() >= self.settings.AeTauntCnt and
mq.TLO.XAssist.XTFullHaterCount() >= self.settings.AeTauntCnt
RGMercUtils.GetXTHaterCount() >= self.settings.AeTauntCnt
end
},
[6] = {
Expand Down Expand Up @@ -1195,7 +1195,7 @@ local _ClassConfig = {
self)
return self.settings.DoBandolier and not mq.TLO.Me.Bandolier("2HS").Active() and
mq.TLO.Me.Bandolier("2HS").Index() and
mq.TLO.XAssist.XTFullHaterCount() < self.settings.BurnMobCount and
RGMercUtils.GetXTHaterCount() < self.settings.BurnMobCount and
not mq.TLO.Target.Named()
end,
cmd = "/bandolier activate 2HS"
Expand Down Expand Up @@ -1247,7 +1247,7 @@ local _ClassConfig = {
self, spell)
return self.settings.DoAE and
mq.TLO.SpawnCount("NPC radius 60 zradius 50")() >= self.settings.AeTauntCnt and
mq.TLO.XAssist.XTFullHaterCount() >= self.settings.AeTauntCnt
RGMercUtils.GetXTHaterCount() >= self.settings.AeTauntCnt
end
},
[8] = {
Expand Down Expand Up @@ -1517,7 +1517,7 @@ local _ClassConfig = {
self)
return self.settings.DoBandolier and not mq.TLO.Me.Bandolier("2HS").Active() and
mq.TLO.Me.Bandolier("2HS").Index() and
mq.TLO.XAssist.XTFullHaterCount() < self.settings.BurnMobCount and
RGMercUtils.GetXTHaterCount() < self.settings.BurnMobCount and
not mq.TLO.Target.Named()
end,
cmd = "/bandolier activate 2HS"
Expand Down
201 changes: 177 additions & 24 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ local ImGui = require('ImGui')
RGMercConfig = require('rgmercs.utils.rgmercs_config')
RGMercConfig:LoadSettings()

local RGMercsLogger = require("rgmercs.utils.rgmercs_logger")
local RGMercsLogger = require("rgmercs.utils.rgmercs_logger")
RGMercsLogger.set_log_level(RGMercConfig:GetSettings().LogLevel)

local RGMercUtils = require("rgmercs.utils.rgmercs_utils")

RGMercNameds = require("rgmercs.utils.rgmercs_named")

-- Initialize class-based moduldes
local RGMercModules = require("rgmercs.utils.rgmercs_modules").load()
RGMercModules = require("rgmercs.utils.rgmercs_modules").load()

-- ImGui Variables
local openGUI = true
local shouldDrawGUI = true
local BgOpacity = tonumber(RGMercConfig:getSettings().BgOpacity)
local BgOpacity = tonumber(RGMercConfig:GetSettings().BgOpacity)

local curState = "Idle..."
local curState = "Downtime"

-- Icon Rendering
local animItems = mq.FindTextureAnimation("A_DragItem")
Expand Down Expand Up @@ -53,7 +57,7 @@ local function display_item_on_cursor()
end

local function renderModulesTabs()
if not RGMercConfig:settingsLoaded() then return end
if not RGMercConfig:SettingsLoaded() then return end

local tabNames = {}
for name, _ in pairs(RGMercModules:getModuleList()) do
Expand Down Expand Up @@ -81,21 +85,36 @@ local function RGMercsGUI()
if shouldDrawGUI then
local pressed
ImGui.PushStyleColor(ImGuiCol.Text, 1.0, 1.0, 1.0, 1)
ImGui.Text(string.format("RGMercs running for %s (%s)", RGMercConfig.CurLoadedChar,
RGMercConfig.CurLoadedClass))
ImGui.Text(string.format("RGMercs running for %s (%s)", RGMercConfig.Globals.CurLoadedChar,
RGMercConfig.Globals.CurLoadedClass))

if RGMercConfig.Globals.PauseMain then
ImGui.PushStyleColor(ImGuiCol.Button, 0.3, 0.7, 0.3, 1)
else
ImGui.PushStyleColor(ImGuiCol.Button, 0.7, 0.3, 0.3, 1)
end

if ImGui.Button(RGMercConfig.Globals.PauseMain and "Unpause" or "Pause", 300, 40) then
RGMercConfig.Globals.PauseMain = not RGMercConfig.Globals.PauseMain
end
ImGui.PopStyleColor()

if ImGui.BeginTabBar("RGMercsTabs") then
ImGui.SetItemDefaultFocus()
if ImGui.BeginTabItem("RGMercsMain") then
ImGui.Text(curState)
ImGui.Text("Current State: " .. curState)
ImGui.Text("Hater Count: " .. tostring(RGMercUtils.GetXTHaterCount()))
if ImGui.CollapsingHeader("Config Options") then
local newSettings = RGMercConfig:getSettings()
local newSettings = RGMercConfig:GetSettings()
newSettings, pressed, _ = RGMercUtils.RenderSettings(newSettings, RGMercConfig.DefaultConfig)
if pressed then
RGMercConfig:setSettings(newSettings)
RGMercConfig:SetSettings(newSettings)
RGMercConfig:SaveSettings(true)
end
end
if ImGui.CollapsingHeader("Zone Named") then
RGMercUtils.RenderZoneNamed()
end

ImGui.EndTabItem()
end
Expand All @@ -113,7 +132,7 @@ local function RGMercsGUI()

BgOpacity, pressed = ImGui.SliderFloat("BG Opacity", BgOpacity, 0, 1.0, "%.1f", 0.1)
if pressed then
RGMercConfig:getSettings().BgOpacity = tostring(BgOpacity)
RGMercConfig:GetSettings().BgOpacity = tostring(BgOpacity)
RGMercConfig:SaveSettings(true)
end

Expand All @@ -132,19 +151,30 @@ end)
-- End UI --
local unloadedPlugins = {}

local function RGInit()
local function RGInit(...)
RGMercUtils.CheckPlugins({
"MQ2Cast",
"MQ2Rez",
"MQ2AdvPath",
"MQ2MoveUtils",
"MQ2Nav",
"MQ2DanNet",
"MQ2Xassist",
"MQ2SpawnMaster" })

unloadedPlugins = RGMercUtils.UnCheckPlugins({ "MQ2Melee" })

if not RGMercConfig:GetSettings().DoTwist then
local unloaded = RGMercUtils.UnCheckPlugins({ "MQ2Twist" })
if #unloaded == 1 then table.insert(unloadedPlugins, unloaded[1]) end
end

local mainAssist = mq.TLO.Me.Name()

-- TODO: Can turn this into an options parser later.
if ... then
mainAssist = ...
end

mq.cmdf("/squelch /rez accept on")
mq.cmdf("/squelch /rez pct 90")

Expand All @@ -155,35 +185,154 @@ local function RGInit()
mq.cmdf("/stick set breakontarget on")

-- TODO: Chat Begs

RGMercUtils.PrintGroupMessage("Pausing the CWTN Plugin on this host If it exists! (/%s pause on)", mq.TLO.Me.Class.ShortName())
mq.cmdf("/squelch /docommand /%s pause on", mq.TLO.Me.Class.ShortName())

if RGMercUtils.CanUseAA("Companion's Discipline") then
mq.cmdf("/pet ghold on")
else
mq.cmdf("/pet hold on")
end

if mq.TLO.Cursor() and mq.TLO.Cursor.ID() > 0 then
RGMercsLogger.log_info("Sending Item(%s) on Cursor to Bag", mq.TLO.Cursor())
mq.cmdf("/autoinventory")
end

RGMercUtils.WelcomeMsg()

if mainAssist:len() > 0 then
RGMercConfig.Globals.MainAssist = mainAssist
RGMercUtils.PopUp("Targetting %s for Main Assist", RGMercConfig.Globals.MainAssist)
RGMercUtils.SetTarget(RGMercConfig:GetAssistId())
RGMercsLogger.log_info("\aw Assisting \ay >> \ag %s \ay << \aw at \ag %d%%", RGMercConfig.Globals.MainAssist, RGMercConfig:GetSettings().AutoAssistAt)
end

if mq.TLO.Group.MainAssist.CleanName() ~= mainAssist then
RGMercUtils.PopUp("Assisting %s NOTICE: Group MainAssist != Your Target. Is This On Purpose?")
end
end

local function Main()
curState = "Idle..."
curState = "Downtime"
if mq.TLO.Me.Zoning() then
mq.delay(1000)
return
end

if mq.TLO.Me.Zoning() then return end
if RGMercConfig.Globals.PauseMain then
mq.delay(1000)
return
end

if mq.TLO.MacroQuest.GameState() ~= "INGAME" then return end

if RGMercConfig.CurLoadedChar ~= mq.TLO.Me.CleanName() then
if RGMercConfig.Globals.CurLoadedChar ~= mq.TLO.Me.CleanName() then
RGMercConfig:LoadSettings()
end

local state = "Downtime"
if mq.TLO.XAssist.XTFullHaterCount() > 0 then
state = "Combat"
RGMercConfig:StoreLastMove()

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

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

RGMercUtils.SetControlTool()

if RGMercUtils.OkToEngage(RGMercConfig:getSettings(), mq.TLO.Me.ID(), mq.TLO.Target.ID(), true) then
RGMercUtils.EngageTarget(RGMercConfig:getSettings(), mq.TLO.Me.ID(), mq.TLO.Target.ID())
if RGMercUtils.FindTargetCheck() then
RGMercUtils.FindTarget()
end

if RGMercUtils.OkToEngage(mq.TLO.Target.ID(), true) then
RGMercUtils.EngageTarget(mq.TLO.Target.ID())
end
end

RGMercModules:execAll("GiveTime", state)
-- TODO: Write Healing Module

-- Handles state for when we're in combat
if RGMercUtils.DoCombatActions() and not RGMercConfig:GetSettings().PriorityHealing then
-- IsHealing or IsMezzing should re-determine their target as this point because they may
-- have switched off to mez or heal after the initial find target check and the target
-- may have changed by this point.
if RGMercUtils.FindTargetCheck() and (not RGMercConfig.Globals.IsHealing or not RGMercConfig.Globals.IsMezzing) then
RGMercUtils.FindTarget()
end

if RGMercConfig:GetSettings().DoMercenary then
local merc = mq.TLO.Me.Mercenary

if merc() then
if RGMercUtils.MercEngage() then
if merc.Class.ShortName():lower() == "war" and merc.Stance():lower() ~= "aggressive" then
mq.cmdf("/squelch /stance aggressive")
end

if merc.Class.ShortName():lower() ~= "war" and merc.Stance():lower() ~= "balanced" then
mq.cmdf("/squelch /stance balanced")
end

RGMercUtils.MercAssist()
else
if merc.Class.ShortName():lower() ~= "clr" and merc.Stance():lower() ~= "passive" then
mq.cmdf("/squelch /stance passive")
end
end
end
end
end

if RGMercUtils.DoCamp() then
if mq.TLO.Me.Mercenary() and mq.TLO.Me.Mercenary.Class.ShortName():lower() ~= "clr" and mq.TLO.Me.Mercenary.Stance():lower() ~= "passive" then
mq.cmdf("/squelch /stance passive")
end
end

if RGMercUtils.DoBuffCheck() and not RGMercConfig:GetSettings().PriorityHealing then
-- TODO: Shrink Check
-- TODO: Group Buffs
-- TODO: Pull Delay Handling
end

if RGMercConfig:GetSettings().DoModRod then
RGMercUtils.ClickModRod()
end

if RGMercConfig:GetSettings().DoMed then
RGMercUtils.AutoMed()
end

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

-- TODO: Fix Curing

-- Revive our mercenary if they're dead and we're using a mercenary
if RGMercConfig:GetSettings().DoMercenary then
if mq.TLO.Me.Mercenary.State():lower() == "dead" then
if mq.TLO.Window("MMGW_ManageWnd").Child("MMGW_SuspendButton").Text():lower() == "revive" then
mq.TLO.Window("MMGW_ManageWnd").Child("MMGW_SuspendButton").LeftMouseUp()
end
else
if mq.TLO.Window("MMGW_ManageWnd").Child("MMGW_AssistModeCheckbox").Checked() then
mq.TLO.Window("MMGW_ManageWnd").Child("MMGW_AssistModeCheckbox").LeftMouseUp()
end
end
end

RGMercModules:execAll("GiveTime", curState)

mq.delay(100)
end

-- Global Messaging callback
---@diagnostic disable-next-line: unused-local
local script_actor = RGMercUtils.Actors.register(function(message)
if message()["from"] == RGMercConfig.CurLoadedChar then return end
if message()["from"] == RGMercConfig.Globals.CurLoadedChar then return end
if message()["script"] ~= RGMercUtils.ScriptName then return end

RGMercsLogger.log_error("\ayGot Event from(\am%s\ay) module(\at%s\ay) event(\at%s\ay)", message()["from"],
Expand All @@ -205,14 +354,18 @@ local function bindHandler(cmd, ...)
RGMercModules:execModule("Chase", "ChaseOn", ...)
elseif cmd:lower() == "chaseoff" then
RGMercModules:execModule("Chase", "ChaseOff", ...)
elseif cmd:lower() == "campon" then
RGMercModules:execModule("Chase", "CampOn", ...)
elseif cmd:lower() == "campoff" then
RGMercModules:execModule("Chase", "CampOff", ...)
else
RGMercsLogger.log_warning("\ayWarning:\ay '\at%s\ay' is not a valid command", cmd)
end
end

mq.bind("/rglua", bindHandler)

RGInit()
RGInit(...)

while not terminate do
Main()
Expand Down
6 changes: 3 additions & 3 deletions modules/basic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local function getConfigFileName()
local server = mq.TLO.EverQuest.Server()
server = server:gsub(" ", "")
return mq.configDir ..
'/rgmercs/PCConfigs/' .. Module.name .. "_" .. server .. "_" .. RGMercConfig.CurLoadedChar .. '.lua'
'/rgmercs/PCConfigs/' .. Module.name .. "_" .. server .. "_" .. RGMercConfig.Globals.CurLoadedChar .. '.lua'
end

function Module:SaveSettings(doBroadcast)
Expand All @@ -22,7 +22,7 @@ function Module:SaveSettings(doBroadcast)
end

function Module:LoadSettings()
RGMercsLogger.log_info("Basic Combat Module Loading Settings for: %s.", RGMercConfig.CurLoadedChar)
RGMercsLogger.log_info("Basic Combat Module Loading Settings for: %s.", RGMercConfig.Globals.CurLoadedChar)
local settings_pickle_path = getConfigFileName()

local config, err = loadfile(settings_pickle_path)
Expand Down Expand Up @@ -55,7 +55,7 @@ function Module:Render()
end
end

function Module:GiveTime()
function Module:GiveTime(combat_state)
-- Main Module logic goes here.
end

Expand Down

0 comments on commit 5a65d08

Please sign in to comment.