forked from DerpleMQ2/rgmercs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
551 lines (445 loc) · 20.9 KB
/
init.lua
File metadata and controls
551 lines (445 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
local mq = require('mq')
local ImGui = require('ImGui')
local GitCommit = require('extras.version')
DanNet = require('lib.dannet.helpers')
RGMercsBinds = require('utils.rgmercs_binds')
RGMercsEvents = require('utils.rgmercs_events')
RGMercsLogger = require("utils.rgmercs_logger")
RGMercConfig = require('utils.rgmercs_config')
RGMercConfig:LoadSettings()
RGMercsConsole = nil
RGMercsLogger.set_log_level(RGMercConfig:GetSettings().LogLevel)
local RGMercUtils = require("utils.rgmercs_utils")
RGMercNameds = require("utils.rgmercs_named")
-- Initialize class-based moduldes
RGMercModules = require("utils.rgmercs_modules").load()
require('utils.rgmercs_datatypes')
-- ImGui Variables
local openGUI = true
local shouldDrawGUI = true
local notifyZoning = true
local curState = "Downtime"
-- Icon Rendering
local animItems = mq.FindTextureAnimation("A_DragItem")
local animBox = mq.FindTextureAnimation("A_RecessedBox")
local derpImg = mq.CreateTexture(mq.TLO.Lua.Dir() .. "/rgmercs/extras/derpdog.jpg")
-- Constants
local ICON_WIDTH = 40
local ICON_HEIGHT = 40
local COUNT_X_OFFSET = 39
local COUNT_Y_OFFSET = 23
local EQ_ICON_OFFSET = 500
-- UI --
local function display_item_on_cursor()
if mq.TLO.Cursor() then
local cursor_item = mq.TLO.Cursor -- this will be an MQ item, so don't forget to use () on the members!
local draw_list = ImGui.GetForegroundDrawList()
local window_x, window_y = ImGui.GetWindowPos()
local window_w, window_h = ImGui.GetWindowSize()
local mouse_x, mouse_y = ImGui.GetMousePos()
if mouse_x < window_x or mouse_x > window_x + window_w then return end
if mouse_y < window_y or mouse_y > window_y + window_h then return end
local icon_x = mouse_x + 10
local icon_y = mouse_y + 10
local stack_x = icon_x + COUNT_X_OFFSET + 10
local stack_y = (icon_y + COUNT_Y_OFFSET)
animItems:SetTextureCell(cursor_item.Icon() - EQ_ICON_OFFSET)
draw_list:AddTextureAnimation(animItems, ImVec2(icon_x, icon_y), ImVec2(ICON_WIDTH, ICON_HEIGHT))
if cursor_item.Stackable() then
local text_size = ImGui.CalcTextSize(tostring(cursor_item.Stack()))
draw_list:AddTextureAnimation(animBox, ImVec2(stack_x, stack_y), ImVec2(text_size, ImGui.GetTextLineHeight()))
draw_list:AddText(ImVec2(stack_x, stack_y), IM_COL32(255, 255, 255, 255), tostring(cursor_item.Stack()))
end
end
end
local function renderModulesTabs()
if not RGMercConfig:SettingsLoaded() then return end
for _, name in ipairs(RGMercModules:GetModuleOrderedNames()) do
if RGMercModules:ExecModule(name, "ShouldRender") then
if ImGui.BeginTabItem(name) then
RGMercModules:ExecModule(name, "Render")
ImGui.EndTabItem()
end
end
end
end
local function Alive()
return mq.TLO.NearestSpawn('pc')() ~= nil
end
local function GetTheme()
return RGMercModules:ExecModule("Class", "GetTheme")
end
local function RenderTarget()
ImGui.Text("Auto Target: ")
ImGui.SameLine()
if RGMercConfig.Globals.AutoTargetID == 0 then
ImGui.Text("None")
ImGui.ProgressBar(0, -1, 25)
else
local assistSpawn = RGMercUtils.GetAutoTarget()
local pctHPs = assistSpawn.PctHPs() or 0
if not pctHPs then pctHPs = 0 end
local ratioHPs = pctHPs / 100
ImGui.PushStyleColor(ImGuiCol.PlotHistogram, 1 - ratioHPs, ratioHPs, 0, 1)
if math.floor(assistSpawn.Distance() or 0) >= 350 then
ImGui.PushStyleColor(ImGuiCol.Text, 1.0, 0.0, 0.0, 1)
else
ImGui.PushStyleColor(ImGuiCol.Text, 1, 1, 1, 1)
end
ImGui.Text(string.format("%s (%s) [%d %s] HP: %d%% Dist: %d", assistSpawn.CleanName() or "", assistSpawn.ID() or 0, assistSpawn.Level() or 0,
assistSpawn.Class.ShortName() or "N/A", assistSpawn.PctHPs() or 0, assistSpawn.Distance() or 0))
ImGui.ProgressBar(ratioHPs, -1, 25)
ImGui.PopStyleColor(2)
end
end
---@return number
local function GetMainOpacity()
return tonumber(RGMercUtils.GetSetting('BgOpacity')) or 1.0
end
local function RGMercsGUI()
local theme = GetTheme()
local themeStylePop = 0
if RGMercsConsole == nil then
RGMercsConsole = ImGui.ConsoleWidget.new("##RGMercsConsole")
RGMercsConsole.maxBufferLines = 100
RGMercsConsole.autoScroll = true
if RGMercsConsole.opacity then
RGMercsConsole.opacity = GetMainOpacity()
end
end
if mq.TLO.MacroQuest.GameState() == "CHARSELECT" then
openGUI = false
return
end
if openGUI and Alive() then
if theme ~= nil then
for _, t in pairs(theme) do
ImGui.PushStyleColor(t.element, t.color.r, t.color.g, t.color.b, t.color.a)
themeStylePop = themeStylePop + 1
end
end
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, GetMainOpacity()) -- Main window opacity.
openGUI, shouldDrawGUI = ImGui.Begin('RGMercs', openGUI)
ImGui.PushID("##RGMercsUI_" .. RGMercConfig.Globals.CurLoadedChar)
if shouldDrawGUI then
local pressed
ImGui.Image(derpImg:GetTextureID(), ImVec2(40, 40))
ImGui.SameLine()
ImGui.Text(string.format("RGMercs [%s/%s] by: %s running for %s (%s)\nBuild: %s", RGMercConfig._version, RGMercConfig._subVersion, RGMercConfig._author,
RGMercConfig.Globals.CurLoadedChar,
RGMercConfig.Globals.CurLoadedClass, GitCommit.commitId or "None"))
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", ImGui.GetWindowWidth(), 40) then
RGMercConfig.Globals.PauseMain = not RGMercConfig.Globals.PauseMain
end
ImGui.PopStyleColor()
RenderTarget()
ImGui.NewLine()
ImGui.Separator()
local newOpacity, changed = ImGui.SliderFloat("Opacity", tonumber(RGMercUtils.GetSetting('BgOpacity')) or 1.0, 0.1, 1.0)
if changed then
RGMercConfig:GetSettings().BgOpacity = tostring(newOpacity)
if RGMercsConsole.opacity then
RGMercsConsole.opacity = GetMainOpacity()
end
RGMercConfig:SaveSettings(false)
end
if ImGui.BeginTabBar("RGMercsTabs", ImGuiTabBarFlags.None) then
ImGui.SetItemDefaultFocus()
if ImGui.BeginTabItem("RGMercsMain") then
ImGui.Text("Current State: " .. curState)
ImGui.Text("Hater Count: " .. tostring(RGMercUtils.GetXTHaterCount()))
-- .. tostring(RGMercConfig.Globals.AutoTargetID))
ImGui.Text("MA: " .. (RGMercUtils.GetMainAssistSpawn().CleanName() or "None"))
if mq.TLO.Target.ID() > 0 and mq.TLO.Target.Type():lower() == "pc" and RGMercConfig.Globals.MainAssist ~= mq.TLO.Target.ID() then
if ImGui.SmallButton("Set MA to Current Target") then
RGMercConfig.Globals.AutoTargetID = mq.TLO.Target.ID()
end
end
ImGui.Text("Stuck To: " .. (mq.TLO.Stick.Active() and (mq.TLO.Stick.StickTargetName() or "None") or "None"))
if ImGui.CollapsingHeader("Config Options") then
local settingsRef = RGMercConfig:GetSettings()
settingsRef, pressed, _ = RGMercUtils.RenderSettings(settingsRef, RGMercConfig.DefaultConfig, RGMercConfig.DefaultCategories)
if pressed then
RGMercConfig:SaveSettings(false)
end
end
for n, s in pairs(RGMercConfig.SubModuleSettings) do
if RGMercModules:ExecModule(n, "ShouldRender") then
ImGui.PushID(n .. "_config_hdr")
if s and s.settings and s.defaults and s.categories then
if ImGui.CollapsingHeader(string.format("%s: Config Options", n)) then
s.settings, pressed, _ = RGMercUtils.RenderSettings(s.settings, s.defaults, s.categories)
if pressed then
RGMercModules:ExecModule(n, "SaveSettings", true)
end
end
end
ImGui.PopID()
end
end
if ImGui.CollapsingHeader("Outside Assist List") then
RGMercUtils.RenderOAList()
end
if ImGui.CollapsingHeader("Zone Named") then
RGMercUtils.RenderZoneNamed()
end
ImGui.EndTabItem()
end
renderModulesTabs()
ImGui.EndTabBar();
end
ImGui.NewLine()
ImGui.NewLine()
ImGui.Separator()
if RGMercsConsole then
local changed
RGMercConfig:GetSettings().LogLevel, changed = ImGui.Combo("Debug Level", RGMercUtils.GetSetting('LogLevel'), RGMercConfig.Constants.LogLevels,
#RGMercConfig.Constants.LogLevels)
if changed then
RGMercConfig:SaveSettings(false)
end
if ImGui.CollapsingHeader("Debug Output", ImGuiTreeNodeFlags.DefaultOpen) then
local cur_x, cur_y = ImGui.GetCursorPos()
local contentSizeX, contentSizeY = ImGui.GetContentRegionAvail()
if not RGMercsConsole.opacity then
local scroll = ImGui.GetScrollY()
ImGui.Dummy(contentSizeX, 410)
ImGui.SetCursorPos(cur_x, cur_y)
RGMercsConsole:Render(ImVec2(contentSizeX, math.min(400, contentSizeY + scroll)))
else
RGMercsConsole:Render(ImVec2(contentSizeX, math.max(200, (contentSizeY - 10))))
end
ImGui.Separator()
end
end
display_item_on_cursor()
end
ImGui.PopID()
ImGui.End()
if themeStylePop > 0 then
ImGui.PopStyleColor(themeStylePop)
end
ImGui.PopStyleVar(1)
end
end
mq.imgui.init('RGMercsUI', RGMercsGUI)
-- End UI --
local unloadedPlugins = {}
local function RGInit(...)
RGMercUtils.CheckPlugins({
"MQ2Cast",
"MQ2Rez",
"MQ2AdvPath",
"MQ2MoveUtils",
"MQ2Nav",
"MQ2DanNet", })
unloadedPlugins = RGMercUtils.UnCheckPlugins({ "MQ2Melee", })
-- complex objects are passed by reference so we can just use these without having to pass them back in for saving.
RGMercConfig.SubModuleSettings = RGMercModules:ExecAll("Init")
if not RGMercUtils.GetSetting('DoTwist') then
local unloaded = RGMercUtils.UnCheckPlugins({ "MQ2Twist", })
if #unloaded == 1 then table.insert(unloadedPlugins, unloaded[1]) end
end
local mainAssist = mq.TLO.Target.CleanName() or ""
if mainAssist:len() == 0 and mq.TLO.Group() then
mainAssist = mq.TLO.Group.MainAssist() or ""
end
for k, v in ipairs(RGMercConfig.ExpansionIDToName) do
RGMercsLogger.log_debug("\ayExpansion \at%s\ao[\am%d\ao]: %s", v, k, RGMercUtils.HaveExpansion(v) and "\agEnabled" or "\arDisabled")
end
-- TODO: Can turn this into an options parser later.
if ... then
mainAssist = ...
end
if not mainAssist or mainAssist == "" then
mainAssist = mq.TLO.Me.CleanName()
end
RGMercUtils.DoCmd("/squelch /rez accept on")
RGMercUtils.DoCmd("/squelch /rez pct 90")
if mq.TLO.Plugin("MQ2DanNet")() then
RGMercUtils.DoCmd("/squelch /dnet commandecho off")
end
RGMercUtils.DoCmd("/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())
RGMercUtils.DoCmd("/squelch /docommand /%s pause on", mq.TLO.Me.Class.ShortName())
if RGMercUtils.CanUseAA("Companion's Discipline") then
RGMercUtils.DoCmd("/pet ghold on")
else
RGMercUtils.DoCmd("/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())
RGMercUtils.DoCmd("/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(RGMercUtils.GetMainAssistId())
RGMercsLogger.log_info("\aw Assisting \ay >> \ag %s \ay << \aw at \ag %d%%", RGMercConfig.Globals.MainAssist, RGMercUtils.GetSetting('AutoAssistAt'))
end
if RGMercUtils.GetGroupMainAssistName() ~= mainAssist then
RGMercUtils.PopUp(string.format("Assisting: %s NOTICE: Group MainAssist [%s] != Your Assist Target [%s]. Is This On Purpose?", mainAssist,
RGMercUtils.GetGroupMainAssistName(), mainAssist))
end
-- store initial positioning data.
RGMercConfig:StoreLastMove()
end
local function Main()
if mq.TLO.Me.Zoning() then
if notifyZoning then
RGMercModules:ExecAll("OnZone")
notifyZoning = false
end
mq.delay(1000)
return
end
notifyZoning = true
if RGMercConfig.Globals.PauseMain then
mq.delay(1000)
mq.doevents()
if RGMercUtils.GetSetting('RunMovePaused') then
RGMercModules:ExecModule("Movement", "GiveTime", curState)
end
return
end
if RGMercUtils.GetXTHaterCount() > 0 then
curState = "Combat"
if os.clock() - RGMercConfig.Globals.LastFaceTime > 6 then
RGMercConfig.Globals.LastFaceTime = os.clock()
RGMercUtils.DoCmd("/squelch /face")
end
else
curState = "Downtime"
end
if mq.TLO.MacroQuest.GameState() ~= "INGAME" then return end
if RGMercConfig.Globals.CurLoadedChar ~= mq.TLO.Me.DisplayName() then
RGMercConfig:LoadSettings()
RGMercModules:ExecAll("LoadSettings")
end
RGMercConfig:StoreLastMove()
if mq.TLO.Me.Hovering() then RGMercUtils.HandleDeath() end
RGMercUtils.SetControlToon()
if RGMercUtils.FindTargetCheck() then
-- This will find a valid target and set it to : RGMercConfig.Globals.AutoTargetID
RGMercUtils.FindTarget()
end
if RGMercUtils.OkToEngage(RGMercConfig.Globals.AutoTargetID) then
RGMercUtils.SetTarget(RGMercConfig.Globals.AutoTargetID)
RGMercUtils.EngageTarget(RGMercConfig.Globals.AutoTargetID)
else
if RGMercUtils.GetXTHaterCount() > 0 and RGMercUtils.GetTargetID() > 0 then
RGMercsLogger.log_debug("\ayClearing Target because we are not OkToEngage() and we are in combat!")
RGMercUtils.ClearTarget()
end
end
-- Handles state for when we're in combat
if RGMercUtils.DoCombatActions() and not RGMercUtils.GetSetting('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 RGMercUtils.IsHealing() or not RGMercUtils.IsMezzing()) then
RGMercUtils.FindTarget()
if RGMercUtils.GetTargetID() ~= RGMercConfig.Globals.AutoTargetID then
RGMercUtils.SetTarget(RGMercConfig.Globals.AutoTargetID)
end
end
if ((os.clock() - RGMercConfig.Globals.LastPetCmd) > 2) then
RGMercConfig.Globals.LastPetCmd = os.clock()
if RGMercUtils.GetSetting('DoPet') and (RGMercUtils.GetTargetPctHPs() <= RGMercUtils.GetSetting('PetEngagePct')) then
RGMercUtils.PetAttack(RGMercConfig.Globals.AutoTargetID)
end
end
if RGMercUtils.GetSetting('DoMercenary') then
local merc = mq.TLO.Me.Mercenary
if merc() and merc.ID() then
if RGMercUtils.MercEngage() then
if merc.Class.ShortName():lower() == "war" and merc.Stance():lower() ~= "aggressive" then
RGMercUtils.DoCmd("/squelch /stance aggressive")
end
if merc.Class.ShortName():lower() ~= "war" and merc.Stance():lower() ~= "balanced" then
RGMercUtils.DoCmd("/squelch /stance balanced")
end
RGMercUtils.MercAssist()
else
if merc.Class.ShortName():lower() ~= "clr" and merc.Stance():lower() ~= "passive" then
RGMercUtils.DoCmd("/squelch /stance passive")
end
end
end
end
end
if RGMercUtils.DoCamp() then
if RGMercUtils.GetSetting('DoMercenary') and mq.TLO.Me.Mercenary.ID() and (mq.TLO.Me.Mercenary.Class.ShortName() or "none"):lower() ~= "clr" and mq.TLO.Me.Mercenary.Stance():lower() ~= "passive" then
RGMercUtils.DoCmd("/squelch /stance passive")
end
end
if RGMercUtils.DoBuffCheck() and not RGMercUtils.GetSetting('PriorityHealing') then
-- TODO: Group Buffs
end
if RGMercUtils.GetSetting('DoModRod') then
RGMercUtils.ClickModRod()
end
if RGMercUtils.GetSetting('DoMed') >= 2 then
RGMercUtils.AutoMed()
end
if RGMercUtils.ShouldKillTargetReset() then
RGMercConfig.Globals.AutoTargetID = 0
end
-- If target is not attackable then turn off attack
local pcCheck = (mq.TLO.Target.Type() or "none"):lower() == "pc" or
((mq.TLO.Target.Type() or "none"):lower() == "pet" and (mq.TLO.Target.Master.Type() or "none"):lower() == "pc")
local mercCheck = mq.TLO.Target.Type() == "mercenary"
if mq.TLO.Me.Combat() and (not mq.TLO.Target() or pcCheck or mercCheck) then
RGMercsLogger.log_debug("\ay[1] Target type check failed \aw[\atinCombat(%s) pcCheckFailed(%s) mercCheckFailed(%s)\aw]\ay - turning attack off!",
RGMercUtils.BoolToString(mq.TLO.Me.Combat()), RGMercUtils.BoolToString(pcCheck), RGMercUtils.BoolToString(mercCheck))
RGMercUtils.DoCmd("/attack off")
end
-- TODO: Fix Curing
-- Revive our mercenary if they're dead and we're using a mercenary
if RGMercUtils.GetSetting('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.doevents()
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.Globals.CurLoadedChar then return end
if message()["script"] ~= RGMercUtils.ScriptName then return end
RGMercsLogger.log_info("\ayGot Event from(\am%s\ay) module(\at%s\ay) event(\at%s\ay)", message()["from"],
message()["module"],
message()["event"])
if message()["module"] then
if message()["module"] == "main" then
RGMercConfig:LoadSettings()
else
RGMercModules:ExecModule(message()["module"], message()["event"], message()["data"])
end
end
end)
-- Binds
mq.bind("/rglua", RGMercsBinds.MainHandler)
RGInit(...)
while openGUI do
Main()
mq.doevents()
mq.delay(10)
end
RGMercModules:ExecAll("Shutdown")