Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/ACF-Team/ACF-3 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
thecraftianman committed Nov 14, 2024
2 parents 27bf58f + 9e33294 commit bb60d09
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
52 changes: 51 additions & 1 deletion lua/acf/damage/damage_sv.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local ACF = ACF
local Damage = ACF.Damage
local Objects = Damage.Objects
local Effects = ACF.Utilities.Effects
local Queue = {}

util.AddNetworkString("ACF_Damage")
Expand Down Expand Up @@ -85,6 +86,50 @@ function Damage.getBulletDamage(Bullet, Trace)

return DmgResult, DmgInfo
end

--- Used to kill and fling the player because it's funny.
--- @param Entity entity The entity to attempt to kill
--- @param Damage number The amount of damage to be dealt to the entity
--- @param HitPos vector The world position to display blood effects at
--- @param Attacker entity The entity that dealt the damage
--- @param Inflictor entity The entity that was used to deal the damage
--- @param Direction vector The normalized direction that the damage is pointing towards
--- @param Explosive boolean Whether this damage should be explosive or not
--- @return boolean # Returns true if the damage has killed the player, false if it has not
function Damage.DoSquishyFlingKill(Entity, Damage, HitPos, Attacker, Inflictor, Direction, Explosive)
if not Entity:IsPlayer() and not Entity:IsNPC() and not Entity:IsNextBot() then return false end

local Health = Entity:Health()

if Damage > Health then
local SourceDamage = DamageInfo()
local ForceMult = 25000 -- Arbitrary force multiplier; just change this to whatever feels the best

SourceDamage:SetAttacker(Attacker)
SourceDamage:SetInflictor(Inflictor)
SourceDamage:SetDamage(Damage)
SourceDamage:SetDamageForce(Direction * ForceMult)
if Explosive then
SourceDamage:SetDamageType(DMG_BLAST)
end
Entity:TakeDamageInfo(SourceDamage)

local EffectTable = {
Origin = HitPos,
Normal = Direction,
Flags = 3,
Scale = 14,
}

Effects.CreateEffect("bloodspray", EffectTable, true, true)
Effects.CreateEffect("BloodImpact", EffectTable, true, true)

return true
end

return false
end

--- Used to inflict damage to any entity that was tagged as "Squishy" by ACF.Check.
-- This function will be internally used by ACF.Damage.dealDamage, you're not expected to use it.
-- @param Entity The entity that will get damaged.
Expand Down Expand Up @@ -123,7 +168,12 @@ function Damage.doSquishyDamage(Entity, DmgResult, DmgInfo)
end
end

Entity:TakeDamage(Damage, DmgInfo:GetAttacker(), DmgInfo:GetInflictor())
local Attacker, Inflictor = DmgInfo:GetAttacker(), DmgInfo:GetInflictor()
local Direction = (DmgInfo.HitPos - DmgInfo.Origin):GetNormalized()

if not ACF.Damage.DoSquishyFlingKill(Entity, Damage, DmgInfo.HitPos, Attacker, Inflictor, Direction, DmgInfo.Type == DMG_BLAST) then
Entity:TakeDamage(Damage, Attacker, Inflictor)
end

HitRes.Kill = false

Expand Down
14 changes: 10 additions & 4 deletions lua/acf/damage/overpressure_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local ACF = ACF
ACF.Squishies = ACF.Squishies or {}

local Squishies = ACF.Squishies

local HitPosOffset = Vector(0, 0, 30)

-- InVehicle and GetVehicle are only for players, we have NPCs too!
local function GetVehicle(Entity)
Expand Down Expand Up @@ -45,8 +45,9 @@ function ACF.Overpressure(Origin, Energy, Inflictor, Source, Forward, Angle)

for V in pairs(Squishies) do
local Position = V:EyePos()
local Direction = (Position - Origin):GetNormalized()

if math.acos(Forward:Dot((Position - Origin):GetNormalized())) < Angle then
if math.acos(Forward:Dot(Direction)) < Angle then
local D = Position:Distance(Origin)

if D / 39.37 <= Radius then
Expand All @@ -56,7 +57,9 @@ function ACF.Overpressure(Origin, Energy, Inflictor, Source, Forward, Angle)
if CanSee(V, Data) then
local Damage = Energy * 175000 * (1 / D^3)

V:TakeDamage(Damage, Inflictor, Source)
if not ACF.Damage.DoSquishyFlingKill(V, Damage, V:GetPos() + HitPosOffset, Inflictor, Source, Direction, true) then
V:TakeDamage(Damage, Inflictor, Source)
end
end
end
end
Expand All @@ -74,8 +77,11 @@ function ACF.Overpressure(Origin, Energy, Inflictor, Source, Forward, Angle)

if CanSee(V, Data) then
local Damage = Energy * 150000 * (1 / D^3)
local Direction = (Source:GetPos() - V:GetPos()):GetNormalized()

V:TakeDamage(Damage, Inflictor, Source)
if not ACF.Damage.DoSquishyFlingKill(V, Damage, V:GetPos() + HitPosOffset, Inflictor, Source, Direction, true) then
V:TakeDamage(Damage, Inflictor, Source)
end
end
end
end
Expand Down

0 comments on commit bb60d09

Please sign in to comment.