Files

255 lines
9.4 KiB
Luau

--!strict
local Text = require(game:GetService("ReplicatedStorage"):WaitForChild("Hunter"):WaitForChild("Strings") :: ModuleScript).interface.HotPoint
local Diagnostics = require(script.Parent.ModeRuntime.ZoneDiagnostics)
local Credit = require(script.Parent.ModeRuntime.HotPointCredit)
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) -> (),
contribute: ((Player, string, number) -> ())?,
}
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 COLLAPSE_SECONDS = .55
local CAPTURE_NOTICE_SECONDS = 2
local NEXT_POINT_WARNING_SECONDS = 5
local TEAM_SPEED = 1.5
local HIT_WINDOW = 1.2
local HIT_DECAY = .8
local neutral = Color3.fromRGB(255, 220, 96)
local contested = Color3.fromRGB(255, 211, 124)
local teamColor: {[Side]: Color3} = {Blue = Color3.fromRGB(76, 228, 255), Orange = Color3.fromRGB(255, 81, 105)}
function HotPoint.attachRing(mark: Marker, radius: number?): (Color3) -> ()
local r = radius or HotPoint.Radius
local body = mark.body
body.Transparency = .92
local beams: {Beam} = {}
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 * r + 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 * r
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
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
end
end
local function closeMarker(mark: Marker)
mark.body:SetAttribute("ObjectiveArrowHidden", true)
mark.body.Parent = nil
end
function HotPoint.start(config: Config): Capture
local state = config.state
local index, credit, hitSince, hitUntil = 0, 0, 0, 0
local movesAt = config.startedAt
local capturedAt = 0
local capturedSide: 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 = Diagnostics.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 Diagnostics.raycast(fighter.root.Position, to, config.geometry) == nil
end
local function step(fighters: {Fighter}, now: number, dt: number)
if index == 0 or now >= movesAt then
if mark then mark.body:Destroy() end
index = index % #config.sites + 1
local activeSite = config.sites[index]
local fresh = config.marker(activeSite)
mark, paint, lastTint = fresh, HotPoint.attachRing(fresh), nil
capturedSide = nil
movesAt = now + ROTATION_SECONDS
clearCapture()
publish(nil, 0, nil)
state:SetAttribute("HotPointPosition", activeSite.position)
state:SetAttribute("HotPointNextPosition", config.sites[index % #config.sites + 1].position)
state:SetAttribute("HotPointMovesAt", movesAt)
elseif capturedSide then
local since = now - capturedAt
if since >= COLLAPSE_SECONDS + CAPTURE_NOTICE_SECONDS then
publish(nil, 0, nil)
config.status(Text.skoroPoyavitsyaNovayaTochka)
elseif since >= COLLAPSE_SECONDS then
publish(capturedSide, 100, "Captured")
config.status(Text.tochkaZakhvachena)
end
return
end
local site = config.sites[index]
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 config.contribute then config.contribute(fighter.player, "holdSeconds", dt) end
if fighter.side == "Blue" then blue += 1 else orange += 1 end
end
local remaining = math.ceil(movesAt - now)
config.status(site.name .. Text.smenaTochkiCherez .. remaining .. Text.s)
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 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))
local count = if side == "Blue" then blue else orange
credit = Credit.advance(credit, dt, damageTime, HIT_DECAY, if count >= 2 then TEAM_SPEED else 1, isContested)
if credit >= CAPTURE_SECONDS then
capturedSide, capturedAt = side, now
movesAt = now + COLLAPSE_SECONDS + CAPTURE_NOTICE_SECONDS + NEXT_POINT_WARNING_SECONDS
config.score(side, 1)
if config.contribute then
for player in capturers do config.contribute(player, "captures", 1) end
end
clearCapture()
publish(nil, 0, nil)
config.status("")
state:SetAttribute("HotPointPosition", nil)
state:SetAttribute("HotPointMovesAt", movesAt)
paintRing(teamColor[side])
if mark then closeMarker(mark) end
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
publish(nil, 0, nil)
paintRing(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()
if mark then mark.body:Destroy() end
publish(nil, 0, nil)
state:SetAttribute("HotPointPosition", nil)
state:SetAttribute("HotPointNextPosition", nil)
state:SetAttribute("HotPointMovesAt", nil)
end,
}
end
return table.freeze(HotPoint)