Add round stages, respawn protection and match highlights
This commit is contained in:
1 parent
b87a3770a1
commit
d1c42a36b8
28 files changed
+753
-45
No files matched your search
@@ -7,6 +7,8 @@ local Common = require(script.Parent.Common)
|
||||
local Scoring = require(script.Parent.Scoring)
|
||||
local Events = require(script.Parent.Events)
|
||||
local Janitor = require(script.Parent.Janitor)
|
||||
local Stats = require(script.Parent.Stats)
|
||||
local Profiles = require(ReplicatedStorage.Hunter.ModeProfiles)
|
||||
local Context = {}
|
||||
|
||||
function Context.collect(members: {Player}): {Types.Fighter}
|
||||
@@ -33,24 +35,22 @@ function Context.create(config: Types.Config, mode: Types.Mode, legacy: RemoteEv
|
||||
folder.Name = "MatchObjectives"
|
||||
folder.Parent = world
|
||||
local janitor = Janitor.new()
|
||||
local contributions: {[number]: {[string]: number}} = {}
|
||||
state:SetAttribute("ObjectiveStatus", "")
|
||||
state:SetAttribute("ResultReason", nil)
|
||||
return {
|
||||
arena = config.arena, rule = config.rule, state = state, liveAt = config.now, duration = config.duration,
|
||||
world = world, geometry = geometry, map = map, folder = folder, janitor = janitor,
|
||||
members = config.members, bench = config.bench, deploy = config.deploy, balanceWaiting = config.balanceWaiting,
|
||||
scoring = Scoring.new(state, function(_, points, reason, player)
|
||||
if not reason or not player then return end
|
||||
local stats = contributions[player.UserId] or {}
|
||||
stats[reason] = (stats[reason] or 0) + points
|
||||
contributions[player.UserId] = stats
|
||||
end),
|
||||
scoring = Scoring.new(state, nil, Profiles[config.rule].scoreMultiplierInFinalPush),
|
||||
contribute = Stats.add,
|
||||
events = Events.new(config.members),
|
||||
status = function(value)
|
||||
if state:GetAttribute("ObjectiveStatus") ~= value then state:SetAttribute("ObjectiveStatus", value) end
|
||||
end,
|
||||
setStage = function(stage) state:SetAttribute("RoundStage", stage) end,
|
||||
setStage = function(stage, stageEndsAt)
|
||||
if stageEndsAt then state:SetAttribute("StageEndsAt", stageEndsAt) end
|
||||
state:SetAttribute("RoundStage", stage)
|
||||
end,
|
||||
cue = function(fighters, captured, side)
|
||||
for _, fighter in fighters do
|
||||
if captured or fighter.side == side then legacy:FireClient(fighter.player, captured) end
|
||||
|
||||
@@ -120,6 +120,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
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)
|
||||
ctx.contribute(fighter.player, "deliveries", 1)
|
||||
ctx.events.fire(Kinds.FlagScored, {side = fighter.side, userId = fighter.player.UserId})
|
||||
ctx.cue(fighters, true, nil)
|
||||
putFlag(flag, flag.marker.origin, 0)
|
||||
@@ -140,6 +141,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
for _, fighter in fighters do
|
||||
if Common.boundsAt(fighter.root.Position, at, 5.5, 6.5) and Common.visibleAt(fighter, at, geometry) then
|
||||
pickUpFlag(flag, fighter)
|
||||
ctx.contribute(fighter.player, "carries", 1)
|
||||
ctx.events.fire(Kinds.FlagPicked, {side = fighter.side, userId = fighter.player.UserId, text = fighter.player.DisplayName})
|
||||
ctx.cue(fighters, false, fighter.side)
|
||||
ctx.status(Strings.flagCarrier(fighter.player.DisplayName))
|
||||
|
||||
@@ -19,14 +19,17 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
zone.marker.label.Text = key .. " · " .. site.name
|
||||
table.insert(zones, zone)
|
||||
end
|
||||
local function presence(fighters: {Fighter}, zone: Common.Zone, geometry: RaycastParams): (boolean, boolean)
|
||||
local function presence(fighters: {Fighter}, zone: Common.Zone, geometry: RaycastParams, dt: number): (boolean, boolean, {Fighter})
|
||||
local blue, orange = false, false
|
||||
local inside: {Fighter} = {}
|
||||
for _, fighter in fighters do
|
||||
if Zones.classify(fighter.root.Position, zone.site.position, SPEC, geometry) == "Inside" then
|
||||
table.insert(inside, fighter)
|
||||
ctx.contribute(fighter.player, "holdSeconds", dt)
|
||||
if fighter.side == "Blue" then blue = true else orange = true end
|
||||
end
|
||||
end
|
||||
return blue, orange
|
||||
return blue, orange, inside
|
||||
end
|
||||
local geometry = ctx.geometry
|
||||
local nextScore = ctx.liveAt + 1
|
||||
@@ -35,7 +38,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
if scoreNow then nextScore = now + 1 end
|
||||
local ownedBlue, ownedOrange = 0, 0
|
||||
for index, zone in zones do
|
||||
local b, o = presence(fighters, zone, geometry)
|
||||
local b, o, inside = presence(fighters, zone, geometry, dt)
|
||||
local side: Side? = if b == o then nil elseif b then "Blue" else "Orange"
|
||||
if side and side ~= zone.owner then
|
||||
if zone.claiming ~= side then
|
||||
@@ -46,6 +49,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
if zone.progress >= 3 then
|
||||
local previous = zone.owner
|
||||
zone.owner, zone.progress = side, 0
|
||||
for _, fighter in inside do ctx.contribute(fighter.player, "captures", 1) end
|
||||
local payload = {side = side, index = index, text = zone.marker.label.Text, value = now - ctx.liveAt}
|
||||
ctx.events.fire(Kinds.ZoneCaptured, payload)
|
||||
if previous then ctx.events.fire(Kinds.ZoneLost, {side = previous, index = index, text = payload.text}) end
|
||||
|
||||
@@ -19,7 +19,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
ctx.scoring.add(side, points, Kinds.ZoneCaptured)
|
||||
ctx.events.fire(Kinds.ZoneCaptured, {side = side, text = Strings.hotPoint})
|
||||
end,
|
||||
status = ctx.status,
|
||||
status = ctx.status, contribute = ctx.contribute,
|
||||
})
|
||||
return Common.instance(ctx, {
|
||||
step = function(now, dt, fighters, elapsed) capture.step(fighters, now, elapsed or dt); return false end,
|
||||
|
||||
@@ -56,6 +56,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
local bonus = leaders[target] == victim
|
||||
ctx.scoring.add(side, if bonus then 3 else 1, if bonus then Kinds.LeaderDown else "Elimination", player)
|
||||
if bonus then
|
||||
ctx.contribute(player, "leaderKills", 1)
|
||||
clearLeader(target)
|
||||
ctx.events.fire(Kinds.LeaderDown, {side = side, userId = player.UserId, text = victim.DisplayName})
|
||||
end
|
||||
|
||||
@@ -48,6 +48,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
local half = SiegeConfig.ATTACK_DURATION
|
||||
local elapsed = now - ctx.liveAt
|
||||
if elapsed >= half and not hadSiegeSwap then
|
||||
ctx.setStage("RoleSwap", ctx.liveAt + half + SiegeConfig.SWAP_FREEZE)
|
||||
hadSiegeSwap = true
|
||||
for _, z in zones do z.marker.body.Parent = nil end
|
||||
siegeSide, siegeIndex, siegeProgress = Common.opposite(siegeSide), 1, 0
|
||||
@@ -76,6 +77,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
ctx.status(Strings.siegeSwap)
|
||||
return false
|
||||
end
|
||||
if state:GetAttribute("RoundStage") == "RoleSwap" then ctx.setStage("Live") end
|
||||
local attacker = Strings.team(siegeSide)
|
||||
local zone = zones[siegeIndex]
|
||||
data:SetAttribute("Index", siegeIndex)
|
||||
@@ -87,10 +89,17 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
end
|
||||
zone.marker.body.Parent = folder
|
||||
local attack, defense = false, false
|
||||
local attackers: {Player} = {}
|
||||
for _, fighter in fighters do
|
||||
local reason = Zones.classify(fighter.root.Position, zone.site.position, SPEC, geometry)
|
||||
if reason == "Inside" then
|
||||
if fighter.side == siegeSide then attack = true else defense = true end
|
||||
ctx.contribute(fighter.player, "holdSeconds", dt)
|
||||
if fighter.side == siegeSide then
|
||||
attack = true
|
||||
table.insert(attackers, fighter.player)
|
||||
else
|
||||
defense = true
|
||||
end
|
||||
end
|
||||
fighter.player:SetAttribute("CitadelZone", reason)
|
||||
end
|
||||
@@ -114,6 +123,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
Common.paint(zone.marker, if phase == "Contested" then Common.orange else Common.blue)
|
||||
if phase ~= "Captured" or not Score.record(siegeTimes, siegeSide, siegeIndex, elapsed - attackStart) then return false end
|
||||
ctx.scoring.add(siegeSide, SiegeConfig.POINTS_PER_OBJECTIVE, Kinds.ZoneCaptured)
|
||||
for _, player in attackers do ctx.contribute(player, "captures", 1) end
|
||||
ctx.events.fire(Kinds.ZoneCaptured, {side = siegeSide, index = siegeIndex, text = zone.site.name, value = elapsed - attackStart})
|
||||
ctx.cue(fighters, true, nil)
|
||||
siegeCaptureStarted = false
|
||||
|
||||
@@ -55,6 +55,7 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
local amount = carried[f.player]
|
||||
if amount and Common.boundsAt(f.root.Position, if f.side == "Blue" then map.blue else map.orange, HotPoint.Radius, 7) then
|
||||
ctx.scoring.add(f.side, amount, Kinds.TokensBanked, f.player)
|
||||
ctx.contribute(f.player, "tokensBanked", amount)
|
||||
ctx.events.fire(Kinds.TokensBanked, {side = f.side, userId = f.player.UserId, value = amount})
|
||||
ctx.cue(fighters, true, nil)
|
||||
carried[f.player] = nil
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
--!strict
|
||||
local RoundState = {}
|
||||
type Movement = {humanoid: Humanoid, root: BasePart, walk: number, jumpHeight: number, jumpPower: number, wasAnchored: boolean}
|
||||
local frozen: {[Player]: Movement} = {}
|
||||
|
||||
function RoundState.thaw(player: Player)
|
||||
local old = frozen[player]
|
||||
if not old then return end
|
||||
frozen[player] = nil
|
||||
old.root.Anchored = old.wasAnchored
|
||||
if old.humanoid.WalkSpeed == 0 then old.humanoid.WalkSpeed = old.walk end
|
||||
if old.humanoid.JumpHeight == 0 then old.humanoid.JumpHeight = old.jumpHeight end
|
||||
if old.humanoid.JumpPower == 0 then old.humanoid.JumpPower = old.jumpPower end
|
||||
end
|
||||
|
||||
function RoundState.freeze(player: Player, character: Model, humanoid: Humanoid)
|
||||
local root = character:FindFirstChild("HumanoidRootPart")
|
||||
if not root or not root:IsA("BasePart") then return end
|
||||
if frozen[player] and frozen[player].root == root then return end
|
||||
RoundState.thaw(player)
|
||||
frozen[player] = {humanoid = humanoid, root = root, walk = humanoid.WalkSpeed,
|
||||
jumpHeight = humanoid.JumpHeight, jumpPower = humanoid.JumpPower, wasAnchored = root.Anchored}
|
||||
root.AssemblyLinearVelocity = Vector3.zero
|
||||
root.AssemblyAngularVelocity = Vector3.zero
|
||||
root.Anchored = true
|
||||
humanoid.WalkSpeed = 0
|
||||
humanoid.JumpHeight = 0
|
||||
humanoid.JumpPower = 0
|
||||
end
|
||||
|
||||
function RoundState.clearShield(player: Player)
|
||||
player:SetAttribute("SpawnShield", nil)
|
||||
local character = player.Character
|
||||
local old = character and character:FindFirstChild("RoundSpawnShield")
|
||||
if old then old:Destroy() end
|
||||
end
|
||||
|
||||
function RoundState.shield(player: Player, character: Model, seconds: number)
|
||||
RoundState.clearShield(player)
|
||||
if seconds <= 0 then return end
|
||||
local untilAt = workspace:GetServerTimeNow() + seconds
|
||||
local field = Instance.new("ForceField")
|
||||
field.Name = "RoundSpawnShield"
|
||||
field.Visible = false
|
||||
field.Parent = character
|
||||
player:SetAttribute("SpawnShield", untilAt)
|
||||
task.delay(seconds, function()
|
||||
field:Destroy()
|
||||
if player:GetAttribute("SpawnShield") == untilAt then player:SetAttribute("SpawnShield", nil) end
|
||||
end)
|
||||
end
|
||||
|
||||
return RoundState
|
||||
@@ -1,12 +1,13 @@
|
||||
--!strict
|
||||
local Types = require(script.Parent.Types)
|
||||
local Scoring = {}
|
||||
function Scoring.new(state: Instance, onAdd: ((Types.Side, number, string?, Player?) -> ())?): Types.Scoring
|
||||
function Scoring.new(state: Instance, onAdd: ((Types.Side, number, string?, Player?) -> ())?, finalMultiplier: number?): Types.Scoring
|
||||
local score: {[Types.Side]: number} = {Blue = 0, Orange = 0}
|
||||
state:SetAttribute("BlueScore", 0)
|
||||
state:SetAttribute("OrangeScore", 0)
|
||||
return {
|
||||
add = function(side, points, reason, credit)
|
||||
if state:GetAttribute("RoundStage") == "FinalPush" then points *= finalMultiplier or 1 end
|
||||
score[side] += points
|
||||
state:SetAttribute(side .. "Score", score[side])
|
||||
if onAdd then onAdd(side, points, reason, credit) end
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
--!strict
|
||||
export type Row = {userId: number, stats: {[string]: number}}
|
||||
local Stats = {}
|
||||
local byPlayer: {[Player]: {[string]: number}} = {}
|
||||
|
||||
function Stats.reset()
|
||||
table.clear(byPlayer)
|
||||
end
|
||||
|
||||
function Stats.add(player: Player, key: string, amount: number)
|
||||
local record = byPlayer[player]
|
||||
if not record then
|
||||
record = {}
|
||||
byPlayer[player] = record
|
||||
end
|
||||
record[key] = (record[key] or 0) + amount
|
||||
end
|
||||
|
||||
function Stats.get(player: Player): {[string]: number}
|
||||
return table.clone(byPlayer[player] or {})
|
||||
end
|
||||
|
||||
function Stats.remove(player: Player)
|
||||
byPlayer[player] = nil
|
||||
end
|
||||
|
||||
function Stats.mvp(rows: {Row}, weights: {[string]: number}): number?
|
||||
local best: number? = nil
|
||||
local bestScore = -math.huge
|
||||
for _, row in rows do
|
||||
local score = 0
|
||||
for key, weight in weights do score += (row.stats[key] or 0) * weight end
|
||||
if score > bestScore or (score == bestScore and best ~= nil and row.userId < best) then
|
||||
best, bestScore = row.userId, score
|
||||
end
|
||||
end
|
||||
return best
|
||||
end
|
||||
|
||||
return Stats
|
||||
@@ -13,7 +13,8 @@ export type ModeContext = {
|
||||
arena: string, rule: string, state: Instance, liveAt: number, duration: number, world: Model,
|
||||
geometry: RaycastParams, folder: Folder, map: Sites.Map?,
|
||||
members: () -> {Player}, bench: (Player) -> (), deploy: (Player) -> (), balanceWaiting: () -> (),
|
||||
scoring: Scoring, events: Events, status: (string) -> (), setStage: (string) -> (), janitor: Janitor,
|
||||
scoring: Scoring, events: Events, status: (string) -> (), setStage: (string, number?) -> (), janitor: Janitor,
|
||||
contribute: (Player, string, number) -> (),
|
||||
cue: ({Fighter}, boolean, Side?) -> (), legacy: (Player, string) -> (),
|
||||
}
|
||||
export type ModeInstance = {
|
||||
|
||||
Reference in new issue
Block a user