Re-organize all projects (#4166)
This commit is contained in:
95
Content.Server/Pointing/Components/PointingArrowComponent.cs
Normal file
95
Content.Server/Pointing/Components/PointingArrowComponent.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Pointing.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
|
||||
|
||||
namespace Content.Server.Pointing.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class PointingArrowComponent : SharedPointingArrowComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// The current amount of seconds left on this arrow.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("duration")]
|
||||
private float _duration = 4;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of seconds before the arrow changes movement direction.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("step")]
|
||||
private float _step = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of units that this arrow will move by when multiplied
|
||||
/// by the frame time.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("speed")]
|
||||
private float _speed = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The current amount of seconds left before the arrow changes
|
||||
/// movement direction.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private float _currentStep;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not this arrow is currently going up.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private bool _up;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not this arrow will convert into a
|
||||
/// <see cref="RoguePointingArrowComponent"/> when its duration runs out.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("rogue")]
|
||||
private bool _rogue = default;
|
||||
|
||||
protected override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
{
|
||||
sprite.DrawDepth = (int) DrawDepth.Overlays;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
var movement = _speed * frameTime * (_up ? 1 : -1);
|
||||
Owner.Transform.LocalPosition += (0, movement);
|
||||
|
||||
_duration -= frameTime;
|
||||
_currentStep -= frameTime;
|
||||
|
||||
if (_duration <= 0)
|
||||
{
|
||||
if (_rogue)
|
||||
{
|
||||
Owner.RemoveComponent<PointingArrowComponent>();
|
||||
Owner.AddComponent<RoguePointingArrowComponent>();
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.Delete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentStep <= 0)
|
||||
{
|
||||
_currentStep = _step;
|
||||
_up ^= true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using Content.Server.Explosion;
|
||||
using Content.Shared.Pointing.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
|
||||
|
||||
namespace Content.Server.Pointing.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class RoguePointingArrowComponent : SharedRoguePointingArrowComponent
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private IEntity? _chasing;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("turningDelay")]
|
||||
private float _turningDelay = 2;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("chasingDelay")]
|
||||
private float _chasingDelay = 1;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("chasingSpeed")]
|
||||
private float _chasingSpeed = 5;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("chasingTime")]
|
||||
private float _chasingTime = 1;
|
||||
|
||||
private IEntity? RandomNearbyPlayer()
|
||||
{
|
||||
var players = _playerManager
|
||||
.GetPlayersInRange(Owner.Transform.Coordinates, 15)
|
||||
.Where(player => player.AttachedEntity != null)
|
||||
.ToArray();
|
||||
|
||||
if (players.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _random.Pick(players).AttachedEntity;
|
||||
}
|
||||
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
if (_chasing == null ||
|
||||
!Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
appearance.SetData(RoguePointingArrowVisuals.Rotation, Owner.Transform.LocalRotation.Degrees);
|
||||
}
|
||||
|
||||
protected override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
{
|
||||
sprite.DrawDepth = (int) DrawDepth.Overlays;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
_chasing ??= RandomNearbyPlayer();
|
||||
|
||||
if (_chasing == null)
|
||||
{
|
||||
Owner.Delete();
|
||||
return;
|
||||
}
|
||||
|
||||
_turningDelay -= frameTime;
|
||||
|
||||
if (_turningDelay > 0)
|
||||
{
|
||||
var difference = _chasing.Transform.WorldPosition - Owner.Transform.WorldPosition;
|
||||
var angle = difference.ToAngle();
|
||||
var adjusted = angle.Degrees + 90;
|
||||
var newAngle = Angle.FromDegrees(adjusted);
|
||||
|
||||
Owner.Transform.LocalRotation = newAngle;
|
||||
|
||||
UpdateAppearance();
|
||||
return;
|
||||
}
|
||||
|
||||
_chasingDelay -= frameTime;
|
||||
|
||||
Owner.Transform.WorldRotation += Angle.FromDegrees(20);
|
||||
|
||||
UpdateAppearance();
|
||||
|
||||
var toChased = _chasing.Transform.WorldPosition - Owner.Transform.WorldPosition;
|
||||
|
||||
Owner.Transform.WorldPosition += toChased * frameTime * _chasingSpeed;
|
||||
|
||||
_chasingTime -= frameTime;
|
||||
|
||||
if (_chasingTime > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.SpawnExplosion(0, 2, 1, 1);
|
||||
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Effects/explosion.ogg", Owner);
|
||||
|
||||
Owner.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
203
Content.Server/Pointing/EntitySystems/PointingSystem.cs
Normal file
203
Content.Server/Pointing/EntitySystems/PointingSystem.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Ghost.Components;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.Pointing.Components;
|
||||
using Content.Server.Visible;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Notification;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Pointing.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class PointingSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private static readonly TimeSpan PointDelay = TimeSpan.FromSeconds(0.5f);
|
||||
|
||||
/// <summary>
|
||||
/// A dictionary of players to the last time that they
|
||||
/// pointed at something.
|
||||
/// </summary>
|
||||
private readonly Dictionary<ICommonSession, TimeSpan> _pointers = new();
|
||||
|
||||
private const float PointingRange = 15f;
|
||||
|
||||
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||
{
|
||||
if (e.NewStatus != SessionStatus.Disconnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_pointers.Remove(e.Session);
|
||||
}
|
||||
|
||||
// TODO: FOV
|
||||
private void SendMessage(IEntity source, IList<IPlayerSession> viewers, IEntity? pointed, string selfMessage,
|
||||
string viewerMessage, string? viewerPointedAtMessage = null)
|
||||
{
|
||||
foreach (var viewer in viewers)
|
||||
{
|
||||
var viewerEntity = viewer.AttachedEntity;
|
||||
if (viewerEntity == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var message = viewerEntity == source
|
||||
? selfMessage
|
||||
: viewerEntity == pointed && viewerPointedAtMessage != null
|
||||
? viewerPointedAtMessage
|
||||
: viewerMessage;
|
||||
|
||||
source.PopupMessage(viewerEntity, message);
|
||||
}
|
||||
}
|
||||
|
||||
public bool InRange(IEntity pointer, EntityCoordinates coordinates)
|
||||
{
|
||||
if (pointer.HasComponent<GhostComponent>()){
|
||||
return pointer.Transform.Coordinates.InRange(EntityManager, coordinates, 15);
|
||||
}
|
||||
else
|
||||
{
|
||||
return pointer.InRangeUnOccluded(coordinates, 15, e => e == pointer);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
||||
{
|
||||
var player = (session as IPlayerSession)?.ContentData()?.Mind?.CurrentEntity;
|
||||
if (player == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_pointers.TryGetValue(session!, out var lastTime) &&
|
||||
_gameTiming.CurTime < lastTime + PointDelay)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EntityManager.TryGetEntity(uid, out var entity) && entity.HasComponent<PointingArrowComponent>())
|
||||
{
|
||||
// this is a pointing arrow. no pointing here...
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!InRange(player, coords))
|
||||
{
|
||||
player.PopupMessage(Loc.GetString("You can't reach there!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ActionBlockerSystem.CanChangeDirection(player))
|
||||
{
|
||||
var diff = coords.ToMapPos(EntityManager) - player.Transform.MapPosition.Position;
|
||||
if (diff.LengthSquared > 0.01f)
|
||||
{
|
||||
player.Transform.LocalRotation = new Angle(diff);
|
||||
}
|
||||
}
|
||||
|
||||
var arrow = EntityManager.SpawnEntity("pointingarrow", coords);
|
||||
|
||||
var layer = (int)VisibilityFlags.Normal;
|
||||
if (player.TryGetComponent(out VisibilityComponent? playerVisibility))
|
||||
{
|
||||
var arrowVisibility = arrow.EnsureComponent<VisibilityComponent>();
|
||||
layer = arrowVisibility.Layer = playerVisibility.Layer;
|
||||
}
|
||||
|
||||
// Get players that are in range and whose visibility layer matches the arrow's.
|
||||
var viewers = _playerManager.GetPlayersBy((playerSession) =>
|
||||
{
|
||||
var ent = playerSession.ContentData()?.Mind?.CurrentEntity;
|
||||
|
||||
if (ent is null || (!ent.TryGetComponent<EyeComponent>(out var eyeComp) || (eyeComp.VisibilityMask & layer) != 0))
|
||||
return false;
|
||||
|
||||
return ent.Transform.MapPosition.InRange(player.Transform.MapPosition, PointingRange);
|
||||
});
|
||||
|
||||
string selfMessage;
|
||||
string viewerMessage;
|
||||
string? viewerPointedAtMessage = null;
|
||||
|
||||
if (EntityManager.TryGetEntity(uid, out var pointed))
|
||||
{
|
||||
selfMessage = player == pointed
|
||||
? Loc.GetString("You point at yourself.")
|
||||
: Loc.GetString("You point at {0:theName}.", pointed);
|
||||
|
||||
viewerMessage = player == pointed
|
||||
? $"{player.Name} {Loc.GetString("points at {0:themself}.", player)}"
|
||||
: $"{player.Name} {Loc.GetString("points at {0:theName}.", pointed)}";
|
||||
|
||||
viewerPointedAtMessage = $"{player.Name} {Loc.GetString("points at you.")}";
|
||||
}
|
||||
else
|
||||
{
|
||||
var tileRef = _mapManager.GetGrid(coords.GetGridId(EntityManager)).GetTileRef(coords);
|
||||
var tileDef = _tileDefinitionManager[tileRef.Tile.TypeId];
|
||||
|
||||
selfMessage = Loc.GetString("You point at {0}.", tileDef.DisplayName);
|
||||
|
||||
viewerMessage = $"{player.Name} {Loc.GetString("points at {0}.", tileDef.DisplayName)}";
|
||||
}
|
||||
|
||||
_pointers[session!] = _gameTiming.CurTime;
|
||||
|
||||
SendMessage(player, viewers, pointed, selfMessage, viewerMessage, viewerPointedAtMessage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.Point, new PointerInputCmdHandler(TryPoint))
|
||||
.Register<PointingSystem>();
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
_playerManager.PlayerStatusChanged -= OnPlayerStatusChanged;
|
||||
_pointers.Clear();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var component in ComponentManager.EntityQuery<PointingArrowComponent>(true))
|
||||
{
|
||||
component.Update(frameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs
Normal file
18
Content.Server/Pointing/EntitySystems/RoguePointingSystem.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Content.Server.Pointing.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Pointing.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class RoguePointingSystem : EntitySystem
|
||||
{
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var component in ComponentManager.EntityQuery<RoguePointingArrowComponent>(true))
|
||||
{
|
||||
component.Update(frameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Content.Server/Pointing/PointingVerb.cs
Normal file
53
Content.Server/Pointing/PointingVerb.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Content.Server.Pointing.Components;
|
||||
using Content.Server.Pointing.EntitySystems;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Pointing
|
||||
{
|
||||
/// <summary>
|
||||
/// Global verb that points at an entity.
|
||||
/// </summary>
|
||||
[GlobalVerb]
|
||||
public class PointingVerb : GlobalVerb
|
||||
{
|
||||
public override bool RequireInteractionRange => false;
|
||||
|
||||
public override void GetData(IEntity user, IEntity target, VerbData data)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
data.IconTexture = "/Textures/Interface/VerbIcons/point.svg.192dpi.png";
|
||||
|
||||
if (!user.HasComponent<ActorComponent>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EntitySystem.Get<PointingSystem>().InRange(user, target.Transform.Coordinates))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.HasComponent<PointingArrowComponent>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
|
||||
data.Text = Loc.GetString("Point at");
|
||||
}
|
||||
|
||||
public override void Activate(IEntity user, IEntity target)
|
||||
{
|
||||
if (!user.TryGetComponent(out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntitySystem.Get<PointingSystem>().TryPoint(actor.PlayerSession, target.Transform.Coordinates, target.Uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user