ESO Lua File v100010

ingame/playertoplayer/playertoplayer.lua

[◄ back to folders ]
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
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
ZO_PlayerToPlayer = ZO_Object:Subclass()
     if IsInGamepadPreferredMode() and data.pendingResponse and data.deferDecisionCallback then
          return true
     end
     return false
end
function ZO_PlayerToPlayer:New(...)
    local playerToPlayer = ZO_Object.New(self)
    playerToPlayer:Initialize(...)
    return playerToPlayer
end
function ZO_PlayerToPlayer:Initialize(control)
    self.control = control
    control.owner = self
    self.container = control:GetNamedChild("PromptContainer")
    self.targetLabel = self.container:GetNamedChild("Target")
    self.ignoreLabel = self.container:GetNamedChild("IgnoreMarker")
    self.actionArea = self.container:GetNamedChild("ActionArea")
    self.actionKeybindButton = self.actionArea:GetNamedChild("ActionKeybindButton")
    self.additionalInfo = self.actionArea:GetNamedChild("AdditionalInfo")
    self.pendingResurrectInfo = self.actionArea:GetNamedChild("PendingResurrectInfo")
    self.gamerID = self.actionArea:GetNamedChild("GamerID")
    self.promptKeybindButton1 = self.actionArea:GetNamedChild("PromptKeybindButton1")
    self.promptKeybindButton1:SetText(GetString(SI_DIALOG_ACCEPT))
    self.promptKeybindButton1:SetKeybind("PLAYER_TO_PLAYER_INTERACT_ACCEPT")
    self.promptKeybindButton1:SetCallback(function() self:OnPromptAccepted() end)
    self.promptKeybindButton2 = self.actionArea:GetNamedChild("PromptKeybindButton2")
    self.promptKeybindButton2:SetText(GetString(SI_DIALOG_DECLINE))
    self.promptKeybindButton2:SetKeybind("PLAYER_TO_PLAYER_INTERACT_DECLINE")
    self.promptKeybindButton2:SetCallback(function() self:OnPromptDeclined() end)
    self.resurrectProgress = ZO_PlayerToPlayerResurrectProgress
    self.resurrectProgressAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("PlayerToPlayerResurrectAnimation", self.resurrectProgress)
    local menuControl = ZO_PlayerToPlayerMenu
    self.menu = ZO_RadialMenu:New(menuControl, "ZO_PlayerToPlayerMenuEntryTemplate", "DefaultRadialMenuAnimation", "DefaultRadialMenuEntryAnimation", "RadialMenu")
    self.menu:SetOnClearCallback(function() self:StopInteraction() end)
    self.msToDelayToShowPrompt = 500
    self.lastFailedPromptTime = GetFrameTimeMilliseconds()
    EVENT_MANAGER:RegisterForUpdate(control:GetName() .. "OnUpdate", 0, function() self:OnUpdate() end)
    SHARED_INFORMATION_AREA:AddPlayerToPlayer(self.container)
end
function ZO_PlayerToPlayer:InitializeKeybinds()
    self.actionKeybindButton:SetKeybind("PLAYER_TO_PLAYER_INTERACT")
end
function ZO_PlayerToPlayer:InitializeSoulGemResurrectionEvents()
    self.control:RegisterForEvent(EVENT_START_SOUL_GEM_RESURRECTION, function(eventCode, ...) self:OnStartSoulGemResurrection(...) end)
    self.control:RegisterForEvent(EVENT_END_SOUL_GEM_RESURRECTION, function(eventCode, ...) self:OnEndSoulGemResurrection(...) end)
end
local AGENT_CHAT_REQUEST = 1
local RITUAL_OF_MARA = 2
local TRADE_INVITE = 3
local GROUP_INVITE = 4
local QUEST_SHARE = 5
local FRIEND_REQUEST = 6
local GUILD_INVITE = 7
local CAMPAIGN_QUEUE = 8
local function GetCampaignQueueData(campaignId, isGroup)
     local campaignName = GetCampaignName(campaignId)
     local remainingSeconds = GetCampaignQueueRemainingConfirmationSeconds(campaignId, isGroup)
     local campaignData = 
          {
               campaignId = campaignId,
               isGroup = isGroup,
               campaignName = campaignName,
               messageFormat = isGroup and SI_NOTIFICATION_CAMPAIGN_QUEUE_MESSAGE_GROUP or SI_NOTIFICATION_CAMPAIGN_QUEUE_MESSAGE_INDIVIDUAL,
               messageParams = { campaignName },
               expiresAt = GetFrameTimeSeconds() + remainingSeconds,
          }
     return campaignData
end
function ZO_PlayerToPlayer:InitializeIncomingEvents()
    self.incomingQueue = {}
    local function OnGroupInviteReceived(eventCode, inviter)
        PlaySound(SOUNDS.GROUP_INVITE)
        self:RemoveFromIncomingQueue(GROUP_INVITE)
        self:AddPromptToIncomingQueue(GROUP_INVITE, inviter, zo_strformat(SI_PLAYER_TO_PLAYER_INCOMING_GROUP, ZO_SELECTED_TEXT:Colorize(inviter)),
            function()
                PlaySound(SOUNDS.GROUP_REQUEST_ACCEPTED)
                AcceptGroupInvite()
            end,
            function()
                PlaySound(SOUNDS.GROUP_REQUEST_DECLINED)
                DeclineGroupInvite()
            end,
               function()
                    PlaySound(SOUNDS.DEFER_NOTIFICATION)
                    self:RemoveFromIncomingQueue(GROUP_INVITE, inviter)
               end)
    end
    local function OnGroupInviteRemoved()
        self:RemoveFromIncomingQueue(GROUP_INVITE)
    end
    local function OnTradeWindowInviteConsidering(eventCode, inviter)
        PlaySound(SOUNDS.TRADE_INVITE_RECEIVED)
        self:RemoveFromIncomingQueue(TRADE_INVITE)
        -- There is server message received when trade is cancelled/accepted/declined, which sends a Lua event which will play a sound in AlertHandlers.lua
        self:AddPromptToIncomingQueue(TRADE_INVITE, inviter, zo_strformat(SI_PLAYER_TO_PLAYER_INCOMING_TRADE, ZO_SELECTED_TEXT:Colorize(inviter)),
            function()
                PlaySound(SOUNDS.TRADE_REQUEST_ACCEPTED)
                TradeInviteAccept()
            end,
            function()
                PlaySound(SOUNDS.TRADE_REQUEST_DECLINED)
                TradeInviteDecline()
            end,
               function()
                    PlaySound(SOUNDS.DEFER_NOTIFICATION)
                    self:RemoveFromIncomingQueue(TRADE_INVITE, inviter)
               end)
    end
    local function OnTradeWindowInviteRemoved()
        self:RemoveFromIncomingQueue(TRADE_INVITE)
    end
    local function OnQuestShared(eventCode, questId)
        PlaySound(SOUNDS.QUEST_SHARED)
        local questName, playerName = GetOfferedQuestShareInfo(questId)
        local data = self:AddPromptToIncomingQueue(QUEST_SHARE, playerName, zo_strformat(SI_PLAYER_TO_PLAYER_INCOMING_QUEST_SHARE, ZO_SELECTED_TEXT:Colorize(playerName), questName),
            function()
                PlaySound(SOUNDS.QUEST_SHARE_ACCEPTED)
                AcceptSharedQuest(questId)
            end,
            function()
                PlaySound(SOUNDS.QUEST_SHARE_DECLINED)
                DeclineSharedQuest(questId)
            end,
               function()
                    PlaySound(SOUNDS.DEFER_NOTIFICATION)
                    self:RemoveFromIncomingQueue(QUEST_SHARE, playerName)
               end)
        data.questId = questId
    end
    local function OnQuestShareRemoved(eventCode, questId)
        -- No need to play a sound for this now, the client might automatically remove stale quest shares.
        self:RemoveQuestShareFromIncomingQueue(questId)
    end
    local function OnPledgeOfMaraOffer(eventCode, targetName, isSender)
        local ritualPrompt = isSender and SI_PLAYER_TO_PLAYER_OUTGOING_RITUAL_OF_MARA or SI_PLAYER_TO_PLAYER_INCOMING_RITUAL_OF_MARA
        PlaySound(SOUNDS.MARA_INVITE_RECEIVED)
        self:RemoveFromIncomingQueue(RITUAL_OF_MARA)
        self:AddDialogToIncomingQueue(RITUAL_OF_MARA, targetName, zo_strformat(ritualPrompt, ZO_SELECTED_TEXT:Colorize(targetName)), "RITUAL_OF_MARA_PROMPT", zo_floor(GetRingOfMaraExperienceBonus() * 100))
    end
    local function OnPledgeOfMaraOfferRemoved()
        self:RemoveFromIncomingQueue(RITUAL_OF_MARA)
    end
    local function OnIncomingFriendInviteAdded(eventCode, inviterName)
        self:AddPromptToIncomingQueue(FRIEND_REQUEST, inviterName, zo_strformat(SI_PLAYER_TO_PLAYER_INCOMING_FRIEND_REQUEST, ZO_SELECTED_TEXT:Colorize(inviterName)),
            function()
                PlaySound(SOUNDS.FRIEND_REQUEST_ACCEPTED)
                AcceptFriendRequest(inviterName)
            end,
            function()
                PlaySound(SOUNDS.FRIEND_REQUEST_DECLINED)
                RejectFriendRequest(inviterName)
            end,
               function()
                    PlaySound(SOUNDS.DEFER_NOTIFICATION)
                    self:RemoveFromIncomingQueue(FRIEND_REQUEST, inviterName)
               end)
    end
    local function OnIncomingFriendRequestRemoved(eventCode, inviterName)
        self:RemoveFromIncomingQueue(FRIEND_REQUEST, inviterName)
    end
    local function OnGuildInviteAdded(eventCode, guildId, guildName, guildAlliance, inviterName)
        local guildNameAlliance = zo_iconTextFormat(GetAllianceBannerIcon(guildAlliance), 24, 24, guildName)
        local data = self:AddPromptToIncomingQueue(GUILD_INVITE, inviterName, zo_strformat(SI_PLAYER_TO_PLAYER_INCOMING_GUILD_REQUEST, ZO_SELECTED_TEXT:Colorize(inviterName), guildNameAlliance),
            function()
                PlaySound(SOUNDS.GUILD_INVITE_ACCEPTED)
                AcceptGuildInvite(guildId)
            end,
            function()
                PlaySound(SOUNDS.GUILD_INVITE_DECLINED)
                RejectGuildInvite(guildId)
            end,
               function()
                    PlaySound(SOUNDS.DEFER_NOTIFICATION)
                    self:RemoveFromIncomingQueue(GUILD_INVITE, inviterName)
               end)
        data.guildId = guildId
    end
    local function OnGuildInviteRemoved(eventCode, guildId)
        self:RemoveGuildInviteFromIncomingQueue(guildId)
    end
    local function OnAgentChatRequested()
        self:AddPromptToIncomingQueue(AGENT_CHAT_REQUEST, nil, GetString(SI_PLAYER_TO_PLAYER_INCOMING_AGENT_CHAT_REQUEST),
            function()
                PlaySound(SOUNDS.AGENT_CHAT_ACCEPTED)
                AcceptAgentChat()
            end,
            function()
                PlaySound(SOUNDS.AGENT_CHAT_DECLINED)
                DeclineAgentChat()
            end,
               function()
                    PlaySound(SOUNDS.DEFER_NOTIFICATION)
                    self:RemoveFromIncomingQueue(AGENT_CHAT_REQUEST)
               end)
    end
    local function OnAgentChatAccepted()
        self:RemoveFromIncomingQueue(AGENT_CHAT_REQUEST)
    end
    local function OnAgentChatDeclined()
        self:RemoveFromIncomingQueue(AGENT_CHAT_REQUEST)
    end
    local function OnCampaignQueueStateChanged( _, campaignId, isGroup, state)
          if state == CAMPAIGN_QUEUE_REQUEST_STATE_CONFIRMING then
               local campaignQueueData = GetCampaignQueueData(campaignId, isGroup)
               local promptData = self:AddPromptToIncomingQueue(CAMPAIGN_QUEUE, campaignId, nil,
                    function()
                         PlaySound(SOUNDS.CAMPAIGN_QUEUE_ACCEPTED)
                         ZO_Dialogs_ShowPlatformDialog("CAMPAIGN_QUEUE_READY", {campaignId = campaignId, isGroup = isGroup}, {mainTextParams = {campaignQueueData.campaignName}})
                    end,
                    function()
                         PlaySound(SOUNDS.CAMPAIGN_QUEUE_DECLINED)
                         ConfirmCampaignEntry(campaignId, isGroup, false)
                    end,
                    function()
                         PlaySound(SOUNDS.DEFER_NOTIFICATION)
                         self:RemoveFromIncomingQueue(CAMPAIGN_QUEUE, campaignId)
                    end)
               promptData.messageFormat = campaignQueueData.messageFormat
               promptData.messageParams = campaignQueueData.messageParams
               promptData.expiresAt = campaignQueueData.expiresAt
          else
               self:RemoveFromIncomingQueue(CAMPAIGN_QUEUE, campaignId)
          end
    end
     local function OnCampaignQueueLeft(_, campaignId, group)
          self:RemoveFromIncomingQueue(CAMPAIGN_QUEUE, campaignId)
     end
    self.control:RegisterForEvent(EVENT_GROUP_INVITE_RECEIVED, OnGroupInviteReceived)
    self.control:RegisterForEvent(EVENT_GROUP_INVITE_REMOVED, OnGroupInviteRemoved)
    self.control:RegisterForEvent(EVENT_TRADE_INVITE_CONSIDERING, OnTradeWindowInviteConsidering)
    self.control:RegisterForEvent(EVENT_TRADE_INVITE_REMOVED, OnTradeWindowInviteRemoved)
    self.control:RegisterForEvent(EVENT_QUEST_SHARED, OnQuestShared)
    self.control:RegisterForEvent(EVENT_QUEST_SHARE_REMOVED, OnQuestShareRemoved)
    self.control:RegisterForEvent(EVENT_PLEDGE_OF_MARA_OFFER, OnPledgeOfMaraOffer)
    self.control:RegisterForEvent(EVENT_PLEDGE_OF_MARA_OFFER_REMOVED, OnPledgeOfMaraOfferRemoved)
    self.control:RegisterForEvent(EVENT_INCOMING_FRIEND_INVITE_ADDED, OnIncomingFriendInviteAdded)
    self.control:RegisterForEvent(EVENT_INCOMING_FRIEND_INVITE_REMOVED, OnIncomingFriendRequestRemoved)
    self.control:RegisterForEvent(EVENT_GUILD_INVITE_ADDED, OnGuildInviteAdded)
    self.control:RegisterForEvent(EVENT_GUILD_INVITE_REMOVED, OnGuildInviteRemoved)
    self.control:RegisterForEvent(EVENT_AGENT_CHAT_REQUESTED, OnAgentChatRequested)
    self.control:RegisterForEvent(EVENT_AGENT_CHAT_ACCEPTED, OnAgentChatAccepted)
    self.control:RegisterForEvent(EVENT_AGENT_CHAT_DECLINED, OnAgentChatDeclined)
     self.control:RegisterForEvent(EVENT_CAMPAIGN_QUEUE_STATE_CHANGED, OnCampaignQueueStateChanged)
     self.control:RegisterForEvent(EVENT_CAMPAIGN_QUEUE_LEFT, OnCampaignQueueLeft)
    local function OnPlayerActivated()
        local groupInviterName = GetGroupInviteInfo()
        if groupInviterName ~= "" then
            OnGroupInviteReceived(nil, groupInviterName)
        end
        local tradeInviterName = GetTradeInviteInfo()
        if tradeInviterName ~= "" then
            OnTradeWindowInviteConsidering(nil, tradeInviterName)
        end
        local sharedQuestName = GetOfferedQuestShareInfo()
        if sharedQuestName ~= "" then
            OnQuestShared()
        end
        local pledgeTarget, _, isSender = GetPledgeOfMaraOfferInfo()
        if pledgeTarget ~= "" then
            OnPledgeOfMaraOffer(nil, pledgeTarget, isSender)
        end
        local chatRequested = GetAgentChatRequestInfo()
        if chatRequested then
            OnAgentChatRequested()
        end
    end
    local function OnPlayerDeactivated()
        self:RemoveFromIncomingQueue(GROUP_INVITE)
        self:RemoveFromIncomingQueue(TRADE_INVITE)
        self:RemoveFromIncomingQueue(RITUAL_OF_MARA)
        self:RemoveFromIncomingQueue(QUEST_SHARE)
    end
    self.control:RegisterForEvent(EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
    self.control:RegisterForEvent(EVENT_PLAYER_DEACTIVATED, OnPlayerDeactivated)
    if IsPlayerActivated() then
        OnPlayerActivated()
    end
end
function ZO_PlayerToPlayer:SetHidden(hidden)
    SHARED_INFORMATION_AREA:SetHidden(self.container, hidden)
end
function ZO_PlayerToPlayer:IsHidden()
    return SHARED_INFORMATION_AREA:IsHidden(self.container)
end
local INCOMING_MESSAGE_TEXT = {
     [GROUP_INVITE] = GetString(SI_NOTIFICATION_GROUP_INVITE),
     [QUEST_SHARE] = GetString(SI_NOTIFICATION_SHARE_QUEST_INVITE),
     [FRIEND_REQUEST] = GetString(SI_NOTIFICATION_FRIEND_INVITE),
     [GUILD_INVITE] = GetString(SI_NOTIFICATION_GUILD_INVITE)
}
local function DisplayNotificationMessage(message, data)
     local typeString = INCOMING_MESSAGE_TEXT[data.incomingType]
     if typeString then
          ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, zo_strformat(message, typeString))
     end
end
local function NotificationDeferred(data)
     data.pendingResponse = false
     if data.deferDecisionCallback then
          data.deferDecisionCallback()
     end
end
local function NotificationAccepted(data)
     data.pendingResponse = false
     if data.acceptCallback then
          data.acceptCallback()
          DisplayNotificationMessage(GetString(SI_NOTIFICATION_ACCEPTED), data)
     end
end
local function NotificationDeclined(data)
     data.pendingResponse = false
      if data.declineCallback then
          data.declineCallback()
          DisplayNotificationMessage(GetString(SI_NOTIFICATION_DECLINED), data)
     end
end
function ZO_PlayerToPlayer:ShowRaidalNotificationMenu(data)
     self.menu:AddEntry( GetString(SI_GAMEPAD_NOTIFICATIONS_DEFER_OPTION), 
                         "EsoUI/Art/HUD/radialIcon_whisper_up.dds",
                         "EsoUI/Art/HUD/radialIcon_whisper_over.dds",
                         function()
                              NotificationDeferred(data)
                         end)
                                             
     self.menu:AddEntry( GetString(SI_GAMEPAD_NOTIFICATIONS_ACCEPT_OPTION),
                         "EsoUI/Art/Buttons/accept_up.dds", 
                         "EsoUI/Art/Buttons/accept_over.dds",
                         function()
                              NotificationAccepted(data)
                         end)
     self.menu:AddEntry( GetString(SI_GAMEPAD_NOTIFICATIONS_DECLINE_OPTION),
                         "EsoUI/Art/HUD/radialIcon_cancel_up.dds", 
                         "EsoUI/Art/HUD/radialIcon_cancel_over.dds", 
                         function()
                              NotificationDeclined(data)
                         end)
     self.menu:Show()
     self.showingNotificationMenu = true
end
function ZO_PlayerToPlayer:AddIncomingEntry(incomingType, inviterName, targetLabel)
    local data = { incomingType = incomingType, targetLabel = targetLabel, inviterName = inviterName, pendingResponse = true }
    zo_binaryinsert(data, incomingType, self.incomingQueue)
    return data
end
function ZO_PlayerToPlayer:AddPromptToIncomingQueue(incomingType, inviterName, targetLabel, acceptCalback, declineCallback, deferDecisionCallback)
    local data = self:AddIncomingEntry(incomingType, inviterName, targetLabel)
    data.acceptCallback = acceptCalback
    TriggerTutorial(TUTORIAL_TRIGGER_INCOMING_PLAYER_TO_PLAYER_NOTIFICATION)
    return data
end
function ZO_PlayerToPlayer:AddDialogToIncomingQueue(incomingType, inviterName, targetLabel, dialogName, ...)
    local data = self:AddIncomingEntry(incomingType, inviterName, targetLabel)
    data.dialogName = dialogName
    data.mainTextParams = {inviterName, ...}
    TriggerTutorial(TUTORIAL_TRIGGER_INCOMING_PLAYER_TO_PLAYER_NOTIFICATION)
    return data
end
function ZO_PlayerToPlayer:RemoveFromIncomingQueue(incomingType, inviterName)
    for i, incomingEntry in ipairs(self.incomingQueue) do
        if incomingEntry.incomingType == incomingType then
            if inviterName == nil or incomingEntry.inviterName == inviterName then
                table.remove(self.incomingQueue, i)
                break
            end
        end
    end
end
function ZO_PlayerToPlayer:RemoveGuildInviteFromIncomingQueue(guildId)
    for i, incomingEntry in ipairs(self.incomingQueue) do
        if incomingEntry.incomingType == GUILD_INVITE and incomingEntry.guildId == guildId then
            table.remove(self.incomingQueue, i)
            break
        end
    end
end
function ZO_PlayerToPlayer:RemoveQuestShareFromIncomingQueue(questId)
    for i, incomingEntry in ipairs(self.incomingQueue) do
        if incomingEntry.incomingType == QUEST_SHARE and incomingEntry.questId == questId then
            table.remove(self.incomingQueue, i)
            break
        end
    end
end
local NO_LEADING_EDGE = false
function ZO_PlayerToPlayer:OnStartSoulGemResurrection(duration)
    self.resurrectProgressAnimation:PlayForward()
    self.resurrectProgress:StartCooldown(duration, duration, CD_TYPE_RADIAL, CD_TIME_TYPE_TIME_REMAINING, NO_LEADING_EDGE)
end
function ZO_PlayerToPlayer:OnEndSoulGemResurrection()
    self.resurrectProgressAnimation:PlayBackward()
end
function ZO_PlayerToPlayer:SetDelayPromptTime(timeMs)
    self.msToDelayToShowPrompt = timeMs
end
function ZO_PlayerToPlayer:TryDisplayingIncomingRequests()
    if self.responding then
        local incomingEntryToRespondTo = self.incomingQueue[1]
        if(incomingEntryToRespondTo.dialogName) then
            ZO_Dialogs_ShowPlatformDialog(incomingEntryToRespondTo.dialogName, nil, {mainTextParams = incomingEntryToRespondTo.mainTextParams})
            table.remove(self.incomingQueue, 1)
               self.responding = false
            self:StopInteraction()
            return true
          elseif ShouldUseRadialNotificationMenu(incomingEntryToRespondTo) then
               LockCameraRotation(true)
               RETICLE:RequestHidden(true)
               self:ShowRaidalNotificationMenu(incomingEntryToRespondTo)
               return true
        end
    end
    return false
end
function ZO_PlayerToPlayer:HasTarget()
    return self.currentTarget ~= nil
end
function ZO_PlayerToPlayer:StartInteraction()
    if not SCENE_MANAGER:IsInUIMode() then
        local isInteractionPossible = self:HasTarget() or self.responding
        if not isInteractionPossible then
            PlaySound(SOUNDS.NO_INTERACT_TARGET)
        elseif not self.isInteracting and not SHARED_INFORMATION_AREA:IsSuppressed() then
            self:SetHidden(false)
            if not self:TryDisplayingIncomingRequests() then
                if self.resurrectable then
                    if self.hasRequiredSoulGem and not self.failedRaidRevives and not self.isBeingResurrected and not self.hasResurrectPending then
                        StartSoulGemResurrection()
                    else
                        return
                    end
                else
                    local isIgnored = IsUnitIgnored("reticleoverplayer")
                    if(isIgnored) then
                        self.ignoreLabel:SetHidden(false)
                    end
                    self:ShowPlayerInteractMenu(isIgnored)
                    LockCameraRotation(true)
                end
                RETICLE:RequestHidden(true)
                self.isInteracting = true
            end
        end
    end
end
function ZO_PlayerToPlayer:StopInteraction()
    if self.isInteracting then
        self.isInteracting = false
        self.ignoreLabel:SetHidden(true)
        RETICLE:RequestHidden(false)
        LockCameraRotation(false)
        CancelSoulGemResurrection()
        self.menu:SelectCurrentEntry()
        self.lastFailedPromptTime = GetFrameTimeMilliseconds() - self.msToDelayToShowPrompt
     elseif self.responding then
          self.responding = false
          if self.showingNotificationMenu then
               RETICLE:RequestHidden(false)
               LockCameraRotation(false)
               self.menu:SelectCurrentEntry()
               self.showingNotificationMenu = false
          end
    end
end
function ZO_PlayerToPlayer:Accept()
end
function ZO_PlayerToPlayer:Decline()
end
function ZO_PlayerToPlayer:OnPromptAccepted()
    if(self.responding) then
        local incomingEntryToRespondTo = table.remove(self.incomingQueue, 1)
          NotificationAccepted(incomingEntryToRespondTo)
    end
end
function ZO_PlayerToPlayer:OnPromptDeclined()
    if(self.responding) then
        local incomingEntryToRespondTo = table.remove(self.incomingQueue, 1)
          NotificationDeclined(incomingEntryToRespondTo)
    end
end
function ZO_PlayerToPlayer:TryShowingResurrectLabel()
    if IsUnitResurrectableByPlayer("reticleoverplayer") then
        local rawTargetName = GetRawUnitName("reticleoverplayer")
        local targetName = zo_strformat(SI_PLAYER_TO_PLAYER_TARGET, rawTargetName)
     
        self.resurrectable = true
        self.targetLabel:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
        self.targetLabel:SetText(targetName)
        self.currentTarget = targetName
        self.currentTargetRaw = rawTargetName
        self.isBeingResurrected = IsUnitBeingResurrected("reticleoverplayer")
        self.hasResurrectPending = DoesUnitHaveResurrectPending("reticleoverplayer")
        if self.isBeingResurrected or self.hasResurrectPending then
            self.pendingResurrectInfo:SetHidden(false)
            if(self.isBeingResurrected) then
                self.pendingResurrectInfo:SetText(GetString(SI_PLAYER_TO_PLAYER_RESURRECT_BEING_RESURRECTED))
            else
                self.pendingResurrectInfo:SetText(GetString(SI_PLAYER_TO_PLAYER_RESURRECT_HAS_RESURRECT_PENDING))
            end
        else
            self.actionKeybindButton:SetHidden(false)
            local targetLevel = GetUnitEffectiveLevel("reticleoverplayer")
            local _, _, stackCount = GetSoulGemInfo(SOUL_GEM_TYPE_FILLED, targetLevel)
            local soulGemSuccess, coloredFilledText, coloredSoulGemIconMarkup = ZO_Death_GetResurrectSoulGemText(targetLevel)
            self.hasRequiredSoulGem = stackCount > 0
            self.failedRaidRevives = IsPlayerInRaid() and not ZO_Death_IsRaidReviveAllowed()
            self.actionKeybindButton:SetEnabled(self.hasRequiredSoulGem and not self.failedRaidRevives)
            local success
            if(ZO_Death_DoesReviveCostRaidLife()) then
                local raidLifeSuccess, coloredRaidLifeIconMarkup = ZO_Death_GetResurrectRaidLifeText()
                success = soulGemSuccess and raidLifeSuccess
                self.actionKeybindButton:SetText(zo_strformat(success and SI_PLAYER_TO_PLAYER_RESURRECT_GEM_LIFE or SI_PLAYER_TO_PLAYER_RESURRECT_GEM_LIFE_FAILED, coloredFilledText, coloredSoulGemIconMarkup, coloredRaidLifeIconMarkup))                
            else
                success = soulGemSuccess
                self.actionKeybindButton:SetText(zo_strformat(success and SI_PLAYER_TO_PLAYER_RESURRECT_GEM or SI_PLAYER_TO_PLAYER_RESURRECT_GEM_FAILED, coloredFilledText, coloredSoulGemIconMarkup))
            end
        end        
        return true
    end
    return false
end
function ZO_PlayerToPlayer:TryShowingStandardInteractLabel()
    if CanUnitTrade("reticleoverplayer") then
        self.resurrectable = false
        local rawTargetName = GetRawUnitName("reticleoverplayer")
        local targetName = zo_strformat(SI_PLAYER_TO_PLAYER_TARGET, rawTargetName)
          
        self.actionKeybindButton:SetHidden(false)
        self.targetLabel:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
        self.targetLabel:SetText(targetName)
        self.actionKeybindButton:SetText(GetString(SI_PLAYER_TO_PLAYER_ACTION_MENU))
        self.currentTarget = targetName
        self.currentTargetRaw = rawTargetName
        return true
    end
    return false
end
function ZO_PlayerToPlayer:TryShowingPromptAfterDelay()
     local now = GetFrameTimeMilliseconds()
     if IsPlayerMoving() then
          self.lastFailedPromptTime = now
     else
          if now - self.lastFailedPromptTime >= self.msToDelayToShowPrompt then
               self:SetHidden(false)
          end
     end
end
function ZO_PlayerToPlayer:ShowResponseActionKeybind(keybindText)
     self.actionKeybindButton:SetHidden(false)
     self.actionKeybindButton:SetText(keybindText)
end
function ZO_PlayerToPlayer:SetupTargetLabel(incomingEntry)
     self.targetLabel:SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
     if incomingEntry.targetLabel then
          self.targetLabel:SetText(incomingEntry.targetLabel)
     elseif incomingEntry.messageFormat then
        if(incomingEntry.expiresAt) then
            local remainingTime = zo_max(incomingEntry.expiresAt - GetFrameTimeSeconds(), 0)
            local formattedTime = ZO_FormatTime(remainingTime, TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_TWELVE_HOUR)
            self.targetLabel:SetText(zo_strformat(incomingEntry.messageFormat, unpack(incomingEntry.messageParams), formattedTime))
        else
            self.targetLabel:SetText(zo_strformat(incomingEntry.messageFormat, unpack(incomingEntry.messageParams)))
        end          
     end
     
     if IsInGamepadPreferredMode() then
          self.targetLabel:SetFont("ZoFontGamepad42")
     else
          self.targetLabel:SetFont("ZoInteractionPrompt")
     end
end
function ZO_PlayerToPlayer:GetKeyboardStringFromInteractionType(interactionType)
    if interactionType == RITUAL_OF_MARA then
        return GetString(SI_PLEDGE_OF_MARA_BEGIN_RITUAL_PROMPT)
    else
        return GetString(SI_PLAYER_TO_PLAYER_ACTION_RESPOND)
    end
end
function ZO_PlayerToPlayer:GetGamepadStringFromInteractionType(interactionType)
    if interactionType and interactionType == RITUAL_OF_MARA then
        return GetString(SI_GAMEPAD_NOTIFICATIONS_PLEDGE_OF_MARA_BEGIN_RITUAL_PROMPT)
    else
        return GetString(SI_GAMEPAD_PLAYER_TO_PLAYER_ACTION_RESPOND)
    end
end
function ZO_PlayerToPlayer:TryShowingResponseLabel()
    if #self.incomingQueue > 0 then
        local incomingEntry = self.incomingQueue[1]
          if incomingEntry.pendingResponse then
               self:SetupTargetLabel(incomingEntry)
               if(incomingEntry.dialogName) then
                    self:ShowResponseActionKeybind(self:GetKeyboardStringFromInteractionType(incomingEntry.incomingType))
               elseif ShouldUseRadialNotificationMenu(incomingEntry) then
                    if not self.showingNotificationMenu then
                         self:ShowResponseActionKeybind(self:GetGamepadStringFromInteractionType(incomingEntry.incomingType))
                    end
               else
                    self.promptKeybindButton1:SetHidden(false)
                    self.promptKeybindButton2:SetHidden(false)
                    self.shouldShowNotificationKeybindLayer = true
               end
               self.responding = true
               return true
          end
    end
    return false
end
function ZO_PlayerToPlayer:IsReticleTargetInteractable()
    return DoesUnitExist("reticleoverplayer")
       and IsUnitOnline("reticleoverplayer")
       and GetUnitAlliance("player") == GetUnitAlliance("reticleoverplayer")
end
local notificationsKeybindLayerName = GetString(SI_KEYBINDINGS_LAYER_NOTIFICATIONS)
function ZO_PlayerToPlayer:OnUpdate()
    if not self.control:IsHidden() then
        self.currentTarget = nil
        self.currentTargetRaw = nil
        self.resurrectable = false
        self.hasRequiredSoulGem = false
        self.failedRaidRevives = false
        self.responding = false
        self:SetHidden(not self.isInteracting)
        self.actionKeybindButton:SetHidden(true)
        self.actionKeybindButton:SetEnabled(true)
        self.additionalInfo:SetHidden(true)
        self.promptKeybindButton1:SetHidden(true)
        self.promptKeybindButton2:SetHidden(true)
        self.pendingResurrectInfo:SetHidden(true)
        if (not self.isInteracting) or (not IsConsoleUI()) then
            self.gamerID:SetHidden(true)
        end
        self.shouldShowNotificationKeybindLayer = false
        local isReticleTargetInteractable = self:IsReticleTargetInteractable()
        if isReticleTargetInteractable and self:TryShowingResurrectLabel() then
            self:SetHidden(false)
        elseif not self.isInteracting and (self.showingNotificationMenu or not IsUnitInCombat("player")) and self:TryShowingResponseLabel() then
            self:SetHidden(false)
        elseif not self.isInteracting and isReticleTargetInteractable and self:TryShowingStandardInteractLabel() then
            self:TryShowingPromptAfterDelay()
        end
        local isNotificationLayerShown = IsActionLayerActiveByName(notificationsKeybindLayerName)
        if self.shouldShowNotificationKeybindLayer ~= isNotificationLayerShown then
            if(self.shouldShowNotificationKeybindLayer) then
                PushActionLayerByName(notificationsKeybindLayerName)
            else
                RemoveActionLayerByName(notificationsKeybindLayerName)
            end
        end
    else
        if(IsActionLayerActiveByName(notificationsKeybindLayerName)) then
            RemoveActionLayerByName(notificationsKeybindLayerName)
        end
    end
end
function ZO_PlayerToPlayer:AddShowGamerCard(target, isIgnored)
    --Attempt to cache the other's information before we need to use it
    local function ShowCard()
       ShowGamerCardFromCharName(target)
    end
    
    -- TODO: Change the icon to the "View Gamer Card" icon based on whether or not the target player is ignored.
    self.menu:AddEntry(GetString(GetGamerCardStringId()), "EsoUI/Art/HUD/radialIcon_whisper_up.dds", "EsoUI/Art/HUD/radialIcon_whisper_over.dds", ShowCard)
    local accountName, consoleId, wasFound = GetConsoleInfoFromCharName(target)
    self.gamerID:SetText(accountName)
    self.gamerID:SetHidden(not wasFound)
end
function ZO_PlayerToPlayer:ShowPlayerInteractMenu(isIgnored)
    local currentTarget = self.currentTarget
    local currentTargetRaw = self.currentTargetRaw
    if(isIgnored) then
        if IsConsoleUI() then
            self:AddShowGamerCard(currentTarget, isIgnored)
        else
            self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_WHISPER), "EsoUI/Art/HUD/radialIcon_whisper_disabled.dds", "EsoUI/Art/HUD/radialIcon_whisper_disabled.dds", function() ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_PLAYER_TO_PLAYER_IGNORED) end)
        end
        self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_ADD_GROUP), "EsoUI/Art/HUD/radialIcon_inviteGroup_disabled.dds", "EsoUI/Art/HUD/radialIcon_inviteGroup_disabled.dds", function() ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_PLAYER_TO_PLAYER_IGNORED) end)
        self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_ADD_FRIEND), "EsoUI/Art/HUD/radialIcon_addFriend_disabled.dds", "EsoUI/Art/HUD/radialIcon_addFriend_disabled.dds", function() ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_PLAYER_TO_PLAYER_IGNORED) end)
        self.menu:AddEntry(zo_strformat(SI_CHAT_PLAYER_CONTEXT_REPORT, currentTargetRaw), "EsoUI/Art/HUD/radialIcon_reportPlayer_up.dds", "EsoUI/Art/HUD/radialIcon_reportPlayer_over.dds", function() ZO_ReportPlayerDialog_Show(currentTarget, REPORT_PLAYER_REASON_BOTTING, currentTargetRaw) end)
        self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_INVITE_TRADE), "EsoUI/Art/HUD/radialIcon_trade_disabled.dds", "EsoUI/Art/HUD/radialIcon_trade_disabled.dds", function() ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_PLAYER_TO_PLAYER_IGNORED) end)
        self.menu:AddEntry(GetString(SI_RADIAL_MENU_CANCEL_BUTTON), "EsoUI/Art/HUD/radialIcon_cancel_up.dds", "EsoUI/Art/HUD/radialIcon_cancel_over.dds")        
    else
        if IsConsoleUI()  then
            self:AddShowGamerCard(currentTarget, isIgnored)
        else
            self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_WHISPER), "EsoUI/Art/HUD/radialIcon_whisper_up.dds", "EsoUI/Art/HUD/radialIcon_whisper_over.dds", function() CHAT_SYSTEM:StartTextEntry(nil, CHAT_CHANNEL_WHISPER, currentTarget) end)
        end
        do
            local playerHasGroupPermissions = not IsUnitGrouped("player") or IsUnitGroupLeader("player")
            local errorReason = not playerHasGroupPermissions and GetString(SI_PLAYER_TO_PLAYER_GROUP_NOT_LEADER) or nil
            if IsPlayerInGroup(currentTargetRaw) then
                --TODO: Get remove icons?
                self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_REMOVE_GROUP), "EsoUI/Art/HUD/radialIcon_inviteGroup_up.dds", "EsoUI/Art/HUD/radialIcon_inviteGroup_over.dds", function() GroupKickByName(currentTargetRaw) end, errorReason)
            else
                self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_ADD_GROUP), "EsoUI/Art/HUD/radialIcon_inviteGroup_up.dds", "EsoUI/Art/HUD/radialIcon_inviteGroup_over.dds", function() 
                    local NOT_SENT_FROM_CHAT = false
                    local DISPLAY_INVITED_MESSAGE = true
                    TryGroupInviteByName(currentTarget, NOT_SENT_FROM_CHAT, DISPLAY_INVITED_MESSAGE) 
                end, errorReason)
            end
        end
        if IsFriend(currentTargetRaw) then
            self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_ADD_FRIEND), "EsoUI/Art/HUD/radialIcon_addFriend_disabled.dds", "EsoUI/Art/HUD/radialIcon_addFriend_disabled.dds", function() ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_PLAYER_TO_PLAYER_ALREADY_FRIEND) end)
        else
            self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_ADD_FRIEND), "EsoUI/Art/HUD/radialIcon_addFriend_up.dds", "EsoUI/Art/HUD/radialIcon_addFriend_over.dds", function() RequestFriend(currentTarget) end, errorReason)
        end
        self.menu:AddEntry(zo_strformat(SI_CHAT_PLAYER_CONTEXT_REPORT, currentTargetRaw), "EsoUI/Art/HUD/radialIcon_reportPlayer_up.dds", "EsoUI/Art/HUD/radialIcon_reportPlayer_over.dds", function() ZO_ReportPlayerDialog_Show(currentTargetRaw, REPORT_PLAYER_REASON_BOTTING) end)
        self.menu:AddEntry(GetString(SI_PLAYER_TO_PLAYER_INVITE_TRADE), "EsoUI/Art/HUD/radialIcon_trade_up.dds", "EsoUI/Art/HUD/radialIcon_trade_over.dds", function() TradeInviteByName(currentTarget) end)
        self.menu:AddEntry(GetString(SI_RADIAL_MENU_CANCEL_BUTTON), "EsoUI/Art/HUD/radialIcon_cancel_up.dds", "EsoUI/Art/HUD/radialIcon_cancel_over.dds")
    end
    self.menu:Show()
end
    PLAYER_TO_PLAYER = ZO_PlayerToPlayer:New(control)
end