-
Notifications
You must be signed in to change notification settings - Fork 234
my new unit_attributes_generic #5608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XNTEABDSC
wants to merge
2
commits into
ZeroK-RTS:master
Choose a base branch
from
XNTEABDSC:unit_attributes_generic
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,288
−966
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
LuaRules/Configs/UnitAttributeHandlers/AbilityDisabled.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| local spSetUnitRulesParam=Spring.SetUnitRulesParam | ||
|
|
||
| return { | ||
| ---@type AttributesHandlerFactory | ||
| AbilityDisabled = { | ||
| handledAttributeNames={abilityDisabled=true}, | ||
| new = function(unitID, unitDefID) | ||
| local abilityDisabledCur = false | ||
|
|
||
| return { | ||
| newDataHandler = function(frame) | ||
| local abilityDisabled = false | ||
|
|
||
| return { | ||
| fold = function(data) | ||
| abilityDisabled = abilityDisabled or data.abilityDisabled | ||
| end, | ||
| apply = function() | ||
| if abilityDisabled ~= abilityDisabledCur then | ||
| spSetUnitRulesParam(unitID, "att_abilityDisabled", abilityDisabled and 1 or 0) | ||
| abilityDisabledCur = abilityDisabled | ||
| end | ||
| end | ||
| } | ||
| end, | ||
| clear = function() | ||
| -- Reset logic can be added here if needed | ||
| end | ||
| } | ||
| end | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| local spSetUnitRulesParam=Spring.SetUnitRulesParam | ||
| local INLOS_ACCESS = {inlos = true} | ||
|
|
||
| GG.att_DeathExplodeMult={} | ||
| return { | ||
| ---@type AttributesHandlerFactory | ||
| DeathExplosion = { | ||
| handledAttributeNames={deathExplode=true}, | ||
| new = function(unitId) | ||
| return { | ||
| newDataHandler = function() | ||
| local deathExplodeMult = 1 | ||
|
|
||
| return { | ||
| fold = function(data) | ||
| deathExplodeMult = deathExplodeMult * (data.deathExplode or 1) | ||
|
|
||
| end, | ||
| apply = function() | ||
| GG.att_DeathExplodeMult[unitId] = deathExplodeMult | ||
| spSetUnitRulesParam(unitId, "deathExplodeMult", deathExplodeMult, INLOS_ACCESS) | ||
| end | ||
| } | ||
| end, | ||
| clear = function() | ||
| GG.att_DeathExplodeMult[unitId] = nil | ||
| end | ||
| } | ||
| end | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| local INLOS_ACCESS = {inlos = true} | ||
| local spSetUnitRulesParam=Spring.SetUnitRulesParam | ||
|
|
||
| GG.att_EconomyChange={} | ||
| return { | ||
| ---@type AttributesHandlerFactory | ||
| Economy = { | ||
| handledAttributeNames={econ=true,energy=true}, | ||
| new = function(unitID, unitDefID) | ||
| local econMultCur = 1 | ||
| local energyMultCur = 1 | ||
|
|
||
| return { | ||
| newDataHandler = function(frame) | ||
| local econMult = 1 | ||
| local energyMult = 1 | ||
|
|
||
| return { | ||
| fold = function(data) | ||
| econMult = econMult * (data.econ or 1) | ||
| energyMult = energyMult * (data.energy or 1) | ||
| end, | ||
| apply = function() | ||
| GG.att_EconomyChange[unitID] = econMult | ||
| if econMult ~= econMultCur or energyMult ~= energyMultCur then | ||
| spSetUnitRulesParam(unitID, "totalEconomyChange", econMult, INLOS_ACCESS) | ||
| spSetUnitRulesParam(unitID, "metalGenerationFactor", econMult, INLOS_ACCESS) | ||
| spSetUnitRulesParam(unitID, "energyGenerationFactor", econMult * energyMult, INLOS_ACCESS) | ||
|
|
||
| econMultCur = econMult | ||
| energyMultCur = energyMult | ||
| end | ||
| end | ||
| } | ||
| end, | ||
| clear = function() | ||
| GG.att_EconomyChange[unitID] = nil | ||
| -- Reset logic can be added here if needed | ||
| end | ||
| } | ||
| end | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| local INLOS_ACCESS = {inlos = true} | ||
|
|
||
| local function GetMass(health, cost) | ||
| return (((cost/2) + (health/8))^0.6)*6.5 | ||
| end | ||
| local spGetUnitHealth=Spring.GetUnitHealth | ||
| local spSetUnitMaxHealth=Spring.SetUnitMaxHealth | ||
| local spSetUnitHealth=Spring.SetUnitHealth | ||
| local spSetUnitCosts=Spring.SetUnitCosts | ||
| local spSetUnitMass=Spring.SetUnitMass | ||
| local spSetUnitRulesParam=Spring.SetUnitRulesParam | ||
|
|
||
| GG.att_CostMult={} | ||
| GG.att_HealthMult={} | ||
|
|
||
| ---@type {[string|number]:AttributesHandlerFactory} | ||
| return{ | ||
| ---@type AttributesHandlerFactory | ||
| HealthCostMass={ | ||
| handledAttributeNames={ | ||
| healthMult=true,healthAdd=true,cost=true,mass=true | ||
| }, | ||
| new=function (unitID,unitDefID) | ||
| local ud=UnitDefs[unitDefID] | ||
| local origUnitHealth= ud.health | ||
| local origUnitCost= ud.buildTime | ||
| local HealthMultCur=1 | ||
| local HealthAddCur=0 | ||
| local CostMultCur=1 | ||
| local MassMultCur=1 | ||
| ---@type AttributesHandler | ||
| return{ | ||
| newDataHandler=function (frame) | ||
| local healthMult=1 | ||
| local healthAdd=0 | ||
| local costMult=1 | ||
| local massMult=1 | ||
|
|
||
| ---@type AttributesDataHandler | ||
| return { | ||
| ---@param data {healthAdd:number?,healthMult:number?,cost:number?,mass:number?} | ||
| fold=function (data) | ||
| healthMult=healthMult*(data.healthMult or 1) | ||
| healthAdd=healthAdd+(data.healthAdd or 0) | ||
| costMult=costMult*(data.cost or 1) | ||
| massMult=massMult*(data.mass or 1) | ||
| end, | ||
| apply=function () | ||
| GG.att_CostMult[unitID] = costMult | ||
| GG.att_HealthMult[unitID] = healthMult | ||
| spSetUnitRulesParam(unitID, "costMult", costMult, INLOS_ACCESS) | ||
|
|
||
| if CostMultCur~=costMult or HealthAddCur~=healthAdd or MassMultCur~=massMult or HealthMultCur~=healthMult then | ||
|
|
||
| local newMaxHealth = (origUnitHealth + healthAdd) * healthMult | ||
| local oldHealth, oldMaxHealth = spGetUnitHealth(unitID) | ||
| spSetUnitMaxHealth(unitID, newMaxHealth) | ||
| spSetUnitHealth(unitID, oldHealth * newMaxHealth / oldMaxHealth) | ||
|
|
||
| local origCost = origUnitCost | ||
| local cost = origCost*costMult | ||
| spSetUnitCosts(unitID, { | ||
| metalCost = cost, | ||
| energyCost = cost, | ||
| buildTime = cost, | ||
| }) | ||
|
|
||
| if massMult == 1 then | ||
| -- Default to update mass based on new stats, if a multiplier is not set. | ||
| local mass = GetMass(newMaxHealth, cost) | ||
| spSetUnitMass(unitID, mass) | ||
| spSetUnitRulesParam(unitID, "massOverride", mass, INLOS_ACCESS) | ||
| else | ||
| local mass = GetMass(origUnitHealth, origCost) * massMult | ||
| spSetUnitMass(unitID, mass) | ||
| spSetUnitRulesParam(unitID, "massOverride", mass, INLOS_ACCESS) | ||
| end | ||
| CostMultCur=costMult | ||
| HealthAddCur=healthAdd | ||
| MassMultCur=massMult | ||
| HealthMultCur=healthMult | ||
| end | ||
| end | ||
| } | ||
| end, | ||
| clear=function () | ||
| GG.att_CostMult[unitID] = nil | ||
| GG.att_HealthMult[unitID] = nil | ||
|
|
||
| end | ||
| } | ||
| end | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
|
|
||
| local INLOS_ACCESS = {inlos = true} | ||
|
|
||
| GG.att_RegenChange={} | ||
| return { | ||
| ---@type AttributesHandlerFactory | ||
| StaticAttributes = { | ||
| handledAttributeNames = {healthRegen=true}, | ||
| new = function(unitID, unitDefID) | ||
|
|
||
| return { | ||
| newDataHandler = function(frame) | ||
|
|
||
| local healthRegen = 1 | ||
|
|
||
| return { | ||
| fold = function(data) | ||
| healthRegen = healthRegen*(data.healthRegen or 1) | ||
| end, | ||
| apply = function() | ||
| GG.att_RegenChange[unitID] = healthRegen | ||
| end | ||
| } | ||
| end, | ||
| clear = function() | ||
| GG.att_RegenChange[unitID] = nil | ||
| -- Reset logic can be added here if needed | ||
| end | ||
| } | ||
| end | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| local spSetUnitRulesParam=Spring.SetUnitRulesParam | ||
| local INLOS_ACCESS = {inlos = true} | ||
|
|
||
| GG.att_JumpRangeChange={} | ||
| return { | ||
| ---@type AttributesHandlerFactory | ||
| JumpRange = { | ||
| handledAttributeNames={ | ||
| build=true | ||
| }, | ||
| new = function(unitID, unitDefID) | ||
| return { | ||
| newDataHandler = function(frame) | ||
| local jumpRangeMult = 1 | ||
|
|
||
| return { | ||
| fold = function(data) | ||
| jumpRangeMult = jumpRangeMult * (data.jumpRange or 1) | ||
| end, | ||
| apply = function() | ||
| GG.att_JumpRangeChange[unitID] = jumpRangeMult | ||
| spSetUnitRulesParam(unitID, "jumpRangeMult", jumpRangeMult, INLOS_ACCESS) | ||
| end | ||
| } | ||
| end, | ||
| clear = function() | ||
| GG.att_JumpRangeChange[unitID] = nil | ||
| -- Reset logic can be added here if needed | ||
| end | ||
| } | ||
| end | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean? What does jump range have to do with "build"?