Skip to content

Commit

Permalink
Merge pull request #451 from ACF-Team/api-updates
Browse files Browse the repository at this point in the history
Review for API changes
  • Loading branch information
marchc1 authored Jan 18, 2025
2 parents d26a777 + c38d7c3 commit f62410a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 28 deletions.
11 changes: 9 additions & 2 deletions lua/acf/ballistics/ballistics_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ local FlightTr = { start = true, endpos = true, filter = true, mask = true }
local GlobalFilter = ACF.GlobalFilter
local AmmoTypes = ACF.Classes.AmmoTypes


-- This will create, or update, the tracer effect on the clientside
function Ballistics.BulletClient(Bullet, Type, Hit, HitPos)
if Bullet.NoEffect then return end -- No clientside effect will be created for this bullet
Expand Down Expand Up @@ -205,7 +204,15 @@ function Ballistics.TestFilter(Entity, Bullet)

if not hook.Run("ACF_OnFilterBullet", Entity, Bullet) then return false end

if Entity._IsSpherical then return false end -- TODO: Remove when damage changes make props unable to be destroyed, as physical props can have friction reduced (good for wheels)
local EntTbl = Entity:GetTable()

if EntTbl._IsSpherical then return false end -- TODO: Remove when damage changes make props unable to be destroyed, as physical props can have friction reduced (good for wheels)
if EntTbl.ACF_InvisibleToBallistics then return false end
if EntTbl.ACF_KillableButIndestructible then
local EntACF = EntTbl.ACF
if EntACF and EntACF.Health <= 0 then return false end
end
if EntTbl.ACF_TestFilter then return EntTbl.ACF_TestFilter(Entity, Bullet) end

return true
end
Expand Down
55 changes: 53 additions & 2 deletions lua/acf/core/classes/entities/registration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,57 @@ Entities.AddDataArgumentType("LinkedEntity",
end
)

-- MARCH: Untested!
-- And if this code stays here, fix the PascalCase issue
--[[
Entities.AddDataArgumentType("LinkedEntities",
function(Value, Specs)
if not Value then return {} end
if isentity(Value) then Value = {Value} end
if not istable(Value) then return {} end
local Ret = {}
local max = Specs.Max
for k, v in ipairs(Value) do
if max and k > max then break end
if not isentity(v) or not IsValid(v) then
v = NULL
else
if Specs.Classes then
local class = v:GetClass()
if not Specs.Classes[class] then
v = NULL
end
end
end
Ret[k] = v
end
return Value
end,
function(_, value)
local ret = {}
for k, v in ipairs(value) do
ret[k] = v:EntIndex()
end
return ret
end,
function(self, value, createdEnts)
local ret = {}
for k, v in ipairs(value) do
local realEnt = createdEnts[v]
ret[k] = realEnt
self:Link(realEnt)
end
return ret
end
)]]

--- Adds extra arguments to a class which has been created via Entities.AutoRegister() (or Entities.Register() with no arguments)
--- @param Class string A class previously registered as an entity class
--- @param DataKeys table A key-value table, where key is the name of the data and value defines the type and restrictions of the data.
Expand Down Expand Up @@ -269,7 +320,7 @@ function Entities.AutoRegister(ENT)
local validated = typedef.Validator(self[k], v)
local ret = typedef.PreCopy(self, validated)
if ret then
duplicator.StoreEntityModifier(self, "ACF_" .. k, {ret})
duplicator.StoreEntityModifier(self, k, {ret})
end
end

Expand All @@ -284,7 +335,7 @@ function Entities.AutoRegister(ENT)

for k, v in pairs(DataVars) do
local typedef = DataArgumentTypes[v.Type]
local entmodData = EntMods["ACF_" .. k][1]
local entmodData = EntMods[k][1]
local ret = typedef.PostPaste(Ent, entmodData, CreatedEntities)
ret = typedef.Validator(ret, v)
if ret then Ent[k] = ret end
Expand Down
42 changes: 27 additions & 15 deletions lua/acf/core/utilities/traces_sh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,59 @@ do -- ACF.trace
-- Does NOT modify the original filter
local util = util

local function doRecursiveTrace(traceData)
local Output = traceData.output
local function DoRecursiveTrace(TraceData)
local Output = TraceData.output

util.TraceLine(traceData)
util.TraceLine(TraceData)

if Output.HitNonWorld and ACF.CheckClips(Output.Entity, Output.HitPos) then
local Filter = traceData.filter
local Filter = TraceData.filter

Filter[#Filter + 1] = Output.Entity

doRecursiveTrace(traceData)
DoRecursiveTrace(TraceData)
end
end

function ACF.trace(traceData)
local Original = traceData.output
local function TestTraceable(Ent)
local EntTbl = Ent:GetTable()

if EntTbl.ACF_InvisibleToTrace then return true end

if EntTbl.ACF_KillableButIndestructible and EntTbl.ACF and EntTbl.ACF.Health <= 0 then
return true
end

return false
end

function ACF.trace(TraceData)
local Original = TraceData.output
local Output = {}

traceData.output = Output
TraceData.output = Output

util.TraceLine(traceData)
util.TraceLine(TraceData)

-- Check for clips or to filter this entity
if Output.HitNonWorld and (ACF.GlobalFilter[Output.Entity:GetClass()] or ACF.CheckClips(Output.Entity, Output.HitPos)) then
local OldFilter = traceData.filter
if Output.HitNonWorld and (ACF.GlobalFilter[Output.Entity:GetClass()] or TestTraceable(Output.Entity) or ACF.CheckClips(Output.Entity, Output.HitPos)) then
local OldFilter = TraceData.filter
local Filter = { Output.Entity }

for _, V in ipairs(OldFilter) do Filter[#Filter + 1] = V end

traceData.filter = Filter
TraceData.filter = Filter

doRecursiveTrace(traceData)
DoRecursiveTrace(TraceData)

traceData.filter = OldFilter
TraceData.filter = OldFilter
end

if Original then
for K in pairs(Original) do Original[K] = nil end
for K, V in pairs(Output) do Original[K] = V end

traceData.output = Original
TraceData.output = Original
end

return Output
Expand Down
11 changes: 10 additions & 1 deletion lua/acf/damage/damage_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ function Damage.doPropDamage(Entity, DmgResult)
local HitRes = DmgResult:Compute()

if HitRes.Damage >= Health then
HitRes.Kill = true
if Entity.ACF_KillableButIndestructible then
HitRes.Kill = false
Entity.ACF.Health = 0
else
HitRes.Kill = true
end
else
local NewHealth = Health - HitRes.Damage
local MaxHealth = EntACF.MaxHealth
Expand All @@ -223,6 +228,10 @@ function Damage.doPropDamage(Entity, DmgResult)
Damage.Network(Entity, nil, NewHealth, MaxHealth)
end

if Entity.ACF_HealthUpdatesWireOverlay then
Entity:UpdateOverlay()
end

return HitRes
end

Expand Down
8 changes: 4 additions & 4 deletions lua/entities/acf_baseplate/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ function ENT:DrawGizmos()
local Size = self.Size

render.SetColorMaterial()
render.DrawBeam(Pos, self:LocalToWorld(Vector(Size.x / 2, 0, 0)), 2, 0, 1, ColorBlack)
render.DrawBeam(Pos, self:LocalToWorld(Vector(Size.x / 2, 0, 0)), 1, 0, 1, ColorRed)
render.DrawBeam(Pos, self:LocalToWorld(Vector(0, -Size.y / 2, 0)), 2, 0, 1, ColorBlack)
render.DrawBeam(Pos, self:LocalToWorld(Vector(0, -Size.y / 2, 0)), 1, 0, 1, ColorGreen)
render.DrawBeam(Pos, self:LocalToWorld(Vector(Size.x / 2, 0, 0)), 1.25, 0, 1, ColorBlack)
render.DrawBeam(Pos, self:LocalToWorld(Vector(Size.x / 2, 0, 0)), .5, 0, 1, ColorRed)
render.DrawBeam(Pos, self:LocalToWorld(Vector(0, -Size.y / 2, 0)), 1.25, 0, 1, ColorBlack)
render.DrawBeam(Pos, self:LocalToWorld(Vector(0, -Size.y / 2, 0)), .5, 0, 1, ColorGreen)

cam.IgnoreZ(false)
end
Expand Down
19 changes: 15 additions & 4 deletions lua/entities/acf_baseplate/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ local ACF = ACF
local Classes = ACF.Classes
local Entities = Classes.Entities

ENT.ACF_Limit = 16
ENT.ACF_UserWeighable = true
ENT.ACF_Limit = 16
ENT.ACF_UserWeighable = true
ENT.ACF_KillableButIndestructible = true
ENT.ACF_HealthUpdatesWireOverlay = true

function ENT.ACF_OnVerifyClientData(ClientData)
ClientData.Size = Vector(ClientData.Length, ClientData.Width, ClientData.Thickness)
Expand All @@ -31,9 +33,18 @@ function ENT:ACF_PostSpawn(_, _, _, ClientData)
end
end

local Text = "Baseplate Size: %.1f x %.1f x %.1f"
function ENT:CFW_OnParentedTo(_, NewEntity)
if IsValid(NewEntity) then
ACF.SendNotify(self:CPPIGetOwner(), false, "Cannot parent an ACF baseplate to another entity.")
end

return false
end

local Text = "Baseplate Size: %.1f x %.1f x %.1f\nBaseplate Health: %.1f%%"
function ENT:UpdateOverlayText()
return Text:format(self.Size[1], self.Size[2], self.Size[3])
local h, mh = self.ACF.Health, self.ACF.MaxHealth
return Text:format(self.Size[1], self.Size[2], self.Size[3], (h / mh) * 100)
end

Entities.Register()
8 changes: 8 additions & 0 deletions lua/weapons/acf_torch/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ function SWEP:PrimaryAttack()
local OldHealth = Entity.ACF.Health
local MaxHealth = Entity.ACF.MaxHealth

local Now = CurTime()
if Now - (self.LastUpdate or 0) > 0.5 then
self.LastUpdate = Now
if Entity.ACF_HealthUpdatesWireOverlay then
Entity:UpdateOverlay()
end
end

if OldHealth >= MaxHealth then return end

local OldArmor = Entity.ACF.Armour
Expand Down

0 comments on commit f62410a

Please sign in to comment.