Files
Hunter/scripts/ArenaClient/CitadelGuide.client.luau
T

169 lines
8.0 KiB
Luau

--!strict
local Players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UI = require(rs:WaitForChild("HunterUI") :: ModuleScript)
local Sounds = require(rs:WaitForChild("SniperEffects") :: ModuleScript)
local Config = require(rs.CitadelAssaultConfig)
local Strings = require(rs.Hunter.Strings)
local Hints = require(rs.Hunter.Hints)
local Kinds = require(rs.Hunter.EventKinds)
local Stage = require(rs.Hunter.Stage)
local Provider = require(script.Parent.HintProviders.Siege)
local Router = require(script.Parent.EventRouter)
local player = Players.LocalPlayer
local pg = player:WaitForChild("PlayerGui")
local match = rs:WaitForChild("ArenaRound"):WaitForChild("Procedural")
local T = Strings.hint.Siege
local gui = Instance.new("ScreenGui")
gui.Name, gui.DisplayOrder, gui.ResetOnSpawn, gui.Enabled = "CitadelGuide", 25, false, false
gui.Parent = pg
local panel = UI.plate(gui, "Direction", UDim2.fromScale(.5, .77), UDim2.new(.88, 0, 0, 74), UI.Outline)
panel.AnchorPoint = Vector2.new(.5, .5)
Instance.new("UISizeConstraint", panel).MaxSize = Vector2.new(326, 74)
local contour = UI.contour(panel, UI.Gold)
local arrow = UI.label(panel, "Arrow", "▲", UDim2.fromOffset(10, 15), UDim2.fromOffset(34, 34), 24, UI.Gold)
local title = UI.label(panel, "Title", "", UDim2.fromOffset(53, 5), UDim2.new(1, -59, 0, 22), 17, UI.Ink)
local distance = UI.label(panel, "Distance", "", UDim2.fromOffset(53, 27), UDim2.new(1, -59, 0, 18), 15, UI.Ink)
local nextLine = UI.label(panel, "Next", "", UDim2.fromOffset(53, 47), UDim2.new(1, -59, 0, 19), 13, UI.Muted)
for _, line in {title, distance, nextLine} do line.TextXAlignment = Enum.TextXAlignment.Left end
local hints = Hints.new()
local pending: Hints.Hint? = nil
local count = 0
local shownTutorial = false
local lastGeneration: unknown = nil
local previousZone: string? = nil
local previousStatus: string? = nil
local lastTick = 0
local charge: Sound? = nil
local currentTarget: Vector3? = nil
local function stopCharge()
if charge then charge:Destroy(); charge = nil end
end
local function eligible(): boolean
return player:GetAttribute("InArena") == true and match:GetAttribute("Ruleset") == "Siege" and match:GetAttribute("Phase") == "Round"
end
local function push(key: string, message: string, priority: number, ttl: number?)
if not Config.HintsEnabled or not eligible() then return end
pending = {key = key, text = message, priority = priority, ttl = ttl or 4, cooldown = Config.HINT_COOLDOWN}
end
local subscriptions = {
Router.on(Kinds.ZoneStarted, function(p)
if not eligible() then return end
if p.side ~= player:GetAttribute("ArenaTeam") then push("sg_def_new", T.defNew(p.index or 1), 90) end
end),
Router.on(Kinds.ZoneCaptured, function(p)
if not eligible() then return end
local i = p.index or 1
local won = p.side == player:GetAttribute("ArenaTeam")
push(if won then "sg_captured" else "sg_def_lost", if won then T.captured(i) else T.defLost(i + 1, Config.MAX_OBJECTIVES), 90)
end),
Router.on(Kinds.AllObjectivesTaken, function(p)
if p.side == player:GetAttribute("ArenaTeam") then push("sg_all", T.all, 94) end
end),
Router.on(Kinds.RoleSwap, function(p)
if not eligible() then return end
Sounds.sound("SiegeEnter")
push("sg_new_role", if p.side == player:GetAttribute("ArenaTeam") then T.newAttack else T.newDefense, 96, 5)
end),
}
local function update()
local data = match:FindFirstChild("CitadelMatchState")
local character = player.Character
local root = character and character:FindFirstChild("HumanoidRootPart")
local human = character and character:FindFirstChildOfClass("Humanoid")
if not eligible() or not data or not root or not root:IsA("BasePart") or not human or human.Health <= 0 then
gui.Enabled = false
currentTarget = nil
pg:SetAttribute("SiegeHint", nil)
stopCharge()
previousZone, previousStatus, lastTick = nil, nil, 0
if not eligible() then hints = Hints.new(); pending = nil end
return
end
local phase = data:GetAttribute("Phase")
local stage = match:GetAttribute("RoundStage")
if not Stage.combatAllowed(match) then
gui.Enabled = false
pg:SetAttribute("SiegeHint", nil)
stopCharge()
previousZone, previousStatus, lastTick = nil, nil, 0
return
end
local generation = match:GetAttribute("MapGeneration")
if lastGeneration ~= generation then count += 1; lastGeneration = generation end
local status = data:GetAttribute("Status") :: string?
local zone = player:GetAttribute("CitadelZone") :: string?
local side = player:GetAttribute("ArenaTeam")
local attacking = side == data:GetAttribute("Attacker")
local point = data:GetAttribute("Point")
local index = (data:GetAttribute("Index") :: number?) or 1
local fraction = (data:GetAttribute("Progress") :: number?) or 0
local percent = math.floor((fraction + 1e-7) * 10) * 10
local delta = if typeof(point) == "Vector3" then point - root.Position else Vector3.zero
if not shownTutorial and Config.HintsEnabled and typeof(point) == "Vector3" and not pending then
shownTutorial = true
push("sg_tutorial", T.tutorial, 95, 6)
end
local candidates = Provider.candidates({
zone = zone, status = status, attacking = attacking, seconds = (data:GetAttribute("Seconds") :: number?) or 0,
first = phase == "Attack1", distance = delta.Magnitude, dy = delta.Y, progress = percent, experienced = count > 3,
})
if pending then table.insert(candidates, pending); pending = nil end
local chosen = if Config.HintsEnabled then Hints.pick(hints, candidates, workspace:GetServerTimeNow()) else nil
pg:SetAttribute("SiegeHint", if chosen then chosen.text else nil)
if zone == "Inside" and previousZone ~= zone then Sounds.sound("SiegeEnter") end
if zone == "Inside" and status == "Capturing" and attacking then
if not charge then charge = Sounds.sound("SiegeCharge") end
if charge then charge.PlaybackSpeed = .9 + .6 * fraction end
if percent > lastTick then Sounds.sound("SiegeTick") end
elseif charge then stopCharge() end
if status ~= previousStatus and status == "Contested" then Sounds.sound("SiegeBlocked")
elseif status ~= previousStatus and status == "Decaying" and attacking then Sounds.sound("SiegeDecay") end
previousZone, previousStatus, lastTick = zone, status, percent
local results = pg:FindFirstChild("ArenaResults")
local main = pg:FindFirstChild("MainMenu")
local blocked = pg:GetAttribute("HunterVoting") == true or (results and results:GetAttribute("LiveScoreboardOpen") == true)
or (main and main:IsA("ScreenGui") and main.Enabled)
gui.Enabled = not blocked and stage ~= "RoleSwap" and typeof(point) == "Vector3" and zone ~= "Inside" and
(attacking or status == "Capturing" or status == "Contested")
currentTarget = if gui.Enabled and typeof(point) == "Vector3" then point else nil
if not gui.Enabled then return end
local tint = if not attacking then UI.Gold elseif side == "Orange" then UI.Orange else UI.Blue
contour:SetAttribute("Accent", tint)
arrow.TextColor3 = tint
title.Text = if attacking then T.point(index, tostring(data:GetAttribute("PointName") or "")) else T.defend
distance.Text = Strings.studs(delta.Magnitude) .. (if delta.Y > 8 then T.above elseif delta.Y < -8 then T.below else "")
local following = data:GetAttribute("NextPoint")
nextLine.Text = if typeof(following) == "Vector3" then T.next(index + 1, Strings.studs((following - root.Position).Magnitude)) else ""
end
local interval = 0
local tick = RunService.Heartbeat:Connect(function(dt)
interval += dt
if interval < Config.CHECK_INTERVAL then return end
interval %= Config.CHECK_INTERVAL
update()
end)
local render = RunService.RenderStepped:Connect(function()
local camera = workspace.CurrentCamera
local target = currentTarget
if not camera or not target then return end
local root = player.Character and player.Character.PrimaryPart
if not root then return end
local delta = target - root.Position
local localDelta = camera.CFrame:VectorToObjectSpace(Vector3.new(delta.X, 0, delta.Z))
arrow.Rotation = math.deg(math.atan2(localDelta.X, -localDelta.Z))
end)
script.Destroying:Once(function()
stopCharge()
tick:Disconnect()
render:Disconnect()
for _, cancel in subscriptions do cancel() end
gui:Destroy()
end)