Skip to content
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

Update Seraphim SACU Enhancement Script #6518

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) 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, #6356) 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 Blueprint
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
Loading