forked from raid/VenturePlan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMissionList.lua
259 lines (245 loc) · 8.4 KB
/
MissionList.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
local _, T = ...
local EV = T.Evie
local W = {} do
local missionCreditCriteria = {}
function W.AddMissionAchievementInfo(missions)
if not missions or #missions == 0 then
return missions
end
if not next(missionCreditCriteria) then
local aid=14844
for i=1,GetAchievementNumCriteria(aid) do
local _, ct, com, _, _, _, _, asid, _, cid = GetAchievementCriteriaInfo(aid, i)
if ct == 174 and asid then
missionCreditCriteria[asid] = aid*2 + cid*1e6 + (com and 1 or 0)
end
end
end
if next(missionCreditCriteria) and missions then
for i=1,#missions do
local mi = missions[i]
local mid = mi.missionID
local ai = missionCreditCriteria[mid]
if ai then
mi.achievementID = math.floor(ai % 1e6 / 2)
if ai % 2 == 1 then
mi.achievementComplete = true
else
local cid = math.floor(ai / 1e6)
local _, _, isComplete = GetAchievementCriteriaInfoByID(mi.achievementID, cid)
mi.achievementComplete, missionCreditCriteria[mid] = isComplete, isComplete and ai + 1 or ai
end
end
end
end
return missions
end
end
local MissionPage, MissionList
local startedMissions, finishedMissions, FlagMissionFinish = {}, {} do
hooksecurefunc(C_Garrison, "StartMission", function(mid)
startedMissions[mid] = 1
end)
function EV:ADVENTURE_MAP_CLOSE()
startedMissions = {}
finishedMissions = {}
if MissionList then
MissionList:ReturnToTop()
end
end
function EV:GARRISON_MISSION_STARTED(_, mid)
if mid then
startedMissions[mid] = nil
end
end
function FlagMissionFinish(mid)
if mid then
finishedMissions[mid] = 1
end
end
end
local function LogCounter_OnClick(self)
local cb = self:GetParent().CopyBox
cb.Title:SetText("Wanted: Adventure Reports")
cb.Intro:SetText("The Cursed Adventurer's Guide hungers. Only the tales of your companions' adventures, conveyed in excruciating detail, will satisfy it.")
cb.FirstInputBoxLabel:SetText("To submit your adventure reports,|n1. Visit:")
cb.SecondInputBoxLabel:SetText("2. Copy the following text:")
cb.ResetButton:SetText("Reset Adventure Reports")
cb.FirstInputBox:SetText("https://www.townlong-yak.com/addons/venture-plan/submit-reports")
cb.FirstInputBox:SetCursorPosition(0)
cb.SecondInputBox:SetText(T.ExportMissionReports())
cb.SecondInputBox:SetCursorPosition(0)
cb:Show()
PlaySound(170567)
end
local function LogCounter_Update()
local lc, c = MissionPage.LogCounter, T.GetMissionReportCount()
lc:SetShown(c > 0)
lc:SetText(BreakUpLargeNumbers(c))
end
local function ConfigureMission(me, mi, isAvailable)
local mid = mi.missionID
local emi = C_Garrison.GetMissionEncounterIconInfo(mid)
mi.encounterIconInfo, mi.isElite, mi.isRare = emi, emi.isElite, emi.isRare
me.missionID, me.isAvailable, me.offerEndTime = mid, isAvailable, mi.offerEndTime
me.baseCost, me.baseCostCurrency = mi.basecost, mi.costCurrencyTypesID
me.hasOvermaxRewards = not not (mi.overmaxRewards and mi.overmaxRewards[1])
me.hasUsefulOvermaxRewards = mi.overmaxRewardScore ~= 0
me.Name:SetText(mi.name)
if (mi.description or "") ~= "" then
me.Description:SetText(mi.description)
end
local mdi = C_Garrison.GetMissionDeploymentInfo(mid)
local timeNow = GetTime()
local expirePrefix, expireAt, expireRoundUp = false, nil, nil, false
me.completableAfter = nil
if mi.offerEndTime then
expirePrefix = "|A:worldquest-icon-clock:0:0:0:0|a"
expireAt = mi.offerEndTime
elseif mi.timeLeftSeconds then
me.completableAfter = timeNow+mi.timeLeftSeconds
me.ProgressBar.Text:SetText("")
me.ProgressBar:SetProgressCountdown(me.completableAfter, mi.durationSeconds, "Click to complete", true, true)
elseif mi.completed then
me.completableAfter = timeNow-1
me.ProgressBar:SetProgress(1)
me.ProgressBar.Text:SetText("Click to complete")
end
me.ProgressBar:SetMouseMotionEnabled(me.completableAfter and me.completableAfter <= timeNow)
me.ExpireTime.tooltipHeader = "Adventure Expires In:"
me.ExpireTime.tooltipCountdownTo = expireAt
me:SetCountdown(expirePrefix, expireAt, nil, nil, true, expireRoundUp)
me.Rewards:SetRewards(mdi.xp, mi.rewards)
me.AchievementReward.assetID = mi.missionID
me.AchievementReward.achievementID = mi.achievementID
me.AchievementReward:SetShown(mi.achievementID and not mi.achievementComplete)
local isMissionActive = not not (mi.completed or mi.timeLeftSeconds)
local veilShade = mi.timeLeftSeconds and 0.65 or 1
me.Veil:SetShown(isMissionActive)
me.ProgressBar:SetShown(isMissionActive and not mi.isFakeStart)
me.ViewButton:SetShown(not isMissionActive)
for i=1,#me.Rewards do
me.Rewards[i].RarityBorder:SetVertexColor(veilShade, veilShade, veilShade)
end
local hasNovelSpells, enemies = false, mdi.enemies
for i=1,#enemies do
for j=1,#enemies[i].autoCombatSpells do
if not T.KnownSpells[enemies[i].autoCombatSpells[j].autoCombatSpellID] then
hasNovelSpells = true
end
end
end
local di, totalHP, totalATK = C_Garrison.GetMissionDeploymentInfo(mi.missionID), 0, 0
for i=1,di and di.enemies and #di.enemies or 0 do
local e = di.enemies[i]
if e then
totalHP = totalHP + e.health
totalATK = totalATK + e.attack
end
end
local tag = "[" .. (mi.missionScalar or 0) .. (mi.isElite and "+]" or mi.isRare and "r]" or "]")
if hasNovelSpells then
tag = tag .. " |TInterface/EncounterJournal/UI-EJ-WarningTextIcon:16:16|t"
end
me.enemyATK:SetText(BreakUpLargeNumbers(totalATK))
me.enemyHP:SetText(BreakUpLargeNumbers(totalHP))
me.animaCost:SetText(BreakUpLargeNumbers(mi.cost))
me.duration:SetText(mi.duration)
me.statLine:SetWidth(me.duration:GetRight() - me.statLine:GetLeft())
me.TagText:SetText(tag)
me:Show()
end
local function cmpMissionInfo(a,b)
local ac, bc = a.completed or a.timeLeftSeconds == 0, b.completed or b.timeLeftSeconds == 0
if ac ~= bc then
return ac
end
ac, bc = a.timeLeftSeconds, b.timeLeftSeconds
if (not ac) ~= (not bc) then
return not ac
end
if ac ~= bc then
return ac < bc
end
ac, bc = a.offerEndTime, b.offerEndTime
if ac and bc and ac ~= bc then
return ac < bc
end
ac, bc = a.durationSeconds, b.durationSeconds
if ac and bc and ac ~= bc then
return ac < bc
end
return a.name < b.name
end
local function UpdateMissions()
MissionList.dirty = nil
local missions = C_Garrison.GetAvailableMissions(123) or {}
local inProgressMissions = C_Garrison.GetInProgressMissions(123)
local cMissions = C_Garrison.GetCompleteMissions(123)
for i=1,#missions do
local m = missions[i]
if startedMissions[m.missionID] and not m.timeLeftSeconds then
m.timeLeftSeconds, m.offerEndTime = m.durationSeconds
end
end
for i=1,inProgressMissions and #inProgressMissions or 0 do
missions[#missions+1] = inProgressMissions[i]
end
for i=1,cMissions and #cMissions or 0 do
local cid = cMissions[i].missionID
for j=1, inProgressMissions and #inProgressMissions or 0 do
if inProgressMissions[j].missionID == cid then
cid = nil
break
end
end
if cid and not finishedMissions[cid] then
missions[#missions+1] = cMissions[i]
end
end
W.AddMissionAchievementInfo(missions)
table.sort(missions, cmpMissionInfo)
local Missions = MissionList.Missions
for i=1,#missions do
ConfigureMission(Missions[i], missions[i], true)
end
MissionList.numMissions = #missions
for i=#missions+1, #Missions do
Missions[i]:Hide()
end
end
local function QueueListSync()
if MissionList:IsShown() and not MissionList.dirty then
MissionList.dirty = true
C_Timer.After(0, UpdateMissions)
end
end
local function HookAndCallOnShow(frame, f)
frame:HookScript("OnShow", f)
if frame:IsVisible() then
f(frame)
end
end
function EV:I_ADVENTURES_UI_LOADED()
MissionPage, MissionList = T.CreateObject("MissionPage", CovenantMissionFrame.MissionTab)
local lc = MissionPage.LogCounter
lc.tooltipHeader, lc.tooltipText = "|cff1eff00Adventure Report", NORMAL_FONT_COLOR_CODE .. "A detailed record of an adventure completed by your companions.|n|n|cff1eff00Use: Feed the Cursed Adventurer's Guide."
lc:SetScript("OnClick", LogCounter_OnClick)
HookAndCallOnShow(CovenantMissionFrame.MissionTab.MissionList, function(self)
self:Hide()
MissionPage:Show()
end)
HookAndCallOnShow(MissionList, function()
CovenantMissionFrameFollowers:Hide()
UpdateMissions()
LogCounter_Update()
end)
hooksecurefunc(C_Garrison, "MissionBonusRoll", FlagMissionFinish)
EV.I_STORED_LOG_UPDATE = LogCounter_Update
EV.GARRISON_MISSION_LIST_UPDATE = QueueListSync
MissionPage.CopyBox.ResetButton:SetScript("OnClick", function(self)
EV("I_RESET_STORED_LOGS")
self:GetParent():Hide()
end)
return "remove"
end