Polish Capture the Flag navigation and feedback

This commit is contained in:
Leshyi committed 2026-11-29 23:58:57 +05:00
1 parent 522344e34b
commit 9fb926537c
8 files changed
+203 -5

No files matched your search

+34 -5
View File
@@ -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)
for _, fighter in (fighters or Context.collect(ctx.members())) do ctx.legacy(fighter.player, "FlagDropped") end
ctx.events.fire(Kinds.FlagDropped, {at = landing})
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 = 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