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,83 @@
|
||||
--!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
|
||||
local HotPoint = require(Runtime.Parent.HotPoint)
|
||||
type Drop = {marker: Common.Marker, amount: number, expires: number}
|
||||
|
||||
local function start(ctx: Types.ModeContext): Types.ModeInstance
|
||||
local map, geometry, folder = assert(ctx.map), ctx.geometry, ctx.folder
|
||||
Common.bases(folder, geometry, map)
|
||||
local tokens: {Drop} = {}
|
||||
local carried: {[Player]: number} = {}
|
||||
local function floorAt(at: Vector3): Vector3
|
||||
local hit = workspace:Raycast(at + Vector3.yAxis * .3, -Vector3.yAxis * 50, geometry)
|
||||
return if hit then hit.Position else map.ground.position
|
||||
end
|
||||
local function tokenDrop(at: Vector3, amount: number, now: number)
|
||||
local floor = floorAt(at)
|
||||
ctx.events.fire(Kinds.TokenDropped, {at = floor, value = amount})
|
||||
for _, existing in tokens do
|
||||
if Common.boundsAt(existing.marker.origin, floor, 3.5, 3) then
|
||||
existing.amount += amount
|
||||
existing.expires = now + 42
|
||||
existing.marker.label.Text = Strings.tokens(existing.amount)
|
||||
return
|
||||
end
|
||||
end
|
||||
if #tokens >= 60 then
|
||||
local old = table.remove(tokens, 1)
|
||||
old.marker.body:Destroy()
|
||||
end
|
||||
table.insert(tokens, {marker = Common.marker(folder, "Tokens", Strings.tokens(amount), floor, Common.gold, 1.55, true), amount = amount, expires = now + 42})
|
||||
end
|
||||
local function runTrophies(fighters: {Fighter}, now: number)
|
||||
for i = #tokens, 1, -1 do
|
||||
local token = tokens[i]
|
||||
local collector: Fighter? = nil
|
||||
if now < token.expires then
|
||||
for _, f in fighters do
|
||||
if Common.boundsAt(f.root.Position, token.marker.origin, 5, 6) and Common.visibleAt(f, token.marker.body.Position, geometry) then collector = f; break end
|
||||
end
|
||||
if not collector then continue end
|
||||
local p = collector.player
|
||||
if not carried[p] then ctx.cue(fighters, false, collector.side) end
|
||||
carried[p] = (carried[p] or 0) + token.amount
|
||||
p:SetAttribute("ArenaTokens", carried[p])
|
||||
end
|
||||
token.marker.body:Destroy()
|
||||
table.remove(tokens, i)
|
||||
end
|
||||
for _, f in fighters do
|
||||
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.events.fire(Kinds.TokensBanked, {side = f.side, userId = f.player.UserId, value = amount})
|
||||
ctx.cue(fighters, true, nil)
|
||||
carried[f.player] = nil
|
||||
f.player:SetAttribute("ArenaTokens", nil)
|
||||
end
|
||||
end
|
||||
ctx.status(Strings.trophyStatus)
|
||||
end
|
||||
local function drop(player: Player, at: Vector3?, now: number)
|
||||
local amount = carried[player]
|
||||
if not amount then return end
|
||||
carried[player] = nil
|
||||
player:SetAttribute("ArenaTokens", nil)
|
||||
if at then tokenDrop(at, amount, now) end
|
||||
end
|
||||
return Common.instance(ctx, {
|
||||
step = function(now, _, fighters) runTrophies(fighters, now); return false end,
|
||||
kill = function(player, _, at, now)
|
||||
if Common.sideOf(player) then tokenDrop(at, 1, now) end
|
||||
end,
|
||||
death = drop, leaving = drop,
|
||||
destroy = function() for p in carried do p:SetAttribute("ArenaTokens", nil) end end,
|
||||
})
|
||||
end
|
||||
|
||||
return {id = "TrophyHunt", usesMap = true, start = start}
|
||||
Reference in new issue
Block a user