Back to Home

ESO Lua File v101044

ingame/campaign/campaignbonuses_shared.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
ZO_CAMPAIGN_BONUS_TYPE_HOME_KEEPS = 1
ZO_CAMPAIGN_BONUS_TYPE_EMPEROR = 2
ZO_CAMPAIGN_BONUS_TYPE_ENEMY_KEEPS = 3
ZO_CAMPAIGN_BONUS_TYPE_EDGE_KEEPS = 4
ZO_CAMPAIGN_BONUS_TYPE_DEFENSIVE_SCROLLS = 5
ZO_CAMPAIGN_BONUS_TYPE_OFFENSIVE_SCROLLS = 6
local function GetFormattedBonusString(data)
    if data and data.stringId then
        if data.value then
            return zo_strformat(SI_CAMPAIGN_BONUSES_INFO_FORMATTER, GetString(data.stringId), ZO_SELECTED_TEXT:Colorize(data.value))
        else
            return GetString(data.stringId)
        end
    end
    return ""
end
local function GetHomeKeepBonusData(campaignId)
    local data = {}
    local allHomeKeepsHeld = GetAvAKeepScore(campaignId, GetUnitAlliance("player"))
    if allHomeKeepsHeld then
        data.stringId = SI_CAMPAIGN_BONUSES_HOME_KEEP_PASS_INFO
    else
        data.stringId = SI_CAMPAIGN_BONUSES_HOME_KEEP_FAIL_INFO
    end
    return data
end
local function GetHomeKeepBonusScore(campaignId)
    local allHomeKeepsHeld = GetAvAKeepScore(campaignId, GetUnitAlliance("player"))
    return allHomeKeepsHeld and 1 or 0
end
local function GetKeepBonusData(campaignId)
    local _, enemyKeepsHeld = GetAvAKeepScore(campaignId, GetUnitAlliance("player"))
    local data =
    {
        stringId = SI_CAMPAIGN_BONUSES_ENEMY_KEEP_INFO,
        value = enemyKeepsHeld,
    }
    return data
end
local function GetKeepBonusScore(campaignId)
    local allHomeKeepsHeld, enemyKeepsHeld = GetAvAKeepScore(campaignId, GetUnitAlliance("player"))
    return allHomeKeepsHeld and enemyKeepsHeld or 0
end
local function GetEdgeKeepBonusScore(campaignId)
    return select(5, GetAvAKeepScore(campaignId, GetUnitAlliance("player")))
end
local function GetEdgeKeepBonusData(campaignId)
    local data =
    {
        stringId = SI_CAMPAIGN_BONUSES_EDGE_KEEP_INFO,
        value = GetEdgeKeepBonusScore(campaignId),
    }
    return data
end
local function GetDefensiveBonusData(campaignId)
    local _, enemyScrollsHeld = GetAvAArtifactScore(campaignId, GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_DEFENSIVE)
    local data =
    {
        stringId = SI_CAMPAIGN_BONUSES_ENEMY_SCROLL_INFO,
        value = enemyScrollsHeld,
    }
    return data
end
local function GetDefensiveBonusCount()
    return GetNumArtifactScoreBonuses(GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_DEFENSIVE)
end
local function GetDefensiveBonusAbilityId(index)
    return GetArtifactScoreBonusAbilityId(GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_DEFENSIVE, index)
end
local function GetDefensiveBonusScore(campaignId)
    local allHomeScrollsHeld, enemyScrollsHeld = GetAvAArtifactScore(campaignId, GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_DEFENSIVE)
    return allHomeScrollsHeld and enemyScrollsHeld or 0
end
local function GetOffensiveBonusData(campaignId)
    local _, enemyScrollsHeld = GetAvAArtifactScore(campaignId, GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_OFFENSIVE)
    local data =
    {
        stringId = SI_CAMPAIGN_BONUSES_ENEMY_SCROLL_INFO,
        value = enemyScrollsHeld,
    }
    return data
end
local function GetOffensiveBonusCount()
    return GetNumArtifactScoreBonuses(GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_OFFENSIVE)
end
local function GetOffensiveBonusAbilityId(index)
    return GetArtifactScoreBonusAbilityId(GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_OFFENSIVE, index)
end
local function GetOffensiveBonusScore(campaignId)
    local allHomeScrollsHeld, enemyScrollsHeld = GetAvAArtifactScore(campaignId, GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_OFFENSIVE)
    return allHomeScrollsHeld and enemyScrollsHeld or 0
end
local function GetEmperorBonusData(campaignId)
    local data = {}
    if DoesCampaignHaveEmperor(campaignId) then
        local alliance = GetCampaignEmperorInfo(campaignId)
        if alliance == GetUnitAlliance("player") then
            data.stringId = SI_CAMPAIGN_BONUSES_EMPEROR_PASS_INFO
        else
            data.stringId = SI_CAMPAIGN_BONUSES_EMPEROR_FAIL_INFO
        end
    else
        data.stringId = SI_CAMPAIGN_BONUSES_EMPEROR_NONE_INFO
    end
    return data
end
-- The rankIndex is always the AvA Keep score minus one
    if DoesCampaignHaveEmperor(campaignId) then
        local alliance = GetCampaignEmperorInfo(campaignId)
        if alliance == GetUnitAlliance("player") then
            local _, _, homeKeepCount = GetAvAKeepScore(campaignId, GetUnitAlliance("player"))
            return homeKeepCount - 1 > 0 and homeKeepCount - 1 or 0
        end
    end
    return 0
end
local function GetEmperorBonusAbilityId(index, campaignId)
    local emperorBonusRank = ZO_CampaignBonuses_GetEmperorBonusRank(campaignId)
    return GetEmperorAllianceBonusAbilityId(emperorBonusRank)
end
local function GetEmperorBonusScore(campaignId)
    if DoesCampaignHaveEmperor(campaignId) then
        local alliance = GetCampaignEmperorInfo(campaignId)
        if alliance == GetUnitAlliance("player") then
            return 1
        end
    end
    return 0
end
local HIDE_COUNT = 0
local BONUS_SECTION_DATA =
{
    [ZO_CAMPAIGN_BONUS_TYPE_HOME_KEEPS] =
    {
        typeIcon = "EsoUI/Art/Campaign/campaignBonus_keepIcon.dds",
        typeIconGamepad = "EsoUI/Art/Campaign/Gamepad/gp_bonusIcon_keeps.dds",
        headerText = GetString(SI_CAMPAIGN_BONUSES_HOME_KEEP_HEADER),
        infoData = GetHomeKeepBonusData,
        count = 1,
        countText = GetString(SI_CAMPAIGN_BONUSES_HOME_KEEP_ALL),
        scoreFunction = GetHomeKeepBonusScore,
    },
    [ZO_CAMPAIGN_BONUS_TYPE_EMPEROR] =
    {
        typeIcon = "EsoUI/Art/Campaign/campaignBonus_emperorshipIcon.dds",
        typeIconGamepad = "EsoUI/Art/Campaign/Gamepad/gp_bonusIcon_emperor.dds",
        headerText = GetString(SI_CAMPAIGN_BONUSES_EMPERORSHIP_HEADER),
        infoData = GetEmperorBonusData,
        count = 1,
        countText = HIDE_COUNT,
        scoreFunction = GetEmperorBonusScore,
    },
    [ZO_CAMPAIGN_BONUS_TYPE_ENEMY_KEEPS] =
    {
        typeIcon = "EsoUI/Art/Campaign/campaignBonus_keepIcon.dds",
        typeIconGamepad = "EsoUI/Art/Campaign/Gamepad/gp_bonusIcon_keeps.dds",
        headerText = GetString(SI_CAMPAIGN_BONUSES_ENEMY_KEEP_HEADER),
        infoData = GetKeepBonusData,
        detailsText = GetString(SI_CAMPAIGN_BONUSES_KEEP_REQUIRE_HOME_KEEP),
        count = GetNumKeepScoreBonuses,
        startIndex = 2,
        scoreFunction = GetKeepBonusScore,
    },
    [ZO_CAMPAIGN_BONUS_TYPE_DEFENSIVE_SCROLLS] =
    {
        typeIcon = "EsoUI/Art/Campaign/campaignBonus_scrollIcon.dds",
        typeIconGamepad = "EsoUI/Art/Campaign/Gamepad/gp_bonusIcon_scrolls.dds",
        headerText = GetString(SI_CAMPAIGN_BONUSES_DEFENSIVE_SCROLL_HEADER),
        infoData = GetDefensiveBonusData,
        detailsText = GetString(SI_CAMPAIGN_BONUSES_KEEP_REQUIRE_HOME_SCROLLS),
        count = GetDefensiveBonusCount,
    },
    [ZO_CAMPAIGN_BONUS_TYPE_OFFENSIVE_SCROLLS] =
    {
        typeIcon = "EsoUI/Art/Campaign/campaignBonus_scrollIcon.dds",
        typeIconGamepad = "EsoUI/Art/Campaign/Gamepad/gp_bonusIcon_scrolls.dds",
        headerText = GetString(SI_CAMPAIGN_BONUSES_OFFENSIVE_SCROLL_HEADER),
        infoData = GetOffensiveBonusData,
        detailsText = GetString(SI_CAMPAIGN_BONUSES_KEEP_REQUIRE_HOME_SCROLLS),
        count = GetOffensiveBonusCount,
    },
    [ZO_CAMPAIGN_BONUS_TYPE_EDGE_KEEPS] =
    {
        typeIcon = "EsoUI/Art/Campaign/campaignBonus_keepIcon.dds",
        typeIconGamepad = "EsoUI/Art/Campaign/Gamepad/gp_bonusIcon_keeps.dds",
        headerText = GetString(SI_CAMPAIGN_BONUSES_EDGE_KEEP_HEADER),
        infoData = GetEdgeKeepBonusData,
        count = GetNumEdgeKeepBonuses,
        scoreFunction = GetEdgeKeepBonusScore,
    },
}
ZO_CampaignBonuses_Shared = ZO_InitializingObject:Subclass()
function ZO_CampaignBonuses_Shared:Initialize(control)
    self.control = control
end
function ZO_CampaignBonuses_Shared:SetCampaignAndQueryType(campaignId, queryType)
    self.campaignId = campaignId
    self.queryType = queryType
end
function ZO_CampaignBonuses_Shared:GetCurrentCampaignId()
    return self.campaignId
end
function ZO_CampaignBonuses_Shared:CreateDataTable()
    self.dataTable = {}
    local nextItemIsHeader = false
    local headerName = nil
    for i = 1, #self.masterList do
        local data = self.masterList[i]
        if data.isHeader then
            nextItemIsHeader = true
            headerName = data.headerString
        else
            self.dataTable[i] = ZO_GamepadEntryData:New(data.name, data.icon)
            if nextItemIsHeader then
                self.dataTable[i]:SetHeader(header)
            end
            self.dataTable[i].index = data.index
            self.dataTable[i].typeIcon = data.typeIcon
            self.dataTable[i].countText = data.countText
            self.dataTable[i].active = data.active
            self.dataTable[i].bonusType = data.bonusType
            self.dataTable[i].description = data.description
            nextItemIsHeader = false
        end
    end
end
function ZO_CampaignBonuses_Shared:BuildMasterList()
    self.masterList = {}
    for bonusType, info in ipairs(BONUS_SECTION_DATA) do
        local infoData = info.infoData
        if type(info.infoData) == "function" then
            infoData = info.infoData(self.campaignId)
        end
        local infoText = ""
        if infoData then
            infoText = GetFormattedBonusString(infoData)
        end
        local detailsText = info.detailsText
        if type(info.detailsText) == "function" then
            detailsText = info.detailsText(self.campaignId)
        end
        local headerData =
        {
            isHeader = true,
            headerString = info.headerText,
            infoString = infoText,
            detailsString = detailsText or "",
            bonusType = bonusType,
        }
        self.masterList[#self.masterList + 1] = headerData
        local startIndex = info.startIndex or 1
        local score = info.scoreFunction(self.campaignId)
        local index = score and score ~= 0 and score + startIndex - 1 or startIndex
        -- Code only supports 10 bonuses even though the player's alliance could have acquired up to 12 keeps
        -- so cap the keep index to the max count allowed by the bonus data info
        local count = type(info.count) == "function" and info.count(self.campaignId) or info.count
        index = zo_min(index, count)
        local scoreIndex = index - startIndex + 1
        local countText = scoreIndex
        local abilityId = info.abilityFunction(index, self.campaignId)
        local name = GetAbilityName(abilityId)
        local icon = GetAbilityIcon(abilityId)
        local description = GetAbilityDescription(abilityId)
        if info.countText then
            if info.countText == HIDE_COUNT then
                countText = nil
            else
                countText = info.countText
            end
        end
        local data =
        {
            index = index,
            isHeader = false,
            typeIcon = info.typeIcon,
            typeIconGamepad = info.typeIconGamepad,
            countText = countText,
            name = zo_strformat(SI_CAMPAIGN_BONUSES_ENTRY_ROW_FORMATTER, name),
            icon = icon,
            active = score and score >= scoreIndex,
            bonusType = bonusType,
            description = description,
            infoData = infoData,
            detailsText = detailsText or "",
        }
        self.masterList[#self.masterList + 1] = data
    end
    return self.masterList
end