aboutsummaryrefslogtreecommitdiffstats
path: root/Malmstone/Addons/PvPMatchAddon.cs
blob: 0acb6177075cfc9cbd592068f6b00d7b6118a09b (plain) (blame)
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
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using Dalamud.Game.Addon.Lifecycle;
using Malmstone.Services;
using Malmstone.Utils;
using Dalamud.Game.Text.SeStringHandling;
using System.Collections.Generic;
using Dalamud.Game.Text.SeStringHandling.Payloads;

namespace Malmstone.Addons
{
    internal class PvPMatchAddon
    {
        private Plugin Plugin;
        private enum PvPContentType
        {
            CrystallineConflict = 1,
            RivalWings = 2,
            Frontlines = 3,
        }
        public PvPMatchAddon(Plugin Plugin)
        {
            this.Plugin = Plugin;
        }

        public void EnablePostMatchProgressionToast()
        {
            Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PreSetup, "MKSRecord", ShowSeriesProgressionToast);
            Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PreSetup, "FrontlineRecord", ShowSeriesProgressionToast);
            Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PreSetup, "ManeuversRecord", ShowSeriesProgressionToast);
        }

        public void DisablePostMatchProgressionToast()
        {
            Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PreSetup, "MKSRecord", ShowSeriesProgressionToast);
            Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PreSetup, "FrontlineRecord", ShowSeriesProgressionToast);
            Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PreSetup, "ManeuversRecord", ShowSeriesProgressionToast);
        }

        public void EnableCrystallineConflictPostMatch()
        {
            Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PostSetup, "MKSRecord", OnCrystallineConflictRecordTrigger);
        }

        public void DisableCrystallineConflictPostMatch()
        {
            Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PostSetup, "MKSRecord", OnCrystallineConflictRecordTrigger);
        }

        public void EnableFrontlinePostMatch()
        {
            Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PostSetup, "FrontlineRecord", OnFrontlineRecordTrigger);
        }

        public void DisableFrontlinePostMatch()
        {
            Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PostSetup, "FrontlineRecord", OnFrontlineRecordTrigger);
        }

        public void EnableRivalWingsPostMatch()
        {
            Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PostSetup, "ManeuversRecord", OnRivalWingsRecordTrigger);
        }
        public void DisableRivalWingsPostMatch()
        {
            Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PostSetup, "ManeuversRecord", OnRivalWingsRecordTrigger);
        }


        // Runs on the result screen of the respective game mode
        private void OnCrystallineConflictRecordTrigger(AddonEvent eventType, AddonArgs addonInfo)
        {
            PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo();
            if (seriesInfo == null) return;
            if (Plugin.Configuration.ShowProgressionChatPostCC)
                ShowSeriesProgressionMessage(seriesInfo, PvPContentType.CrystallineConflict);
        }

        private void OnFrontlineRecordTrigger(AddonEvent eventType, AddonArgs addonInfo)
        {
            PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo();
            if (seriesInfo == null) return;
            if (Plugin.Configuration.ShowProgressionChatPostFL)
                ShowSeriesProgressionMessage(seriesInfo, PvPContentType.RivalWings);
        }

        private void OnRivalWingsRecordTrigger(AddonEvent eventType, AddonArgs addonInfo)
        {
            PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo();
            if (seriesInfo == null) return;
            if (Plugin.Configuration.ShowProgressionChatPostRW)
                ShowSeriesProgressionMessage(seriesInfo, PvPContentType.RivalWings);
        }

        private void ShowSeriesProgressionToast(AddonEvent eventType, AddonArgs addonInfo)
        {
            PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo();
            if (seriesInfo == null) return;
            switch (Plugin.Configuration.PostmatchProgressionToastType)
            {
                case 0:
                    Plugin.ToastGui.ShowNormal("Series Level " + seriesInfo.CurrentSeriesRank +
                        "     " + seriesInfo.SeriesExperience + "/" + MalmstoneXPCalculator.GetXPTargetForCurrentLevel(seriesInfo.CurrentSeriesRank) + " EXP");
                    break;
                case 1:
                    Plugin.ToastGui.ShowQuest("Series Level " + seriesInfo.CurrentSeriesRank +
                        "     " + seriesInfo.SeriesExperience + "/" + MalmstoneXPCalculator.GetXPTargetForCurrentLevel(seriesInfo.CurrentSeriesRank) + " EXP");
                    break;
                case 2:
                    Plugin.ToastGui.ShowError("Series Level " + seriesInfo.CurrentSeriesRank +
                        "     " + seriesInfo.SeriesExperience + "/" + MalmstoneXPCalculator.GetXPTargetForCurrentLevel(seriesInfo.CurrentSeriesRank) + " EXP");
                    break;
                default:
                    Plugin.ToastGui.ShowNormal("Series Level " + seriesInfo.CurrentSeriesRank +
                        "     " + seriesInfo.SeriesExperience + "/" + MalmstoneXPCalculator.GetXPTargetForCurrentLevel(seriesInfo.CurrentSeriesRank) + " EXP");
                    break;
            }

        }

        private void ShowSeriesProgressionMessage(PvPSeriesInfo seriesInfo, PvPContentType contentType)
        {
            var seString = new SeString(new List<Payload>());
            switch (contentType)
            {
                case PvPContentType.CrystallineConflict:
                    MalmstoneXPCalculator.XpCalculationResult ccResultData = MalmstoneXPCalculator.CalculateCrystallineConflictMatches(
                        seriesInfo.CurrentSeriesRank, seriesInfo.CurrentSeriesRank + 1, seriesInfo.SeriesExperience);
                    if (ccResultData.CrystallineConflictLose == 0) break;
                    seString.Append(new TextPayload("[Crystalline Conflict to Level " + (seriesInfo.CurrentSeriesRank + 1) + "]\n"));
                    seString.Append(new UIForegroundPayload(35));
                    seString.Append(new TextPayload($"Win: {ccResultData.CrystallineConflictWin} " + (ccResultData.CrystallineConflictWin == 1 ? "time" : "times") + "\n"));
                    seString.Append(new TextPayload($"Lose: {ccResultData.CrystallineConflictLose} " + (ccResultData.CrystallineConflictLose == 1 ? "time" : "times")));
                    seString.Append(UIForegroundPayload.UIForegroundOff);
                    break;
                case PvPContentType.Frontlines:
                    MalmstoneXPCalculator.XpCalculationResult flResultData = MalmstoneXPCalculator.CalculateCrystallineConflictMatches(
                        seriesInfo.CurrentSeriesRank, seriesInfo.CurrentSeriesRank + 1, seriesInfo.SeriesExperience);
                    if (flResultData.FrontlineDailyLose3rd == 0) break;
                    seString.Append(new TextPayload("[Frontlines to Level " + (seriesInfo.CurrentSeriesRank + 1) + "]\n"));
                    seString.Append(new UIForegroundPayload(518));
                    seString.Append(new TextPayload($"Take 1st Place: {flResultData.FrontlineWin} " + (flResultData.FrontlineWin == 1 ? "time" : "times") +" (" + (flResultData.FrontlineDailyWin) + ")\n"));
                    seString.Append(new TextPayload($"Take 2nd Place: {flResultData.FrontlineWin} " + (flResultData.FrontlineWin == 1 ? "time" : "times") + " (" + (flResultData.FrontlineDailyLose2nd) + ")\n"));
                    seString.Append(new TextPayload($"Take 3rd Place: {flResultData.FrontlineWin} " + (flResultData.FrontlineWin == 1 ? "time" : "times") + " (" + (flResultData.FrontlineDailyLose3rd) + ")\n"));
                    seString.Append(UIForegroundPayload.UIForegroundOff);
                    break;
                case PvPContentType.RivalWings:
                    MalmstoneXPCalculator.XpCalculationResult rwResultData = MalmstoneXPCalculator.CalculateRivalWingsMatches(
                        seriesInfo.CurrentSeriesRank, seriesInfo.CurrentSeriesRank + 1, seriesInfo.SeriesExperience);
                    if (rwResultData.RivalWingsLose == 0) break;
                    seString.Append(new TextPayload("[Rival Wings to Level " + (seriesInfo.CurrentSeriesRank + 1) + "]\n"));
                    seString.Append(new UIForegroundPayload(43));
                    seString.Append(new TextPayload($"Win: {rwResultData.RivalWingsWin} " + (rwResultData.RivalWingsWin == 1 ? "time" : "times") + "\n"));
                    seString.Append(new TextPayload($"Lose: {rwResultData.RivalWingsLose} " + (rwResultData.RivalWingsLose == 1 ? "time" : "times")));
                    seString.Append(UIForegroundPayload.UIForegroundOff);
                    break;
            }
            Plugin.Chat.Print(seString);
        }

        
    }
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage