2024-12-09 20:39:46 +03:00
|
|
|
using Content.Shared._CP14.ZLevel;
|
2025-06-21 02:46:01 +03:00
|
|
|
using Content.Shared.Actions;
|
2024-12-09 20:39:46 +03:00
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server._CP14.ZLevels.EntitySystems;
|
|
|
|
|
|
|
|
|
|
public sealed partial class CP14StationZLevelsSystem
|
|
|
|
|
{
|
2025-06-21 02:46:01 +03:00
|
|
|
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
2024-12-09 20:39:46 +03:00
|
|
|
private void InitActions()
|
|
|
|
|
{
|
2025-06-21 02:46:01 +03:00
|
|
|
SubscribeLocalEvent<CP14ZLevelMoverComponent, MapInitEvent>(OnMapInit);
|
|
|
|
|
SubscribeLocalEvent<CP14ZLevelMoverComponent, ComponentRemove>(OnRemove);
|
|
|
|
|
SubscribeLocalEvent<CP14ZLevelMoverComponent, CP14ZLevelActionUp>(OnZLevelUpGhost);
|
|
|
|
|
SubscribeLocalEvent<CP14ZLevelMoverComponent, CP14ZLevelActionDown>(OnZLevelDownGhost);
|
2024-12-09 20:39:46 +03:00
|
|
|
}
|
|
|
|
|
|
2025-06-21 02:46:01 +03:00
|
|
|
private void OnMapInit(Entity<CP14ZLevelMoverComponent> ent, ref MapInitEvent args)
|
2024-12-09 20:39:46 +03:00
|
|
|
{
|
2025-06-21 02:46:01 +03:00
|
|
|
_actions.AddAction(ent, ref ent.Comp.CP14ZLevelUpActionEntity, ent.Comp.UpActionProto);
|
|
|
|
|
_actions.AddAction(ent, ref ent.Comp.CP14ZLevelDownActionEntity, ent.Comp.DownActionProto);
|
2024-12-09 20:39:46 +03:00
|
|
|
}
|
|
|
|
|
|
2025-06-21 02:46:01 +03:00
|
|
|
private void OnRemove(Entity<CP14ZLevelMoverComponent> ent, ref ComponentRemove args)
|
2025-06-13 14:15:48 +03:00
|
|
|
{
|
2025-06-21 02:46:01 +03:00
|
|
|
_actions.RemoveAction(ent.Comp.CP14ZLevelUpActionEntity);
|
|
|
|
|
_actions.RemoveAction(ent.Comp.CP14ZLevelDownActionEntity);
|
2025-06-13 14:15:48 +03:00
|
|
|
}
|
|
|
|
|
|
2025-06-21 02:46:01 +03:00
|
|
|
private void OnZLevelDownGhost(Entity<CP14ZLevelMoverComponent> ent, ref CP14ZLevelActionDown args)
|
2025-06-13 14:15:48 +03:00
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ZLevelMove(ent, -1);
|
|
|
|
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 02:46:01 +03:00
|
|
|
private void OnZLevelUpGhost(Entity<CP14ZLevelMoverComponent> ent, ref CP14ZLevelActionUp args)
|
2024-12-09 20:39:46 +03:00
|
|
|
{
|
2024-12-11 14:44:16 +03:00
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-12-09 20:39:46 +03:00
|
|
|
ZLevelMove(ent, 1);
|
2024-12-11 14:44:16 +03:00
|
|
|
|
|
|
|
|
args.Handled = true;
|
2024-12-09 20:39:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|