-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMephisto.lua
805 lines (683 loc) · 21.4 KB
/
Mephisto.lua
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
Mephisto = Mephisto or {}
local MP = Mephisto
local MPQ = MP.queue
local MPV = MP.validation
MP.name = "Mephisto"
MP.simpleName = "Mephisto"
MP.displayName =
"|ca5cd84M|caca665E|cae7A49P|ca91922H|cc2704DI|cd8b080S|ce1c895T|ce4d09dO|"
MP.version = "2.2.7"
MP.zones = {}
MP.currentIndex = 0
local cancelAnimation = false
local cpCooldown = 0
local wipeChangeCooldown = false
local bossLastName = "MP"
local blockTrash = nil
local logger = LibDebugLogger( MP.name )
function MP.GetSetupsAmount()
local count = 0
for _ in pairs( MP.setups[ MP.selection.zone.tag ][ MP.selection.pageId ] ) do
count = count + 1
end
return count
end
function MP.LoadSetupAdjacent( direct )
local zone = MP.selection.zone
local pageId = MP.selection.pageId
local newSetupId = MP.currentIndex + direct
if newSetupId > MP.GetSetupsAmount() then newSetupId = 1 end
if newSetupId < 1 then newSetupId = MP.GetSetupsAmount() end
MP.LoadSetup( zone, pageId, newSetupId, false )
end
function MP.LoadSetup( zone, pageId, index, auto )
if not zone or not pageId or not index then
return false
end
local setup = Setup:FromStorage( zone.tag, pageId, index )
if setup:IsEmpty() then
if not auto then
MP.Log( GetString( MP_MSG_EMPTYSETUP ), MP.LOGTYPES.INFO )
end
return false
end
if MP.settings.auto.gear then MP.LoadGear( setup ) end
if MP.settings.auto.skills then MP.LoadSkills( setup ) end
if MP.settings.auto.cp then MP.LoadCP( setup ) end
if MP.settings.auto.food then MP.EatFood( setup ) end
local pageName = MP.pages[ zone.tag ][ pageId ].name
MP.gui.SetPanelText( zone.tag, pageName, setup:GetName() )
local logMessage = IsUnitInCombat( "player" ) and GetString( MP_MSG_LOADINFIGHT ) or GetString( MP_MSG_LOADSETUP )
local logColor = IsUnitInCombat( "player" ) and MP.LOGTYPES.INFO or MP.LOGTYPES.NORMAL
MP.Log( logMessage, logColor, "FFFFFF", setup:GetName(), zone.name )
setup:ExecuteCode( setup, zone, pageId, index, auto )
MP.currentIndex = index
MPV.SetupFailWorkaround()
return true
end
function MP.LoadSetupCurrent( index, auto )
local zone = MP.selection.zone
local pageId = MP.selection.pageId
MP.LoadSetup( zone, pageId, index, auto )
end
function MP.LoadSetupSubstitute( index )
if not MP.zones[ "SUB" ] or not MP.pages[ "SUB" ] then return end
MP.LoadSetup( MP.zones[ "SUB" ], MP.pages[ "SUB" ][ 0 ].selected, index, true )
end
function MP.SaveSetup( zone, pageId, index, skip )
local setup = Setup:FromStorage( zone.tag, pageId, index )
if not skip and not setup:IsEmpty() and MP.settings.overwriteWarning then
MP.gui.ShowConfirmationDialog( "OverwriteConfirmation",
string.format( GetString( MP_OVERWRITESETUP_WARNING ), setup:GetName() ),
function()
MP.SaveSetup( zone, pageId, index, true )
end )
return
end
if MP.settings.auto.gear then MP.SaveGear( setup ) end
if MP.settings.auto.skills then MP.SaveSkills( setup ) end
if MP.settings.auto.cp then MP.SaveCP( setup ) end
if MP.settings.auto.food then MP.SaveFood( setup ) end
setup:ToStorage( zone.tag, pageId, index )
MP.gui.RefreshSetup( MP.gui.GetSetupControl( index ), setup )
MP.Log( GetString( MP_MSG_SAVESETUP ), MP.LOGTYPES.NORMAL, "FFFFFF", setup:GetName() )
end
function MP.DeleteSetup( zone, pageId, index )
local setup = Setup:FromStorage( zone.tag, pageId, index )
local setupName = setup:GetName()
if MP.setups[ zone.tag ]
and MP.setups[ zone.tag ][ pageId ]
and MP.setups[ zone.tag ][ pageId ][ index ] then
table.remove( MP.setups[ zone.tag ][ pageId ], index )
end
MP.markers.BuildGearList()
MP.conditions.LoadConditions()
if zone.tag == MP.selection.zone.tag
and pageId == MP.selection.pageId then
MP.gui.BuildPage( zone, pageId )
end
MP.Log( GetString( MP_MSG_DELETESETUP ), MP.LOGTYPES.NORMAL, "FFFFFF", setupName )
end
function MP.ClearSetup( zone, pageId, index )
local setup = Setup:FromStorage( zone.tag, pageId, index )
local setupName = setup:GetName()
setup:Clear()
setup:SetName( setupName )
setup:ToStorage( zone.tag, pageId, index )
MP.markers.BuildGearList()
MP.conditions.LoadConditions()
if zone.tag == MP.selection.zone.tag
and pageId == MP.selection.pageId then
MP.gui.BuildPage( zone, pageId )
end
MP.Log( GetString( MP_MSG_DELETESETUP ), MP.LOGTYPES.NORMAL, "FFFFFF", setupName )
end
function MP.LoadSkills( setup )
local delay = 0
for hotbarCategory = 0, 1 do
local hotbarData = ACTION_BAR_ASSIGNMENT_MANAGER:GetHotbar( hotbarCategory )
local slotData = hotbarData:GetSlotData( 8 )
-- wait until mythic get changed before changing ult if mythic is cryptcanon
if slotData.abilityId == 195031 then
delay = 600
end
end
local skillTask = function()
local skillTable = setup:GetSkills()
for hotbarCategory = 0, 1 do
for slotIndex = 3, 8 do
local abilityId = skillTable[ hotbarCategory ][ slotIndex ]
if abilityId and abilityId > 0 then
MP.SlotSkill( hotbarCategory, slotIndex, abilityId )
else
if MP.settings.unequipEmpty then
abilityId = 0
MP.SlotSkill( hotbarCategory, slotIndex, 0 )
end
end
end
end
end
MPQ.Push( skillTask, delay )
MP.prebuff.cache = {}
end
function MP.SlotSkill( hotbarCategory, slotIndex, abilityId )
local hotbarData = ACTION_BAR_ASSIGNMENT_MANAGER:GetHotbar( hotbarCategory )
-- if using cryptcanon dont slot skill, since cryptcanon does it on its own
if abilityId == 195031 then
return
end
if abilityId and abilityId > 0 then
local progressionData = SKILLS_DATA_MANAGER:GetProgressionDataByAbilityId( abilityId )
if progressionData
and progressionData:GetSkillData()
and progressionData:GetSkillData():IsPurchased() then
hotbarData:AssignSkillToSlot( slotIndex, progressionData:GetSkillData() )
return true
else
local abilityName = zo_strformat( "<<C:1>>", progressionData:GetName() )
MP.Log( GetString( MP_MSG_SKILLENOENT ), MP.LOGTYPES.ERROR, "FFFFFF", abilityName )
return false
end
else
hotbarData:ClearSlot( slotIndex )
return true
end
end
function MP.SaveSkills( setup )
local skillTable = {}
for hotbarCategory = 0, 1 do
skillTable[ hotbarCategory ] = {}
for slotIndex = 3, 8 do
local hotbarData = ACTION_BAR_ASSIGNMENT_MANAGER:GetHotbar( hotbarCategory )
local slotData = hotbarData:GetSlotData( slotIndex )
local abilityId = 0
-- Cant save cryptcanons special ult.
if slotData.abilityId == 195031 then
abilityId = slotData.abilityId
elseif
not slotData:IsEmpty() then -- check if there is even a spell
abilityId = slotData:GetEffectiveAbilityId()
end
skillTable[ hotbarCategory ][ slotIndex ] = abilityId
end
end
setup:SetSkills( skillTable )
--end
end
function MP.AreSkillsEqual( abilityId1, abilityId2 ) -- gets base abilityIds first, then compares
if abilityId1 == abilityId2 then return true end
local baseMorphAbilityId1 = MP.GetBaseAbilityId( previousAbilityId )
if not baseMorphAbilityId1 then return end
local baseMorphAbilityId2 = MP.GetBaseAbilityId( previousAbilityId )
if not baseMorphAbilityId2 then return end
if baseMorphAbilityId1 == baseMorphAbilityId2 then
return true
end
return false
end
function MP.GetBaseAbilityId( abilityId )
if abilityId == 0 then return 0 end
local playerSkillProgressionData = SKILLS_DATA_MANAGER:GetProgressionDataByAbilityId( abilityId )
if not playerSkillProgressionData then
return nil
end
local baseMorphData = playerSkillProgressionData:GetSkillData():GetMorphData( MORPH_SLOT_BASE )
return baseMorphData:GetAbilityId()
end
function MP.LoadGear( setup )
if GetNumBagFreeSlots( BAG_BACKPACK ) == 0 then
MP.Log( GetString( MP_MSG_FULLINV ), MP.LOGTYPES.INFO )
end
local itemTaskList = {}
local inventoryList = MP.GetItemLocation()
-- unequip mythic if needed
local mythicDelay = 0
if setup:GetMythic() then
local mythicSlot = MP.HasMythic()
local mythicId = Id64ToString( GetItemUniqueId( BAG_WORN, mythicSlot ) )
local _, gear = setup:GetMythic()
if mythicSlot and mythicId ~= gear.id then
mythicDelay = 500
table.insert( itemTaskList, {
sourceBag = BAG_WORN,
sourceSlot = mythicSlot,
destBag = BAG_BACKPACK,
destSlot = nil,
itemId = mythicId,
} )
end
end
for _, gearSlot in ipairs( MP.GEARSLOTS ) do
local gear = setup:GetGearInSlot( gearSlot )
if gear then
if gearSlot == EQUIP_SLOT_POISON or gearSlot == EQUIP_SLOT_BACKUP_POISON then
-- handle poisons
local lookupLink = GetItemLink( BAG_WORN, gearSlot, LINK_STYLE_DEFAULT )
if lookupLink ~= gear.link then
MP.poison.EquipPoisons( gear.link, gearSlot )
end
else
-- equip item (if not already equipped)
local lookupId = Id64ToString( GetItemUniqueId( BAG_WORN, gearSlot ) )
if lookupId ~= gear.id then
if inventoryList[ gear.id ] then
local bag, slot = inventoryList[ gear.id ].bag, inventoryList[ gear.id ].slot
local delay = MP.IsMythic( bag, slot ) and mythicDelay or 0
local workaround = gearSlot == EQUIP_SLOT_BACKUP_MAIN and slot == EQUIP_SLOT_MAIN_HAND
if workaround then
-- Front to back
-- Be sure to give enough time so backbar can find new location
delay = delay + 500
end
table.insert( itemTaskList, {
sourceBag = bag,
sourceSlot = slot,
destBag = BAG_WORN,
destSlot = gearSlot,
delay = delay,
itemId = gear.id,
workaround = workaround,
} )
else
MP.Log( GetString( MP_MSG_GEARENOENT ), MP.LOGTYPES.ERROR, nil,
MP.ChangeItemLinkStyle( gear.link, LINK_STYLE_BRACKETS ) )
end
end
end
else
-- unequip if option is set to true, but ignore tabards if set to do so
if MP.settings.unequipEmpty and (gearSlot ~= EQUIP_SLOT_COSTUME or ((gearSlot == EQUIP_SLOT_COSTUME) and MP.settings.ignoreTabards == false)) then
table.insert( itemTaskList, {
sourceBag = BAG_WORN,
sourceSlot = gearSlot,
destBag = BAG_BACKPACK,
destSlot = nil,
} )
end
end
end
MP.MoveItems( itemTaskList )
end
function MP.GetFreeSlots( bag )
local freeSlotMap = {}
for slot in ZO_IterateBagSlots( bag ) do
local itemId = GetItemId( bag, slot )
if itemId == 0 then
table.insert( freeSlotMap, slot )
end
end
return freeSlotMap
end
function MP.MoveItems( itemTaskList )
for _, item in ipairs( itemTaskList ) do
local itemTask = function()
if not item.destSlot then
item.destSlot = FindFirstEmptySlotInBag( item.destBag )
end
if not item.sourceSlot or item.workaround then
local newLocation = MP.GetItemLocation()[ item.itemId ]
if not newLocation then return end
item.sourceBag = newLocation.bag
item.sourceSlot = newLocation.slot
end
if not item.sourceSlot or not item.destSlot then return end
--local itemId = Id64ToString(GetItemUniqueId(item.sourceBag, item.sourceSlot))
--local itemLink = GetItemLink(item.sourceBag, item.sourceSlot, LINK_STYLE_BRACKETS)
if item.destBag == BAG_WORN then
EquipItem( item.sourceBag, item.sourceSlot, item.destSlot )
else
CallSecureProtected( "RequestMoveItem", item.sourceBag, item.sourceSlot, item.destBag, item.destSlot, 1 )
end
end
MPQ.Push( itemTask, item.delay )
end
end
function MP.HasMythic()
for _, gearSlot in ipairs( MP.GEARSLOTS ) do
if MP.IsMythic( BAG_WORN, gearSlot ) then
return gearSlot
end
end
return nil
end
function MP.Undress( itemTaskList )
if GetNumBagFreeSlots( BAG_BACKPACK ) == 0 then
MP.Log( GetString( MP_MSG_FULLINV ), MP.LOGTYPES.INFO )
end
if not itemTaskList or type( itemTaskList ) ~= "table" then
local freeSlotMap = MP.GetFreeSlots( BAG_BACKPACK )
itemTaskList = {}
for _, gearSlot in ipairs( MP.GEARSLOTS ) do
local _, stack = GetItemInfo( BAG_WORN, gearSlot )
if stack > 0 then
table.insert( itemTaskList, {
sourceBag = BAG_WORN,
sourceSlot = gearSlot,
destBag = BAG_BACKPACK,
destSlot = table.remove( freeSlotMap ),
f = "m",
} )
end
end
end
MP.MoveItems( itemTaskList )
end
function MP.SaveGear( setup )
local gearTable = { mythic = nil }
for _, gearSlot in ipairs( MP.GEARSLOTS ) do
gearTable[ gearSlot ] = {
id = Id64ToString( GetItemUniqueId( BAG_WORN, gearSlot ) ),
link = GetItemLink( BAG_WORN, gearSlot, LINK_STYLE_DEFAULT ),
}
if MP.IsMythic( BAG_WORN, gearSlot ) then
gearTable.mythic = gearSlot
end
if GetItemLinkItemType( gearTable[ gearSlot ].link ) == ITEMTYPE_TABARD then
gearTable[ gearSlot ].creator = GetItemCreatorName( BAG_WORN, gearSlot )
end
end
setup:SetGear( gearTable )
end
function MP.LoadCP( setup )
if #setup:GetCP() == 0 then
return
end
if MP.CompareCP( setup ) then
return
end
local cpTask = function()
-- fixes animation call with nil
if CHAMPION_PERKS_SCENE:GetState() == "shown" then
CHAMPION_PERKS:PrepareStarConfirmAnimation()
cancelAnimation = false
else
cancelAnimation = true
end
PrepareChampionPurchaseRequest()
for slotIndex = 1, 12 do
local starId = setup:GetCP()[ slotIndex ]
if starId and starId > 0 then
local skillPoints = GetNumPointsSpentOnChampionSkill( starId )
if skillPoints > 0 then
AddHotbarSlotToChampionPurchaseRequest( slotIndex, starId )
else
MP.Log( GetString( MP_MSG_CPENOENT ), MP.LOGTYPES.ERROR, MP.CPCOLOR[ slotIndex ],
zo_strformat( "<<C:1>>", GetChampionSkillName( starId ) ) )
end
else
if MP.settings.unequipEmpty then
AddHotbarSlotToChampionPurchaseRequest( slotIndex, 0 )
end
end
end
SendChampionPurchaseRequest()
end
if cpCooldown > 0 then
zo_callLater( function()
MPQ.Push( cpTask )
MP.Log( GetString( MP_MSG_CPCOOLDOWNOVER ), MP.LOGTYPES.INFO )
end, cpCooldown * 1000 )
MP.Log( GetString( MP_MSG_CPCOOLDOWN ), MP.LOGTYPES.INFO, nil, tostring( cpCooldown ) )
return
end
MPQ.Push( cpTask )
end
function MP.SaveCP( setup )
local cpTable = {}
for slotIndex = 1, 12 do
cpTable[ slotIndex ] = GetSlotBoundId( slotIndex, HOTBAR_CATEGORY_CHAMPION )
end
setup:SetCP( cpTable )
end
function MP.UpdateCPCooldown()
if cpCooldown > 0 then
cpCooldown = cpCooldown - 1
return
end
cpCooldown = 0
EVENT_MANAGER:UnregisterForUpdate( MP.name .. "CPCooldownLoop" )
end
function MP.EatFood( setup )
local savedFood = setup:GetFood()
if not savedFood.id then return end
local currentFood = MP.HasFoodRunning()
if MP.BUFFFOOD[ savedFood.id ] == currentFood then
-- same bufffood, dont renew it
return
end
local foodChoice = MP.lookupBuffFood[ MP.BUFFFOOD[ savedFood.id ] ]
foodTask = function()
local foodIndex = MP.FindFood( foodChoice )
if not foodIndex then
MP.Log( GetString( MP_MSG_FOODENOENT ), MP.LOGTYPES.ERROR )
return
end
CallSecureProtected( "UseItem", BAG_BACKPACK, foodIndex )
-- check if eaten
-- API cannot track sprinting
zo_callLater( function()
if not MP.HasFoodIdRunning( savedFood.id ) then
MPQ.Push( foodTask )
end
end, 1000 )
end
MPQ.Push( foodTask )
end
function MP.SaveFood( setup, foodIndex )
if not foodIndex then
local currentFood = MP.HasFoodRunning()
local foodChoice = MP.lookupBuffFood[ currentFood ]
foodIndex = MP.FindFood( foodChoice )
if not foodIndex then
MP.Log( GetString( MP_MSG_NOFOODRUNNING ), MP.LOGTYPES.INFO )
return
end
end
local foodLink = GetItemLink( BAG_BACKPACK, foodIndex, LINK_STYLE_DEFAULT )
local foodId = GetItemLinkItemId( foodLink )
setup:SetFood( {
link = foodLink,
id = foodId,
} )
end
function MP.SetupIterator()
local setupList = {}
for _, zone in ipairs( MP.gui.GetSortedZoneList() ) do
if MP.setups[ zone.tag ] then
for pageId, _ in ipairs( MP.setups[ zone.tag ] ) do
if MP.setups[ zone.tag ][ pageId ] then
for index, setup in ipairs( MP.setups[ zone.tag ][ pageId ] ) do
if setup then
table.insert( setupList, { zone = zone, pageId = pageId, index = index, setup = setup } )
end
end
end
end
end
end
local i = 0
return function()
i = i + 1
return setupList[ i ]
end
end
function MP.PageIterator( zone, pageId )
local setupList = {}
if MP.setups[ zone.tag ] and MP.setups[ zone.tag ][ pageId ] then
for index, setup in ipairs( MP.setups[ zone.tag ][ pageId ] ) do
if setup then
table.insert( setupList, { zone = zone, pageId = pageId, index = index, setup = setup } )
end
end
end
local i = 0
return function()
i = i + 1
return setupList[ i ]
end
end
function MP.OnBossChange( _, isBoss, manualBossName )
if IsUnitInCombat( "player" ) and not manualBossName then
return
end
if WasRaidSuccessful() then
return
end
local bossName = GetUnitName( "boss1" )
local sideBoss = GetUnitName( "boss2" )
if manualBossName then
bossName = manualBossName
end
if bossName == GetString( MP_TRASH ) then
bossName = ""
end
if #bossName == 0 and #sideBoss > 0 then
bossName = sideBoss
end
if blockTrash and #bossName == 0 then
--d("Trash is being blocked.")
return
end
if #bossName > 0 and not IsUnitInCombat( "player" ) then
--d("Changed to boss. Block trash for 6s.")
if blockTrash then
--d("Boss detected. Remove trash blockade. #" .. bossName)
zo_removeCallLater( blockTrash )
blockTrash = nil
end
--d("New trash blockade.")
blockTrash = zo_callLater( function()
--d("Trash blockade over.")
blockTrash = nil
--MP.OnBossChange(_, true, manualBossName)
MP.OnBossChange( _, true, nil )
end, 6000 )
end
if bossName == bossLastName then
return
end
if wipeChangeCooldown or MP.IsWipe() then
return
end
--d("BOSS: " .. bossName)
bossLastName = bossName
zo_callLater( function()
MP.currentZone.OnBossChange( bossName )
end, 500 )
end
function MP.OnZoneChange( _, _ )
local isFirstZoneAfterReload = (MP.currentZoneId == 0)
local zone, x, y, z = GetUnitWorldPosition( "player" )
if zone == MP.currentZoneId then
-- no zone change
return
end
MP.currentZoneId = zone
-- reset old zone
MP.currentZone.Reset()
MP.conditions.ResetCache()
if MP.lookupZones[ zone ] then
MP.currentZone = MP.lookupZones[ zone ]
else
MP.currentZone = MP.zones[ "GEN" ]
end
bossLastName = "MP"
zo_callLater( function()
-- init new zone
MP.currentZone.Init()
-- change ui if loaded, only swap if trial zone
if isFirstZoneAfterReload or MP.currentZone.tag ~= "GEN" then
MP.gui.OnZoneSelect( MP.currentZone )
end
if MP.settings.fixes.surfingWeapons then
MP.fixes.FixSurfingWeapons()
end
if MP.settings.autoEquipSetups
and not isFirstZoneAfterReload
and MP.currentZone.tag ~= "PVP" then
-- equip first setup
local firstSetupName = MP.currentZone.bosses[ 1 ]
if firstSetupName then
MP.OnBossChange( _, false, firstSetupName.name )
end
end
end, 250 )
end
function MP.RegisterEvents()
EVENT_MANAGER:UnregisterForEvent( MP.name, EVENT_ADD_ON_LOADED )
-- repair cp animation
ZO_PreHook( CHAMPION_PERKS, "StartStarConfirmAnimation", function()
if cancelAnimation then
cancelAnimation = false
return true
end
end )
-- cp cooldown
EVENT_MANAGER:RegisterForEvent( MP.name, EVENT_CHAMPION_PURCHASE_RESULT, function( _, result )
if result == CHAMPION_PURCHASE_SUCCESS then
cpCooldown = 31
EVENT_MANAGER:RegisterForUpdate( MP.name .. "CPCooldownLoop", 1000, MP.UpdateCPCooldown )
end
end )
-- check for wipe
EVENT_MANAGER:RegisterForEvent( MP.name, EVENT_UNIT_DEATH_STATE_CHANGED, function( _, unitTag, isDead )
if not isDead then return end
if not IsUnitGrouped( "player" ) and unitTag ~= "player" then return end
if IsUnitGrouped( "player" ) and unitTag:sub( 1, 1 ) ~= "g" then return end
if not wipeChangeCooldown and MP.IsWipe() then
wipeChangeCooldown = true
zo_callLater( function()
wipeChangeCooldown = false
end, 15000 )
end
end )
EVENT_MANAGER:RegisterForEvent( MP.name, EVENT_PLAYER_ACTIVATED, MP.OnZoneChange )
EVENT_MANAGER:RegisterForEvent( MP.name, EVENT_BOSSES_CHANGED, MP.OnBossChange )
end
function MP.Init()
MP.lookupZones = {}
for _, zone in pairs( MP.zones ) do
zone.lookupBosses = {}
for i, boss in ipairs( zone.bosses ) do
zone.lookupBosses[ boss.name ] = i
end
-- support multiple zones per entry
if type( zone.id ) == "table" then
for zoneId in pairs( zone.id ) do
MP.lookupZones[ zoneId ] = zone
end
else
MP.lookupZones[ zone.id ] = zone
end
end
MP.lookupBuffFood = {}
for itemId, abilityId in pairs( MP.BUFFFOOD ) do
if not MP.lookupBuffFood[ abilityId ] then
MP.lookupBuffFood[ abilityId ] = {}
end
table.insert( MP.lookupBuffFood[ abilityId ], itemId )
end
for i, trait in ipairs( MP.TRAITS ) do
local char = tostring( MP.PREVIEW.CHARACTERS[ i ] )
MP.PREVIEW.TRAITS[ trait ] = char
MP.PREVIEW.TRAITS[ char ] = trait
end
local bufffoodCache = {}
for food, _ in pairs( MP.BUFFFOOD ) do
table.insert( bufffoodCache, food )
end
table.sort( bufffoodCache )
for i, food in ipairs( bufffoodCache ) do
local char = tostring( MP.PREVIEW.CHARACTERS[ i ] )
MP.PREVIEW.FOOD[ food ] = char
MP.PREVIEW.FOOD[ char ] = food
end
MP.currentZone = MP.zones[ "GEN" ]
MP.currentZoneId = 0
MP.selection = {
zone = MP.zones[ "GEN" ],
pageId = 1
}
end
function MP.OnAddOnLoaded( _, addonName )
if addonName ~= MP.name then return end
-- Refactor this
MP.Init()
MP.menu.Init()
MP.queue.Init()
MP.gui.Init()
MP.conditions.Init()
MP.transfer.Init()
MP.repair.Init()
MP.poison.Init()
MP.prebuff.Init()
MP.banking.Init()
MP.food.Init()
MP.markers.Init()
MP.preview.Init()
MP.code.Init()
MP.fixes.Init()
MP.RegisterEvents()
end
EVENT_MANAGER:RegisterForEvent( MP.name, EVENT_ADD_ON_LOADED, MP.OnAddOnLoaded )