Polish One Life mini-rounds and spectating
This commit is contained in:
1 parent
0c949fadf0
commit
ebe8db5359
12 files changed
+175
-17
No files matched your search
@@ -4,25 +4,30 @@ local Types = require(Runtime.Types)
|
||||
local Common = require(Runtime.Common)
|
||||
local Kinds = require(game.ReplicatedStorage.Hunter.EventKinds)
|
||||
local Strings = require(game.ReplicatedStorage.Hunter.Strings)
|
||||
local Rules = require(Runtime.OneLifeRules)
|
||||
type Fighter = Types.Fighter
|
||||
|
||||
local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
local lifeActive, miniNumber = false, 0
|
||||
local lifeEnds, nextMini = math.huge, ctx.liveAt + 2
|
||||
local lifeEnds, nextMini = math.huge, ctx.liveAt
|
||||
local state = ctx.state
|
||||
local function runOneLife(members: {Player}, fighters: {Fighter}, now: number): boolean
|
||||
if lifeActive then
|
||||
local b, o = 0, 0
|
||||
for _, f in fighters do if f.side == "Blue" then b += 1 else o += 1 end end
|
||||
state:SetAttribute("MiniAliveBlue", b)
|
||||
state:SetAttribute("MiniAliveOrange", o)
|
||||
if (b > 0 and o > 0) and now < lifeEnds then
|
||||
ctx.status(Strings.lifeActive(miniNumber, b, o, math.ceil(lifeEnds - now)))
|
||||
return false
|
||||
end
|
||||
local side: Types.Side? = if b == o then nil elseif b > o then "Blue" else "Orange"
|
||||
local side = Rules.winner(b,o)
|
||||
if side then ctx.scoring.add(side, 1, Kinds.MiniRoundEnded) end
|
||||
ctx.events.fire(Kinds.MiniRoundEnded, {side = side, index = miniNumber})
|
||||
if ctx.scoring.get("Blue") >= 3 or ctx.scoring.get("Orange") >= 3 then return true end
|
||||
state:SetAttribute("MiniRoundActive", false)
|
||||
ctx.events.fire(Kinds.MiniRoundEnded, {side = side, index = miniNumber, blue = b, orange = o})
|
||||
if Rules.finished(ctx.scoring.get("Blue"),ctx.scoring.get("Orange")) then return true end
|
||||
for _, p in members do ctx.bench(p) end
|
||||
lifeActive, nextMini = false, now + 4
|
||||
lifeActive, nextMini = false, now + Rules.INTERMISSION
|
||||
end
|
||||
if now >= nextMini then ctx.balanceWaiting() end
|
||||
local ready: {Player} = {}
|
||||
@@ -37,12 +42,16 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
if b and o and now >= nextMini then
|
||||
for _, p in ready do ctx.deploy(p) end
|
||||
miniNumber += 1
|
||||
lifeActive, lifeEnds = true, now + 45
|
||||
lifeActive, lifeEnds = true, now + Rules.DURATION
|
||||
state:SetAttribute("MiniRoundActive",true)
|
||||
state:SetAttribute("MiniRoundNextAt",nil)
|
||||
ctx.status(Strings.lifeStart(miniNumber))
|
||||
ctx.events.fire(Kinds.MiniRoundStarted, {index = miniNumber})
|
||||
ctx.events.fire(Kinds.MiniRoundStarted, {index = miniNumber, blue = ctx.scoring.get("Blue"), orange = ctx.scoring.get("Orange")})
|
||||
elseif not b or not o then
|
||||
state:SetAttribute("MiniRoundNextAt",nil)
|
||||
ctx.status(Strings.lifeWaiting)
|
||||
else
|
||||
state:SetAttribute("MiniRoundNextAt",nextMini)
|
||||
ctx.status(Strings.lifeNext(math.ceil(nextMini - now)))
|
||||
end
|
||||
return false
|
||||
@@ -50,6 +59,9 @@ local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
return Common.instance(ctx, {
|
||||
step = function(now, _, fighters) return runOneLife(ctx.members(), fighters, now) end,
|
||||
death = function(player) ctx.bench(player) end,
|
||||
destroy = function()
|
||||
for _, name in {"MiniRoundActive","MiniRoundNextAt","MiniAliveBlue","MiniAliveOrange"} do state:SetAttribute(name,nil) end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user