Files
Hunter/scripts/ModeRuntime/Modes/Domination.luau
T

70 lines
2.7 KiB
Luau

--!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)
local Zones = require(Runtime.Zones)
local HotPoint = require(Runtime.Parent.HotPoint)
type Fighter = Types.Fighter
type Side = Types.Side
local SPEC: Zones.Spec = {radius = HotPoint.Radius, height = 8, sightHeight = 2.7, exclusiveHeight = true}
local function start(ctx: Types.ModeContext): Types.ModeInstance
local map = assert(ctx.map)
local zones: {Common.Zone} = {}
for i, site in {map.west, map.gallery, map.east} do
local key = string.char(64 + i)
local zone = Common.makeZone(ctx.folder, ctx.geometry, site, key)
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 blue, orange = false, false
for _, fighter in fighters do
if Zones.classify(fighter.root.Position, zone.site.position, SPEC, geometry) == "Inside" then
if fighter.side == "Blue" then blue = true else orange = true end
end
end
return blue, orange
end
local geometry = ctx.geometry
local nextScore = ctx.liveAt + 1
return Common.instance(ctx, {step = function(now, dt, fighters)
local scoreNow = now >= nextScore
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 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
zone.claiming, zone.progress = side, 0
ctx.cue(fighters, false, side)
end
zone.progress += dt
if zone.progress >= 3 then
local previous = zone.owner
zone.owner, zone.progress = side, 0
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
ctx.cue(fighters, true, nil)
end
else
zone.claiming, zone.progress = nil, 0
end
Common.paint(zone.marker, Common.color(zone.owner))
if zone.owner == "Blue" then ownedBlue += 1 elseif zone.owner == "Orange" then ownedOrange += 1 end
end
if scoreNow then
if ownedBlue > 0 then ctx.scoring.add("Blue", ownedBlue) end
if ownedOrange > 0 then ctx.scoring.add("Orange", ownedOrange) end
end
ctx.status(Strings.dominationStatus(ownedBlue, ownedOrange))
return false
end})
end
return {id = "Domination", usesMap = true, start = start}