mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-24 09:08:04 +03:00
This cherry-pick's Wizden's Antag Refactor, which is needed for all future antag updates, as well as for me to cherry-pick over Cultists(Who are going to need some editing to fit the antag refactor), Changelings, Heretics, and Wizards. I actually selected the White-Dream-Public version of the Antag Refactor, due to it having commits made tailored to our repository, so it comes prepackaged with all the changes necessary for our repo-specific content. https://github.com/frosty-dev/ss14-wwdp/pull/10 Signed-off-by: Timemaster99 <57200767+Timemaster99@users.noreply.github.com> Co-authored-by: ThereDrD <88589686+ThereDrD0@users.noreply.github.com> Co-authored-by: Jeff <velcroboy333@hotmail.com> Co-authored-by: Timemaster99 <57200767+Timemaster99@users.noreply.github.com> Co-authored-by: Timemaster99 <elijahrobot@gmail.com> Co-authored-by: luckywill339@gmail.com <luckywill339@gmail.com> Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com> Co-authored-by: Azzy <azzydev@icloud.com>
81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
using Content.Server.Antag;
|
|
using Content.Server.GameTicking.Components;
|
|
using Content.Server.GameTicking.Rules.Components;
|
|
using Content.Server.Spawners.Components;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Server.Maps;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.GameTicking.Rules;
|
|
|
|
public sealed class LoadMapRuleSystem : GameRuleSystem<LoadMapRuleComponent>
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly MapSystem _map = default!;
|
|
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;
|
|
[Dependency] private readonly TransformSystem _transform = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<LoadMapRuleComponent, AntagSelectLocationEvent>(OnSelectLocation);
|
|
SubscribeLocalEvent<GridSplitEvent>(OnGridSplit);
|
|
}
|
|
|
|
private void OnGridSplit(ref GridSplitEvent args)
|
|
{
|
|
var rule = QueryActiveRules();
|
|
while (rule.MoveNext(out _, out var mapComp, out _))
|
|
{
|
|
if (!mapComp.MapGrids.Contains(args.Grid))
|
|
continue;
|
|
|
|
mapComp.MapGrids.AddRange(args.NewGrids);
|
|
break;
|
|
}
|
|
}
|
|
|
|
protected override void Added(EntityUid uid, LoadMapRuleComponent comp, GameRuleComponent rule, GameRuleAddedEvent args)
|
|
{
|
|
if (comp.Map != null)
|
|
return;
|
|
|
|
_map.CreateMap(out var mapId);
|
|
comp.Map = mapId;
|
|
|
|
if (comp.GameMap != null)
|
|
{
|
|
var gameMap = _prototypeManager.Index(comp.GameMap.Value);
|
|
comp.MapGrids.AddRange(GameTicker.LoadGameMap(gameMap, comp.Map.Value, new MapLoadOptions()));
|
|
}
|
|
else if (comp.MapPath != null)
|
|
{
|
|
if (_mapLoader.TryLoad(comp.Map.Value, comp.MapPath.Value.ToString(), out var roots, new MapLoadOptions { LoadMap = true }))
|
|
comp.MapGrids.AddRange(roots);
|
|
}
|
|
else
|
|
{
|
|
Log.Error($"No valid map prototype or map path associated with the rule {ToPrettyString(uid)}");
|
|
}
|
|
}
|
|
|
|
private void OnSelectLocation(Entity<LoadMapRuleComponent> ent, ref AntagSelectLocationEvent args)
|
|
{
|
|
var query = EntityQueryEnumerator<SpawnPointComponent, TransformComponent>();
|
|
while (query.MoveNext(out var uid, out _, out var xform))
|
|
{
|
|
if (xform.MapID != ent.Comp.Map)
|
|
continue;
|
|
|
|
if (xform.GridUid == null || !ent.Comp.MapGrids.Contains(xform.GridUid.Value))
|
|
continue;
|
|
|
|
if (ent.Comp.SpawnerWhitelist != null && !ent.Comp.SpawnerWhitelist.IsValid(uid, EntityManager))
|
|
continue;
|
|
|
|
args.Coordinates.Add(_transform.GetMapCoordinates(xform));
|
|
}
|
|
}
|
|
}
|