Skip to content

Commit

Permalink
Remove adjacency exception for extractors and fabricators (FAForever#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas authored Nov 6, 2022
1 parent 172137f commit 398e38a
Showing 1 changed file with 10 additions and 62 deletions.
72 changes: 10 additions & 62 deletions lua/defaultunits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ StructureUnit = Class(Unit) {
FxDamage2 = {EffectTemplate.DamageStructureFireSmoke01, EffectTemplate.DamageStructureSparks01},
FxDamage3 = {EffectTemplate.DamageStructureFire01, EffectTemplate.DamageStructureSparks01},

ConsumptionActive = true,

---@param self StructureUnit
OnCreate = function(self)
Unit.OnCreate(self)
Expand Down Expand Up @@ -563,8 +565,10 @@ StructureUnit = Class(Unit) {
adjacentUnit.AdjacentUnits[self.EntityId] = self

-- apply the buffs
for k, v in AdjacencyBuffs[adjBuffs] do
Buff.ApplyBuff(adjacentUnit, v, self)
if self.ConsumptionActive then
for k, v in AdjacencyBuffs[adjBuffs] do
Buff.ApplyBuff(adjacentUnit, v, self)
end
end

-- refresh the UI
Expand Down Expand Up @@ -1178,42 +1182,14 @@ MassCollectionUnit = Class(StructureUnit) {
OnConsumptionActive = function(self)
StructureUnit.OnConsumptionActive(self)
self:ApplyAdjacencyBuffs()
self._productionActive = true
self.ConsumptionActive = true
end,

---@param self MassCollectionUnit
OnConsumptionInActive = function(self)
StructureUnit.OnConsumptionInActive(self)
self:RemoveAdjacencyBuffs()
self._productionActive = false
end,

---@param self MassCollectionUnit
---@param adjacentUnit MassCollectionUnit
---@param triggerUnit MassCollectionUnit
OnAdjacentTo = function(self, adjacentUnit, triggerUnit) -- What is triggerUnit?
if self:IsBeingBuilt() then return end
if adjacentUnit:IsBeingBuilt() then return end

-- Does the unit have any adjacency buffs to use?
local adjBuffs = self.Blueprint.Adjacency
if not adjBuffs then return end

-- Apply each buff needed to you and/or adjacent unit, only if turned on
if self._productionActive then
for k, v in AdjacencyBuffs[adjBuffs] do
Buff.ApplyBuff(adjacentUnit, v, self)
end
end

-- Keep track of adjacent units
if not self.AdjacentUnits then
self.AdjacentUnits = {}
end
table.insert(self.AdjacentUnits, adjacentUnit)

self:RequestRefreshUI()
adjacentUnit:RequestRefreshUI()
self.ConsumptionActive = false
end,

---@param self MassCollectionUnit
Expand Down Expand Up @@ -1358,7 +1334,7 @@ MassFabricationUnit = Class(StructureUnit) {
self:SetMaintenanceConsumptionActive()
self:SetProductionActive(true)
self:ApplyAdjacencyBuffs()
self._productionActive = true
self.ConsumptionActive = true
end,

---@param self MassFabricationUnit
Expand All @@ -1367,35 +1343,7 @@ MassFabricationUnit = Class(StructureUnit) {
self:SetMaintenanceConsumptionInactive()
self:SetProductionActive(false)
self:RemoveAdjacencyBuffs()
self._productionActive = false
end,

---@param self MassFabricationUnit
---@param adjacentUnit MassFabricationUnit
---@param triggerUnit MassFabricationUnit
OnAdjacentTo = function(self, adjacentUnit, triggerUnit) -- What is triggerUnit?
if self:IsBeingBuilt() then return end
if adjacentUnit:IsBeingBuilt() then return end

-- Does the unit have any adjacency buffs to use?
local adjBuffs = self.Blueprint.Adjacency
if not adjBuffs then return end

-- Apply each buff needed to you and/or adjacent unit, only if turned on
if self._productionActive then
for _, v in AdjacencyBuffs[adjBuffs] do
Buff.ApplyBuff(adjacentUnit, v, self)
end
end

-- Keep track of adjacent units
if not self.AdjacentUnits then
self.AdjacentUnits = {}
end
table.insert(self.AdjacentUnits, adjacentUnit)

self:RequestRefreshUI()
adjacentUnit:RequestRefreshUI()
self.ConsumptionActive = false
end,

---@param self MassFabricationUnit
Expand Down

0 comments on commit 398e38a

Please sign in to comment.