125 lines
5.7 KiB
Luau
125 lines
5.7 KiB
Luau
--!strict
|
|
local Diagnostics = require(script.Parent.ZoneDiagnostics)
|
|
local Types = require(script.Parent.Types)
|
|
local HotPoint = require(script.Parent.Parent.HotPoint)
|
|
local Sites = require(script.Parent.Parent.ArenaObjectiveSites)
|
|
local Strings = require(game.ReplicatedStorage.Hunter.Strings)
|
|
type Side = Types.Side
|
|
type Fighter = Types.Fighter
|
|
export type Marker = HotPoint.Marker & {recolor: ((Color3) -> ())?}
|
|
export type Zone = {site: Sites.Site, marker: Marker, owner: Side?, claiming: Side?, progress: number}
|
|
local sides: {Side} = {"Blue", "Orange"}
|
|
local blue = Color3.fromRGB(67, 216, 255)
|
|
local orange = Color3.fromRGB(255, 150, 68)
|
|
local gold = Color3.fromRGB(255, 220, 96)
|
|
local neutral = Color3.fromRGB(255, 220, 96)
|
|
local function opposite(side: Side): Side
|
|
return if side == "Blue" then "Orange" else "Blue"
|
|
end
|
|
|
|
local function color(side: Side?): Color3
|
|
return if side == "Blue" then blue elseif side == "Orange" then orange else neutral
|
|
end
|
|
|
|
local function sideOf(player: Player): Side?
|
|
local side = player:GetAttribute("ArenaTeam")
|
|
return if side == "Blue" then "Blue" elseif side == "Orange" then "Orange" else nil
|
|
end
|
|
|
|
local function boundsAt(position: Vector3, target: Vector3, radius: number, height: number): boolean
|
|
local delta = position - target
|
|
return math.abs(delta.Y) < height and delta.X * delta.X + delta.Z * delta.Z <= radius * radius
|
|
end
|
|
|
|
local function label(adornee: BasePart, name: string, tint: Color3, offset: number, waypoint: boolean?): TextLabel
|
|
local gui = Instance.new("BillboardGui")
|
|
gui.Name = "ObjectiveLabel"
|
|
gui.Size = UDim2.fromOffset(220, 26)
|
|
gui.StudsOffsetWorldSpace = Vector3.yAxis * offset
|
|
gui.MaxDistance = if waypoint then 710 else 170
|
|
gui.AlwaysOnTop = waypoint == true
|
|
gui.LightInfluence = 0
|
|
gui.Parent = adornee
|
|
local text = Instance.new("TextLabel")
|
|
text.Size = UDim2.fromScale(1, 1)
|
|
text.BackgroundTransparency = 1
|
|
text.Font = Enum.Font.GothamBlack
|
|
text.TextSize = 15
|
|
text.Text, text.TextColor3 = name, tint
|
|
text.TextStrokeColor3, text.TextStrokeTransparency = Color3.fromRGB(9, 13, 25), .14
|
|
text.Parent = gui
|
|
return text
|
|
end
|
|
|
|
local function marker(parent: Instance, id: string, name: string, at: Vector3, tint: Color3, diameter: number, tall: boolean?): Marker
|
|
local part = Instance.new("Part")
|
|
part.Name = id
|
|
if not tall then part:SetAttribute("ObjectiveArrow", true) end
|
|
part.Shape = if tall then Enum.PartType.Ball else Enum.PartType.Cylinder
|
|
part.Size = if tall then Vector3.new(diameter, diameter, diameter) else Vector3.new(.16, diameter, diameter)
|
|
part.CFrame = CFrame.new(at + Vector3.yAxis * (if tall then 2.4 else .12)) * CFrame.Angles(0, 0, math.pi / 2)
|
|
part.Anchored, part.CanCollide, part.CanQuery, part.CanTouch, part.CastShadow = true, false, false, false, false
|
|
part.Material, part.Color = Enum.Material.Neon, tint
|
|
part.Transparency = if tall then .04 else .76
|
|
local aura = Instance.new("PointLight")
|
|
aura.Range, aura.Brightness, aura.Color = if tall then 13 else 9, .7, tint
|
|
aura.Parent = part
|
|
part.Parent = parent
|
|
return {body = part, label = label(part, name, tint, if tall then 2.1 else 4, id ~= "Tokens"), origin = at}
|
|
end
|
|
|
|
local function ring(parent: Instance, id: string, name: string, at: Vector3, tint: Color3, radius: number?): Marker
|
|
local r = radius or HotPoint.Radius
|
|
local mark = marker(parent, id, name, at, tint, r * 2)
|
|
local recolor = HotPoint.attachRing(mark, r)
|
|
mark.recolor = recolor
|
|
recolor(tint)
|
|
return mark
|
|
end
|
|
|
|
local function paint(mark: Marker, tint: Color3)
|
|
if mark.body.Color == tint then return end
|
|
if mark.recolor then
|
|
mark.recolor(tint)
|
|
return
|
|
end
|
|
mark.body.Color = tint
|
|
mark.label.TextColor3 = tint
|
|
local aura = mark.body:FindFirstChildOfClass("PointLight")
|
|
if aura then aura.Color = tint end
|
|
end
|
|
local function visibleAt(fighter: Fighter, at: Vector3, geometry: RaycastParams): boolean
|
|
return Diagnostics.raycast(fighter.root.Position, at - fighter.root.Position, geometry) == nil
|
|
end
|
|
local function makeZone(folder: Folder, geometry: RaycastParams, site: Sites.Site, name: string, radius: number?, tint: Color3?): Zone
|
|
local r = radius or HotPoint.Radius
|
|
local center, fits = Sites.clearCircle(site.position, geometry, r)
|
|
if radius and not fits then warn("Нет свободного места для рубежа:", site.name) end
|
|
site = {name = site.name, position = center}
|
|
return {site = site, marker = ring(folder, name, site.name, center, tint or neutral, r), owner = nil, claiming = nil, progress = 0}
|
|
end
|
|
local function bases(folder: Folder, geometry: RaycastParams, map: Sites.Map)
|
|
map.blue = Sites.clearCircle(map.blue, geometry, HotPoint.Radius)
|
|
map.orange = Sites.clearCircle(map.orange, geometry, HotPoint.Radius)
|
|
for _, side in sides do
|
|
local at = if side == "Blue" then map.blue else map.orange
|
|
ring(folder, side .. "Base", Strings.bases[side], at, color(side))
|
|
end
|
|
end
|
|
local function winner(scoring: Types.Scoring): (string, string?)
|
|
local b, o = scoring.get("Blue"), scoring.get("Orange")
|
|
local side = if b == o then "Draw" elseif b > o then "Blue" else "Orange"
|
|
return side, nil
|
|
end
|
|
local function instance(ctx: Types.ModeContext, callbacks: {[string]: any}): Types.ModeInstance
|
|
local function noop() end
|
|
return {
|
|
step = callbacks.step or function() return false end, kill = callbacks.kill or noop,
|
|
hit = callbacks.hit, death = callbacks.death or noop, leaving = callbacks.leaving or noop,
|
|
winner = callbacks.winner or function() return winner(ctx.scoring) end, destroy = callbacks.destroy or noop,
|
|
}
|
|
end
|
|
return {sides = sides, blue = blue, orange = orange, gold = gold, neutral = neutral, opposite = opposite,
|
|
color = color, sideOf = sideOf, boundsAt = boundsAt, label = label, marker = marker, ring = ring,
|
|
paint = paint, visibleAt = visibleAt, makeZone = makeZone, bases = bases, instance = instance}
|