Travelling pointing arrows, brains can no longer point (#24864)
* Decoupled from gravity, constant animation time, manual networking, cubic interpolation * Reduced overshoot * Implemented PointAttemptEvent, reacts with mobstate & sleeping * Brains can no longer point, PBs must be inside a chassis * Removed chassis check, made callback more obvious
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Pointing.Components;
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Eye;
|
||||
@@ -10,13 +9,13 @@ using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Pointing;
|
||||
using Content.Shared.Popups;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
@@ -34,7 +33,6 @@ namespace Content.Server.Pointing.EntitySystems
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
|
||||
[Dependency] private readonly SharedMindSystem _minds = default!;
|
||||
@@ -50,6 +48,15 @@ namespace Content.Server.Pointing.EntitySystems
|
||||
|
||||
private const float PointingRange = 15f;
|
||||
|
||||
private void GetCompState(Entity<PointingArrowComponent> entity, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new SharedPointingArrowComponentState
|
||||
{
|
||||
StartPosition = entity.Comp.StartPosition,
|
||||
EndTime = entity.Comp.EndTime
|
||||
};
|
||||
}
|
||||
|
||||
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||
{
|
||||
if (e.NewStatus != SessionStatus.Disconnected)
|
||||
@@ -97,7 +104,7 @@ namespace Content.Server.Pointing.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUid pointed)
|
||||
public bool TryPoint(ICommonSession? session, EntityCoordinates coordsPointed, EntityUid pointed)
|
||||
{
|
||||
if (session?.AttachedEntity is not { } player)
|
||||
{
|
||||
@@ -105,9 +112,9 @@ namespace Content.Server.Pointing.EntitySystems
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!coords.IsValid(EntityManager))
|
||||
if (!coordsPointed.IsValid(EntityManager))
|
||||
{
|
||||
Log.Warning($"Player {ToPrettyString(player)} attempted to point at invalid coordinates: {coords}");
|
||||
Log.Warning($"Player {ToPrettyString(player)} attempted to point at invalid coordinates: {coordsPointed}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -123,33 +130,30 @@ namespace Content.Server.Pointing.EntitySystems
|
||||
return false;
|
||||
}
|
||||
|
||||
// Checking mob state directly instead of some action blocker, as many action blockers are blocked for
|
||||
// ghosts and there is no obvious choice for pointing.
|
||||
if (_mobState.IsIncapacitated(player))
|
||||
if (!CanPoint(player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HasComp<SleepingComponent>(player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!InRange(player, coords))
|
||||
if (!InRange(player, coordsPointed))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("pointing-system-try-point-cannot-reach"), player, player);
|
||||
return false;
|
||||
}
|
||||
|
||||
var mapCoordsPointed = coordsPointed.ToMap(EntityManager);
|
||||
_rotateToFaceSystem.TryFaceCoordinates(player, mapCoordsPointed.Position);
|
||||
|
||||
var mapCoords = coords.ToMap(EntityManager);
|
||||
_rotateToFaceSystem.TryFaceCoordinates(player, mapCoords.Position);
|
||||
|
||||
var arrow = EntityManager.SpawnEntity("PointingArrow", coords);
|
||||
var arrow = EntityManager.SpawnEntity("PointingArrow", coordsPointed);
|
||||
|
||||
if (TryComp<PointingArrowComponent>(arrow, out var pointing))
|
||||
{
|
||||
pointing.EndTime = _gameTiming.CurTime + TimeSpan.FromSeconds(4);
|
||||
if (TryComp(player, out TransformComponent? xformPlayer))
|
||||
pointing.StartPosition = EntityCoordinates.FromMap(arrow, xformPlayer.Coordinates.ToMap(EntityManager)).Position;
|
||||
|
||||
pointing.EndTime = _gameTiming.CurTime + PointDuration;
|
||||
|
||||
Dirty(arrow, pointing);
|
||||
}
|
||||
|
||||
if (EntityQuery<PointingArrowAngeringComponent>().FirstOrDefault() != null)
|
||||
@@ -215,10 +219,10 @@ namespace Content.Server.Pointing.EntitySystems
|
||||
TileRef? tileRef = null;
|
||||
string? position = null;
|
||||
|
||||
if (_mapManager.TryFindGridAt(mapCoords, out var gridUid, out var grid))
|
||||
if (_mapManager.TryFindGridAt(mapCoordsPointed, out var gridUid, out var grid))
|
||||
{
|
||||
position = $"EntId={gridUid} {grid.WorldToTile(mapCoords.Position)}";
|
||||
tileRef = grid.GetTileRef(grid.WorldToTile(mapCoords.Position));
|
||||
position = $"EntId={gridUid} {grid.WorldToTile(mapCoordsPointed.Position)}";
|
||||
tileRef = grid.GetTileRef(grid.WorldToTile(mapCoordsPointed.Position));
|
||||
}
|
||||
|
||||
var tileDef = _tileDefinitionManager[tileRef?.Tile.TypeId ?? 0];
|
||||
@@ -228,7 +232,7 @@ namespace Content.Server.Pointing.EntitySystems
|
||||
|
||||
viewerMessage = Loc.GetString("pointing-system-other-point-at-tile", ("otherName", playerName), ("tileName", name));
|
||||
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(player):user} pointed at {name} {(position == null ? mapCoords : position)}");
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(player):user} pointed at {name} {(position == null ? mapCoordsPointed : position)}");
|
||||
}
|
||||
|
||||
_pointers[session] = _gameTiming.CurTime;
|
||||
@@ -242,6 +246,8 @@ namespace Content.Server.Pointing.EntitySystems
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<PointingArrowComponent, ComponentGetState>(GetCompState);
|
||||
|
||||
SubscribeNetworkEvent<PointingAttemptEvent>(OnPointAttempt);
|
||||
|
||||
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||
@@ -255,8 +261,8 @@ namespace Content.Server.Pointing.EntitySystems
|
||||
{
|
||||
var target = GetEntity(ev.Target);
|
||||
|
||||
if (TryComp(target, out TransformComponent? xform))
|
||||
TryPoint(args.SenderSession, xform.Coordinates, target);
|
||||
if (TryComp(target, out TransformComponent? xformTarget))
|
||||
TryPoint(args.SenderSession, xformTarget.Coordinates, target);
|
||||
else
|
||||
Log.Warning($"User {args.SenderSession} attempted to point at a non-existent entity uid: {ev.Target}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user