Polish Capture the Flag navigation and feedback
This commit is contained in:
1 parent
522344e34b
commit
9fb926537c
8 files changed
+202
-4
No files matched your search
BIN
Binary file not shown.
@@ -0,0 +1,36 @@
|
||||
--!strict
|
||||
local rs = game:GetService("ReplicatedStorage")
|
||||
local S = require(rs.Hunter.Strings).flagHints
|
||||
local H = require(rs.Hunter.Hints)
|
||||
local Provider = {}
|
||||
|
||||
function Provider.candidates(match: Instance, player: Player): {H.Hint}
|
||||
local side = match:GetAttribute("FlagCarrierSide")
|
||||
local at = match:GetAttribute("FlagReturnAt")
|
||||
local own = player:GetAttribute("ArenaTeam")
|
||||
local key, text, priority = "flag_roof", S.roof, 30
|
||||
if player:GetAttribute("ArenaFlag") == true then key,text,priority = "flag_deliver",S.deliver,90
|
||||
elseif typeof(side) == "string" and side ~= own then key,text,priority = "flag_enemy",S.enemy,80
|
||||
elseif side == own and typeof(side) == "string" then key,text,priority = "flag_escort",S.escort,60
|
||||
elseif typeof(at) == "number" then
|
||||
key,text,priority = "flag_drop",string.format(S.dropped,math.max(0,math.ceil(at-workspace:GetServerTimeNow()))),70
|
||||
end
|
||||
return {{key=key,text=text,priority=priority,ttl=.4}}
|
||||
end
|
||||
|
||||
function Provider.target(match: Instance, player: Player): (Vector3?, string?, string?)
|
||||
local own = player:GetAttribute("ArenaTeam")
|
||||
if player:GetAttribute("ArenaFlag") == true and typeof(own) == "string" then
|
||||
local base = match:GetAttribute("FlagBase_" .. own)
|
||||
return if typeof(base) == "Vector3" then base else nil, S.base, own
|
||||
end
|
||||
local point = match:GetAttribute("FlagPosition")
|
||||
local carrierSide = match:GetAttribute("FlagCarrierSide")
|
||||
local name = if carrierSide == own and typeof(carrierSide) == "string" then S.escortTitle else S.title
|
||||
return if typeof(point) == "Vector3" then point else nil, name, if typeof(carrierSide) == "string" then carrierSide else nil
|
||||
end
|
||||
|
||||
function Provider.highlight(_match: Instance, _viewer: Player, member: Player): boolean
|
||||
return member:GetAttribute("ArenaFlag") == true
|
||||
end
|
||||
return Provider
|
||||
@@ -56,6 +56,12 @@ 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 == "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}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local rs = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local UI = require(rs:WaitForChild("HunterUI") :: ModuleScript)
|
||||
local S = require(rs.Hunter.Strings)
|
||||
local Stage = require(rs.Hunter.Stage)
|
||||
local player = Players.LocalPlayer
|
||||
local pg = player:WaitForChild("PlayerGui")
|
||||
local match = rs:WaitForChild("ArenaRound"):WaitForChild("Procedural")
|
||||
local providers = script.Parent.HintProviders
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name, gui.DisplayOrder, gui.ResetOnSpawn, gui.Enabled = "ModeGuide", 25, false, false
|
||||
gui.Parent = pg
|
||||
local panel = UI.plate(gui,"Direction",UDim2.fromScale(.5,.73),UDim2.new(.85,0,0,60),UI.Outline)
|
||||
panel.AnchorPoint = Vector2.new(.5,.5)
|
||||
Instance.new("UISizeConstraint",panel).MaxSize = Vector2.new(326,60)
|
||||
local contour = UI.contour(panel,UI.Gold)
|
||||
local arrow = UI.label(panel,"Arrow","▲",UDim2.fromOffset(11,10),UDim2.fromOffset(40,38),26,UI.Gold)
|
||||
local title = UI.label(panel,"Title","",UDim2.fromOffset(54,6),UDim2.new(1,-65,0,22),18,UI.Ink)
|
||||
local detail = UI.label(panel,"Distance","",UDim2.fromOffset(54,30),UDim2.new(1,-65,0,22),15,UI.Muted)
|
||||
title.TextXAlignment, detail.TextXAlignment = Enum.TextXAlignment.Left, Enum.TextXAlignment.Left
|
||||
local markers = Instance.new("Folder")
|
||||
markers.Name = "ModeTargets"
|
||||
markers.Parent = workspace
|
||||
local highlights: {[Player]: Highlight} = {}
|
||||
local provider: any = nil
|
||||
local currentMode: string? = nil
|
||||
local current: Vector3? = nil
|
||||
local function color(side: unknown): Color3
|
||||
return if side=="Blue" then UI.Blue elseif side=="Orange" then UI.Orange else UI.Gold
|
||||
end
|
||||
local function refresh()
|
||||
local id = match:GetAttribute("Ruleset")
|
||||
local active = player:GetAttribute("InArena")==true and match:GetAttribute("Phase")=="Round" and Stage.combatAllowed(match)
|
||||
if id~=currentMode then
|
||||
currentMode = if typeof(id)=="string" then id else nil
|
||||
local module = if typeof(id)=="string" then providers:FindFirstChild(id) else nil
|
||||
provider = if module and module:IsA("ModuleScript") then require(module) else nil
|
||||
end
|
||||
local ready: {[Player]: boolean} = {}
|
||||
if active and provider and provider.highlight then
|
||||
for _, member in Players:GetPlayers() do
|
||||
local character = member.Character
|
||||
if member~=player and character and provider.highlight(match,player,member) then
|
||||
ready[member]=true
|
||||
local entry=highlights[member]
|
||||
if not entry then
|
||||
entry=Instance.new("Highlight")
|
||||
entry.Name = "ModeTarget"
|
||||
entry.DepthMode=Enum.HighlightDepthMode.AlwaysOnTop
|
||||
entry.FillTransparency=.77
|
||||
entry.OutlineTransparency=.16
|
||||
entry.Parent=markers
|
||||
highlights[member]=entry
|
||||
end
|
||||
entry.Adornee=character
|
||||
local tone=color(member:GetAttribute("ArenaTeam"))
|
||||
entry.FillColor,entry.OutlineColor=tone,tone
|
||||
end
|
||||
end
|
||||
end
|
||||
for member,entry in highlights do
|
||||
if not ready[member] then entry:Destroy(); highlights[member]=nil end
|
||||
end
|
||||
local root=player.Character and player.Character.PrimaryPart
|
||||
local menu=pg:FindFirstChild("MainMenu")
|
||||
local results=pg:FindFirstChild("ArenaResults")
|
||||
local blocked=pg:GetAttribute("HunterVoting")==true or (menu and menu:IsA("ScreenGui") and menu.Enabled)
|
||||
or (results and results:GetAttribute("LiveScoreboardOpen")==true)
|
||||
gui.Enabled=active and not blocked
|
||||
panel.Visible=false
|
||||
current=nil
|
||||
if not gui.Enabled or not root or not provider or not provider.target then return end
|
||||
local point,label,side=provider.target(match,player)
|
||||
if not point or not label then return end
|
||||
local delta=point-root.Position
|
||||
current=point
|
||||
panel.Visible=true
|
||||
title.Text=label
|
||||
local copy=S.hint.Siege
|
||||
detail.Text=S.studs(delta.Magnitude)..(if delta.Y>8 then copy.above elseif delta.Y < -8 then copy.below else "")
|
||||
local tint=color(side)
|
||||
arrow.TextColor3=tint
|
||||
contour:SetAttribute("Accent",tint)
|
||||
end
|
||||
local elapsed=0
|
||||
local step=RunService.Heartbeat:Connect(function(dt)
|
||||
elapsed+=dt
|
||||
if elapsed < .14 then return end
|
||||
elapsed%=.14
|
||||
refresh()
|
||||
end)
|
||||
local render=RunService.RenderStepped:Connect(function()
|
||||
local camera=workspace.CurrentCamera
|
||||
local root=player.Character and player.Character.PrimaryPart
|
||||
if not camera or not root or not current then return end
|
||||
local d=current-root.Position
|
||||
local v=camera.CFrame:VectorToObjectSpace(Vector3.new(d.X,0,d.Z))
|
||||
arrow.Rotation=math.deg(math.atan2(v.X,-v.Z))
|
||||
end)
|
||||
script.Destroying:Once(function()
|
||||
step:Disconnect()
|
||||
render:Disconnect()
|
||||
markers:Destroy()
|
||||
gui:Destroy()
|
||||
end)
|
||||
@@ -56,6 +56,13 @@ local hotHints = table.freeze({
|
||||
captured = "Точка захвачена — следующая через %d с.",
|
||||
contest = "ОСПАРИВАЕТСЯ", underFire = "ПОД ОГНЁМ", taking = "ЗАХВАТ · С СОЮЗНИКОМ ×1,5",
|
||||
})
|
||||
local flagHints = table.freeze({
|
||||
roof="Флаг на крыше цитадели.", deliver="Несите флаг на свою базу.",
|
||||
enemy="Флаг у соперника — остановите его!", escort="Сопроводите союзника с флагом.",
|
||||
dropped="Флаг упал — подберите его (%d с).", dropLabel="ФЛАГ УПАЛ · %d с",
|
||||
base="НА СВОЮ БАЗУ",title="ФЛАГ",escortTitle="СОПРОВОДИТЕ НОСИТЕЛЯ",
|
||||
picked="ФЛАГ ВЗЯТ!", enemyPicked="СОПЕРНИКИ ВЗЯЛИ ФЛАГ!", scored="ФЛАГ ДОСТАВЛЕН! +1",
|
||||
})
|
||||
local function flagCarrier(name: string): string return name .. " несёт флаг" end
|
||||
local round = table.freeze({
|
||||
mode = "РЕЖИМ", fight = "В БОЙ!", final = "ФИНАЛЬНЫЙ РЫВОК", swap = "СМЕНА РОЛЕЙ",
|
||||
@@ -89,6 +96,7 @@ return table.freeze({
|
||||
studs = studs,
|
||||
domination = domination,
|
||||
hotHints = hotHints,
|
||||
flagHints = flagHints,
|
||||
hint = table.freeze({Siege = siegeHints}),
|
||||
team = team, clock = clock,
|
||||
bases = table.freeze({Blue = "БАЗА СИНИХ", Orange = "БАЗА ОРАНЖЕВЫХ"}),
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
--!strict
|
||||
local Rules = {RETURN_SECONDS = 20}
|
||||
function Rules.remaining(deadline: number, now: number): number
|
||||
return math.max(0, math.ceil(deadline - now))
|
||||
end
|
||||
return table.freeze(Rules)
|
||||
@@ -5,6 +5,7 @@ local Common = require(Runtime.Common)
|
||||
local Kinds = require(game.ReplicatedStorage.Hunter.EventKinds)
|
||||
local Strings = require(game.ReplicatedStorage.Hunter.Strings)
|
||||
local Context = require(Runtime.Context)
|
||||
local Rules = require(Runtime.FlagRules)
|
||||
local HotPoint = require(Runtime.Parent.HotPoint)
|
||||
type Fighter = Types.Fighter
|
||||
type Flag = {
|
||||
@@ -68,11 +69,20 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
local map, geometry = assert(ctx.map), ctx.geometry
|
||||
local flag = makeFlag(ctx.folder, map.roof.position)
|
||||
Common.bases(ctx.folder, geometry, map)
|
||||
local state = ctx.state
|
||||
local lastSeconds = -1
|
||||
state:SetAttribute("FlagPosition", flag.marker.origin)
|
||||
state:SetAttribute("FlagBase_Blue", map.blue)
|
||||
state:SetAttribute("FlagBase_Orange", map.orange)
|
||||
|
||||
local function putFlag(object: Flag, at: Vector3, droppedUntil: number)
|
||||
if object.carrier then object.carrier:SetAttribute("ArenaFlag", nil) end
|
||||
if object.tether then object.tether:Destroy() end
|
||||
object.carrier, object.tether, object.droppedUntil = nil, nil, droppedUntil
|
||||
state:SetAttribute("FlagCarrierSide", nil)
|
||||
state:SetAttribute("FlagPosition", at)
|
||||
state:SetAttribute("FlagReturnAt", if droppedUntil > 0 then droppedUntil else nil)
|
||||
lastSeconds = -1
|
||||
local mark = object.marker
|
||||
mark.body.Anchored = true
|
||||
mark.body.CFrame = CFrame.new(at + Vector3.yAxis * 2.4)
|
||||
@@ -92,6 +102,9 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
body.Anchored = false
|
||||
object.carrier, object.tether, object.droppedUntil = fighter.player, tether, 0
|
||||
fighter.player:SetAttribute("ArenaFlag", true)
|
||||
state:SetAttribute("FlagCarrierSide", fighter.side)
|
||||
state:SetAttribute("FlagReturnAt", nil)
|
||||
state:SetAttribute("FlagPosition", fighter.root.Position)
|
||||
local tint = Common.color(fighter.side)
|
||||
object.marker.label.Text = Strings.flagCarrierLabel(fighter.player.DisplayName)
|
||||
object.marker.label.TextColor3, object.banner.Color = tint, tint
|
||||
@@ -103,10 +116,14 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
if flag.carrier == player then
|
||||
if at then
|
||||
local floor = workspace:Raycast(at + Vector3.yAxis * .3, -Vector3.yAxis * 50, geometry)
|
||||
local landing = if floor then floor.Position else at
|
||||
putFlag(flag, landing, now + 20)
|
||||
if floor then
|
||||
putFlag(flag, floor.Position, now + Rules.RETURN_SECONDS)
|
||||
for _, fighter in (fighters or Context.collect(ctx.members())) do ctx.legacy(fighter.player, "FlagDropped") end
|
||||
ctx.events.fire(Kinds.FlagDropped, {at = landing})
|
||||
ctx.events.fire(Kinds.FlagDropped, {at = floor.Position})
|
||||
else
|
||||
putFlag(flag, flag.marker.origin, 0)
|
||||
ctx.events.fire(Kinds.FlagReturned, {at = flag.marker.origin})
|
||||
end
|
||||
else
|
||||
putFlag(flag, flag.marker.origin, 0)
|
||||
ctx.events.fire(Kinds.FlagReturned, {at = flag.marker.origin})
|
||||
@@ -117,6 +134,8 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
if flag.carrier then
|
||||
for _, fighter in fighters do
|
||||
if fighter.player ~= flag.carrier then continue end
|
||||
state:SetAttribute("FlagPosition", fighter.root.Position)
|
||||
state:SetAttribute("FlagCarrierSide", fighter.side)
|
||||
local base = if fighter.side == "Blue" then map.blue else map.orange
|
||||
if Common.boundsAt(fighter.root.Position, base, HotPoint.Radius, 7) then
|
||||
ctx.scoring.add(fighter.side, 1, Kinds.FlagScored, fighter.player)
|
||||
@@ -137,6 +156,13 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
putFlag(flag, flag.marker.origin, 0)
|
||||
ctx.events.fire(Kinds.FlagReturned, {at = flag.marker.origin})
|
||||
end
|
||||
if flag.droppedUntil > 0 then
|
||||
local seconds = Rules.remaining(flag.droppedUntil, now)
|
||||
if seconds ~= lastSeconds then
|
||||
lastSeconds = seconds
|
||||
flag.marker.label.Text = string.format(Strings.flagHints.dropLabel, seconds)
|
||||
end
|
||||
end
|
||||
local at = flag.marker.body.Position
|
||||
for _, fighter in fighters do
|
||||
if Common.boundsAt(fighter.root.Position, at, 5.5, 6.5) and Common.visibleAt(fighter, at, geometry) then
|
||||
@@ -153,7 +179,10 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
return Common.instance(ctx, {
|
||||
step = function(now, _, fighters) runFlag(fighters, now); return false end,
|
||||
death = dropCarried, leaving = dropCarried,
|
||||
destroy = function() if flag.carrier then flag.carrier:SetAttribute("ArenaFlag", nil) end end,
|
||||
destroy = function()
|
||||
if flag.carrier then flag.carrier:SetAttribute("ArenaFlag", nil) end
|
||||
for _, name in {"FlagPosition","FlagCarrierSide","FlagReturnAt","FlagBase_Blue","FlagBase_Orange"} do state:SetAttribute(name,nil) end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
--!strict
|
||||
return function(rules: any)
|
||||
assert(rules.remaining(30,10)==20)
|
||||
assert(rules.remaining(30,29.99)==1)
|
||||
assert(rules.remaining(30,30)==0 and rules.remaining(30,31)==0)
|
||||
end
|
||||
Reference in new issue
Block a user