92 lines
3.4 KiB
Lua
92 lines
3.4 KiB
Lua
include("shared.lua")
|
|
|
|
local healingBeam = Material("effects/laser1")
|
|
local healingGlow = Material("sprites/light_glow02_add")
|
|
local beamColor = Color(255, 218, 65, 235)
|
|
local beamCoreColor = Color(255, 252, 205, 255)
|
|
|
|
local function LightPosition(scanner)
|
|
local attachmentID = scanner:LookupAttachment("light")
|
|
local attachment = attachmentID and attachmentID > 0 and scanner:GetAttachment(attachmentID)
|
|
return attachment and attachment.Pos or (scanner:WorldSpaceCenter() + scanner:GetForward() * 16)
|
|
end
|
|
|
|
local function DrawHealingArc(startPosition, endPosition, scannerIndex)
|
|
local direction = endPosition - startPosition
|
|
local normalized = direction:GetNormalized()
|
|
local perpendicular = normalized:Cross(Vector(0, 0, 1))
|
|
if perpendicular:LengthSqr() < 0.01 then perpendicular = Vector(1, 0, 0) end
|
|
perpendicular:Normalize()
|
|
local vertical = normalized:Cross(perpendicular):GetNormalized()
|
|
local time = CurTime()
|
|
local segments = 12
|
|
|
|
render.SetMaterial(healingBeam)
|
|
render.StartBeam(segments + 1)
|
|
for segment = 0, segments do
|
|
local fraction = segment / segments
|
|
local position = LerpVector(fraction, startPosition, endPosition)
|
|
if segment > 0 and segment < segments then
|
|
local taper = math.sin(fraction * math.pi)
|
|
position = position
|
|
+ perpendicular * math.sin(time * 13 + segment * 2.31 + scannerIndex) * 6 * taper
|
|
+ vertical * math.cos(time * 17 + segment * 1.73 + scannerIndex) * 4 * taper
|
|
end
|
|
render.AddBeam(position, 4.5, fraction, beamColor)
|
|
end
|
|
render.EndBeam()
|
|
render.DrawBeam(startPosition, endPosition, 1.25, 0, 1, beamCoreColor)
|
|
end
|
|
|
|
function ENT:Draw()
|
|
self:DrawModel()
|
|
end
|
|
|
|
function ENT:Think()
|
|
self.CustomCoopTailBone = self.CustomCoopTailBone or self:LookupBone("Scanner.Tail")
|
|
local tailBone = self.CustomCoopTailBone
|
|
if tailBone then
|
|
if self:GetNW2Bool("CustomCoopScannerWreck", false) then
|
|
self:ManipulateBoneAngles(tailBone, angle_zero)
|
|
else
|
|
-- Client-only bone motion: this gives the tail some life without
|
|
-- feeding any rotation back into the VPhysics flight controller.
|
|
local speed = math.Clamp(self:GetVelocity():Length() / 80, 0, 1)
|
|
local phase = RealTime() + self:EntIndex() * 0.37
|
|
local yaw = math.sin(phase * 2.1) * (6 + speed * 4)
|
|
local pitch = math.sin(phase * 1.35 + 0.8) * 3.5
|
|
local roll = math.sin(phase * 1.7 + 2.2) * 2
|
|
self:ManipulateBoneAngles(tailBone, Angle(pitch, yaw, roll))
|
|
end
|
|
end
|
|
|
|
self:SetNextClientThink(CurTime())
|
|
return true
|
|
end
|
|
|
|
function ENT:DrawTranslucent()
|
|
if self:GetNW2Bool("CustomCoopScannerWreck", false) then return end
|
|
|
|
local lightPosition = LightPosition(self)
|
|
render.SetMaterial(healingGlow)
|
|
render.DrawSprite(lightPosition, 24, 24, beamColor)
|
|
|
|
local light = DynamicLight(self:EntIndex())
|
|
if light then
|
|
light.pos = lightPosition
|
|
light.r = 255
|
|
light.g = 205
|
|
light.b = 45
|
|
light.brightness = 2
|
|
light.Decay = 500
|
|
light.Size = 105
|
|
light.DieTime = CurTime() + 0.2
|
|
end
|
|
|
|
local patient = self:GetHealingTarget()
|
|
if IsValid(patient) and patient:IsPlayer() then
|
|
DrawHealingArc(lightPosition, patient:WorldSpaceCenter(), self:EntIndex())
|
|
render.DrawSprite(patient:WorldSpaceCenter(), 15, 15, beamCoreColor)
|
|
end
|
|
end
|