-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathBuildSpeed.lua
More file actions
50 lines (46 loc) · 1.89 KB
/
Copy pathBuildSpeed.lua
File metadata and controls
50 lines (46 loc) · 1.89 KB
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
local REPAIR_ENERGY_COST_FACTOR = Game.repairEnergyCostFactor
local spSetUnitBuildSpeed=Spring.SetUnitBuildSpeed
local spSetUnitRulesParam=Spring.SetUnitRulesParam
local INLOS_ACCESS = {inlos = true}
GG.attRaw_BuildSpeed={}
return {
---@type AttributesHandlerFactory
BuildSpeed = {
handledAttributeNames={
build=true
},
new = function(unitID, unitDefID)
local ud = UnitDefs[unitDefID]
local buildSpeed = ud.buildSpeed or 0
local buildMultCur = 1
return {
newDataHandler = function(frame)
local buildMult = 1
return {
fold = function(data)
buildMult = buildMult * (data.build or 1)
end,
apply = function()
GG.attRaw_BuildSpeed[unitID] = buildSpeed*buildMult
spSetUnitRulesParam(unitID, "totalBuildPowerChange", buildMult, INLOS_ACCESS)
if buildMult ~= buildMultCur and buildSpeed > 0 then
local newBuildSpeed = buildSpeed * buildMult
spSetUnitBuildSpeed(unitID,
newBuildSpeed, -- build
newBuildSpeed / REPAIR_ENERGY_COST_FACTOR, -- repair
newBuildSpeed, -- reclaim
0.5 * newBuildSpeed -- rezz
)
buildMultCur = buildMult
end
end
}
end,
clear = function()
GG.attRaw_BuildSpeed[unitID] = nil
-- Reset logic can be added here if needed
end
}
end
}
}