Improves examine code

Examining now has larger range. Ghosts have no range limit.
Fixed some messy code and some bad netcode.
This commit is contained in:
Pieter-Jan Briers
2019-07-19 10:45:04 +02:00
parent 1f320eccd7
commit 1a92d08399
8 changed files with 93 additions and 34 deletions

View File

@@ -137,6 +137,8 @@ namespace Content.Client
factory.RegisterIgnore("AiController");
factory.RegisterIgnore("PlayerInputMover");
factory.Register<ExaminerComponent>();
IoCManager.Register<IGameHud, GameHud>();
IoCManager.Register<IClientNotifyManager, ClientNotifyManager>();
IoCManager.Register<ISharedNotifyManager, ClientNotifyManager>();

View File

@@ -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.Player;
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 @@ using Robust.Shared.Players;
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 @@ namespace Content.Client.GameObjects.EntitySystems
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)
return;
DoExamine(entity);
if (playerEntity == null || !CanExamine(playerEntity, examined))
{
return;
}
DoExamine(examined);
}
public async void DoExamine(IEntity entity)

View File

@@ -195,6 +195,8 @@ namespace Content.Server
factory.Register<CombatModeComponent>();
factory.Register<ExaminerComponent>();
IoCManager.Register<ISharedNotifyManager, ServerNotifyManager>();
IoCManager.Register<IServerNotifyManager, ServerNotifyManager>();
IoCManager.Register<IGameTicker, GameTicker>();

View File

@@ -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 @@ namespace Content.Server.GameObjects.EntitySystems
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 @@ namespace Content.Server.GameObjects.EntitySystems
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);
}
}
}

View File

@@ -163,6 +163,9 @@ namespace Content.Server.GameObjects.EntitySystems
public GridCoordinates LandingLocation { get; }
}
/// <summary>
/// This interface gives components behavior when being used to "attack".
/// </summary>
public interface IAttack
{
void Attack(AttackEventArgs eventArgs);

View File

@@ -0,0 +1,30 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Mobs
{
/// <summary>
/// Component required for a player to be able to examine things.
/// </summary>
public sealed class ExaminerComponent : Component
{
public override string Name => "Examiner";
[ViewVariables(VVAccess.ReadWrite)]
private bool _doRangeCheck = true;
/// <summary>
/// Whether to do a distance check on examine.
/// If false, the user can theoretically examine from infinitely far away.
/// </summary>
public bool DoRangeCheck => _doRangeCheck;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _doRangeCheck, "DoRangeCheck", true);
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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