2024-12-09 20:39:46 +03:00
|
|
|
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)
|
|
|
|
|
{
|
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 OnZLevelUp(Entity<GhostComponent> ent, ref CP14ZLevelActionUp args)
|
|
|
|
|
{
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|