-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker.lua
785 lines (621 loc) · 25 KB
/
tracker.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
--[[
Tracker
The Tracking system. Detects and tracks loot drops. Stores data and triggers events to be used by the rest of the addon.
--]]
Tracker = {}
local Private = {
trackedLoot = {},
identityByEntity = {},
lootEventHistory = {},
CYCLE_Refresh = nil,
CYCLE_LootEventHistoryCleanup = nil,
canSendLimitWarning = true,
limitWarningTimeout = 60, -- seconds before canSendLimitWarning is reset
crystiteTypeId = tostring(10), -- Fixme: maybe put this elsewhere
trackedLootCounter = 0,
}
--[[
Tracker.Setup()
Performs OnOptionsLoaded tasks.
--]]
function Tracker.Setup()
if Options['Tracker']['UpdateMode'] == TrackerUpdateMode.Global then
Private.CYCLE_Refresh = Callback2.CreateCycle(Tracker.Refresh)
Private.CYCLE_Refresh:Run(tonumber(Options['Tracker']['RefreshInterval']))
end
Private.CYCLE_LootEventHistoryCleanup = Callback2.CreateCycle(Private.LootEventHistoryCleanup)
Private.CYCLE_LootEventHistoryCleanup:Run(tonumber(Options['Tracker']['LootEventHistoryCleanupInterval']))
end
--[[
Tracker.OnOptionChange(id, value)
Called by Options when a Tracker Option is changed.
Used to handle switching of tracking modes cleanly.
--]]
function Tracker.OnOptionChange(id, value)
if id == 'Tracker_UpdateMode' then
-- Switching from global to indivudal update mode
if value == TrackerUpdateMode.Individual then
-- Clear global refresh cycle
if Private.CYCLE_Refresh then
Private.CYCLE_Refresh:Stop()
Private.CYCLE_Refresh:Release()
Private.CYCLE_Refresh = nil
end
-- Create individual update cycles for each existing loot
if not _table.empty(Private.trackedLoot) then
for id, loot in pairs(Private.trackedLoot) do
if not loot.CYCLE_Update then
-- Setup update cycle
loot.CYCLE_Update = Callback2.CreateCycle(Tracker.Update, loot:GetId())
-- Start update cycle
loot.CYCLE_Update:Run(tonumber(Options['Tracker']['LootUpdateInterval']))
end
end
end
-- Switching from indivudal update to global
elseif value == TrackerUpdateMode.Global then
-- Clear indivudal updates
if not _table.empty(Private.trackedLoot) then
for id, loot in pairs(Private.trackedLoot) do
if loot.CYCLE_Update then
loot.CYCLE_Update:Stop()
loot.CYCLE_Update:Release()
loot.CYCLE_Update = nil
end
end
end
-- Create global refresh cycle
if not Private.CYCLE_Refresh then
Private.CYCLE_Refresh = Callback2.CreateCycle(Tracker.Refresh)
Private.CYCLE_Refresh:Run(tonumber(Options['Tracker']['RefreshInterval']))
end
end
elseif id == 'Tracker_LootUpdateInterval' then
if Options['Tracker']['UpdateMode'] == TrackerUpdateMode.Global then
for id, loot in pairs(Private.trackedLoot) do
if loot.CYCLE_Update then
loot.CYCLE_Update:Stop()
loot.CYCLE_Update:Run(tonumber(Options['Tracker']['LootUpdateInterval']))
end
end
end
elseif id == 'Tracker_RefreshInterval' then
if Private.CYCLE_Refresh then
Private.CYCLE_Refresh:Stop()
Private.CYCLE_Refresh:Run(tonumber(Options['Tracker']['RefreshInterval']))
end
elseif id == 'LootEventHistoryCleanupInterval' then
if Private.CYCLE_LootEventHistoryCleanup then
Private.CYCLE_LootEventHistoryCleanup:Stop()
Private.CYCLE_LootEventHistoryCleanup:Run(tonumber(Options['Tracker']['LootEventHistoryCleanupInterval']))
end
else
--Debug.Log('Unhandled Option Id '..tostring(id))
end
end
--[[
Tracker.GetLoot()
Returns a copy of all current loot data.
--]]
function Tracker.GetLoot()
return _table.copy(Private.trackedLoot)
end
--[[
Tracker.GetAvailableLoot()
Returns a table of all loot that is currently available.
--]]
function Tracker.GetAvailableLoot()
local result = {}
for id, loot in pairs(Private.trackedLoot) do
if loot:GetState() == LootState.Available then
result[#result + 1] = loot
end
end
return _table.copy(result) -- Fixme: I think I derped here, this is just a copy of all the loot references rather than a copy of the loot data, right? If so then this copy is just a waste of time, but as for the intended purpose there may be code relying on this oversight...
end
--[[
Tracker.GetCount()
Returns the number of currently tracked items.
--]]
function Tracker.GetCount()
local count = Private.trackedLootCounter
return count
end
--[[
Tracker.Refresh()
Updates all tracked items.
--]]
function Tracker.Refresh()
if not _table.empty(Private.trackedLoot) then
local refresh = Tracker.Update
for id, loot in pairs(Private.trackedLoot) do
refresh(loot)
end
end
end
--[[
Tracker.OnLootableEntity(args)
Checks if the entity should be added to Tracker, and does so if deemed appropriate.
Call when an OnEntityAvailable with type 'loot' has occured.
--]]
function Tracker.OnEntityAvailable(args)
-- Do we have an entityId?
if not args.entityId then
return -- You were useless!
-- Is it loot?
elseif args.type ~= 'loot' then
return -- Nobody cares!
-- Are we tracking this?
elseif Tracker.IsTrackedEntity(args.entityId) then
return -- This is old news!
-- Do we have room for it?
elseif Private.trackedLootCounter >= tonumber(Options['Tracker']['Limit']) then
if Private.canSendLimitWarning then
Messages.SendSystemMessage(Lokii.GetString('SystemMessage_Tracker_HitLimit'))
Private.canSendLimitWarning = false
Callback2.FireAndForget(function(refPrivate) refPrivate.canSendLimitWarning = true end, Private, Private.limitWarningTimeout)
end
return -- Fire second thruster! Full ahead!
end
-- Sweet, a new entity. Track it!
Callback2.FireAndForget(Tracker.Track, args, Options['Tracker']['TrackDelay'])
end
--[[
Tracker.OnLootableEntity(args)
Checks if the entity was being tracked. If it was, try to figure out if it despawned or not. Trigger an update so that the loot will eventually be removed.
Call when an OnEntityLost has occured.
--]]
function Tracker.OnEntityLost(args)
--Debug.Log('Tracker.OnEntityLost on entityId ' .. tostring(args.entityId))
-- Do we have an entityId?
if not args.entityId then
return -- Nothing we could do!
-- Are we tracking this?
elseif not Tracker.IsTrackedEntity(args.entityId) then
return -- Not one of ours
end
-- Okay, let's see what we know about this
local loot = Tracker.GetLootByEntityId(args.entityId)
--Debug.Log('Tracker.OnEntityLost for '..loot:ToString())
-- Do we have any loot events for this kinda item?
if Private.lootEventHistory[loot:GetTypeId()] and #Private.lootEventHistory[loot:GetTypeId()] > 0 then
-- Ooh I like this. We'll assume they picked up the oldest one we've got.
local event = nil
for i, e in ipairs(Private.lootEventHistory[loot:GetTypeId()]) do
if not event or e.occuredAt < event.occuredAt then
event = e
end
end
if event == nil then
Debug.Error('Tracker.OnEntityLost somehow failed to find an event after counting a positive number of events')
end
-- Get that shit.
--Debug.Log('Tracker.OnEntityLost found a previous loot event that matches! Assuming looted by '..tostring(event.lootedBy)..' and to '..tostring(event.lootedTo)..', detected through '..tostring(event.event))
Private.SetLooted({loot = loot, lootedTo = event.lootedTo, lootedBy = event.lootedBy})
end
-- Since we've lost the entity, we gotta update.
Callback2.FireAndForget(Tracker.Update, loot:GetId(), Options['Tracker']['UpdateDelay'])
end
--[[
Tracker.OnLootEvent(args)
When an OnLootCollected or OnLootPickup has occured.
Determines whether some form of OnLoot event should occur.
]]--
function Tracker.OnLootEvent(args)
-- Requires args.itemTypeId, otherwise we can't get item info
if not args.itemTypeId then return end
-- Ignore Crystite
if args.itemTypeId == Private.crystiteTypeId and Options['Tracker']['IgnoreCrystite'] then
return
end
-- Get itemInfo
local itemInfo = Game.GetItemInfoByType(args.itemTypeId)
-- Is it loot that we care about?
if itemInfo and IsTrackableItem(itemInfo) then
-- Debug
if Options['Debug']['LogLootableCollection'] then
Debug.Log('Tracker.OnLootEvent', 'Name:' .. itemInfo.name, 'TypeId:' .. itemInfo.itemTypeId, 'lootedBy:' .. args.lootedBy, 'lootedTo:' .. args.lootedTo)
end
-- Okay, do we have any identified loot?
if not _table.empty(Private.trackedLoot) then
-- So we should try to find a match.
local loot = nil
local matches = {}
-- So, are we tracking anything like this?
--Debug.Log('Scanning for match: Available and typeId ' .. tostring(args.itemTypeId))
for id, item in pairs(Private.trackedLoot) do
if item.state == LootState.Available and tostring(item:GetTypeId()) == tostring(args.itemTypeId) then
loot = item
matches[#matches + 1] = item
end
end
--Debug.Log('Scan Result: ' .. tostring(#matches))
-- Do we have more than one matches?
if #matches > 1 then
-- Shit.
-- Okay, we're gonna have to store this lootevent for now.
--Debug.Log('Tracker.OnLootEvent Multiple potential matches (' .. tostring(count) .. ') for ' .. tostring(itemInfo.name) .. ', ' .. tostring(args.itemTypeId))
-- If we haven't recently stored any lootevents of this type, create the table
if not Private.lootEventHistory[args.itemTypeId] then
Private.lootEventHistory[args.itemTypeId] = {}
end
-- Setup lootevent
local lootEvent = {
occuredAt = tonumber(System.GetClientTime()),
lootedBy = args.lootedBy,
lootedTo = args.lootedTo
}
-- Insert lootevent into history
table.insert(Private.lootEventHistory[args.itemTypeId], lootEvent)
--[[
-- Not sure if this was reasonable but it seems somewhat unneccessary now
for i, item in ipairs(matches) do
Callback2.FireAndForget(Tracker.Update, item:GetId(), i)
end
--]]
-- Is this the one?
elseif #matches == 1 then
-- Aww yeah! Get that shit.
--Debug.Log('Tracker.OnLootEvent for '..loot:GetName()..', '..tostring(loot:GetEntityId())..', '..loot:GetId())
--Debug.Log('It is being looted by '..tostring(args.lootedBy)..' and to '..tostring(args.lootedTo)..' and it was detected through '..tostring(args.event))
-- Set the looted status
Private.SetLooted({loot = loot, lootedTo = args.lootedTo, lootedBy = args.lootedBy})
-- Force update.
Callback2.FireAndForget(Tracker.Update, loot:GetId(), Options['Tracker']['UpdateDelay'])
-- No matches?
else
-- Hmm, so we weren't tracking this item
--Debug.Log('Tracker.OnLootEvent found no matches for ' .. tostring(itemInfo.name) .. ', ' .. tostring(args.itemTypeId))
end
end
end
end
--[[
Tracker.Track(entityId, [targetInfo], [itemInfo])
Identifies entity, adding it to a list of items that have been seen
]]--
function Tracker.Track(args)
args.event = 'Tracker.Track'
--Debug.Event(args)
-- Setup vars from args
local entityId = args.entityId
local targetInfo = args.targetInfo
local itemInfo = args.itemInfo
-- Check entityId
if not entityId then
-- We should have an entityId
Debug.Warn('Loot.Create called without an entityId')
end
-- Be sure it still exists
if not Game.IsTargetAvailable(entityId) and not IsDebugLoot({entityId=entityId}) then
return
end
-- Setup targetInfo
if not targetInfo then
-- Do we have a valid entityId?
if Game.IsTargetAvailable(entityId) then
-- Get targetInfo by entityId
targetInfo = Game.GetTargetInfo(entityId)
-- Verify success
if not targetInfo then
Debug.Error('Loot.Create unable to acquire targetInfo for entityId '..tostring(entityId))
return
end
-- Control types
targetInfo.itemTypeId = tostring(targetInfo.itemTypeId)
-- If we don't have targetInfo, we must have an entityId that references a valid target, so that we can retrieve information.
else
Debug.Error('Loot.Create called without targetInfo, and lacks available entity.')
return
end
end
-- Setup itemInfo
if not itemInfo then
-- Do we have a valid itemTypeId?
if targetInfo.itemTypeId then
-- Get itemInfo by itemTypeId
itemInfo = Game.GetItemInfoByType(targetInfo.itemTypeId, targetInfo.modules)
-- Verify success
if not itemInfo then
Debug.Error('Loot.Create was unable to acquire itemInfo for itemTypeId '..tostring(targetInfo.itemTypeId))
return
end
-- We don't have a valid itemTypeId? Then what do we do...
else
Debug.Log('Loot.Create called without itemInfo, and lacks target with itemTypeId')
Debug.Table({entityId, targetInfo, itemInfo})
return
end
end
-- Simplify testing a little -- Note: Still?
targetInfo.name = targetInfo.name or itemInfo.name
-- Be sure we haven't already identified this
if Tracker.IsTrackedEntity(entityId) then
Debug.Warn('Attempted to identify an already identified item.')
return
end
-- Be sure we want this
if not IsTrackableItem(itemInfo) then
return
end
-- Ignore Crystite
if targetInfo.itemTypeId == Private.crystiteTypeId and Options['Tracker']['IgnoreCrystite'] then
return
end
-- Ignore Blacklisted typeIds
if Options['Blacklist']['Tracker'][tostring(targetInfo.itemTypeId)] then
return
end
-- Ignore Metals in Tornado
if Options['Tracker']['IgnoreMetalsTornado'] and Loot.DetermineCategory(targetInfo, itemInfo) == LootCategory.Metals then
for i, tornadoZoneId in ipairs(TornadoPocketZoneIds) do
if State.zoneId == tornadoZoneId then
return
end
end
end
-- Create loot
--Debug.Log('About to create loot')
local loot = Loot(entityId, targetInfo, itemInfo)
-- Save loot
Private.trackedLoot[loot:GetId()] = loot
Private.identityByEntity[loot:GetEntityId()] = loot:GetId()
-- Increment counter
Private.trackedLootCounter = Private.trackedLootCounter + 1
-- Debug
if Options['Debug']['LogTrackerLight'] then
Debug.Log('Tracker.Track: ' .. loot:ToString())
end
-- Fire event
--Component.GenerateEvent('XLT_ON_TRACKER_NEW', {lootId = loot:GetId()})
OnTrackerNew({lootId = loot:GetId()})
-- Setup indivdual updates
if Options['Tracker']['UpdateMode'] == 'individual' then
-- Setup update cycle
loot.CYCLE_Update = Callback2.CreateCycle(Tracker.Update, loot:GetId())
-- Start update cycle
loot.CYCLE_Update:Run(Options['Tracker']['LootUpdateInterval'])
end
end
--[[
Tracker.Update(lootArg)
Updates the state of a loot instance.
Fires the OnTrackerUpdate event if the state of the loot has changed.
Additionally, if the item was looted, fires the OnTrackerLooted event.
Additionally, queues the removal of items that are no longer available.
]]--
function Tracker.Update(lootArg)
-- Handle argument
local loot = nil
if type(lootArg) == 'table' then
loot = lootArg
else
loot = Tracker.GetLootById(lootArg)
end
if not loot then
Debug.Warn('Tracker.Update called with invalid loot argument ' .. tostring(lootArg))
return
end
-- Store pre-update state
local previousState = loot:GetState()
-- Call update
loot:Update()
-- Get post-update state
local newState = loot:GetState()
-- Has the state changed? If so, trigger events
if newState ~= previousState then
-- XLT_ON_TRACKER_UPDATE is always triggered when the state changes
--Component.GenerateEvent('XLT_ON_TRACKER_UPDATE', {lootId = loot:GetId(), previousState = previousState, newState = newState})
OnTrackerUpdate({lootId = loot:GetId(), previousState = previousState, newState = newState})
-- XLT_ON_TRACKER_LOOTED is triggered when an item that was available changes to having been looted
if previousState == LootState.Available and newState == LootState.Looted then
--Component.GenerateEvent('XLT_ON_TRACKER_LOOTED', {lootId = loot:GetId(), previousState = previousState, newState = newState})
OnTrackerLooted({lootId = loot:GetId(), previousState = previousState, newState = newState})
end
-- Trigger internal removal from Tracker
if previousState == LootState.Available and not loot.markedForDeletion then
loot.markedForDeletion = true
Callback2.FireAndForget(Tracker.Remove, loot, Options['Tracker']['RemoveDelay'])
end
end
end
--[[
Tracker.Remove(lootArg)
Removes a tracked loot instance cleanly.
Fires the OnTrackerRemove event.
--]]
function Tracker.Remove(lootArg)
local loot = nil
if type(lootArg) == 'table' then
loot = lootArg
else
loot = Tracker.GetLootById(lootArg)
end
if not loot then
Debug.Warn('Tracker.Remove called with invalid loot argument ' .. tostring(lootArg))
return
end
-- Debug
if Options['Debug']['LogTrackerLight'] then
Debug.Log('Tracker.Remove: ' .. loot:ToString())
end
local lootId = loot:GetId()
-- Clear update cycle
if loot.CYCLE_Update then
loot.CYCLE_Update:Stop()
loot.CYCLE_Update:Release()
loot.CYCLE_Update = nil
end
-- Clear ent to id reference
if loot:GetState() == LootState.Available or Private.identityByEntity[loot:GetEntityId()] then
Private.identityByEntity[loot:GetEntityId()] = nil
end
-- Clear tracker reference
Private.trackedLoot[loot:GetId()] = nil
-- Decrement counter
Private.trackedLootCounter = Private.trackedLootCounter - 1
-- Self destruct
loot:Destroy()
-- Fire Event
--Component.GenerateEvent('XLT_ON_TRACKER_REMOVE', {lootId = lootId})
OnTrackerRemove({lootId = lootId})
end
--[[
Tracker.IsTrackedEntity(entityId)
Returns true if entityId is currently being tracked.
--]]
function Tracker.IsTrackedEntity(entityId)
local id = Private.identityByEntity[entityId]
if id then
return (Private.trackedLoot[id] ~= nil)
end
return false
end
--[[
Tracker.GetLootById(id)
Returns the loot instance with the matching lootId.
--]]
function Tracker.GetLootById(lootId)
local loot = Private.trackedLoot[lootId]
if not loot then
Debug.Log('Tracker.GetLootById returning nil because it did not find any matching loot for lootId: ' .. tostring(lootId))
end
return loot
end
--[[
Tracker.GetLootByEntityId(entityId)
Returns the loot instance with the matching entityId.
--]]
function Tracker.GetLootByEntityId(entityId)
local loot = Private.trackedLoot[Private.identityByEntity[entityId]]
if not loot then
Debug.Log('Tracker.GetLootByEntityId returning nil because it did not find any matching loot for entityId ' .. tostring(entityId))
end
return loot
end
--[[
Tracker.Clear()
Clears trackedLoot and the lootEventHistory as cleanly as possible.
--]]
function Tracker.Clear()
for i, loot in pairs(Private.trackedLoot) do
Tracker.Remove(loot)
end
for i, array in pairs(Private.lootEventHistory) do
array = nil
end
Private.trackedLoot = {}
Private.lootEventHistory = {}
Private.identityByEntity = {}
end
--[[
Tracker.Stat()
Debug output for the Stat slash command.
--]]
function Tracker.Stat()
--Debug.Table('trackedLoot', Private.trackedLoot)
--Debug.Table('lootEventHistory', Private.lootEventHistory)
Debug.Log('Tracker.GetCount(): ' .. tostring(Tracker.GetCount()))
end
--[[
Private.SetLooted(args)
Sets the lootedBy/To properties of a loot instance.
--]]
function Private.SetLooted(args)
args.loot:SetLootedBy(tostring(args.lootedBy))
args.loot:SetLootedTo(tostring(args.lootedTo))
end
--[[
Private.LootEventHistoryCleanup()
Removes aged entries in the lootEventHistory.
--]]
function Private.LootEventHistoryCleanup()
if not _table.empty(Private.lootEventHistory) then
local remove = table.remove -- I don't know if this helps
local asnumber = tonumber -- But give me that performance pls
local emptyTable = _table.empty -- This looks so bad
local currentTime = asnumber(System.GetClientTime())
local lifetime = asnumber(Options['Tracker']['LootEventHistoryLifetime'])
for itemTypeId, events in pairs(Private.lootEventHistory) do
-- Go trough events if not empty
if not emptyTable(events) then
local i=1
while i <= #events do
local event = events[i]
-- If has lived longer than life, remove
if (currentTime - asnumber(event.occuredAt) > lifetime) then
remove(events, i)
else
i = i + 1
end
end
end
-- Remove table if empty (second check, in case events have been removed)
if emptyTable(events) then
Private.lootEventHistory[itemTypeId] = nil
end
end
end
end
--[[
IsTrackableItem(itemInfo)
Whether or not an item can be tracked by the addon.
]]--
function IsTrackableItem(itemInfo)
-- Verify that the looted item is of a type that we care about
return (IsEquipment(itemInfo) or IsModule(itemInfo) or IsSalvage(itemInfo) or IsConsumable(itemInfo) or IsMetal(itemInfo) or IsComponent(itemInfo) or IsCurrency(itemInfo))
end
function IsEquipment(itemInfo)
local EquipmentItemTypes = {
'frame_module',
'ability_module',
'weapon',
}
for i, v in ipairs(EquipmentItemTypes) do
if itemInfo.type == v then
return true
end
end
return false
end
function IsComponent(itemInfo)
-- SubTypeIds.Resource should be 15 and represent Crafting Components
local old = (itemInfo.type == 'crafting_component')
local new = (itemInfo.type == 'resource_item' and itemInfo.subTypeId and Game.IsItemOfType(itemInfo.itemTypeId, SubTypeIds.Resource))
local extra = (itemInfo.type == 'basic' and itemInfo.flags.resource and itemInfo.flags.is_tradable)
return (new or extra or old)
end
function IsMetal(itemInfo)
local rawMetalsSubTypeId = 3288
local metals = (itemInfo.type == 'resource_item' and itemInfo.flags.resource and itemInfo.subTypeId and Game.IsItemOfType(itemInfo.itemTypeId, rawMetalsSubTypeId))
return (metals)
end
function IsBioMaterial(itemInfo)
local rawBioMaterialsSubTypeId = 3291
local biomaterials = (itemInfo.type == 'resource_item' and itemInfo.flags.resource and itemInfo.subTypeId and Game.IsItemOfType(itemInfo.itemTypeId, rawBioMaterialsSubTypeId))
return (biomaterials)
end
function IsCurrency(itemInfo)
-- SubTypeIds.Currency should be 207 and represent Currency
return (itemInfo.subTypeId and Game.IsItemOfType(itemInfo.itemTypeId, SubTypeIds.Currency))
end
function IsSalvage(itemInfo)
local cond1 = (itemInfo.type == 'basic' or itemInfo.type == 'resource_item')
local cond2 = (itemInfo.rarity == 'salvage')
local cond3 = (itemInfo.flags and itemInfo.flags.is_salvageable)
return ((cond1 or cond2) and cond3)
end
function IsModule(itemInfo)
return (itemInfo.type == 'item_module')
end
function IsConsumable(itemInfo)
return (itemInfo.type == 'consumable')
end
-- Verify if loot is fake or not
-- args.entityId - Verify by entityId
function IsDebugLoot(args)
if args.entityId then
return (Options['Debug']['Enabled'] and tonumber(args.entityId) <= 2000)
end
return false
end