Skip to content

Commit

Permalink
Arm maverick fix range not increasing with xp (#4239)
Browse files Browse the repository at this point in the history
The callin for UnitExperience() doesn't trigger without this other
function being called to set the experience grade at which to check.

---------

Co-authored-by: Floris <[email protected]>
  • Loading branch information
SethDGamre and Ruwetuin authored Jan 27, 2025
1 parent f402d90 commit f6b0983
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions luarules/gadgets/unit_xp_range_bonus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ if not gadgetHandler:IsSyncedCode() then
end


local SetUnitWeaponState = Spring.SetUnitWeaponState
local SetUnitMaxRange = Spring.SetUnitMaxRange
local spSetUnitWeaponState = Spring.SetUnitWeaponState
local spSetUnitMaxRange = Spring.SetUnitMaxRange
local gainsRangeFromXp = {}

for unitDefID, unitDef in pairs(UnitDefs) do
Expand All @@ -26,15 +26,17 @@ for unitDefID, unitDef in pairs(UnitDefs) do
end
end

function gadget:Initialize()
Spring.SetExperienceGrade(0.01) --without this, gadget:UnitExperience doesn't work at all.
end

function gadget:UnitExperience(unitID, unitDefID, unitTeam, xp, oldxp)
if gainsRangeFromXp[unitDefID] then

local rangeXPScale, originalRange = unpack(gainsRangeFromXp[unitDefID])
local limitXP = ((3 * xp) / (1 + 3 * xp)) * rangeXPScale
local newRange = originalRange * (1 + limitXP)

SetUnitWeaponState(unitID, 1, "range", newRange)
SetUnitMaxRange(unitID, newRange)
spSetUnitWeaponState(unitID, 1, "range", newRange)
spSetUnitMaxRange(unitID, newRange)
end
end

0 comments on commit f6b0983

Please sign in to comment.