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

122 lines
5.1 KiB
Luau

--!strict
local Players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local UI = require(rs:WaitForChild("HunterUI") :: ModuleScript)
local Sounds = require(rs:WaitForChild("SniperEffects") :: ModuleScript)
local S = require(rs.Hunter.Strings)
local Hints = require(rs.Hunter.Hints)
local Kinds = require(rs.Hunter.EventKinds)
local Router = require(script.Parent.EventRouter)
local player = Players.LocalPlayer
local pg = player:WaitForChild("PlayerGui")
local match = rs:WaitForChild("ArenaRound"):WaitForChild("Procedural")
local providers = script.Parent:WaitForChild("HintProviders")
local gui = Instance.new("ScreenGui")
gui.Name, gui.DisplayOrder, gui.ResetOnSpawn = "ModeFeedback", 24, false
gui.Parent = pg
local banner = UI.plate(gui, "EventBanner", UDim2.fromScale(.5, .34), UDim2.new(.8, 0, 0, 58), UI.Gold)
banner.AnchorPoint = Vector2.new(.5,.5)
Instance.new("UISizeConstraint", banner).MaxSize = Vector2.new(430,58)
local contour = UI.contour(banner, UI.Gold)
local title = UI.label(banner,"Title","",UDim2.fromScale(.02,0),UDim2.fromScale(.96,1),24,UI.Ink)
title.FontFace = UI.Display
banner.Visible = false
local wave = Instance.new("Part")
wave.Name = "LocalObjectiveWave"
wave.Shape, wave.Material = Enum.PartType.Cylinder, Enum.Material.Neon
wave.Anchored, wave.CanCollide, wave.CanTouch, wave.CanQuery = true, false, false, false
wave.Transparency = 1
wave.Parent = workspace
local effect: Tween? = nil
local pending: Hints.Hint? = nil
local activeMode: string? = nil
local provider: any = nil
local selection = Hints.new()
local bannerUntil = 0
local function tint(side: string?): Color3
return if side == "Blue" then UI.Blue elseif side == "Orange" then UI.Orange else UI.Gold
end
local function showWave(at: Vector3, color: Color3)
if effect then effect:Cancel() end
wave.CFrame = CFrame.new(at + Vector3.yAxis*.3) * CFrame.Angles(0, 0, math.pi/2)
wave.Size = Vector3.new(.1,12,12)
wave.Color, wave.Transparency = color, .64
effect = TweenService:Create(wave,TweenInfo.new(.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),
{Size=Vector3.new(.1,42,42),Transparency=1})
effect:Play()
end
local function event(kind: string, p: any)
if player:GetAttribute("InArena") ~= true or match:GetAttribute("Phase") ~= "Round" then return end
local id = match:GetAttribute("Ruleset")
local tone = tint(p.side)
if id == "CaptureFlag" and (kind == Kinds.FlagPicked or kind == Kinds.FlagScored) then
contour:SetAttribute("Accent", tone)
title.Text = if kind == Kinds.FlagScored then S.flagHints.scored
elseif p.side == player:GetAttribute("ArenaTeam") then S.flagHints.picked else S.flagHints.enemyPicked
bannerUntil = workspace:GetServerTimeNow() + 2.7
end
if id == "TrophyHunt" and p.userId == player.UserId then
if kind == Kinds.TokensBanked then
contour:SetAttribute("Accent", tone)
title.Text = string.format(S.trophyHints.banked, p.value or 0)
bannerUntil = workspace:GetServerTimeNow() + 2.7
elseif kind == Kinds.TokensLost then
pending = {key="th_lost",priority=60,text=S.trophyHints.lost,ttl=4}
end
end
if id == "Domination" then
if kind == Kinds.ZoneLost and p.side == player:GetAttribute("ArenaTeam") then
pending = {key="dp_lost",priority=70,text=S.domination.lost(string.sub(p.text or "A",1,1)),ttl=4}
elseif kind == Kinds.FullControl then
contour:SetAttribute("Accent",tone)
title.Text = S.domination.control
bannerUntil = workspace:GetServerTimeNow()+3
Sounds.sound("RoundStart")
elseif kind == Kinds.ZoneCaptured and typeof(p.at)=="Vector3" then
showWave(p.at,tone)
end
end
end
local subscriptions: {() -> ()} = {}
for _, kind in Kinds do table.insert(subscriptions,Router.on(kind,function(p) event(kind,p) end)) end
local elapsed = 0
local heartbeat = RunService.Heartbeat:Connect(function(dt)
elapsed += dt
if elapsed < .12 then return end
elapsed %= .12
local now = workspace:GetServerTimeNow()
local mode = match:GetAttribute("Ruleset")
local playing = player:GetAttribute("InArena") == true and match:GetAttribute("Phase")=="Round"
if not playing or typeof(mode)~="string" or mode=="Siege" then
activeMode, provider, pending, bannerUntil = nil,nil,nil,0
pg:SetAttribute("ModeHint",nil)
banner.Visible = false
return
end
if mode ~= activeMode then
activeMode, selection = mode,Hints.new()
local source = providers:FindFirstChild(mode)
provider = if source and source:IsA("ModuleScript") then require(source) else nil
end
local candidates = if provider then provider.candidates(match,player) else {}
if pending then table.insert(candidates,pending);pending=nil end
local hint = Hints.pick(selection,candidates,now)
pg:SetAttribute("ModeHint",if hint then hint.text else nil)
local results = pg:FindFirstChild("ArenaResults")
banner.Visible = now<bannerUntil and pg:GetAttribute("HunterVoting")~=true and (not results or results:GetAttribute("LiveScoreboardOpen")~=true)
end)
script.Destroying:Once(function()
heartbeat:Disconnect()
for _, remove in subscriptions do remove() end
if effect then effect:Cancel() end
wave:Destroy()
gui:Destroy()
end)