Files
Hunter/scripts/HotPoint.luau
T
2026-11-29 15:49:17 +03:00

232 lines
8.8 KiB
Luau
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
--!strict
local Sites = require(script.Parent:WaitForChild("ArenaObjectiveSites") :: ModuleScript)
type Side = "Blue" | "Orange"
export type Fighter = {player: Player, side: Side, root: BasePart}
export type Marker = {body: Part, label: TextLabel, origin: Vector3}
type Config = {
state: Instance, geometry: RaycastParams, sites: {Sites.Site}, startedAt: number,
marker: (Sites.Site) -> Marker, score: (Side, number) -> (), status: (string) -> (),
}
type Capture = {
step: ({Fighter}, number, number) -> (), hit: (Player, number, boolean) -> (),
death: (Player) -> (), destroy: () -> (),
}
local HotPoint = {Radius = 18}
local CAPTURE_SECONDS = 10
local ROTATION_SECONDS = 40
local TEAM_SPEED = 1.5
local HIT_WINDOW = 1.2
local HIT_DECAY = .8
local neutral = Color3.fromRGB(183, 132, 255)
local contested = Color3.fromRGB(255, 211, 124)
local teamColor: {[Side]: Color3} = {Blue = Color3.fromRGB(76, 228, 255), Orange = Color3.fromRGB(255, 81, 105)}
local function magicRing(mark: Marker): (Color3) -> ()
local body = mark.body
body.Transparency = .92
local beams: {Beam} = {}
local sparks: {ParticleEmitter} = {}
local function anchor(angle: number, height: number): Attachment
local radial = Vector3.new(math.cos(angle), 0, math.sin(angle))
local tangent = Vector3.new(-radial.Z, 0, radial.X)
local item = Instance.new("Attachment")
local world = CFrame.fromMatrix(mark.origin + radial * HotPoint.Radius + Vector3.yAxis * height, tangent, Vector3.yAxis)
item.CFrame = body.CFrame:ToObjectSpace(world)
item.Parent = body
return item
end
local function halo(name: string, height: number, width: number, transparency: number)
local corners: {Attachment} = {}
for index = 0, 3 do
table.insert(corners, anchor(index * math.pi / 2, height))
end
local handle = 4 * (math.sqrt(2) - 1) / 3 * HotPoint.Radius
for index, start in corners do
local beam = Instance.new("Beam")
beam.Name = name
beam.Attachment0, beam.Attachment1 = start, corners[index % #corners + 1]
beam.CurveSize0, beam.CurveSize1 = handle, handle
beam.Segments, beam.FaceCamera = 18, true
beam.Width0, beam.Width1 = width, width
beam.Transparency = NumberSequence.new(transparency)
beam.LightEmission, beam.LightInfluence, beam.Brightness = 1, 0, 2
beam.Parent = body
table.insert(beams, beam)
end
end
halo("FloorRing", .29, .32, .1)
for index = 0, 19 do
local angle = index * math.pi / 10
local source = anchor(angle, .28)
if index % 2 == 0 then
local veil = Instance.new("Beam")
veil.Name = "RisingVeil"
veil.Attachment0, veil.Attachment1 = source, anchor(angle, 7.4)
veil.FaceCamera, veil.Segments = true, 8
veil.Width0, veil.Width1 = .78, .3
veil.LightEmission, veil.LightInfluence, veil.Brightness = 1, 0, 1.4
veil.Transparency = NumberSequence.new({
NumberSequenceKeypoint.new(0, .42), NumberSequenceKeypoint.new(.38, .74), NumberSequenceKeypoint.new(1, 1),
})
veil.Parent = body
table.insert(beams, veil)
end
local emitter = Instance.new("ParticleEmitter")
emitter.Name = "RisingSparks"
emitter.Texture = "rbxasset://textures/particles/sparkles_main.dds"
emitter.EmissionDirection = Enum.NormalId.Top
emitter.Rate, emitter.Speed = 12, NumberRange.new(16.5, 27)
emitter.Lifetime, emitter.SpreadAngle = NumberRange.new(.6, 1.08), Vector2.new(8, 8)
emitter.Rotation, emitter.RotSpeed = NumberRange.new(-180, 180), NumberRange.new(-95, 95)
emitter.LightEmission, emitter.LightInfluence, emitter.Brightness = 1, 0, 2
emitter.Size = NumberSequence.new({
NumberSequenceKeypoint.new(0, .16), NumberSequenceKeypoint.new(.25, .55), NumberSequenceKeypoint.new(1, .08),
})
emitter.Transparency = NumberSequence.new({
NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(.22, .12), NumberSequenceKeypoint.new(1, 1),
})
emitter.Parent = source
table.insert(sparks, emitter)
end
return function(tint: Color3)
body.Color, mark.label.TextColor3 = tint, tint
local light = body:FindFirstChildOfClass("PointLight")
if light then light.Color, light.Range = tint, 18 end
local spectrum = ColorSequence.new({
ColorSequenceKeypoint.new(0, tint), ColorSequenceKeypoint.new(.5, tint:Lerp(Color3.new(1, 1, 1), .38)),
ColorSequenceKeypoint.new(1, tint),
})
for _, beam in beams do beam.Color = spectrum end
for _, emitter in sparks do emitter.Color = spectrum end
end
end
function HotPoint.start(config: Config): Capture
local state = config.state
local index, credit, hitSince, hitUntil, flashUntil = 0, 0, 0, 0, 0
local owner: Side? = nil
local claiming: Side? = nil
local capturers: {[Player]: boolean} = {}
local mark: Marker? = nil
local paint: ((Color3) -> ())? = nil
local lastTint: Color3? = nil
local function publish(side: Side?, percent: number, phase: string?)
if state:GetAttribute("HotPointTeam") ~= side then state:SetAttribute("HotPointTeam", side) end
if state:GetAttribute("HotPointProgress") ~= percent then state:SetAttribute("HotPointProgress", percent) end
if state:GetAttribute("HotPointPhase") ~= phase then state:SetAttribute("HotPointPhase", phase) end
end
local function clearCapture()
claiming, credit, hitSince, hitUntil = nil, 0, 0, 0
table.clear(capturers)
end
local function paintRing(tint: Color3)
if paint and lastTint ~= tint then
lastTint = tint
paint(tint)
end
end
local function isInside(fighter: Fighter, origin: Vector3): boolean
local delta = fighter.root.Position - origin
if delta.Y < -.5 or delta.Y > 60 or delta.X * delta.X + delta.Z * delta.Z > HotPoint.Radius ^ 2 then return false end
if delta.Y > 8 then
-- A jump over the point still counts when the first floor below is the capture floor.
local floor = workspace:Raycast(fighter.root.Position, -Vector3.yAxis * (delta.Y + .8), config.geometry)
return floor ~= nil and math.abs(floor.Position.Y - origin.Y) < .65
end
local to = origin + Vector3.yAxis * 2.7 - fighter.root.Position
return workspace:Raycast(fighter.root.Position, to, config.geometry) == nil
end
local function step(fighters: {Fighter}, now: number, dt: number)
local elapsed = math.max(0, now - config.startedAt)
local slot = math.floor(elapsed / ROTATION_SECONDS) % #config.sites + 1
local site = config.sites[slot]
if index ~= slot then
if mark then mark.body:Destroy() end
local fresh = config.marker(site)
index, mark, paint = slot, fresh, magicRing(fresh)
owner, flashUntil, lastTint = nil, 0, nil
clearCapture()
end
local blue, orange = 0, 0
local inside: {Fighter} = {}
for _, fighter in fighters do
if not isInside(fighter, site.position) then continue end
table.insert(inside, fighter)
if fighter.side == "Blue" then blue += 1 else orange += 1 end
end
local remaining = math.ceil(ROTATION_SECONDS - elapsed % ROTATION_SECONDS)
config.status(site.name .. " · Смена точки через " .. remaining .. " с")
local soleSide: Side? = if blue > 0 and orange == 0 then "Blue" elseif orange > 0 and blue == 0 then "Orange" else nil
local isContested = blue > 0 and orange > 0
if soleSide and soleSide ~= owner then
if claiming ~= soleSide then
clearCapture()
claiming = soleSide
dt = 0
end
elseif not isContested or not claiming then
clearCapture()
end
local side = claiming
if side then
table.clear(capturers)
for _, fighter in inside do
if fighter.side == side then capturers[fighter.player] = true end
end
local underFire = now < hitUntil
local damageTime = math.max(0, math.min(now, hitUntil) - math.max(now - dt, hitSince))
if damageTime > 0 then credit = math.max(0, credit - damageTime * HIT_DECAY) end
if not isContested then
local count = if side == "Blue" then blue else orange
credit += (dt - damageTime) * (if count >= 2 then TEAM_SPEED else 1)
end
if credit >= CAPTURE_SECONDS then
owner, flashUntil = side, now + 1.25
config.score(side, 1)
clearCapture()
publish(side, 100, "Captured")
paintRing(teamColor[side])
else
local phase = if isContested then "Contested" elseif underFire then "UnderFire" else "Capturing"
publish(side, math.floor(100 * credit / CAPTURE_SECONDS), phase)
paintRing(if isContested then contested else teamColor[side])
end
elseif isContested then
publish(nil, 0, "Contested")
paintRing(contested)
else
if owner and now < flashUntil then publish(owner, 100, "Captured") else publish(nil, 0, nil) end
paintRing(if owner then teamColor[owner] else neutral)
end
end
local function death(player: Player)
if not capturers[player] then return end
clearCapture()
publish(nil, 0, nil)
end
return {
step = step,
hit = function(player: Player, now: number, killed: boolean)
if killed then death(player)
elseif capturers[player] then
if now >= hitUntil then hitSince = now end
hitUntil = now + HIT_WINDOW
end
end,
death = death,
destroy = function()
publish(nil, 0, nil)
end,
}
end
return table.freeze(HotPoint)