Refactor arena modes and add objective event feed
This commit is contained in:
1 parent
df6ab8efe1
commit
b87a3770a1
26 files changed
+1221
-654
No files matched your search
@@ -0,0 +1,71 @@
|
||||
--!strict
|
||||
local Runtime = script.Parent.Parent
|
||||
local Types = require(Runtime.Types)
|
||||
local Common = require(Runtime.Common)
|
||||
local Kinds = require(game.ReplicatedStorage.Hunter.EventKinds)
|
||||
local Strings = require(game.ReplicatedStorage.Hunter.Strings)
|
||||
type Fighter = Types.Fighter
|
||||
type Side = Types.Side
|
||||
local rng = Random.new()
|
||||
|
||||
local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
local leaders: {[Side]: Player} = {}
|
||||
local previousLeader: {[Side]: Player} = {}
|
||||
local leaderLabels: {[Player]: BillboardGui} = {}
|
||||
local function clearLeader(side: Side)
|
||||
local p = leaders[side]
|
||||
if not p then return end
|
||||
previousLeader[side] = p
|
||||
leaders[side] = nil
|
||||
p:SetAttribute("ArenaLeader", nil)
|
||||
local badge = leaderLabels[p]
|
||||
if badge then badge:Destroy() end
|
||||
leaderLabels[p] = nil
|
||||
end
|
||||
local function updateLeaders(fighters: {Fighter})
|
||||
for _, side in Common.sides do
|
||||
local roster: {Fighter} = {}
|
||||
local present = false
|
||||
for _, f in fighters do
|
||||
if f.side ~= side then continue end
|
||||
table.insert(roster, f)
|
||||
if f.player == leaders[side] then present = true end
|
||||
end
|
||||
if present then continue end
|
||||
clearLeader(side)
|
||||
if #roster == 0 then continue end
|
||||
local pick = rng:NextInteger(1, #roster)
|
||||
if #roster > 1 and roster[pick].player == previousLeader[side] then pick = pick % #roster + 1 end
|
||||
local p = roster[pick].player
|
||||
local head = p.Character and p.Character:FindFirstChild("Head")
|
||||
if not head or not head:IsA("BasePart") then continue end
|
||||
leaders[side] = p
|
||||
p:SetAttribute("ArenaLeader", true)
|
||||
leaderLabels[p] = Common.label(head, Strings.leaderLabel, Common.gold, 2.7).Parent :: BillboardGui
|
||||
ctx.events.fire(Kinds.LeaderAssigned, {side = side, userId = p.UserId, text = p.DisplayName})
|
||||
end
|
||||
local a, b = leaders.Blue, leaders.Orange
|
||||
ctx.status(Strings.leaders(if a then a.DisplayName else nil, if b then b.DisplayName else nil))
|
||||
end
|
||||
return Common.instance(ctx, {
|
||||
step = function(_, _, fighters) updateLeaders(fighters); return false end,
|
||||
kill = function(player, victim)
|
||||
local side = Common.sideOf(player)
|
||||
if not side then return end
|
||||
local target = Common.opposite(side)
|
||||
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
|
||||
clearLeader(target)
|
||||
ctx.events.fire(Kinds.LeaderDown, {side = side, userId = player.UserId, text = victim.DisplayName})
|
||||
end
|
||||
end,
|
||||
leaving = function(player)
|
||||
local side = Common.sideOf(player)
|
||||
if side and leaders[side] == player then clearLeader(side) end
|
||||
end,
|
||||
destroy = function() for _, side in Common.sides do clearLeader(side) end end,
|
||||
})
|
||||
end
|
||||
|
||||
return {id = "HuntLeader", usesMap = false, start = start}
|
||||
Reference in new issue
Block a user