From 503d7ad53084bc5e356392702e239e36245ccc94 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 3 Nov 2024 11:30:46 +0000 Subject: [PATCH 1/7] Update URL0301_script.lua --- units/URL0301/URL0301_script.lua | 302 ++++++++++++++++++------------- 1 file changed, 172 insertions(+), 130 deletions(-) diff --git a/units/URL0301/URL0301_script.lua b/units/URL0301/URL0301_script.lua index 50723218c0..4a0212ab11 100644 --- a/units/URL0301/URL0301_script.lua +++ b/units/URL0301/URL0301_script.lua @@ -71,141 +71,183 @@ URL0301 = ClassUnit(CCommandUnit) { self.RightArmUpgrade = 'Disintegrator' end, + + -- =====================================================================================================================4 + -- ENHANCEMENTS + + ProcessEnhancementCloakingGenerator = function (self, bp) + self:RemoveToggleCap('RULEUTC_StealthToggle') + self:AddToggleCap('RULEUTC_CloakToggle') + self.StealthEnh = false + self.CloakEnh = true + self:EnableUnitIntel('Enhancement', 'Cloak') + if not Buffs['CybranSCUCloakBonus'] then + BuffBlueprint { + Name = 'CybranSCUCloakBonus', + DisplayName = 'CybranSCUCloakBonus', + BuffType = 'SCUCLOAKBONUS', + Stacks = 'ALWAYS', + Duration = -1, + Affects = { + MaxHealth = { + Add = bp.NewHealth, + Mult = 1.0, + }, + }, + } + end + if Buff.HasBuff(self, 'CybranSCUCloakBonus') then + Buff.RemoveBuff(self, 'CybranSCUCloakBonus') + end + Buff.ApplyBuff(self, 'CybranSCUCloakBonus') + end, + + ProcessEnhancementCloakingGeneratorRemove = function (self, bp) + -- remove prerequisites + self:RemoveToggleCap('RULEUTC_StealthToggle') + self:DisableUnitIntel('Enhancement', 'RadarStealth') + self:DisableUnitIntel('Enhancement', 'SonarStealth') + + -- remove cloak + self:DisableUnitIntel('Enhancement', 'Cloak') + self.CloakEnh = false + self:RemoveToggleCap('RULEUTC_CloakToggle') + if Buff.HasBuff(self, 'CybranSCUCloakBonus') then + Buff.RemoveBuff(self, 'CybranSCUCloakBonus') + end + end, + + ProcessEnhancementStealthGenerator = function (self, bp) + self:AddToggleCap('RULEUTC_StealthToggle') + if self.IntelEffectsBag then + EffectUtil.CleanupEffectBag(self, 'IntelEffectsBag') + self.IntelEffectsBag = nil + end + self.StealthEnh = true + self:EnableUnitIntel('Enhancement', 'RadarStealth') + self:EnableUnitIntel('Enhancement', 'SonarStealth') + end, + + ProcessEnhancementStealthGeneratorRemove = function (self, bp) + self:RemoveToggleCap('RULEUTC_StealthToggle') + self:DisableUnitIntel('Enhancement', 'RadarStealth') + self:DisableUnitIntel('Enhancement', 'SonarStealth') + self.StealthEnh = false + end, + + ProcessEnhancementNaniteMissileSystem = function(self, bp) + self:ShowBone('AA_Gun', true) + self:SetWeaponEnabledByLabel('NMissile', true) + end, + + ProcessEnhancementNaniteMissileSystemRemove = function(self, bp) + self:HideBone('AA_Gun', true) + self:SetWeaponEnabledByLabel('NMissile', false) + end, + + ProcessEnhancementSelfRepairSystem = function(self, bp) + local bpRegenRate = self.Blueprint.Enhancements.SelfRepairSystem.NewRegenRate or 0 + if not Buffs['CybranSCURegenerateBonus'] then + BuffBlueprint { + Name = 'CybranSCURegenerateBonus', + DisplayName = 'CybranSCURegenerateBonus', + BuffType = 'SCUREGENERATEBONUS', + Stacks = 'ALWAYS', + Duration = -1, + Affects = { + Regen = { + Add = bpRegenRate, + Mult = 1.0, + }, + }, + } + end + if Buff.HasBuff(self, 'CybranSCURegenerateBonus') then + Buff.RemoveBuff(self, 'CybranSCURegenerateBonus') + end + Buff.ApplyBuff(self, 'CybranSCURegenerateBonus') + end, + + ProcessEnhancementSelfRepairSystemRemove = function(self, bp) + if Buff.HasBuff(self, 'CybranSCURegenerateBonus') then + Buff.RemoveBuff(self, 'CybranSCURegenerateBonus') + end + end, + + ProcessEnhancementResourceAllocation = function(self, bp) + local bpEcon = self.Blueprint.Economy + self:SetProductionPerSecondEnergy((bp.ProductionPerSecondEnergy + bpEcon.ProductionPerSecondEnergy) or 0) + self:SetProductionPerSecondMass((bp.ProductionPerSecondMass + bpEcon.ProductionPerSecondMass) or 0) + end, + + ProcessEnhancementResourceAllocationRemove = function(self, bp) + local bpEcon = self.Blueprint.Economy + self:SetProductionPerSecondEnergy(bpEcon.ProductionPerSecondEnergy or 0) + self:SetProductionPerSecondMass(bpEcon.ProductionPerSecondMass or 0) + end, + + ProcessEnhancementSwitchback = function(self, bp) + self.BuildBotTotal = 4 + if not Buffs['CybranSCUBuildRate'] then + BuffBlueprint { + Name = 'CybranSCUBuildRate', + DisplayName = 'CybranSCUBuildRate', + BuffType = 'SCUBUILDRATE', + Stacks = 'REPLACE', + Duration = -1, + Affects = { + BuildRate = { + Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, + Mult = 1, + }, + }, + } + end + Buff.ApplyBuff(self, 'CybranSCUBuildRate') + end, + + ProcessEnhancementSwitchbackRemove = function(self, bp) + self.BuildBotTotal = 3 + if Buff.HasBuff(self, 'CybranSCUBuildRate') then + Buff.RemoveBuff(self, 'CybranSCUBuildRate') + end + end, + + ProcessEnhancementFocusConvertor = function(self, bp) + local wep = self:GetWeaponByLabel('RightDisintegrator') + wep:AddDamageMod(bp.NewDamageMod or 0) + wep:ChangeMaxRadius(bp.NewMaxRadius or 35) + end, + + ProcessEnhancementFocusConvertorRemove = function(self, bp) + local wep = self:GetWeaponByLabel('RightDisintegrator') + wep:AddDamageMod(-self.Blueprint.Enhancements['FocusConvertor'].NewDamageMod) + wep:ChangeMaxRadius(self.Blueprint.Weapon[1].MaxRadius or 25) + end, + + ProcessEnhancementEMPCharge = function(self, bp) + local wep = self:GetWeaponByLabel('RightDisintegrator') + wep:ReEnableBuff('STUN') + end, + + ProcessEnhancementEMPChargeRemove = function(self, bp) + local wep = self:GetWeaponByLabel('RightDisintegrator') + wep:DisableBuff('STUN') + end, + -- Enhancements CreateEnhancement = function(self, enh) CCommandUnit.CreateEnhancement(self, enh) local bp = self.Blueprint.Enhancements[enh] if not bp then return end - if enh == 'CloakingGenerator' then - self:RemoveToggleCap('RULEUTC_StealthToggle') - self:AddToggleCap('RULEUTC_CloakToggle') - self.StealthEnh = false - self.CloakEnh = true - self:EnableUnitIntel('Enhancement', 'Cloak') - if not Buffs['CybranSCUCloakBonus'] then - BuffBlueprint { - Name = 'CybranSCUCloakBonus', - DisplayName = 'CybranSCUCloakBonus', - BuffType = 'SCUCLOAKBONUS', - Stacks = 'ALWAYS', - Duration = -1, - Affects = { - MaxHealth = { - Add = bp.NewHealth, - Mult = 1.0, - }, - }, - } - end - if Buff.HasBuff(self, 'CybranSCUCloakBonus') then - Buff.RemoveBuff(self, 'CybranSCUCloakBonus') - end - Buff.ApplyBuff(self, 'CybranSCUCloakBonus') - elseif enh == 'CloakingGeneratorRemove' then - -- remove prerequisites - self:RemoveToggleCap('RULEUTC_StealthToggle') - self:DisableUnitIntel('Enhancement', 'RadarStealth') - self:DisableUnitIntel('Enhancement', 'SonarStealth') - - -- remove cloak - self:DisableUnitIntel('Enhancement', 'Cloak') - self.CloakEnh = false - self:RemoveToggleCap('RULEUTC_CloakToggle') - if Buff.HasBuff(self, 'CybranSCUCloakBonus') then - Buff.RemoveBuff(self, 'CybranSCUCloakBonus') - end - elseif enh == 'StealthGenerator' then - self:AddToggleCap('RULEUTC_StealthToggle') - if self.IntelEffectsBag then - EffectUtil.CleanupEffectBag(self, 'IntelEffectsBag') - self.IntelEffectsBag = nil - end - self.StealthEnh = true - self:EnableUnitIntel('Enhancement', 'RadarStealth') - self:EnableUnitIntel('Enhancement', 'SonarStealth') - elseif enh == 'StealthGeneratorRemove' then - self:RemoveToggleCap('RULEUTC_StealthToggle') - self:DisableUnitIntel('Enhancement', 'RadarStealth') - self:DisableUnitIntel('Enhancement', 'SonarStealth') - self.StealthEnh = false - elseif enh == 'NaniteMissileSystem' then - self:ShowBone('AA_Gun', true) - self:SetWeaponEnabledByLabel('NMissile', true) - elseif enh == 'NaniteMissileSystemRemove' then - self:HideBone('AA_Gun', true) - self:SetWeaponEnabledByLabel('NMissile', false) - elseif enh == 'SelfRepairSystem' then - CCommandUnit.CreateEnhancement(self, enh) - local bpRegenRate = self.Blueprint.Enhancements.SelfRepairSystem.NewRegenRate or 0 - if not Buffs['CybranSCURegenerateBonus'] then - BuffBlueprint { - Name = 'CybranSCURegenerateBonus', - DisplayName = 'CybranSCURegenerateBonus', - BuffType = 'SCUREGENERATEBONUS', - Stacks = 'ALWAYS', - Duration = -1, - Affects = { - Regen = { - Add = bpRegenRate, - Mult = 1.0, - }, - }, - } - end - if Buff.HasBuff(self, 'CybranSCURegenerateBonus') then - Buff.RemoveBuff(self, 'CybranSCURegenerateBonus') - end - Buff.ApplyBuff(self, 'CybranSCURegenerateBonus') - elseif enh == 'SelfRepairSystemRemove' then - CCommandUnit.CreateEnhancement(self, enh) - if Buff.HasBuff(self, 'CybranSCURegenerateBonus') then - Buff.RemoveBuff(self, 'CybranSCURegenerateBonus') - end - elseif enh == 'ResourceAllocation' then - local bpEcon = self.Blueprint.Economy - self:SetProductionPerSecondEnergy((bp.ProductionPerSecondEnergy + bpEcon.ProductionPerSecondEnergy) or 0) - self:SetProductionPerSecondMass((bp.ProductionPerSecondMass + bpEcon.ProductionPerSecondMass) or 0) - elseif enh == 'ResourceAllocationRemove' then - local bpEcon = self.Blueprint.Economy - self:SetProductionPerSecondEnergy(bpEcon.ProductionPerSecondEnergy or 0) - self:SetProductionPerSecondMass(bpEcon.ProductionPerSecondMass or 0) - elseif enh == 'Switchback' then - self.BuildBotTotal = 4 - if not Buffs['CybranSCUBuildRate'] then - BuffBlueprint { - Name = 'CybranSCUBuildRate', - DisplayName = 'CybranSCUBuildRate', - BuffType = 'SCUBUILDRATE', - Stacks = 'REPLACE', - Duration = -1, - Affects = { - BuildRate = { - Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, - Mult = 1, - }, - }, - } - end - Buff.ApplyBuff(self, 'CybranSCUBuildRate') - elseif enh == 'SwitchbackRemove' then - self.BuildBotTotal = 3 - if Buff.HasBuff(self, 'CybranSCUBuildRate') then - Buff.RemoveBuff(self, 'CybranSCUBuildRate') - end - elseif enh == 'FocusConvertor' then - local wep = self:GetWeaponByLabel('RightDisintegrator') - wep:AddDamageMod(bp.NewDamageMod or 0) - wep:ChangeMaxRadius(bp.NewMaxRadius or 35) - elseif enh == 'FocusConvertorRemove' then - local wep = self:GetWeaponByLabel('RightDisintegrator') - wep:AddDamageMod(-self.Blueprint.Enhancements['FocusConvertor'].NewDamageMod) - wep:ChangeMaxRadius(self.Blueprint.Weapon[1].MaxRadius or 25) - elseif enh == 'EMPCharge' then - local wep = self:GetWeaponByLabel('RightDisintegrator') - wep:ReEnableBuff('STUN') - elseif enh == 'EMPChargeRemove' then - local wep = self:GetWeaponByLabel('RightDisintegrator') - wep:DisableBuff('STUN') + + 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, From 8c95dc41b82ef1eebb341dd7c7a8b1391778985c Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 11 Nov 2024 21:07:56 +0000 Subject: [PATCH 2/7] updates --- changelog/snippets/other.6498.md | 2 +- units/URL0301/URL0301_script.lua | 45 ++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/changelog/snippets/other.6498.md b/changelog/snippets/other.6498.md index 237a2857b1..5c3b44a8cf 100644 --- a/changelog/snippets/other.6498.md +++ b/changelog/snippets/other.6498.md @@ -1 +1 @@ -- (#6498, #6502) 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, #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. diff --git a/units/URL0301/URL0301_script.lua b/units/URL0301/URL0301_script.lua index 4a0212ab11..4485d313ee 100644 --- a/units/URL0301/URL0301_script.lua +++ b/units/URL0301/URL0301_script.lua @@ -41,7 +41,7 @@ URL0301 = ClassUnit(CCommandUnit) { NMissile = ClassWeapon(CAAMissileNaniteWeapon) {}, }, - -- Creation + ---@param self URL0301 OnCreate = function(self) CCommandUnit.OnCreate(self) self:SetCapturable(false) @@ -56,10 +56,14 @@ URL0301 = ClassUnit(CCommandUnit) { end end, + ---@param self URL0301 __init = function(self) CCommandUnit.__init(self, 'RightDisintegrator') end, + ---@param self URL0301 + ---@param builder Unit + ---@param layer Layer OnStopBeingBuilt = function(self, builder, layer) CCommandUnit.OnStopBeingBuilt(self, builder, layer) self:BuildManipulatorSetEnabled(false) @@ -75,6 +79,8 @@ URL0301 = ClassUnit(CCommandUnit) { -- =====================================================================================================================4 -- ENHANCEMENTS + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementCloakingGenerator = function (self, bp) self:RemoveToggleCap('RULEUTC_StealthToggle') self:AddToggleCap('RULEUTC_CloakToggle') @@ -102,6 +108,8 @@ URL0301 = ClassUnit(CCommandUnit) { Buff.ApplyBuff(self, 'CybranSCUCloakBonus') end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementCloakingGeneratorRemove = function (self, bp) -- remove prerequisites self:RemoveToggleCap('RULEUTC_StealthToggle') @@ -117,6 +125,8 @@ URL0301 = ClassUnit(CCommandUnit) { end end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementStealthGenerator = function (self, bp) self:AddToggleCap('RULEUTC_StealthToggle') if self.IntelEffectsBag then @@ -128,6 +138,8 @@ URL0301 = ClassUnit(CCommandUnit) { self:EnableUnitIntel('Enhancement', 'SonarStealth') end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementStealthGeneratorRemove = function (self, bp) self:RemoveToggleCap('RULEUTC_StealthToggle') self:DisableUnitIntel('Enhancement', 'RadarStealth') @@ -135,16 +147,22 @@ URL0301 = ClassUnit(CCommandUnit) { self.StealthEnh = false end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementNaniteMissileSystem = function(self, bp) self:ShowBone('AA_Gun', true) self:SetWeaponEnabledByLabel('NMissile', true) end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementNaniteMissileSystemRemove = function(self, bp) self:HideBone('AA_Gun', true) self:SetWeaponEnabledByLabel('NMissile', false) end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementSelfRepairSystem = function(self, bp) local bpRegenRate = self.Blueprint.Enhancements.SelfRepairSystem.NewRegenRate or 0 if not Buffs['CybranSCURegenerateBonus'] then @@ -168,24 +186,32 @@ URL0301 = ClassUnit(CCommandUnit) { Buff.ApplyBuff(self, 'CybranSCURegenerateBonus') end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementSelfRepairSystemRemove = function(self, bp) if Buff.HasBuff(self, 'CybranSCURegenerateBonus') then Buff.RemoveBuff(self, 'CybranSCURegenerateBonus') end end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementResourceAllocation = function(self, bp) local bpEcon = self.Blueprint.Economy self:SetProductionPerSecondEnergy((bp.ProductionPerSecondEnergy + bpEcon.ProductionPerSecondEnergy) or 0) self:SetProductionPerSecondMass((bp.ProductionPerSecondMass + bpEcon.ProductionPerSecondMass) or 0) end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementResourceAllocationRemove = function(self, bp) local bpEcon = self.Blueprint.Economy self:SetProductionPerSecondEnergy(bpEcon.ProductionPerSecondEnergy or 0) self:SetProductionPerSecondMass(bpEcon.ProductionPerSecondMass or 0) end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementSwitchback = function(self, bp) self.BuildBotTotal = 4 if not Buffs['CybranSCUBuildRate'] then @@ -206,6 +232,8 @@ URL0301 = ClassUnit(CCommandUnit) { Buff.ApplyBuff(self, 'CybranSCUBuildRate') end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementSwitchbackRemove = function(self, bp) self.BuildBotTotal = 3 if Buff.HasBuff(self, 'CybranSCUBuildRate') then @@ -213,29 +241,38 @@ URL0301 = ClassUnit(CCommandUnit) { end end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementFocusConvertor = function(self, bp) local wep = self:GetWeaponByLabel('RightDisintegrator') wep:AddDamageMod(bp.NewDamageMod or 0) wep:ChangeMaxRadius(bp.NewMaxRadius or 35) end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementFocusConvertorRemove = function(self, bp) local wep = self:GetWeaponByLabel('RightDisintegrator') wep:AddDamageMod(-self.Blueprint.Enhancements['FocusConvertor'].NewDamageMod) wep:ChangeMaxRadius(self.Blueprint.Weapon[1].MaxRadius or 25) end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementEMPCharge = function(self, bp) local wep = self:GetWeaponByLabel('RightDisintegrator') wep:ReEnableBuff('STUN') end, + ---@param self URL0301 + ---@param bp UnitBlueprintEnhancements ProcessEnhancementEMPChargeRemove = function(self, bp) local wep = self:GetWeaponByLabel('RightDisintegrator') wep:DisableBuff('STUN') end, - -- Enhancements + ---@param self URL0301 + ---@param enh string CreateEnhancement = function(self, enh) CCommandUnit.CreateEnhancement(self, enh) local bp = self.Blueprint.Enhancements[enh] @@ -296,6 +333,8 @@ URL0301 = ClassUnit(CCommandUnit) { }, }, + ---@param self URL0301 + ---@param intel string OnIntelEnabled = function(self, intel) CCommandUnit.OnIntelEnabled(self, intel) if self.CloakEnh and self:IsIntelEnabled('Cloak') then @@ -317,6 +356,8 @@ URL0301 = ClassUnit(CCommandUnit) { end end, + ---@param self URL0301 + ---@param intel string OnIntelDisabled = function(self, intel) CCommandUnit.OnIntelDisabled(self, intel) if self.IntelEffectsBag then From c0bc570cfcb76eb500142a897eced978c1de886f Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:04:37 -0800 Subject: [PATCH 3/7] Fix wrong enhancement blueprint type annotation --- units/URL0301/URL0301_script.lua | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/units/URL0301/URL0301_script.lua b/units/URL0301/URL0301_script.lua index 4485d313ee..c1ca8152fe 100644 --- a/units/URL0301/URL0301_script.lua +++ b/units/URL0301/URL0301_script.lua @@ -80,7 +80,7 @@ URL0301 = ClassUnit(CCommandUnit) { -- ENHANCEMENTS ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementCloakingGenerator = function (self, bp) self:RemoveToggleCap('RULEUTC_StealthToggle') self:AddToggleCap('RULEUTC_CloakToggle') @@ -109,7 +109,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementCloakingGeneratorRemove = function (self, bp) -- remove prerequisites self:RemoveToggleCap('RULEUTC_StealthToggle') @@ -126,7 +126,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementStealthGenerator = function (self, bp) self:AddToggleCap('RULEUTC_StealthToggle') if self.IntelEffectsBag then @@ -139,7 +139,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementStealthGeneratorRemove = function (self, bp) self:RemoveToggleCap('RULEUTC_StealthToggle') self:DisableUnitIntel('Enhancement', 'RadarStealth') @@ -148,21 +148,21 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementNaniteMissileSystem = function(self, bp) self:ShowBone('AA_Gun', true) self:SetWeaponEnabledByLabel('NMissile', true) end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementNaniteMissileSystemRemove = function(self, bp) self:HideBone('AA_Gun', true) self:SetWeaponEnabledByLabel('NMissile', false) end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementSelfRepairSystem = function(self, bp) local bpRegenRate = self.Blueprint.Enhancements.SelfRepairSystem.NewRegenRate or 0 if not Buffs['CybranSCURegenerateBonus'] then @@ -187,7 +187,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementSelfRepairSystemRemove = function(self, bp) if Buff.HasBuff(self, 'CybranSCURegenerateBonus') then Buff.RemoveBuff(self, 'CybranSCURegenerateBonus') @@ -195,7 +195,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementResourceAllocation = function(self, bp) local bpEcon = self.Blueprint.Economy self:SetProductionPerSecondEnergy((bp.ProductionPerSecondEnergy + bpEcon.ProductionPerSecondEnergy) or 0) @@ -203,7 +203,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementResourceAllocationRemove = function(self, bp) local bpEcon = self.Blueprint.Economy self:SetProductionPerSecondEnergy(bpEcon.ProductionPerSecondEnergy or 0) @@ -211,7 +211,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementSwitchback = function(self, bp) self.BuildBotTotal = 4 if not Buffs['CybranSCUBuildRate'] then @@ -233,7 +233,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementSwitchbackRemove = function(self, bp) self.BuildBotTotal = 3 if Buff.HasBuff(self, 'CybranSCUBuildRate') then @@ -242,7 +242,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementFocusConvertor = function(self, bp) local wep = self:GetWeaponByLabel('RightDisintegrator') wep:AddDamageMod(bp.NewDamageMod or 0) @@ -250,7 +250,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementFocusConvertorRemove = function(self, bp) local wep = self:GetWeaponByLabel('RightDisintegrator') wep:AddDamageMod(-self.Blueprint.Enhancements['FocusConvertor'].NewDamageMod) @@ -258,14 +258,14 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementEMPCharge = function(self, bp) local wep = self:GetWeaponByLabel('RightDisintegrator') wep:ReEnableBuff('STUN') end, ---@param self URL0301 - ---@param bp UnitBlueprintEnhancements + ---@param bp UnitBlueprintEnhancement ProcessEnhancementEMPChargeRemove = function(self, bp) local wep = self:GetWeaponByLabel('RightDisintegrator') wep:DisableBuff('STUN') From 6d62b0d18fafb555185183d44398997025d977b3 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:05:28 -0800 Subject: [PATCH 4/7] Use `IntelType` type annotation --- units/URL0301/URL0301_script.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/units/URL0301/URL0301_script.lua b/units/URL0301/URL0301_script.lua index c1ca8152fe..a9b1a130f7 100644 --- a/units/URL0301/URL0301_script.lua +++ b/units/URL0301/URL0301_script.lua @@ -334,7 +334,7 @@ URL0301 = ClassUnit(CCommandUnit) { }, ---@param self URL0301 - ---@param intel string + ---@param intel IntelType OnIntelEnabled = function(self, intel) CCommandUnit.OnIntelEnabled(self, intel) if self.CloakEnh and self:IsIntelEnabled('Cloak') then @@ -357,7 +357,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param intel string + ---@param intel IntelType OnIntelDisabled = function(self, intel) CCommandUnit.OnIntelDisabled(self, intel) if self.IntelEffectsBag then From 896b8876ff60196eaeabfac34ceaa831aa830995 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:06:03 -0800 Subject: [PATCH 5/7] Use `Enhancement` type --- units/URL0301/URL0301_script.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/units/URL0301/URL0301_script.lua b/units/URL0301/URL0301_script.lua index a9b1a130f7..bace9ca500 100644 --- a/units/URL0301/URL0301_script.lua +++ b/units/URL0301/URL0301_script.lua @@ -272,7 +272,7 @@ URL0301 = ClassUnit(CCommandUnit) { end, ---@param self URL0301 - ---@param enh string + ---@param enh Enhancement CreateEnhancement = function(self, enh) CCommandUnit.CreateEnhancement(self, enh) local bp = self.Blueprint.Enhancements[enh] From d9cd9f3c422be61aacf0758e50adad691ebefc6c Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:08:04 -0800 Subject: [PATCH 6/7] Annotate stealth/cloak intel effect booleans --- units/URL0301/URL0301_script.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/units/URL0301/URL0301_script.lua b/units/URL0301/URL0301_script.lua index bace9ca500..1b4df58091 100644 --- a/units/URL0301/URL0301_script.lua +++ b/units/URL0301/URL0301_script.lua @@ -26,6 +26,8 @@ local CDFLaserDisintegratorWeapon = CWeapons.CDFLaserDisintegratorWeapon02 local SCUDeathWeapon = import("/lua/sim/defaultweapons.lua").SCUDeathWeapon ---@class URL0301 : CCommandUnit +---@field StealthEnh? boolean +---@field CloakEnh? boolean URL0301 = ClassUnit(CCommandUnit) { LeftFoot = 'Left_Foot02', RightFoot = 'Right_Foot02', From 9f21fe232b9987d880eaedead4d10635ce412147 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:10:54 -0800 Subject: [PATCH 7/7] Refactor the cloak/stealth bool names to `HasXEnh` --- units/URL0301/URL0301_script.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/units/URL0301/URL0301_script.lua b/units/URL0301/URL0301_script.lua index 1b4df58091..53fcd34a5b 100644 --- a/units/URL0301/URL0301_script.lua +++ b/units/URL0301/URL0301_script.lua @@ -26,8 +26,8 @@ local CDFLaserDisintegratorWeapon = CWeapons.CDFLaserDisintegratorWeapon02 local SCUDeathWeapon = import("/lua/sim/defaultweapons.lua").SCUDeathWeapon ---@class URL0301 : CCommandUnit ----@field StealthEnh? boolean ----@field CloakEnh? boolean +---@field HasStealthEnh? boolean +---@field HasCloakEnh? boolean URL0301 = ClassUnit(CCommandUnit) { LeftFoot = 'Left_Foot02', RightFoot = 'Right_Foot02', @@ -86,8 +86,8 @@ URL0301 = ClassUnit(CCommandUnit) { ProcessEnhancementCloakingGenerator = function (self, bp) self:RemoveToggleCap('RULEUTC_StealthToggle') self:AddToggleCap('RULEUTC_CloakToggle') - self.StealthEnh = false - self.CloakEnh = true + self.HasStealthEnh = false + self.HasCloakEnh = true self:EnableUnitIntel('Enhancement', 'Cloak') if not Buffs['CybranSCUCloakBonus'] then BuffBlueprint { @@ -120,7 +120,7 @@ URL0301 = ClassUnit(CCommandUnit) { -- remove cloak self:DisableUnitIntel('Enhancement', 'Cloak') - self.CloakEnh = false + self.HasCloakEnh = false self:RemoveToggleCap('RULEUTC_CloakToggle') if Buff.HasBuff(self, 'CybranSCUCloakBonus') then Buff.RemoveBuff(self, 'CybranSCUCloakBonus') @@ -135,7 +135,7 @@ URL0301 = ClassUnit(CCommandUnit) { EffectUtil.CleanupEffectBag(self, 'IntelEffectsBag') self.IntelEffectsBag = nil end - self.StealthEnh = true + self.HasStealthEnh = true self:EnableUnitIntel('Enhancement', 'RadarStealth') self:EnableUnitIntel('Enhancement', 'SonarStealth') end, @@ -146,7 +146,7 @@ URL0301 = ClassUnit(CCommandUnit) { self:RemoveToggleCap('RULEUTC_StealthToggle') self:DisableUnitIntel('Enhancement', 'RadarStealth') self:DisableUnitIntel('Enhancement', 'SonarStealth') - self.StealthEnh = false + self.HasStealthEnh = false end, ---@param self URL0301 @@ -339,7 +339,7 @@ URL0301 = ClassUnit(CCommandUnit) { ---@param intel IntelType OnIntelEnabled = function(self, intel) CCommandUnit.OnIntelEnabled(self, intel) - if self.CloakEnh and self:IsIntelEnabled('Cloak') then + if self.HasCloakEnh and self:IsIntelEnabled('Cloak') then self:SetEnergyMaintenanceConsumptionOverride(self.Blueprint.Enhancements['CloakingGenerator'].MaintenanceConsumptionPerSecondEnergy or 0) self:SetMaintenanceConsumptionActive() @@ -347,7 +347,7 @@ URL0301 = ClassUnit(CCommandUnit) { self.IntelEffectsBag = {} self:CreateTerrainTypeEffects(self.IntelEffects.Cloak, 'FXIdle', self.Layer, nil, self.IntelEffectsBag) end - elseif self.StealthEnh and self:IsIntelEnabled('RadarStealth') and self:IsIntelEnabled('SonarStealth') then + elseif self.HasStealthEnh and self:IsIntelEnabled('RadarStealth') and self:IsIntelEnabled('SonarStealth') then self:SetEnergyMaintenanceConsumptionOverride(self.Blueprint.Enhancements['StealthGenerator'].MaintenanceConsumptionPerSecondEnergy or 0) self:SetMaintenanceConsumptionActive() @@ -366,9 +366,9 @@ URL0301 = ClassUnit(CCommandUnit) { EffectUtil.CleanupEffectBag(self, 'IntelEffectsBag') self.IntelEffectsBag = nil end - if self.CloakEnh and not self:IsIntelEnabled('Cloak') then + if self.HasCloakEnh and not self:IsIntelEnabled('Cloak') then self:SetMaintenanceConsumptionInactive() - elseif self.StealthEnh and not self:IsIntelEnabled('RadarStealth') and not self:IsIntelEnabled('SonarStealth') then + elseif self.HasStealthEnh and not self:IsIntelEnabled('RadarStealth') and not self:IsIntelEnabled('SonarStealth') then self:SetMaintenanceConsumptionInactive() end end,