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:
@@ -137,6 +137,8 @@ namespace Content.Client
|
|||||||
factory.RegisterIgnore("AiController");
|
factory.RegisterIgnore("AiController");
|
||||||
factory.RegisterIgnore("PlayerInputMover");
|
factory.RegisterIgnore("PlayerInputMover");
|
||||||
|
|
||||||
|
factory.Register<ExaminerComponent>();
|
||||||
|
|
||||||
IoCManager.Register<IGameHud, GameHud>();
|
IoCManager.Register<IGameHud, GameHud>();
|
||||||
IoCManager.Register<IClientNotifyManager, ClientNotifyManager>();
|
IoCManager.Register<IClientNotifyManager, ClientNotifyManager>();
|
||||||
IoCManager.Register<ISharedNotifyManager, ClientNotifyManager>();
|
IoCManager.Register<ISharedNotifyManager, ClientNotifyManager>();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.Shared.GameObjects.EntitySystemMessages;
|
using Content.Shared.GameObjects.EntitySystemMessages;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects.EntitySystems;
|
using Robust.Client.GameObjects.EntitySystems;
|
||||||
@@ -11,7 +12,6 @@ using Robust.Client.Player;
|
|||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
|
||||||
using Robust.Shared.Input;
|
using Robust.Shared.Input;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -22,13 +22,10 @@ using Robust.Shared.Players;
|
|||||||
namespace Content.Client.GameObjects.EntitySystems
|
namespace Content.Client.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
internal sealed class ExamineSystem : EntitySystem
|
internal sealed class ExamineSystem : ExamineSystemShared
|
||||||
{
|
{
|
||||||
public const string StyleClassEntityTooltip = "entity-tooltip";
|
public const string StyleClassEntityTooltip = "entity-tooltip";
|
||||||
|
|
||||||
public const float ExamineRange = 1.5f;
|
|
||||||
public const float ExamineRangeSquared = ExamineRange * ExamineRange;
|
|
||||||
|
|
||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
[Dependency] private IInputManager _inputManager;
|
[Dependency] private IInputManager _inputManager;
|
||||||
[Dependency] private IUserInterfaceManager _userInterfaceManager;
|
[Dependency] private IUserInterfaceManager _userInterfaceManager;
|
||||||
@@ -56,19 +53,19 @@ namespace Content.Client.GameObjects.EntitySystems
|
|||||||
|
|
||||||
private void HandleExamine(ICommonSession session, GridCoordinates coords, EntityUid uid)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var playerEntity = _playerManager.LocalPlayer.ControlledEntity;
|
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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DoExamine(entity);
|
DoExamine(examined);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void DoExamine(IEntity entity)
|
public async void DoExamine(IEntity entity)
|
||||||
|
|||||||
@@ -195,6 +195,8 @@ namespace Content.Server
|
|||||||
|
|
||||||
factory.Register<CombatModeComponent>();
|
factory.Register<CombatModeComponent>();
|
||||||
|
|
||||||
|
factory.Register<ExaminerComponent>();
|
||||||
|
|
||||||
IoCManager.Register<ISharedNotifyManager, ServerNotifyManager>();
|
IoCManager.Register<ISharedNotifyManager, ServerNotifyManager>();
|
||||||
IoCManager.Register<IServerNotifyManager, ServerNotifyManager>();
|
IoCManager.Register<IServerNotifyManager, ServerNotifyManager>();
|
||||||
IoCManager.Register<IGameTicker, GameTicker>();
|
IoCManager.Register<IGameTicker, GameTicker>();
|
||||||
|
|||||||
@@ -1,20 +1,11 @@
|
|||||||
using System;
|
using Content.Shared.GameObjects.EntitySystemMessages;
|
||||||
using System.Text;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.GameObjects.EntitySystemMessages;
|
|
||||||
using Content.Shared.Input;
|
|
||||||
using Robust.Server.GameObjects.EntitySystems;
|
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
|
||||||
using Robust.Shared.Input;
|
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
|
||||||
using Robust.Shared.Interfaces.Network;
|
using Robust.Shared.Interfaces.Network;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Log;
|
|
||||||
using Robust.Shared.Map;
|
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Players;
|
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.EntitySystems
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
@@ -27,11 +18,8 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
void Examine(FormattedMessage message);
|
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
|
#pragma warning disable 649
|
||||||
[Dependency] private IEntityManager _entityManager;
|
[Dependency] private IEntityManager _entityManager;
|
||||||
[Dependency] private IPlayerManager _playerManager;
|
[Dependency] private IPlayerManager _playerManager;
|
||||||
@@ -105,18 +93,17 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
var session = _playerManager.GetSessionByChannel(channel);
|
var session = _playerManager.GetSessionByChannel(channel);
|
||||||
var playerEnt = session.AttachedEntity;
|
var playerEnt = session.AttachedEntity;
|
||||||
|
|
||||||
if((playerEnt == null) ||
|
if (playerEnt == null
|
||||||
(!_entityManager.TryGetEntity(request.EntityUid, out var entity)) ||
|
|| !_entityManager.TryGetEntity(request.EntityUid, out var entity)
|
||||||
(entity.Transform.MapID != playerEnt.Transform.MapID) ||
|
|| !CanExamine(playerEnt, entity))
|
||||||
((entity.Transform.WorldPosition - playerEnt.Transform.WorldPosition).LengthSquared > ExamineRangeSquared))
|
|
||||||
{
|
{
|
||||||
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
|
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
|
||||||
request.EntityUid, _entityNotFoundMessage));
|
request.EntityUid, _entityNotFoundMessage), channel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var text = GetExamineText(entity);
|
var text = GetExamineText(entity);
|
||||||
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text));
|
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text), channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,6 +163,9 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
public GridCoordinates LandingLocation { get; }
|
public GridCoordinates LandingLocation { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This interface gives components behavior when being used to "attack".
|
||||||
|
/// </summary>
|
||||||
public interface IAttack
|
public interface IAttack
|
||||||
{
|
{
|
||||||
void Attack(AttackEventArgs eventArgs);
|
void Attack(AttackEventArgs eventArgs);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,6 +66,7 @@
|
|||||||
|
|
||||||
- type: CombatMode
|
- type: CombatMode
|
||||||
- type: Teleportable
|
- type: Teleportable
|
||||||
|
- type: Examiner
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: MobObserver
|
id: MobObserver
|
||||||
@@ -81,6 +82,8 @@
|
|||||||
aabb: "-0.5,-0.25,-0.05,0.25"
|
aabb: "-0.5,-0.25,-0.05,0.25"
|
||||||
- type: Input
|
- type: Input
|
||||||
context: "ghost"
|
context: "ghost"
|
||||||
|
- type: Examiner
|
||||||
|
DoRangeCheck: false
|
||||||
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
|
|||||||
Reference in New Issue
Block a user