Skip to content

Commit

Permalink
Apply new enhancement processing convention to Seraphim SACU (FAForev…
Browse files Browse the repository at this point in the history
…er#6518)

---------

Co-authored-by: lL1l1 <82986251+lL1l1@users.noreply.github.com>
  • Loading branch information
MrRowey and lL1l1 authored Nov 18, 2024
1 parent 53ecbd2 commit d9e49e7
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 109 deletions.
2 changes: 1 addition & 1 deletion changelog/snippets/other.6498.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- (#6498, #6502, #6503, #6514, #6517) Refactor the Enhancements section in the ACU/SACU scripts to replace the long if/else chain with a more modular design that is easier to maintain and hook. Each enhancement has its own dedicated function, named with the format `ProcessEnhancement[EnhancementName]`. The CreateEnhancement function now calls the appropriate enhancement function automatically by that name format.
- (#6498, #6502, #6503, #6514, #6517, #6518) Refactor the Enhancements section in the ACU/SACU scripts to replace the long if/else chain with a more modular design that is easier to maintain and hook. Each enhancement has its own dedicated function, named with the format `ProcessEnhancement[EnhancementName]`. The CreateEnhancement function now calls the appropriate enhancement function automatically by that name format.
285 changes: 177 additions & 108 deletions units/XSL0301/XSL0301_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ XSL0301 = ClassUnit(CommandUnit) {
},
},

---@param self XSL0301
__init = function(self)
CommandUnit.__init(self, 'LightChronatronCannon')
end,

---@param self XSL0301
OnCreate = function(self)
CommandUnit.OnCreate(self)
self:SetCapturable(false)
Expand All @@ -51,126 +53,193 @@ XSL0301 = ClassUnit(CommandUnit) {
self:GetWeaponByLabel('AutoOverCharge').NeedsUpgrade = true
end,

---@param self XSL0301
---@param builder Unit
---@param layer Layer
StartBeingBuiltEffects = function(self, builder, layer)
CommandUnit.StartBeingBuiltEffects(self, builder, layer)
self.Trash:Add(ForkThread(EffectUtil.CreateSeraphimBuildThread, self, builder, self.OnBeingBuiltEffectsBag, 2))
end,

---@param self XSL0301
---@param unitBeingBuilt Unit
---@param order string unused
CreateBuildEffects = function(self, unitBeingBuilt, order)
EffectUtil.CreateSeraphimUnitEngineerBuildingEffects(self, unitBeingBuilt, self.BuildEffectBones,
self.BuildEffectsBag)
EffectUtil.CreateSeraphimUnitEngineerBuildingEffects(self, unitBeingBuilt, self.BuildEffectBones, self.BuildEffectsBag)
end,

-- =====================================================================================================================
-- EMHANCEMENTS

---@param self XSL0301
---@param bp UnitBlueprintEnhancement unused
ProcessEnhancementTeleporter = function(self, bp)
self:AddCommandCap('RULEUCC_Teleport')
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement unused
ProcessEnhancementTeleporterRemove = function(self, bp)
self:RemoveCommandCap('RULEUCC_Teleport')
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement unused
ProcessEnhancementMissile = function(self, bp)
self:AddCommandCap('RULEUCC_Tactical')
self:AddCommandCap('RULEUCC_SiloBuildTactical')
self:SetWeaponEnabledByLabel('Missile', true)
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement unused
ProcessEnhancementMissileRemove = function(self, bp)
self:RemoveCommandCap('RULEUCC_Tactical')
self:RemoveCommandCap('RULEUCC_SiloBuildTactical')
self:SetWeaponEnabledByLabel('Missile', false)
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement
ProcessEnhancementShield = function(self, bp)
self:AddToggleCap('RULEUTC_ShieldToggle')
self:SetEnergyMaintenanceConsumptionOverride(bp.MaintenanceConsumptionPerSecondEnergy or 0)
self:SetMaintenanceConsumptionActive()
self:CreateShield(bp)
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement unused
ProcessEnhancementShieldRemove = function(self, bp)
self:DestroyShield()
self:SetMaintenanceConsumptionInactive()
self:RemoveToggleCap('RULEUTC_ShieldToggle')
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement unused
ProcessEnhancementOvercharge = function(self, bp)
self:AddCommandCap('RULEUCC_Overcharge')
self:GetWeaponByLabel('OverCharge').NeedsUpgrade = false
self:GetWeaponByLabel('AutoOverCharge').NeedsUpgrade = false
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement unused
ProcessEnhancementOverchargeRemove = function(self, bp)
self:RemoveCommandCap('RULEUCC_Overcharge')
self:SetWeaponEnabledByLabel('OverCharge', false)
self:SetWeaponEnabledByLabel('AutoOverCharge', false)
self:GetWeaponByLabel('OverCharge').NeedsUpgrade = true
self:GetWeaponByLabel('AutoOverCharge').NeedsUpgrade = true
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement
ProcessEnhancementEngineeringThroughput = function(self, bp)
if not Buffs['SeraphimSCUBuildRate'] then
BuffBlueprint {
Name = 'SeraphimSCUBuildRate',
DisplayName = 'SeraphimSCUBuildRate',
BuffType = 'SCUBUILDRATE',
Stacks = 'REPLACE',
Duration = -1,
Affects = {
BuildRate = {
Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate,
Mult = 1,
},
},
}
end
Buff.ApplyBuff(self, 'SeraphimSCUBuildRate')
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement
ProcessEnhancementEngineeringThroughputRemove = function(self, bp)
if Buff.HasBuff(self, 'SeraphimSCUBuildRate') then
Buff.RemoveBuff(self, 'SeraphimSCUBuildRate')
end
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement
ProcessEnhancementDamageStabilization = function (self, bp)
if not Buffs['SeraphimSCUDamageStabilization'] then
BuffBlueprint {
Name = 'SeraphimSCUDamageStabilization',
DisplayName = 'SeraphimSCUDamageStabilization',
BuffType = 'SCUUPGRADEDMG',
Stacks = 'ALWAYS',
Duration = -1,
Affects = {
MaxHealth = {
Add = bp.NewHealth,
Mult = 1.0,
},
Regen = {
Add = bp.NewRegenRate,
Mult = 1.0,
},
},
}
end
if Buff.HasBuff(self, 'SeraphimSCUDamageStabilization') then
Buff.RemoveBuff(self, 'SeraphimSCUDamageStabilization')
end
Buff.ApplyBuff(self, 'SeraphimSCUDamageStabilization')
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement unused
ProcessEnhancementDamageStabilizationRemove = function (self, bp)
if Buff.HasBuff(self, 'SeraphimSCUDamageStabilization') then
Buff.RemoveBuff(self, 'SeraphimSCUDamageStabilization')
end
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement
ProcessEnhancementEnhancedSensors = function(self, bp)
self:SetIntelRadius('Vision', bp.NewVisionRadius or 104)
self:SetIntelRadius('Omni', bp.NewOmniRadius or 104)
local wep = self:GetWeaponByLabel('LightChronatronCannon')
wep:ChangeMaxRadius(bp.NewMaxRadius or 35)
local wep = self:GetWeaponByLabel('OverCharge')
wep:ChangeMaxRadius(35)
local aoc = self:GetWeaponByLabel('AutoOverCharge')
aoc:ChangeMaxRadius(35)
end,

---@param self XSL0301
---@param bp UnitBlueprintEnhancement
ProcessEnhancementEnhancedSensorsRemove = function(self, bp)
local bpIntel = self.Blueprint.Intel
self:SetIntelRadius('Vision', bpIntel.VisionRadius or 26)
self:SetIntelRadius('Omni', bpIntel.OmniRadius or 16)
local wep = self:GetWeaponByLabel('LightChronatronCannon')
wep:ChangeMaxRadius(bp.NewMaxRadius or 25)
local wep = self:GetWeaponByLabel('OverCharge')
wep:ChangeMaxRadius(bp.NewMaxRadius or 25)
local aoc = self:GetWeaponByLabel('AutoOverCharge')
aoc:ChangeMaxRadius(bp.NewMaxRadius or 25)
end,

---@param self XSL0301
---@param enh Enhancement
CreateEnhancement = function(self, enh)
CommandUnit.CreateEnhancement(self, enh)
local bp = self.Blueprint.Enhancements[enh]
if not bp then return end
-- Teleporter
if enh == 'Teleporter' then
self:AddCommandCap('RULEUCC_Teleport')
elseif enh == 'TeleporterRemove' then
self:RemoveCommandCap('RULEUCC_Teleport')
-- Missile
elseif enh == 'Missile' then
self:AddCommandCap('RULEUCC_Tactical')
self:AddCommandCap('RULEUCC_SiloBuildTactical')
self:SetWeaponEnabledByLabel('Missile', true)
elseif enh == 'MissileRemove' then
self:RemoveCommandCap('RULEUCC_Tactical')
self:RemoveCommandCap('RULEUCC_SiloBuildTactical')
self:SetWeaponEnabledByLabel('Missile', false)
-- Shields
elseif enh == 'Shield' then
self:AddToggleCap('RULEUTC_ShieldToggle')
self:SetEnergyMaintenanceConsumptionOverride(bp.MaintenanceConsumptionPerSecondEnergy or 0)
self:SetMaintenanceConsumptionActive()
self:CreateShield(bp)
elseif enh == 'ShieldRemove' then
self:DestroyShield()
self:SetMaintenanceConsumptionInactive()
self:RemoveToggleCap('RULEUTC_ShieldToggle')
-- Overcharge
elseif enh == 'Overcharge' then
self:AddCommandCap('RULEUCC_Overcharge')
self:GetWeaponByLabel('OverCharge').NeedsUpgrade = false
self:GetWeaponByLabel('AutoOverCharge').NeedsUpgrade = false
elseif enh == 'OverchargeRemove' then
self:RemoveCommandCap('RULEUCC_Overcharge')
self:SetWeaponEnabledByLabel('OverCharge', false)
self:SetWeaponEnabledByLabel('AutoOverCharge', false)
self:GetWeaponByLabel('OverCharge').NeedsUpgrade = true
self:GetWeaponByLabel('AutoOverCharge').NeedsUpgrade = true
-- Engineering Throughput Upgrade
elseif enh == 'EngineeringThroughput' then
if not Buffs['SeraphimSCUBuildRate'] then
BuffBlueprint {
Name = 'SeraphimSCUBuildRate',
DisplayName = 'SeraphimSCUBuildRate',
BuffType = 'SCUBUILDRATE',
Stacks = 'REPLACE',
Duration = -1,
Affects = {
BuildRate = {
Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate,
Mult = 1,
},
},
}
end
Buff.ApplyBuff(self, 'SeraphimSCUBuildRate')
elseif enh == 'EngineeringThroughputRemove' then
if Buff.HasBuff(self, 'SeraphimSCUBuildRate') then
Buff.RemoveBuff(self, 'SeraphimSCUBuildRate')
end
-- Damage Stabilization
elseif enh == 'DamageStabilization' then
if not Buffs['SeraphimSCUDamageStabilization'] then
BuffBlueprint {
Name = 'SeraphimSCUDamageStabilization',
DisplayName = 'SeraphimSCUDamageStabilization',
BuffType = 'SCUUPGRADEDMG',
Stacks = 'ALWAYS',
Duration = -1,
Affects = {
MaxHealth = {
Add = bp.NewHealth,
Mult = 1.0,
},
Regen = {
Add = bp.NewRegenRate,
Mult = 1.0,
},
},
}
end
if Buff.HasBuff(self, 'SeraphimSCUDamageStabilization') then
Buff.RemoveBuff(self, 'SeraphimSCUDamageStabilization')
end
Buff.ApplyBuff(self, 'SeraphimSCUDamageStabilization')
elseif enh == 'DamageStabilizationRemove' then
if Buff.HasBuff(self, 'SeraphimSCUDamageStabilization') then
Buff.RemoveBuff(self, 'SeraphimSCUDamageStabilization')
end
-- Enhanced Sensor Systems
elseif enh == 'EnhancedSensors' then
self:SetIntelRadius('Vision', bp.NewVisionRadius or 104)
self:SetIntelRadius('Omni', bp.NewOmniRadius or 104)
local wep = self:GetWeaponByLabel('LightChronatronCannon')
wep:ChangeMaxRadius(bp.NewMaxRadius or 35)
local wep = self:GetWeaponByLabel('OverCharge')
wep:ChangeMaxRadius(35)
local aoc = self:GetWeaponByLabel('AutoOverCharge')
aoc:ChangeMaxRadius(35)
elseif enh == 'EnhancedSensorsRemove' then
local bpIntel = self.Blueprint.Intel
self:SetIntelRadius('Vision', bpIntel.VisionRadius or 26)
self:SetIntelRadius('Omni', bpIntel.OmniRadius or 16)
local wep = self:GetWeaponByLabel('LightChronatronCannon')
wep:ChangeMaxRadius(bp.NewMaxRadius or 25)
local wep = self:GetWeaponByLabel('OverCharge')
wep:ChangeMaxRadius(bp.NewMaxRadius or 25)
local aoc = self:GetWeaponByLabel('AutoOverCharge')
aoc:ChangeMaxRadius(bp.NewMaxRadius or 25)

local ref = 'ProcessEnhancement' .. enh
local handler = self[ref]

if handler then
handler(self, bp)
else
WARN("Missing enhancement: ", enh, " for unit: ", self:GetUnitId(), " note that the function name should be called: ", ref)
end
end,
}
Expand Down

1 comment on commit d9e49e7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (23)
benbalter
blog
changelog
config
Gemfile
github
gitignore
https
jekyllrb
localhost
metadata
plugin
README
scm
seo
ubuntu
url
USERNAME
wiki
wikipedia
workflow
yaml
yml
Available 📚 dictionaries could cover words not in the 📘 dictionary
Dictionary Entries Covers Uniquely
cspell:software-terms/dict/softwareTerms.txt 1288 13 3
cspell:k8s/dict/k8s.txt 153 8 1
cspell:npm/dict/npm.txt 302 7 1
cspell:node/dict/node.txt 891 5
cspell:php/dict/php.txt 1689 5

Consider adding them (in .github/workflows/docs-spelling-check.yaml) in jobs:/verify::

      with:
        extra_dictionaries: |
          cspell:software-terms/dict/softwareTerms.txt
          cspell:k8s/dict/k8s.txt
          cspell:npm/dict/npm.txt
          cspell:node/dict/node.txt
          cspell:php/dict/php.txt

To stop checking additional dictionaries, add (in .github/workflows/docs-spelling-check.yaml):

check_extra_dictionaries: ''

Please sign in to comment.