Ghost z-levels move actions + mapping z-levels combine command (#654)

* some setup

* fast ghost zlevels-moving

* zlevel combine command for mapping
This commit is contained in:
Ed
2024-12-09 20:39:46 +03:00
committed by GitHub
parent 5384adb2b3
commit bec8d7a7d4
17 changed files with 320 additions and 165 deletions

View File

@@ -213,18 +213,22 @@ namespace Content.Server.Ghost
private void OnMapInit(EntityUid uid, GhostComponent component, MapInitEvent args)
{
if (_actions.AddAction(uid, ref component.BooActionEntity, out var act, component.BooAction)
&& act.UseDelay != null)
{
var start = _gameTiming.CurTime;
var end = start + act.UseDelay.Value;
_actions.SetCooldown(component.BooActionEntity.Value, start, end);
}
//if (_actions.AddAction(uid, ref component.BooActionEntity, out var act, component.BooAction)
// && act.UseDelay != null)
//{
// var start = _gameTiming.CurTime;
// var end = start + act.UseDelay.Value;
// _actions.SetCooldown(component.BooActionEntity.Value, start, end);
//}
_actions.AddAction(uid, ref component.ToggleGhostHearingActionEntity, component.ToggleGhostHearingAction);
_actions.AddAction(uid, ref component.ToggleLightingActionEntity, component.ToggleLightingAction);
_actions.AddAction(uid, ref component.ToggleFoVActionEntity, component.ToggleFoVAction);
_actions.AddAction(uid, ref component.ToggleGhostsActionEntity, component.ToggleGhostsAction);
//CP14
_actions.AddAction(uid, ref component.CP14ZLevelUpActionEntity, component.CP14ZLevelUpAction);
_actions.AddAction(uid, ref component.CP14ZLevelDownActionEntity, component.CP14ZLevelDownAction);
//CP14 end
}
private void OnGhostExamine(EntityUid uid, GhostComponent component, ExaminedEvent args)

View File

@@ -1,5 +1,4 @@
using Content.Server.Administration;
using Content.Shared._CP14.DayCycle;
using Content.Shared.Administration;
using Robust.Shared.Console;
using CP14DayCycleComponent = Content.Shared._CP14.DayCycle.Components.CP14DayCycleComponent;

View File

@@ -1,16 +0,0 @@
using Robust.Shared.Map;
namespace Content.Server._CP14.PortalAutoLink;
/// <summary>
/// allows you to automatically link entities to each other, through key matching searches
/// </summary>
[RegisterComponent, Access(typeof(CP14AutoLinkSystem))]
public sealed partial class CP14AutoLinkComponent : Component
{
/// <summary>
/// a key that is used to search for another autolinked entity installed in the worlds
/// </summary>
[DataField]
public string? AutoLinkKey = "Hello";
}

View File

@@ -1,44 +0,0 @@
using Content.Shared.Interaction;
using Content.Shared.Teleportation.Systems;
namespace Content.Server._CP14.PortalAutoLink;
public sealed partial class CP14AutoLinkSystem : EntitySystem
{
[Dependency] private readonly LinkedEntitySystem _link = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14AutoLinkComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(Entity<CP14AutoLinkComponent> autolink, ref MapInitEvent args)
{
TryAutoLink(autolink, out var otherLink);
}
public bool TryAutoLink(Entity<CP14AutoLinkComponent> autolink, out EntityUid? linkedEnt)
{
linkedEnt = null;
var query = EntityQueryEnumerator<CP14AutoLinkComponent>();
while (query.MoveNext(out var uid, out var otherAutolink))
{
if (autolink.Comp == otherAutolink)
continue;
if (autolink.Comp.AutoLinkKey == otherAutolink.AutoLinkKey)
{
if (_link.TryLink(autolink, uid, false))
{
RemComp<CP14AutoLinkComponent>(uid);
RemComp<CP14AutoLinkComponent>(autolink);
return true;
}
}
}
return false;
}
}

View File

@@ -0,0 +1,94 @@
using System.Linq;
using Content.Server._CP14.ZLevels.Components;
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.Map;
namespace Content.Server._CP14.ZLevels.Commands;
[AdminCommand(AdminFlags.VarEdit)]
public sealed class CP14CombineMapsIntoZLevelsCommand : LocalizedCommands
{
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IMapManager _map = default!;
private const string Name = "cp14-combineMapsIntoZLevels";
public override string Command => Name;
public override string Description => "Connects a number of maps into a common network of z-levels. Does not work if one of the maps is already in the z-level network";
public override string Help => $"{Name} <MapId 1> <MapId 2> ... <MapId X> (from ground to sky)";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length == 1)
{
shell.WriteError("Not enough maps to form a network of levels");
return;
}
List<MapId> maps = new();
foreach (var arg in args)
{
if (!int.TryParse(arg, out var mapIdInt))
{
shell.WriteError($"Cannot parse `{arg}` into mapId");
return;
}
var mapId = new MapId(mapIdInt);
if (mapId == MapId.Nullspace)
{
shell.WriteError($"Cannot parse NullSpace");
return;
}
if (!_map.MapExists(mapId))
{
shell.WriteError($"Map {mapId} dont exist");
return;
}
//if (!_mapSystem.TryGetMap(mapId, out var mapUid))
//{
// shell.WriteError($"Map {mapId} dont exist");
// return;
//}
if (maps.Contains(mapId))
{
shell.WriteError($"Duplication maps: {mapId}");
return;
}
maps.Add(mapId);
}
//Check maps already in zLevel links
var query = _entities.EntityQueryEnumerator<CP14StationZLevelsComponent>();
while (query.MoveNext(out var uid, out var zLevelComp))
{
foreach (var findMap in maps)
{
if (zLevelComp.LevelEntities.ContainsKey(findMap))
{
shell.WriteError($"{findMap} already in z-level network! Z-Network Entity: {uid}");
return;
}
}
}
//Ok, all check passed, we create new z-level network
var zLevelEnt = _entities.Spawn();
_entities.EnsureComponent<CP14StationZLevelsComponent>(zLevelEnt, out var newZLevelComp);
var count = 0;
foreach (var map in maps)
{
newZLevelComp.LevelEntities.Add(map, count);
count++;
}
shell.WriteLine($"Successfully created z-level network! Z-Network entity: {zLevelEnt}");
}
}

View File

@@ -1,13 +1,14 @@
using Content.Server._CP14.StationDungeonMap.EntitySystems;
using Content.Server._CP14.ZLevels.Commands;
using Content.Server._CP14.ZLevels.EntitySystems;
using Robust.Shared.Map;
using Robust.Shared.Utility;
namespace Content.Server._CP14.StationDungeonMap.Components;
namespace Content.Server._CP14.ZLevels.Components;
/// <summary>
/// Initializes the z-level system by creating a series of linked maps
/// </summary>
[RegisterComponent, Access(typeof(CP14StationZLevelsSystem))]
[RegisterComponent, Access(typeof(CP14StationZLevelsSystem), typeof(CP14CombineMapsIntoZLevelsCommand))]
public sealed partial class CP14StationZLevelsComponent : Component
{
[DataField(required: true)]

View File

@@ -1,7 +1,7 @@
using Content.Server._CP14.StationDungeonMap.EntitySystems;
using Content.Server._CP14.ZLevels.EntitySystems;
using Robust.Shared.Prototypes;
namespace Content.Server._CP14.StationDungeonMap.Components;
namespace Content.Server._CP14.ZLevels.Components;
/// <summary>
/// automatically creates a linked portal at a different relative z-level, and then the component is removed

View File

@@ -0,0 +1,41 @@
using System.Numerics;
using Content.Shared._CP14.ZLevel;
using Content.Shared.Ghost;
using Robust.Shared.Map;
namespace Content.Server._CP14.ZLevels.EntitySystems;
public sealed partial class CP14StationZLevelsSystem
{
private void InitActions()
{
SubscribeLocalEvent<GhostComponent, CP14ZLevelActionUp>(OnZLevelUp);
SubscribeLocalEvent<GhostComponent, CP14ZLevelActionDown>(OnZLevelDown);
}
private void OnZLevelDown(Entity<GhostComponent> ent, ref CP14ZLevelActionDown args)
{
ZLevelMove(ent, -1);
}
private void OnZLevelUp(Entity<GhostComponent> ent, ref CP14ZLevelActionUp args)
{
ZLevelMove(ent, 1);
}
private void ZLevelMove(EntityUid ent, int offset)
{
var xform = Transform(ent);
var map = xform.MapUid;
if (map is null)
return;
var targetMap = GetMapOffset(map.Value, offset);
if (targetMap is null)
return;
_transform.SetMapCoordinates(ent, new MapCoordinates(_transform.GetWorldPosition(ent), targetMap.Value));
}
}

View File

@@ -0,0 +1,50 @@
using Content.Server._CP14.ZLevels.Components;
using Content.Server.GameTicking.Events;
using Content.Shared.Teleportation.Systems;
using Robust.Shared.Map;
namespace Content.Server._CP14.ZLevels.EntitySystems;
public sealed partial class CP14StationZLevelsSystem
{
[Dependency] private readonly LinkedEntitySystem _linkedEntity = default!;
private void InitializePortals()
{
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
SubscribeLocalEvent<CP14ZLevelAutoPortalComponent, MapInitEvent>(OnPortalMapInit);
}
private void OnRoundStart(RoundStartingEvent ev)
{
var query = EntityQueryEnumerator<CP14ZLevelAutoPortalComponent>();
while (query.MoveNext(out var uid, out var portal))
{
InitPortal((uid, portal));
}
}
private void OnPortalMapInit(Entity<CP14ZLevelAutoPortalComponent> autoPortal, ref MapInitEvent args)
{
InitPortal(autoPortal);
}
private void InitPortal(Entity<CP14ZLevelAutoPortalComponent> autoPortal)
{
var mapId = Transform(autoPortal).MapUid;
if (mapId is null)
return;
var offsetMap = GetMapOffset(mapId.Value, autoPortal.Comp.ZLevelOffset);
if (offsetMap is null)
return;
var currentWorldPos = _transform.GetWorldPosition(autoPortal);
var targetMapPos = new MapCoordinates(currentWorldPos, offsetMap.Value);
var otherSidePortal = Spawn(autoPortal.Comp.OtherSideProto, targetMapPos);
if (_linkedEntity.TryLink(autoPortal, otherSidePortal, true))
RemComp<CP14ZLevelAutoPortalComponent>(autoPortal);
}
}

View File

@@ -1,17 +1,14 @@
using Content.Server._CP14.StationDungeonMap.Components;
using Content.Server.GameTicking.Events;
using Content.Server._CP14.ZLevels.Components;
using Content.Server.Station.Components;
using Content.Server.Station.Events;
using Content.Server.Station.Systems;
using Content.Shared.Maps;
using Content.Shared.Station.Components;
using Content.Shared.Teleportation.Systems;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Map;
using Robust.Shared.Random;
namespace Content.Server._CP14.StationDungeonMap.EntitySystems;
namespace Content.Server._CP14.ZLevels.EntitySystems;
public sealed partial class CP14StationZLevelsSystem : EntitySystem
{
@@ -20,29 +17,18 @@ public sealed partial class CP14StationZLevelsSystem : EntitySystem
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly TileSystem _tile = default!;
[Dependency] private readonly SharedMapSystem _maps = default!;
[Dependency] private readonly LinkedEntitySystem _linkedEntity = default!;
public override void Initialize()
{
base.Initialize();
InitializePortals();
InitActions();
SubscribeLocalEvent<CP14ZLevelAutoPortalComponent, MapInitEvent>(OnPortalMapInit);
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
SubscribeLocalEvent<CP14StationZLevelsComponent, StationPostInitEvent>(OnStationPostInit);
}
private void OnRoundStart(RoundStartingEvent ev)
{
var query = EntityQueryEnumerator<CP14ZLevelAutoPortalComponent>();
while (query.MoveNext(out var uid, out var portal))
{
InitPortal((uid, portal));
}
}
private void OnStationPostInit(Entity<CP14StationZLevelsComponent> ent, ref StationPostInitEvent args)
{
if (ent.Comp.Initialized)
@@ -98,35 +84,10 @@ public sealed partial class CP14StationZLevelsSystem : EntitySystem
}
}
private void OnPortalMapInit(Entity<CP14ZLevelAutoPortalComponent> autoPortal, ref MapInitEvent args)
{
InitPortal(autoPortal);
}
private void InitPortal(Entity<CP14ZLevelAutoPortalComponent> autoPortal)
{
var mapId = Transform(autoPortal).MapUid;
if (mapId is null)
return;
var offsetMap = GetMapOffset(mapId.Value, autoPortal.Comp.ZLevelOffset);
if (offsetMap is null)
return;
var currentWorldPos = _transform.GetWorldPosition(autoPortal);
var targetMapPos = new MapCoordinates(currentWorldPos, offsetMap.Value);
var otherSidePortal = Spawn(autoPortal.Comp.OtherSideProto, targetMapPos);
if (_linkedEntity.TryLink(autoPortal, otherSidePortal, true))
RemComp<CP14ZLevelAutoPortalComponent>(autoPortal);
}
public MapId? GetMapOffset(EntityUid mapUid, int offset)
{
var query = EntityQueryEnumerator<CP14StationZLevelsComponent, StationDataComponent>();
while (query.MoveNext(out var uid, out var zLevel, out _))
var query = EntityQueryEnumerator<CP14StationZLevelsComponent>();
while (query.MoveNext(out var uid, out var zLevel))
{
if (!zLevel.LevelEntities.TryGetValue(Transform(mapUid).MapID, out var currentLevel))
continue;

View File

@@ -39,6 +39,20 @@ public sealed partial class GhostComponent : Component
[DataField, AutoNetworkedField]
public EntityUid? BooActionEntity;
//CP14 Ghost abilities
[DataField]
public EntProtoId CP14ZLevelUpAction = "CP14ActionZLevelUp";
[DataField, AutoNetworkedField]
public EntityUid? CP14ZLevelUpActionEntity;
[DataField]
public EntProtoId CP14ZLevelDownAction = "CP14ActionZLevelDown";
[DataField, AutoNetworkedField]
public EntityUid? CP14ZLevelDownActionEntity;
//CP14 Ghost entities end
// End actions
[ViewVariables(VVAccess.ReadWrite), DataField]

View File

@@ -0,0 +1,17 @@
using Content.Shared.Actions;
namespace Content.Shared._CP14.ZLevel;
/// <summary>
/// Should be relayed upon using the action.
/// </summary>
public sealed partial class CP14ZLevelActionUp : InstantActionEvent
{
}
/// <summary>
/// Should be relayed upon using the action.
/// </summary>
public sealed partial class CP14ZLevelActionDown : InstantActionEvent
{
}

View File

@@ -34,53 +34,53 @@
- NuclearOperative
- SyndicateAgent
- CentralCommand
- type: UserInterface
interfaces:
enum.SolarControlConsoleUiKey.Key:
type: SolarControlConsoleBoundUserInterface
enum.CommunicationsConsoleUiKey.Key:
type: CommunicationsConsoleBoundUserInterface
enum.RadarConsoleUiKey.Key:
type: RadarConsoleBoundUserInterface
enum.CargoConsoleUiKey.Orders:
type: CargoOrderConsoleBoundUserInterface
enum.CrewMonitoringUIKey.Key:
type: CrewMonitoringBoundUserInterface
enum.GeneralStationRecordConsoleKey.Key:
# who the fuck named this bruh
type: GeneralStationRecordConsoleBoundUserInterface
- type: IntrinsicUI
uis:
enum.SolarControlConsoleUiKey.Key:
toggleAction: ActionAGhostShowSolar
enum.CommunicationsConsoleUiKey.Key:
toggleAction: ActionAGhostShowCommunications
enum.RadarConsoleUiKey.Key:
toggleAction: ActionAGhostShowRadar
enum.CargoConsoleUiKey.Orders:
toggleAction: ActionAGhostShowCargo
enum.CrewMonitoringUIKey.Key:
toggleAction: ActionAGhostShowCrewMonitoring
enum.GeneralStationRecordConsoleKey.Key:
toggleAction: ActionAGhostShowStationRecords
- type: SolarControlConsole # look ma i AM the computer!
- type: CommunicationsConsole
title: comms-console-announcement-title-centcom
color: "#228b22"
- type: RadarConsole
followEntity: true
- type: CargoOrderConsole
- type: BankClient
- type: CrewMonitoringConsole
- type: GeneralStationRecordConsole
canDeleteEntries: true
- type: DeviceNetwork
deviceNetId: Wireless
receiveFrequencyId: CrewMonitor
transmitFrequencyId: ShuttleTimer
- type: WirelessNetworkConnection
range: 500
- type: StationLimitedNetwork
#- type: UserInterface
# interfaces:
# enum.SolarControlConsoleUiKey.Key:
# type: SolarControlConsoleBoundUserInterface
# enum.CommunicationsConsoleUiKey.Key:
# type: CommunicationsConsoleBoundUserInterface
# enum.RadarConsoleUiKey.Key:
# type: RadarConsoleBoundUserInterface
# enum.CargoConsoleUiKey.Orders:
# type: CargoOrderConsoleBoundUserInterface
# enum.CrewMonitoringUIKey.Key:
# type: CrewMonitoringBoundUserInterface
# enum.GeneralStationRecordConsoleKey.Key:
# # who the fuck named this bruh
# type: GeneralStationRecordConsoleBoundUserInterface
#- type: IntrinsicUI
# uis:
# enum.SolarControlConsoleUiKey.Key:
# toggleAction: ActionAGhostShowSolar
# enum.CommunicationsConsoleUiKey.Key:
# toggleAction: ActionAGhostShowCommunications
# enum.RadarConsoleUiKey.Key:
# toggleAction: ActionAGhostShowRadar
# enum.CargoConsoleUiKey.Orders:
# toggleAction: ActionAGhostShowCargo
# enum.CrewMonitoringUIKey.Key:
# toggleAction: ActionAGhostShowCrewMonitoring
# enum.GeneralStationRecordConsoleKey.Key:
# toggleAction: ActionAGhostShowStationRecords
#- type: SolarControlConsole # look ma i AM the computer!
#- type: CommunicationsConsole
# title: comms-console-announcement-title-centcom
# color: "#228b22"
#- type: RadarConsole
# followEntity: true
#- type: CargoOrderConsole
#- type: BankClient
#- type: CrewMonitoringConsole
#- type: GeneralStationRecordConsole
# canDeleteEntries: true
#- type: DeviceNetwork
# deviceNetId: Wireless
# receiveFrequencyId: CrewMonitor
# transmitFrequencyId: ShuttleTimer
#- type: WirelessNetworkConnection
# range: 500
#- type: StationLimitedNetwork
- type: Thieving
stripTimeReduction: 9999
stealthy: true

View File

@@ -0,0 +1,17 @@
- type: entity
id: CP14ActionZLevelUp
name: Move up
description: Move up one Z-Level
components:
- type: InstantAction
icon: _CP14/Actions/zLevel.rsi/up.png
event: !type:CP14ZLevelActionUp
- type: entity
id: CP14ActionZLevelDown
name: Move down
description: Move down one Z-Level
components:
- type: InstantAction
icon: _CP14/Actions/zLevel.rsi/down.png
event: !type:CP14ZLevelActionDown

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

View File

@@ -0,0 +1,17 @@
{
"version": 1,
"size": {
"x": 32,
"y": 32
},
"license": "CLA",
"copyright": "Created by TheShuEd",
"states": [
{
"name": "down"
},
{
"name": "up"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B