diff --git a/lua/acf/core/globals.lua b/lua/acf/core/globals.lua index 7564def3f..7de2572a4 100644 --- a/lua/acf/core/globals.lua +++ b/lua/acf/core/globals.lua @@ -77,6 +77,7 @@ do -- ACF global vars ACF.AmmoCaseScale = 1 -- How much larger the diameter of the case is versus the projectile (necked cartridges, M829 is 1.4, .50 BMG is 1.6) ACF.AmmoMinSize = 6 -- Defines the shortest possible length of ammo crates for all their axises, in gmu ACF.AmmoMaxSize = 96 -- Defines the highest possible length of ammo crates for all their axises, in gmu + ACF.AmmoRefillColor = Color(255, 255, 0, 10) -- The color to use for the ammo refill effect ACF.PropImpetus = 1075 -- Energy in KJ produced by 1kg of propellant, based off M30A1 propellant ACF.PDensity = 0.95 -- Propellant loading density (Density of propellant + volume lost due to packing density) @@ -133,6 +134,7 @@ do -- ACF global vars ACF.FuelMinSize = 6 -- Defines the shortest possible length of fuel tanks for all their axises, in gmu ACF.FuelMaxSize = 96 -- Defines the highest possible length of fuel tanks for all their axises, in gmu ACF.FuelArmor = 5 -- How many millimeters of armor fuel tanks have + ACF.FuelRefillColor = Color(76, 201, 250, 10) -- The color to use for the fuel refill effect ACF.TankVolumeMul = 1 -- Multiplier for fuel tank capacity, 1.0 is approx real world ACF.LiIonED = 0.458 -- li-ion energy density: kw hours / liter ACF.RefillDistance = 300 -- Distance in which ammo crate starts refilling. diff --git a/lua/acf/core/utilities/effects/effects_cl.lua b/lua/acf/core/utilities/effects/effects_cl.lua new file mode 100644 index 000000000..a08704040 --- /dev/null +++ b/lua/acf/core/utilities/effects/effects_cl.lua @@ -0,0 +1,64 @@ +local ACF = ACF +local Refills = {} + +ACF.Utilities.Effects.Refills = Refills + +do -- Resupply effect (applies to ammo and fuel) + local render = render + local Distance = ACF.RefillDistance + + local function DrawSpheres(bDrawingDepth, _, isDraw3DSkybox) + if bDrawingDepth or isDraw3DSkybox then return end + render.SetColorMaterial() + + for Entity in pairs(Refills) do + local Pos = Entity:GetPos() + local RefillColor + + if Entity:GetClass() == "acf_fueltank" then + RefillColor = ACF.FuelRefillColor + else + RefillColor = ACF.AmmoRefillColor + end + + render.DrawSphere(Pos, Distance, 50, 50, RefillColor) + render.DrawSphere(Pos, -Distance, 50, 50, RefillColor) + end + end + + local function Remove(Entity) + if not IsValid(Entity) then return end + + Refills[Entity] = nil + + Entity:RemoveCallOnRemove("ACF_Refill") + + if not next(Refills) then + hook.Remove("PostDrawOpaqueRenderables", "ACF_Refill") + end + end + + local function Add(Entity) + if not IsValid(Entity) then return end + + if not next(Refills) then + hook.Add("PostDrawOpaqueRenderables", "ACF_Refill", DrawSpheres) + end + + Refills[Entity] = true + + Entity:CallOnRemove("ACF_Refill", Remove) + end + + net.Receive("ACF_RefillEffect", function() + local Entity = net.ReadEntity() + + Add(Entity) + end) + + net.Receive("ACF_StopRefillEffect", function() + local Entity = net.ReadEntity() + + Remove(Entity) + end) +end \ No newline at end of file diff --git a/lua/acf/menu/items_cl/settings.lua b/lua/acf/menu/items_cl/settings.lua index 89ff10496..11fd6c428 100644 --- a/lua/acf/menu/items_cl/settings.lua +++ b/lua/acf/menu/items_cl/settings.lua @@ -69,6 +69,26 @@ do -- Clientside settings Particles:SetConVar("acf_cl_particlemul") Base:AddHelp("Defines the clientside particle multiplier, reduce it if you're experiencing lag when ACF effects are created.") + + Base:AddLabel("Ammo Refill Color") + local AmmoRefillColor = Base:AddPanel("DColorMixer") + AmmoRefillColor:SetColor(ACF.AmmoRefillColor) + AmmoRefillColor:SetClientData("AmmoRefillColor", "ValueChanged") + AmmoRefillColor:DefineSetter(function(_, _, _, Value) + ACF.AmmoRefillColor = Value + + return Value + end) + + Base:AddLabel("Fuel Refill Color") + local FuelRefillColor = Base:AddPanel("DColorMixer") + FuelRefillColor:SetColor(ACF.FuelRefillColor) + FuelRefillColor:SetClientData("FuelRefillColor", "ValueChanged") + FuelRefillColor:DefineSetter(function(_, _, _, Value) + ACF.FuelRefillColor = Value + + return Value + end) end) ACF.AddClientSettings(201, "Legal Checks", function(Base) diff --git a/lua/acf/persisted_vars/vars_cl.lua b/lua/acf/persisted_vars/vars_cl.lua index c22beac5a..4a8d40eb9 100644 --- a/lua/acf/persisted_vars/vars_cl.lua +++ b/lua/acf/persisted_vars/vars_cl.lua @@ -2,6 +2,8 @@ -- Settings ACF.PersistClientData("Volume", 0.5) +ACF.PersistClientData("AmmoRefillColor", Color(255, 255, 0, 10)) +ACF.PersistClientData("FuelRefillColor", Color(76, 201, 250, 10)) -- Crate size ACF.PersistClientData("CrateSizeX", 24) diff --git a/lua/entities/acf_ammo/cl_init.lua b/lua/entities/acf_ammo/cl_init.lua index c272d0736..710a396a6 100644 --- a/lua/entities/acf_ammo/cl_init.lua +++ b/lua/entities/acf_ammo/cl_init.lua @@ -1,6 +1,6 @@ local ACF = ACF local MaxRounds = GetConVar("acf_maxroundsdisplay") -local Refills = {} +local Refills = ACF.Utilities.Effects.Refills local Queued = {} DEFINE_BASECLASS("acf_base_scalable") -- Required to get the local BaseClass @@ -103,61 +103,6 @@ function ENT:OnRemove() cvars.RemoveChangeCallback("acf_maxroundsdisplay", "Ammo Crate " .. self:EntIndex()) end --- TODO: Resupply effect library, should apply for both ammo and fuel -do -- Resupply effect - local render = render - local Yellow = Color(255, 255, 0, 10) - local Distance = ACF.RefillDistance - - local function DrawSpheres(bDrawingDepth, _, isDraw3DSkybox) - if bDrawingDepth or isDraw3DSkybox then return end - render.SetColorMaterial() - - for Entity in pairs(Refills) do - local Pos = Entity:GetPos() - - render.DrawSphere(Pos, Distance, 50, 50, Yellow) - render.DrawSphere(Pos, -Distance, 50, 50, Yellow) - end - end - - local function Remove(Entity) - if not IsValid(Entity) then return end - - Refills[Entity] = nil - - Entity:RemoveCallOnRemove("ACF_Refill") - - if not next(Refills) then - hook.Remove("PostDrawOpaqueRenderables", "ACF_Refill") - end - end - - local function Add(Entity) - if not IsValid(Entity) then return end - - if not next(Refills) then - hook.Add("PostDrawOpaqueRenderables", "ACF_Refill", DrawSpheres) - end - - Refills[Entity] = true - - Entity:CallOnRemove("ACF_Refill", Remove) - end - - net.Receive("ACF_RefillEffect", function() - local Entity = net.ReadEntity() - - Add(Entity) - end) - - net.Receive("ACF_StopRefillEffect", function() - local Entity = net.ReadEntity() - - Remove(Entity) - end) -end - do -- Ammo overlay local DrawBoxes = GetConVar("acf_drawboxes") diff --git a/lua/entities/acf_fueltank/init.lua b/lua/entities/acf_fueltank/init.lua index 55d4ad7fa..8a5d73766 100644 --- a/lua/entities/acf_fueltank/init.lua +++ b/lua/entities/acf_fueltank/init.lua @@ -519,53 +519,74 @@ function ENT:Consume(Amount, SelfTbl) end end -function ENT:Think() - self:NextThink(Clock.CurTime + 1) +do + local function RefillEffect(Entity) + net.Start("ACF_RefillEffect") + net.WriteEntity(Entity) + net.Broadcast() + end - local Leaking = self.Leaking + local function StopRefillEffect(Entity) + net.Start("ACF_StopRefillEffect") + net.WriteEntity(Entity) + net.Broadcast() + end - if Leaking > 0 then - self:Consume(Leaking) + function ENT:Think() + self:NextThink(Clock.CurTime + 1) - local Fuel = self.Fuel - Leaking = Clamp(Leaking - (1 / math.max(Fuel, 1)) ^ 0.5, 0, Fuel) -- Fuel tanks are self healing - self.Leaking = Leaking + local Leaking = self.Leaking - WireLib.TriggerOutput(self, "Leaking", Leaking > 0 and 1 or 0) + if Leaking > 0 then + self:Consume(Leaking) - self:NextThink(Clock.CurTime + 0.25) - end + local Fuel = self.Fuel + Leaking = Clamp(Leaking - (1 / math.max(Fuel, 1)) ^ 0.5, 0, Fuel) -- Fuel tanks are self healing + self.Leaking = Leaking - -- Refuelling - if self.SupplyFuel and self:CanConsume() then - local DeltaTime = Clock.CurTime - self.LastThink - local Position = self:GetPos() + WireLib.TriggerOutput(self, "Leaking", Leaking > 0 and 1 or 0) - for Tank in pairs(ACF.FuelTanks) do - if CanRefuel(self, Tank, Position:DistToSqr(Tank:GetPos())) then - local Exchange = math.min(DeltaTime * ACF.RefuelSpeed * ACF.FuelRate, self.Fuel, Tank.Capacity - Tank.Fuel) + self:NextThink(Clock.CurTime + 0.25) + end - if HookRun("ACF_CanRefuel", self, Tank, Exchange) == false then continue end + if self.Refilling then + StopRefillEffect(self) + self.Refilling = false + end - self:Consume(Exchange) - Tank:Consume(-Exchange) + -- Refuelling + if self.SupplyFuel and self:CanConsume() then + local DeltaTime = Clock.CurTime - self.LastThink + local Position = self:GetPos() - if self.FuelType == "Electric" then - Sounds.SendSound(self, "ambient/energy/newspark04.wav", 70, 100, 0.5) - Sounds.SendSound(Tank, "ambient/energy/newspark04.wav", 70, 100, 0.5) - else - Sounds.SendSound(self, "vehicles/jetski/jetski_no_gas_start.wav", 70, 120, 0.5) - Sounds.SendSound(Tank, "vehicles/jetski/jetski_no_gas_start.wav", 70, 120, 0.5) + for Tank in pairs(ACF.FuelTanks) do + if CanRefuel(self, Tank, Position:DistToSqr(Tank:GetPos())) then + local Exchange = math.min(DeltaTime * ACF.RefuelSpeed * ACF.FuelRate, self.Fuel, Tank.Capacity - Tank.Fuel) + + if HookRun("ACF_CanRefuel", self, Tank, Exchange) == false then continue end + + self:Consume(Exchange) + Tank:Consume(-Exchange) + + if self.FuelType == "Electric" then + Sounds.SendSound(self, "ambient/energy/newspark04.wav", 70, 100, 0.5) + Sounds.SendSound(Tank, "ambient/energy/newspark04.wav", 70, 100, 0.5) + else + Sounds.SendSound(self, "vehicles/jetski/jetski_no_gas_start.wav", 70, 120, 0.5) + Sounds.SendSound(Tank, "vehicles/jetski/jetski_no_gas_start.wav", 70, 120, 0.5) + end + + RefillEffect(self) + self.Refilling = true end end end - end - self.LastThink = Clock.CurTime + self.LastThink = Clock.CurTime - return true + return true + end end - function ENT:OnRemove() local Class = self.ClassData