Back to Home

ESO Lua File v100035

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
ZO_CAMPAIGN_BONUS_TYPE_HOME_KEEPS = 1
ZO_CAMPAIGN_BONUS_TYPE_ENEMY_KEEPS = 2
ZO_CAMPAIGN_BONUS_TYPE_EDGE_KEEPS = 3
ZO_CAMPAIGN_BONUS_TYPE_DEFENSIVE_SCROLLS = 4
ZO_CAMPAIGN_BONUS_TYPE_OFFENSIVE_SCROLLS = 5
ZO_CAMPAIGN_BONUS_TYPE_EMPEROR = 6
local function GetHomeKeepBonusString(campaignId)
    local allHomeKeepsHeld = GetAvAKeepScore(campaignId, GetUnitAlliance("player"))
    if allHomeKeepsHeld then
        return GetString(SI_CAMPAIGN_BONUSES_HOME_KEEP_PASS_INFO)
    else
        return GetString(SI_CAMPAIGN_BONUSES_HOME_KEEP_FAIL_INFO)
    end
end
local function GetHomeKeepBonusScore(campaignId)
    local allHomeKeepsHeld = GetAvAKeepScore(campaignId, GetUnitAlliance("player"))
    return allHomeKeepsHeld and 1 or 0
end
local function GetKeepBonusString(campaignId)
    local _, enemyKeepsHeld = GetAvAKeepScore(campaignId, GetUnitAlliance("player"))
    return zo_strformat(SI_CAMPAIGN_BONUSES_ENEMY_KEEP_INFO, enemyKeepsHeld)
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 GetEdgeKeepBonusString(campaignId)
    return zo_strformat(SI_CAMPAIGN_BONUSES_EDGE_KEEP_INFO, GetEdgeKeepBonusScore(campaignId))
end
local function GetDefensiveBonusString(campaignId)
    local _, enemyScrollsHeld = GetAvAArtifactScore(campaignId, GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_DEFENSIVE)
    return zo_strformat(SI_CAMPAIGN_BONUSES_ENEMY_SCROLL_INFO, enemyScrollsHeld)
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 GetOffensiveBonusString(campaignId)
    local _, enemyScrollsHeld = GetAvAArtifactScore(campaignId, GetUnitAlliance("player"), OBJECTIVE_ARTIFACT_OFFENSIVE)
    return zo_strformat(SI_CAMPAIGN_BONUSES_ENEMY_SCROLL_INFO, enemyScrollsHeld)
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 GetEmperorBonusString(campaignId)
    if DoesCampaignHaveEmperor(campaignId) then
        local alliance = GetCampaignEmperorInfo(campaignId)
        if alliance == GetUnitAlliance("player") then
            return GetString(SI_CAMPAIGN_BONUSES_EMPEROR_PASS_INFO)
        else
            return GetString(SI_CAMPAIGN_BONUSES_EMPEROR_FAIL_INFO)
        end
    else
        return GetString(SI_CAMPAIGN_BONUSES_EMPEROR_NONE_INFO)
    end
end
local function GetEmperorBonusAbilityId(campaignId)
    return GetEmperorAllianceBonusAbilityId(campaignId, GetUnitAlliance("player"))
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),
                                            infoText = GetHomeKeepBonusString,
                                            count = 1, 
                                            countText = GetString(SI_CAMPAIGN_BONUSES_HOME_KEEP_ALL), 
                                            abilityFunction = GetKeepScoreBonusAbilityId,
                                            scoreFunction = GetHomeKeepBonusScore,
                                        },
    [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),
                                            infoText = GetKeepBonusString,
                                            count = GetNumKeepScoreBonuses,
                                            startIndex = 2,
                                            abilityFunction = GetKeepScoreBonusAbilityId,
                                            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),
                                            infoText = GetDefensiveBonusString,
                                            count = GetDefensiveBonusCount,
                                            abilityFunction = GetDefensiveBonusAbilityId,
                                            scoreFunction = GetDefensiveBonusScore,
                                        },
    [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),
                                            infoText = GetOffensiveBonusString,
                                            count = GetOffensiveBonusCount,
                                            abilityFunction = GetOffensiveBonusAbilityId,
                                            scoreFunction = GetOffensiveBonusScore,
                                        },
    [ZO_CAMPAIGN_BONUS_TYPE_EMPEROR] =              {
                                            typeIcon = "EsoUI/Art/Campaign/campaignBonus_emporershipIcon.dds",
                                            typeIconGamepad = "EsoUI/Art/Campaign/Gamepad/gp_bonusIcon_emperor.dds",
                                            headerText = GetString(SI_CAMPAIGN_BONUSES_EMPERORSHIP_HEADER),
                                            infoText = GetEmperorBonusString,
                                            count = 1,
                                            countText = HIDE_COUNT,
                                            abilityFunction = GetEmperorBonusAbilityId,
                                            scoreFunction = GetEmperorBonusScore,
                                        },
    [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),
                                            infoText = GetEdgeKeepBonusString,
                                            count = GetNumEdgeKeepBonuses, 
                                            abilityFunction = GetEdgeKeepBonusAbilityId,
                                            scoreFunction = GetEdgeKeepBonusScore,
                                        },
}
ZO_CampaignBonuses_Shared = ZO_Object:Subclass()
function ZO_CampaignBonuses_Shared:New(...)
    local manager = ZO_Object.New(self)
    manager:Initialize(...)
    return manager
end
function ZO_CampaignBonuses_Shared:Initialize(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 data = {
            isHeader = true,
            headerString = info.headerText,
            infoString = type(info.infoText) == "function" and info.infoText(self.campaignId) or info.infoText,
            bonusType = bonusType,
        }
        self.masterList[#self.masterList + 1] = data
        local count = type(info.count) == "function" and info.count(self.campaignId) or info.count
        local startIndex = info.startIndex or 1
        local score = info.scoreFunction(self.campaignId)
        for i = startIndex, count do
            local abilityId = info.abilityFunction(i)
            local name = GetAbilityName(abilityId)
            local icon = GetAbilityIcon(abilityId)
            local description = GetAbilityDescription(abilityId)
            local scoreIndex = i - startIndex + 1
            local countText = scoreIndex
            if info.countText then
                if info.countText == HIDE_COUNT then
                    countText = nil
                else
                    countText = info.countText
                end
            end
            local data = {
                index = i,
                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,
            }
            self.masterList[#self.masterList + 1] = data
        end
    end
    return self.masterList
end