Files
crystall-punk-14/Content.Server/_CP14/StationDungeonMap/CP14StationDungeonMapSystem.cs
Ed 811cc8a41d Underworld + Overworld (#151)
* Setup new dungeon system (v2)

* add custom basic generation

* add maps linking

shitcode, boo

* add auto linking sub-world portal

* fix deleted component

* clearing otherside of the tiles manually (im stuck in wall, brother!)

* Upgrade cave biome generation

* add TODO

* add ladder and hole sprites

* add dungeon entrance prototypes

* clean up, add docs

* add many ambient sounds

* Update CP14StationDungeonMapSystem.cs

* remove bugs
2024-05-17 17:07:29 +03:00

55 lines
2.0 KiB
C#

using Content.Server.Parallax;
using Content.Server.Station.Components;
using Content.Server.Station.Events;
using Content.Server.Station.Systems;
using Content.Shared.Teleportation.Systems;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
namespace Content.Server._CP14.StationDungeonMap;
public sealed partial class CP14StationDungeonMapSystem : EntitySystem
{
[Dependency] private readonly BiomeSystem _biome = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly MapSystem _map = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly LinkedEntitySystem _linkedEntity = default!;
[Dependency] private readonly StationSystem _station = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14StationDungeonMapComponent, StationPostInitEvent>(OnStationPostInit);
}
private void OnStationPostInit(Entity<CP14StationDungeonMapComponent> map, ref StationPostInitEvent args)
{
if (!TryComp(map, out StationDataComponent? dataComp))
return;
var mapUid = _map.CreateMap(out var mapId);
_metaData.SetEntityName(mapUid, map.Comp.MapName);
_biome.EnsurePlanet(mapUid, _proto.Index(map.Comp.Biome), map.Comp.Seed, mapLight: map.Comp.MapLightColor);
EntityManager.AddComponents(mapUid, map.Comp.Components);
TryLinkDungeonAndStationMaps(dataComp, mapUid);
}
private bool TryLinkDungeonAndStationMaps(StationDataComponent dataComp, EntityUid mapUid)
{
var station = _station.GetLargestGrid(dataComp);
if (station == null)
return false;
var stationMapId = Transform(station.Value).MapID;
_map.TryGetMap(stationMapId, out var stationMapUid);
if (stationMapUid == null)
return false;
return _linkedEntity.TryLink(mapUid, stationMapUid.Value);
}
}