diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index 1b9894011e669b..0fab1ae930159d 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -137,6 +137,8 @@ public override void Init() factory.RegisterIgnore("AiController"); factory.RegisterIgnore("PlayerInputMover"); + factory.Register(); + IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs b/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs index be25d0be11ce86..37c45abd7cd247 100644 --- a/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs @@ -1,6 +1,7 @@ using System.Threading; using System.Threading.Tasks; using Content.Shared.GameObjects.EntitySystemMessages; +using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Input; using JetBrains.Annotations; using Robust.Client.GameObjects.EntitySystems; @@ -11,7 +12,6 @@ using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; -using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; @@ -22,13 +22,10 @@ namespace Content.Client.GameObjects.EntitySystems { [UsedImplicitly] - internal sealed class ExamineSystem : EntitySystem + internal sealed class ExamineSystem : ExamineSystemShared { public const string StyleClassEntityTooltip = "entity-tooltip"; - public const float ExamineRange = 1.5f; - public const float ExamineRangeSquared = ExamineRange * ExamineRange; - #pragma warning disable 649 [Dependency] private IInputManager _inputManager; [Dependency] private IUserInterfaceManager _userInterfaceManager; @@ -56,19 +53,19 @@ public override void RegisterMessageTypes() private void HandleExamine(ICommonSession session, GridCoordinates coords, EntityUid uid) { - if (!uid.IsValid() || !_entityManager.TryGetEntity(uid, out var entity)) + if (!uid.IsValid() || !_entityManager.TryGetEntity(uid, out var examined)) { return; } var playerEntity = _playerManager.LocalPlayer.ControlledEntity; - if(playerEntity == null) - return; - - if((entity.Transform.WorldPosition - playerEntity.Transform.WorldPosition).LengthSquared > ExamineRangeSquared) + + if (playerEntity == null || !CanExamine(playerEntity, examined)) + { return; + } - DoExamine(entity); + DoExamine(examined); } public async void DoExamine(IEntity entity) diff --git a/Content.Server/EntryPoint.cs b/Content.Server/EntryPoint.cs index 1fa2ed4e6f949d..612d1633a40643 100644 --- a/Content.Server/EntryPoint.cs +++ b/Content.Server/EntryPoint.cs @@ -195,6 +195,8 @@ public override void Init() factory.Register(); + factory.Register(); + IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Server/GameObjects/EntitySystems/Click/ExamineSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/ExamineSystem.cs index d189e3f7b3ed94..c3b6dd967af15a 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/ExamineSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/ExamineSystem.cs @@ -1,20 +1,11 @@ -using System; -using System.Text; -using Content.Shared.GameObjects.EntitySystemMessages; -using Content.Shared.Input; -using Robust.Server.GameObjects.EntitySystems; +using Content.Shared.GameObjects.EntitySystemMessages; +using Content.Shared.GameObjects.EntitySystems; using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; -using Robust.Shared.GameObjects.Systems; -using Robust.Shared.Input; using Robust.Shared.Interfaces.GameObjects; -using Robust.Shared.Interfaces.GameObjects.Components; using Robust.Shared.Interfaces.Network; using Robust.Shared.IoC; -using Robust.Shared.Log; -using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Players; using Robust.Shared.Utility; namespace Content.Server.GameObjects.EntitySystems @@ -27,11 +18,8 @@ public interface IExamine void Examine(FormattedMessage message); } - public class ExamineSystem : EntitySystem + public class ExamineSystem : ExamineSystemShared { - public const float ExamineRange = 1.5f; - public const float ExamineRangeSquared = ExamineRange * ExamineRange; - #pragma warning disable 649 [Dependency] private IEntityManager _entityManager; [Dependency] private IPlayerManager _playerManager; @@ -105,18 +93,17 @@ public override void HandleNetMessage(INetChannel channel, EntitySystemMessage m var session = _playerManager.GetSessionByChannel(channel); var playerEnt = session.AttachedEntity; - if((playerEnt == null) || - (!_entityManager.TryGetEntity(request.EntityUid, out var entity)) || - (entity.Transform.MapID != playerEnt.Transform.MapID) || - ((entity.Transform.WorldPosition - playerEnt.Transform.WorldPosition).LengthSquared > ExamineRangeSquared)) + if (playerEnt == null + || !_entityManager.TryGetEntity(request.EntityUid, out var entity) + || !CanExamine(playerEnt, entity)) { RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage( - request.EntityUid, _entityNotFoundMessage)); + request.EntityUid, _entityNotFoundMessage), channel); return; } var text = GetExamineText(entity); - RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text)); + RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text), channel); } } } diff --git a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index f9cb49eb9933c8..8f7283d349f1e8 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -163,6 +163,9 @@ public LandEventArgs(IEntity user, GridCoordinates landingLocation) public GridCoordinates LandingLocation { get; } } + /// + /// This interface gives components behavior when being used to "attack". + /// public interface IAttack { void Attack(AttackEventArgs eventArgs); diff --git a/Content.Shared/GameObjects/Components/Mobs/ExaminerComponent.cs b/Content.Shared/GameObjects/Components/Mobs/ExaminerComponent.cs new file mode 100644 index 00000000000000..536a4f573ab277 --- /dev/null +++ b/Content.Shared/GameObjects/Components/Mobs/ExaminerComponent.cs @@ -0,0 +1,30 @@ +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization; +using Robust.Shared.ViewVariables; + +namespace Content.Shared.GameObjects.Components.Mobs +{ + /// + /// Component required for a player to be able to examine things. + /// + public sealed class ExaminerComponent : Component + { + public override string Name => "Examiner"; + + [ViewVariables(VVAccess.ReadWrite)] + private bool _doRangeCheck = true; + + /// + /// Whether to do a distance check on examine. + /// If false, the user can theoretically examine from infinitely far away. + /// + public bool DoRangeCheck => _doRangeCheck; + + public override void ExposeData(ObjectSerializer serializer) + { + base.ExposeData(serializer); + + serializer.DataField(ref _doRangeCheck, "DoRangeCheck", true); + } + } +} diff --git a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs new file mode 100644 index 00000000000000..a34ca1053ba84a --- /dev/null +++ b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs @@ -0,0 +1,35 @@ +using Content.Shared.GameObjects.Components.Mobs; +using JetBrains.Annotations; +using Robust.Shared.GameObjects.Systems; +using Robust.Shared.Interfaces.GameObjects; + +namespace Content.Shared.GameObjects.EntitySystems +{ + public abstract class ExamineSystemShared : EntitySystem + { + public const float ExamineRange = 8f; + public const float ExamineRangeSquared = ExamineRange * ExamineRange; + + [Pure] + protected static bool CanExamine(IEntity examiner, IEntity examined) + { + if (!examiner.TryGetComponent(out ExaminerComponent examinerComponent)) + { + return false; + } + + if (!examinerComponent.DoRangeCheck) + { + return true; + } + + if (examiner.Transform.MapID != examined.Transform.MapID) + { + return false; + } + + var delta = examined.Transform.WorldPosition - examiner.Transform.WorldPosition; + return delta.LengthSquared <= ExamineRangeSquared; + } + } +} diff --git a/Resources/Prototypes/Entities/Mobs.yml b/Resources/Prototypes/Entities/Mobs.yml index 7629db5035e1ad..a22cd6381af0de 100644 --- a/Resources/Prototypes/Entities/Mobs.yml +++ b/Resources/Prototypes/Entities/Mobs.yml @@ -49,7 +49,7 @@ - type: Input context: "human" - + - type: Species Template: Human HeatResistance: 323 @@ -66,6 +66,7 @@ - type: CombatMode - type: Teleportable + - type: Examiner - type: entity id: MobObserver @@ -81,6 +82,8 @@ aabb: "-0.5,-0.25,-0.05,0.25" - type: Input context: "ghost" + - type: Examiner + DoRangeCheck: false - type: entity