Skip to content

Commit

Permalink
Assorted Thorns fixes (#51)
Browse files Browse the repository at this point in the history
* There is only ever one CEffectData, values need to be applied each time

* TeslaHitboxes doesn't use radius

* Also restart effect timer

* Use custom inflictor, don't fill PostEntityTakeDamage with incorrect events

* Use a base-game sound

* Louder

* Remove prints

* Add content

* Remove old test comments
  • Loading branch information
legokidlogan authored Dec 20, 2024
1 parent 75eec44 commit 8d21670
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 35 deletions.
13 changes: 13 additions & 0 deletions lua/entities/cfc_powerup_thorns_inflictor.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
AddCSLuaFile!

DEFINE_BASECLASS "base_point"

ENT.Type = "point"
ENT.Spawnable = false


ENT.Initialize = =>
-- Do nothing

ENT.UpdateTransmitState = ->
TRANSMIT_NEVER
8 changes: 3 additions & 5 deletions lua/powerups/client/thorns.moon
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class ThornManager
@drawThorns!

getSparkSound: =>
sparkNumber = random 1, 11
"ambient/energy/newspark#{string.format "%02d", sparkNumber}.wav"
sparkNumber = random 3, 6
"ambient/energy/spark#{sparkNumber}.wav"

playSparkSound: (attacker) =>
sparkSound = @getSparkSound!
attacker\EmitSound sparkSound, 75, 100, 0.6
attacker\EmitSound sparkSound, 75, 100, 1

generateThornSegments: (thorn) =>
:ply, :attacker, :amount, :createdAt = thorn
Expand Down Expand Up @@ -101,9 +101,7 @@ class Thorn
manager = ThornManager!

net.Receive "CFC_Powerups-ThornsDamage", ->
print "Receiving thorns damage.."
damageData = net.ReadTable!
PrintTable damageData

for ply, attackers in pairs damageData do
continue unless IsValid ply
Expand Down
1 change: 1 addition & 0 deletions lua/powerups/loaders/cfc_powerups_killicons.moon
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
icolOrange = Color 255, 80, 0, 255

killicon.Add "cfc_powerup_hotshot_inflictor", "vgui/hud/cfc_powerup_hotshot", icolOrange
killicon.Add "cfc_powerup_thorns_inflictor", "vgui/hud/cfc_powerup_thorns", icolOrange
73 changes: 43 additions & 30 deletions lua/powerups/server/thorns.moon
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class ThornsPowerup extends BasePowerup
super ply

@holo = @MakeHolo!
@aoeEffect = @MakeAoeEffect!

-- We batch up damage broadcasts to lessen the network load
-- Interval is in seconds
Expand All @@ -43,17 +42,19 @@ class ThornsPowerup extends BasePowerup
@HookName = @TimerName
@ZapperName = "#{@TimerName}-Zapper"

with @damageInflictor = ents.Create "cfc_powerup_thorns_inflictor"
\SetOwner @owner
\Spawn!

@ApplyEffect!

MakeAoeEffect: =>
effect = EffectData!
with effect
PlayAoeEffect: =>
with effect = EffectData!
\SetEntity @holo
\SetScale 1
\SetMagnitude 12
\SetRadius 20

effect
Effect "TeslaHitboxes", effect, true, true

MakeHolo: =>
holo = ents.Create "base_anim"
Expand All @@ -75,10 +76,6 @@ class ThornsPowerup extends BasePowerup

BroadcastDamage: =>
net.Start "CFC_Powerups-ThornsDamage"

print "Preparing to broadcast damage queue:"
PrintTable @BroadcastQueue

net.WriteTable @BroadcastQueue
net.Broadcast!

Expand All @@ -94,9 +91,6 @@ class ThornsPowerup extends BasePowerup
else
@BroadcastQueue[@owner][attacker] = amount

print "Queued damage of amount #{amount} for broadcast. New queue:"
PrintTable @BroadcastQueue

now = CurTime!
diff = now - @LastDamageBroadcast

Expand All @@ -111,43 +105,51 @@ class ThornsPowerup extends BasePowerup
return unless ent == @owner
return if took == false

originalAttacker = dmg\GetAttacker!
return unless IsValid originalAttacker
--return unless originalAttacker\IsPlayer!
return if ent == originalAttacker
attacker = dmg\GetAttacker!
return unless IsValid attacker
return if ent == attacker

damageAmount = dmg\GetDamage!
inflictor = dmg\GetInflictor!
return if IsValid(inflictor) and inflictor\GetClass! == "cfc_powerup_thorns_inflictor"

damageAmount = dmg\GetDamage!
return unless damageAmount > 0
--return unless originalAttacker\Alive! -- TODO: Does this actually prevent reflect damage being reflected?

damageScale = getConf "thorns_return_percentage"
damageScale = damageScale / 100
reflectedAmount = math.ceil damageAmount * damageScale
thornsInflictor = @damageInflictor

-- CTakeDamageInfo is a singleton, need to deal damage in a timer otherwise it'll break other PED hook listeners
timer.Simple 0, ->
return unless IsValid attacker
return unless IsValid ent
return unless IsValid thornsInflictor

-- Now we modify the damage and return it to the originalAttacker
dmg\SetAttacker @owner
dmg\ScaleDamage damageScale
with refDmg = DamageInfo!
\SetAttacker ent
\SetInflictor thornsInflictor
\SetDamage reflectedAmount
\SetDamageType DMG_GENERIC

newDamageAmount = damageAmount * damageScale
@QueueDamageForBroadcast originalAttacker, newDamageAmount
attacker\TakeDamageInfo refDmg

originalAttacker\TakeDamageInfo dmg
@QueueDamageForBroadcast attacker, reflectedAmount

--originalAttacker\ChatPrint "[CFC Powerups] You took #{Round newDamageAmount} reflected damage!"
return nil

ApplyEffect: =>
super self

duration = getConf "thorns_duration"
@duration = getConf "thorns_duration"

damageWatcher = @DamageWatcher!
hook.Add "PostEntityTakeDamage", @HookName, damageWatcher
hook.Add "DoPlayerDeath", @HookName, (ply, _, dmg ) ->
damageWatcher ply, dmg

timer.Create @TimerName, duration, 1, -> @Remove!
timer.Create @ZapperName, 0.1, duration * 10, ->
Effect("TeslaHitboxes", @aoeEffect, true, true )
timer.Create @TimerName, @duration, 1, -> @Remove!
timer.Create @ZapperName, 0.1, @duration * 10, -> @PlayAoeEffect!

@passiveSound\Play!
@passiveSound\ChangeVolume 0.1
Expand All @@ -159,6 +161,7 @@ class ThornsPowerup extends BasePowerup
Refresh: =>
super self
timer.Start @TimerName
timer.Create @ZapperName, 0.1, @duration * 10, -> @PlayAoeEffect!

@owner\ChatPrint "You've refreshed the duration of your Thorns Powerup"

Expand All @@ -169,10 +172,20 @@ class ThornsPowerup extends BasePowerup
hook.Remove "DoPlayerDeath", @HookName
timer.Remove @TimerName
timer.Remove @ZapperName

@passiveSound\Stop!
damageInflictor = @damageInflictor

if IsValid @holo
@holo\Remove!

-- Remove damageInflictor after a decent delay to ensure all damage reflections finish first.
-- There's no harm in having it exist for a little longer, and overlaps aren't a problem, so this is safe.
timer.Simple 0.5, ->
return unless IsValid damageInflictor

damageInflictor\Remove!

return unless IsValid @owner

@owner\SetNWBool "CFC_Powerups-HasThorns", false
Expand Down
8 changes: 8 additions & 0 deletions materials/vgui/hud/cfc_powerup_thorns.vmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"UnlitGeneric"
{
"$basetexture" "vgui/hud/cfc_powerup_thorns"
"$vertexcolor" 1
"$vertexalpha" 1
"$nolod" 1
"$additive" 1
}
Binary file added materials/vgui/hud/cfc_powerup_thorns.vtf
Binary file not shown.

0 comments on commit 8d21670

Please sign in to comment.