--!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 Run = require(Runtime.DominationRules) local RADIUS = HotPoint.Radius -- Общий радиус зон до отдельного баланса режима. local SPEC: Zones.Spec = {radius = 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} = {} local contested: {[number]: boolean} = {} local affected: {[Player]: boolean} = {} local state = ctx.state local full: Side? = nil 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, dt: number, reasons: {[Player]: string}): (boolean, boolean, {Fighter}) local blue, orange = false, false local inside: {Fighter} = {} for _, fighter in fighters do local reason = Zones.classify(fighter.root.Position, zone.site.position, SPEC, geometry) if reason ~= "Outside" and reasons[fighter.player] ~= "Inside" then reasons[fighter.player] = reason end if reason == "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, inside end local geometry = ctx.geometry local nextScore = ctx.liveAt + 1 return Common.instance(ctx, {step = function(now, dt, fighters) local scoreNow, nextAt = Run.tick(now, nextScore) nextScore = nextAt local reasons: {[Player]: string} = {} local ownedBlue, ownedOrange = 0, 0 for index, zone in zones do local b, o, inside = presence(fighters, zone, geometry, dt, reasons) local key = string.char(64 + index) if b and o and not contested[index] then ctx.events.fire(Kinds.ZoneContested, {index = index, text = key}) end contested[index] = b and o local side = Run.claimSide(b, o) 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 >= Run.CAPTURE_SECONDS 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, at = zone.site.position} 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 local shade = Common.color(zone.owner) Common.paint(zone.marker, if contested[index] then shade:Lerp(Color3.fromRGB(80, 88, 103), .55) else shade) state:SetAttribute("ZoneOwner_" .. key, zone.owner) state:SetAttribute("ZoneClaim_" .. key, zone.claiming) state:SetAttribute("ZoneProgress_" .. key, math.clamp(zone.progress / Run.CAPTURE_SECONDS, 0, 1)) state:SetAttribute("ZoneContested_" .. key, contested[index]) if zone.owner == "Blue" then ownedBlue += 1 elseif zone.owner == "Orange" then ownedOrange += 1 end end for player in affected do if not reasons[player] then player:SetAttribute("DominationZone", nil); affected[player] = nil end end for player, reason in reasons do affected[player] = true player:SetAttribute("DominationZone", reason) end state:SetAttribute("ScoreRate_Blue", ownedBlue) state:SetAttribute("ScoreRate_Orange", ownedOrange) local owner: Side? = if ownedBlue == #zones then "Blue" elseif ownedOrange == #zones then "Orange" else nil if owner ~= full then full = owner if owner then ctx.events.fire(Kinds.FullControl, {side = owner}) 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, destroy = function() for player in affected do player:SetAttribute("DominationZone", nil) end for _, id in {"A", "B", "C"} do for _, name in {"ZoneOwner_", "ZoneClaim_", "ZoneProgress_", "ZoneContested_"} do state:SetAttribute(name .. id, nil) end end state:SetAttribute("ScoreRate_Blue", nil) state:SetAttribute("ScoreRate_Orange", nil) end}) end return {id = "Domination", usesMap = true, start = start}