Back to Home

ESO Lua File v100016

ingame/stable/stablemanager.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
STABLE_TRAINING_TEXTURES =
{
    [RIDING_TRAIN_SPEED] = "EsoUI/Art/Mounts/ridingSkill_speed.dds",
    [RIDING_TRAIN_STAMINA] = "EsoUI/Art/Mounts/ridingSkill_stamina.dds",
    [RIDING_TRAIN_CARRYING_CAPACITY] = "EsoUI/Art/Mounts/ridingSkill_capacity.dds",
}
STABLE_TRAINING_TEXTURES_GAMEPAD =
{
    [RIDING_TRAIN_SPEED] = "EsoUI/Art/Mounts/Gamepad/gp_ridingSkill_speed.dds",
    [RIDING_TRAIN_STAMINA] = "EsoUI/Art/Mounts/Gamepad/gp_ridingSkill_stamina.dds",
    [RIDING_TRAIN_CARRYING_CAPACITY] = "EsoUI/Art/Mounts/Gamepad/gp_ridingSkill_capacity.dds",
}
STABLE_TRAINING_SOUNDS =
{
    [RIDING_TRAIN_SPEED] = SOUNDS.STABLE_FEED_SPEED,
    [RIDING_TRAIN_STAMINA] = SOUNDS.STABLE_FEED_STAMINA,
    [RIDING_TRAIN_CARRYING_CAPACITY] = SOUNDS.STABLE_FEED_CARRY,
}
----------------
--Initialization
----------------
ZO_Stable_Manager = ZO_CallbackObject:Subclass()
function ZO_Stable_Manager:New(...)
    local singleton = ZO_CallbackObject.New(self)
    singleton:Initialize(...)
    return singleton
end
function ZO_Stable_Manager:Initialize(control)
    self.trainingCost = GetTrainingCost()
    self.currentMoney = GetCarriedCurrencyAmount(CURT_MONEY)
    self:UpdateStats()
    self.ridingSkillAnnoucementInfo = {}
end
function ZO_Stable_Manager:RegisterForEvents()
    local function InteractStart()
        self:UpdateStats()
        self:FireCallbacks("StableInteractStart")
    end
    local function ActiveMountChanged()
        if not IsInTutorialZone() then
            TriggerTutorial(TUTORIAL_TRIGGER_MOUNT_SET)
        end
        self:FireCallbacks("ActiveMountChanged")
    end
    EVENT_MANAGER:RegisterForEvent("ZO_Stable_Manager", EVENT_STABLE_INTERACT_START, InteractStart)
    EVENT_MANAGER:RegisterForEvent("ZO_Stable_Manager", EVENT_STABLE_INTERACT_END, function(eventCode) self:FireCallbacks("StableInteractEnd") end)
    EVENT_MANAGER:RegisterForEvent("ZO_Stable_Manager", EVENT_ACTIVE_MOUNT_CHANGED, ActiveMountChanged)
    local function UpdateStats()
        self:UpdateStats()
        self:FireCallbacks("StableMountInfoUpdated")
    end
    EVENT_MANAGER:RegisterForEvent("ZO_Stable_Manager", EVENT_MOUNT_INFO_UPDATED, UpdateStats)
    local function RidingSkillImprovement(_, ...)
        self:ProcessRidingSkillAnnouncement(...)
    end
    EVENT_MANAGER:RegisterForEvent("ZO_Stable_Manager", EVENT_RIDING_SKILL_IMPROVEMENT, RidingSkillImprovement)
    local function UpdateMoney()
        self.currentMoney = GetCarriedCurrencyAmount(CURT_MONEY)
        self:FireCallbacks("StableMoneyUpdate")
    end
    EVENT_MANAGER:RegisterForEvent("ZO_Stable_Manager", EVENT_MONEY_UPDATE, UpdateMoney)
    EVENT_MANAGER:RegisterForUpdate("ZO_Stable_Manager", 100, function(...) self:OnUpdate(...) end)
end
function ZO_Stable_Manager:UpdateStats()
    local inventoryBonus, maxInventoryBonus, staminaBonus, maxStaminaBonus, speedBonus, maxSpeedBonus = GetRidingStats()
    self.stats =
    {
        [RIDING_TRAIN_SPEED] = {speedBonus, maxSpeedBonus},
        [RIDING_TRAIN_STAMINA] = {staminaBonus, maxStaminaBonus},
        [RIDING_TRAIN_CARRYING_CAPACITY] = {inventoryBonus, maxInventoryBonus},
    }
    self.ridingSkillMaxedOut = (inventoryBonus == maxInventoryBonus) and (staminaBonus == maxStaminaBonus) and (speedBonus == maxSpeedBonus)
end
local TIMER_DURATION_MS = 2000
function ZO_Stable_Manager:ProcessRidingSkillAnnouncement(ridingSkill, previous, current, source)
    if source == RIDING_TRAIN_SOURCE_ITEM then
        local currentSkillInfo = self.ridingSkillAnnoucementInfo[ridingSkill]
        if currentSkillInfo == nil then
            currentSkillInfo = 
            {
                start = previous,
            }
            self.ridingSkillAnnoucementInfo[ridingSkill] = currentSkillInfo
        end
        currentSkillInfo.timerMS = GetGameTimeMilliseconds() + TIMER_DURATION_MS
        currentSkillInfo.stop = current
    end
end
function ZO_Stable_Manager:ShowRidingSkillAnnouncement(ridingSkill, start, stop)
    local skillImprovementText = zo_strformat(SI_RIDING_SKILL_ANNOUCEMENT_SKILL_INCREASE, GetString("SI_RIDINGTRAINTYPE", ridingSkill), start, stop)
    CENTER_SCREEN_ANNOUNCE:AddMessage(EVENT_RIDING_SKILL_IMPROVEMENT, CSA_EVENT_COMBINED_TEXT, STABLE_TRAINING_SOUNDS[ridingSkill], GetString(SI_RIDING_SKILL_ANNOUCEMENT_BANNER), skillImprovementText)
end
function ZO_Stable_Manager:OnUpdate(timeMS)
    for skillType, info in pairs(self.ridingSkillAnnoucementInfo) do
        if timeMS > info.timerMS then
            self.ridingSkillAnnoucementInfo[skillType] = nil
            self:ShowRidingSkillAnnouncement(skillType, info.start, info.stop)
        end
    end
end
function ZO_Stable_Manager:CanAffordTraining()
    return self.trainingCost > 0 and self.currentMoney >= self.trainingCost
end
local STAT_BONUS_INDEX = 1
local MAX_STAT_BONUS_INDEX = 2
function ZO_Stable_Manager:GetStats(trainingType)
    if trainingType then
        return self.stats[trainingType][STAT_BONUS_INDEX], self.stats[trainingType][MAX_STAT_BONUS_INDEX]
    else
        local speed, speedMax = self:GetStats(RIDING_TRAIN_SPEED)
        local stamina, staminaMax = self:GetStats(RIDING_TRAIN_STAMINA)
        local carry, carryMax = self:GetStats(RIDING_TRAIN_CARRYING_CAPACITY)
        return speed, speedMax, stamina, staminaMax, carry, carryMax
    end
end
function ZO_Stable_Manager:IsRidingSkillMaxedOut()
    return self.ridingSkillMaxedOut
end
STABLE_MANAGER = ZO_Stable_Manager:New()