Back to Home

ESO Lua File v101044

pregame/charactercreate/zo_charactercreatedata.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
--[[ Character Creation Data]]--
-- The important stuff, data describing all the valid options you can choose from
ZO_CharacterCreateData = ZO_Object:Subclass()
function ZO_CharacterCreateData:New()
    local createData = ZO_Object.New(self)
    createData:Initialize()
    return createData
end
function ZO_CharacterCreateData:Initialize()
end
function ZO_CharacterCreateData:PerformDeferredInitialization()
    local missingDataPosition = 0
    local function SafeGetPosition(position)
        if position > 0 then
            return position
        end
        missingDataPosition = missingDataPosition + 1
        return missingDataPosition
    end
    local function ResetMissingDataPosition()
        missingDataPosition = 0
    end
    self.alliances = {}
    local alliances = self.alliances
    for i = 1, GetNumAlliances() do
        local alliance, name, normalIcon, pressedIcon, mouseoverIcon, backdropTop, backdropBottom, position, lore, gamepadNormalIcon, gamepadPressedIcon = GetAllianceInfo(i)
        alliances[i] =
        {
            alliance = alliance,
            name = name,
            normalIcon = normalIcon,
            pressedIcon = pressedIcon,
            mouseoverIcon = mouseoverIcon,
            backdropTop = backdropTop,
            backdropBottom = backdropBottom,
            position = SafeGetPosition(position),
            lore = lore,
            isSelectable = false,
            gamepadNormalIcon = gamepadNormalIcon,
            gamepadPressedIcon = gamepadPressedIcon,
        }
    end
    self.classes = {}
    local classes = self.classes
    for i = 1, GetNumClasses() do
        local class, lore, normalIcon, pressedIcon, mouseoverIcon, isSelectable, _, _, gamepadNormalIcon, gamepadPressedIcon = GetClassInfo(i)
        classes[i] =
        {
            class = class,
            lore = lore,
            normalIcon = normalIcon,
            pressedIcon = pressedIcon,
            mouseoverIcon = mouseoverIcon,
            isSelectable = isSelectable,
            gamepadNormalIcon = gamepadNormalIcon,
            gamepadPressedIcon = gamepadPressedIcon,
        }
    end
    self.races = {}
    local races = self.races
    for i = 1, GetNumRaces() do
        local raceDef, lore, alliance, normalIcon, pressedIcon, mouseoverIcon, position, isSelectable, gamepadNormalIcon, gamepadPressedIcon = GetRaceInfo(i)
        races[i] =
        {
            race = raceDef,
            alliance = alliance,
            lore = lore,
            normalIcon = normalIcon,
            pressedIcon = pressedIcon,
            mouseoverIcon = mouseoverIcon,
            position = SafeGetPosition(position),
            isSelectable = isSelectable,
            isRadioEnabled = isSelectable,
            gamepadNormalIcon = gamepadNormalIcon,
            gamepadPressedIcon = gamepadPressedIcon,
        }
    end
    self.templates = {}
    local templatesAllowed, templatesRequired = GetTemplateStatus()
    if templatesAllowed then
        local templates = self.templates
        if not templatesRequired then
            -- add the no template option
            table.insert(templates, self:GetNoneTemplate())
        end
        -- Keep these in the order that they are returned in so the template list matches the def order
        -- If lookup time ever becomes a problem, make a table that maps templateDefId -> tableIndex
        for i = 1, GetNumTemplates() do
            local templateDef, name, race, class, gender, alliance, overrideAppearance, isSelectable = GetTemplateInfo(i)
            table.insert(templates,
            {
                template = templateDef,
                name = name,
                race = race,
                class = class,
                gender = gender,
                alliance = alliance,
                overrideAppearance = overrideAppearance,
                isSelectable = isSelectable
            })
        end
    end
end
do
    local NONE_TEMPLATE =
        {
            template = 0,
            name = GetString(SI_TEMPLATE_NONE),
            race = 0,
            class = 0,
            gender = 0,
            alliance = 0,
            overrideAppearance = false,
            isSelectable = true
        }
    function ZO_CharacterCreateData:GetNoneTemplate()
        return NONE_TEMPLATE
    end
end
function ZO_CharacterCreateData:UpdateAllianceSelectability()
    -- Updates whether or not an alliance is selectable based on whether or not the races in the alliance can be selected
    -- This could actually be overridden by the "play any race as any alliance" entitlement, it's just a safe starting point
    for allianceIndex, allianceData in ipairs(self.alliances) do
        local currentAlliance = allianceData.alliance
        allianceData.isSelectable = false
        for raceIndex, raceData in ipairs(self.races) do
            if raceData.alliance == currentAlliance and raceData.isSelectable and raceData.isRadioEnabled then
                allianceData.isSelectable = true
                break
            end
        end
    end
end
function ZO_CharacterCreateData:GetAllianceInfo()
    return self.alliances
end
function ZO_CharacterCreateData:GetRaceInfo()
    return self.races
end
function ZO_CharacterCreateData:GetClassInfo()
    return self.classes
end
function ZO_CharacterCreateData:GetTemplateInfo()
    return self.templates
end
function ZO_CharacterCreateData:GetRaceForRaceDef(defId)
    local races = self.races
    for _, raceInfo in ipairs(races) do
        if raceInfo.race == defId then
            return raceInfo
        end
    end
end
function ZO_CharacterCreateData:GetAllianceForAllianceDef(defId)
    local alliances = self.alliances
    for _, allianceInfo in ipairs(alliances) do
        if allianceInfo.alliance == defId then
            return allianceInfo
        end
    end
end
function ZO_CharacterCreateData:GetClassForClassDef(defId)
    local classes = self.classes
    for _, classInfo in ipairs(classes) do
        if classInfo.class == defId then
            return classInfo
        end
    end
end
function ZO_CharacterCreateData:GetTemplate(templateDef)
    for _, templateInfo in ipairs(self.templates) do
        if templateInfo.template == templateDef then
            return templateInfo
        end
    end
end
do
    local function CheckAddOption(optionsTable, option)
        if option.isSelectable then
            optionsTable[#optionsTable + 1] = option
        end
    end
    function ZO_CharacterCreateData:PickRandom(validIndices, dataTable, defIdFieldName)
        local optionsTable = {}
        if validIndices then
            for _, dataIndex in ipairs(validIndices) do
                CheckAddOption(optionsTable, dataTable[dataIndex])
            end
        else
            for _, data in pairs(dataTable) do
                CheckAddOption(optionsTable, data)
            end
        end
        if #optionsTable > 0 then
            local randomIndex = zo_random(#optionsTable)
            return optionsTable[randomIndex][defIdFieldName]
        end
        return 1
    end
end
function ZO_CharacterCreateData:PickRandomRace(validIndicesTable)
    return self:PickRandom(validIndicesTable, self.races, "race")
end
function ZO_CharacterCreateData:PickRandomAlliance(validIndicesTable)
    -- Needs special behavior because this will usually follow the selected race...however
    -- some races have no alliance, so we should actually make a random choice for the alliance.
    -- So, if there are no preselected alliances do the fancy business.
    if not validIndicesTable then
        local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
        local currentRace = self:GetRaceForRaceDef(CharacterCreateGetRace(characterMode))
        if not currentRace or currentRace.alliance == 0 then
            return self:PickRandom(nil, self.alliances, "alliance")
        else
            return currentRace.alliance
        end
    end
    return self:PickRandom(validIndicesTable, self.alliances, "alliance")
end
function ZO_CharacterCreateData:PickRandomGender()
    local gender = zo_random(2)
    if gender == 1 then
        return GENDER_MALE
    end
    return GENDER_FEMALE
end
function ZO_CharacterCreateData:PickRandomClass()
    return self:PickRandom(nil, self.classes, "class")
end