Fix being able to do most verbs from within a container (#1613)

* Fix being able to do most verbs from within a container

* Fix missing container check when using global verbs
This commit is contained in:
DrSmugleaf
2020-08-15 20:38:37 +02:00
committed by GitHub
parent f37d6343ce
commit add4986001
7 changed files with 77 additions and 22 deletions

View File

@@ -210,6 +210,9 @@ namespace Content.Client.GameObjects.EntitySystems
if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(user, entity))
continue;
if (verb.BlockedByContainers && !user.IsInSameOrNoContainer(entity))
continue;
var verbData = verb.GetData(user, component);
if (verbData.IsInvisible)
@@ -232,6 +235,9 @@ namespace Content.Client.GameObjects.EntitySystems
if (globalVerb.RequireInteractionRange && !VerbUtility.InVerbUseRange(user, entity))
continue;
if (globalVerb.BlockedByContainers && !user.IsInSameOrNoContainer(entity))
continue;
var verbData = globalVerb.GetData(user, entity);
if (verbData.IsInvisible)

View File

@@ -11,6 +11,8 @@ namespace Content.Client.GlobalVerbs
{
public override bool RequireInteractionRange => false;
public override bool BlockedByContainers => false;
public override void GetData(IEntity user, IEntity target, VerbData data)
{
data.Visibility = VerbVisibility.Visible;

View File

@@ -4,6 +4,7 @@ using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
namespace Content.Server.GameObjects.EntitySystems.Click
@@ -19,7 +20,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
static ExamineSystem()
{
_entityNotFoundMessage = new FormattedMessage();
_entityNotFoundMessage.AddText("That entity doesn't exist");
_entityNotFoundMessage.AddText(Loc.GetString("That entity doesn't exist"));
}
public override void Initialize()

View File

@@ -2,6 +2,7 @@
using System.Reflection;
using Content.Shared.GameObjects.Verbs;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
@@ -37,6 +38,12 @@ namespace Content.Server.GameObjects.EntitySystems
var session = eventArgs.SenderSession;
var userEntity = session.AttachedEntity;
if (userEntity == null)
{
Logger.Warning($"{nameof(UseVerb)} called by player {session} with no attached entity.");
return;
}
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
{
if ($"{component.GetType()}:{verb.GetType()}" != use.VerbKey)
@@ -44,14 +51,14 @@ namespace Content.Server.GameObjects.EntitySystems
continue;
}
if (verb.RequireInteractionRange)
{
var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition)
.LengthSquared;
if (distanceSquared > VerbUtility.InteractionRangeSquared)
if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
{
break;
}
if (verb.BlockedByContainers && !userEntity.IsInSameOrNoContainer(entity))
{
break;
}
verb.Activate(userEntity, component);
@@ -65,14 +72,15 @@ namespace Content.Server.GameObjects.EntitySystems
continue;
}
if (globalVerb.RequireInteractionRange)
{
var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition)
.LengthSquared;
if (distanceSquared > VerbUtility.InteractionRangeSquared)
if (globalVerb.RequireInteractionRange &&
!VerbUtility.InVerbUseRange(userEntity, entity))
{
break;
}
if (globalVerb.BlockedByContainers && !userEntity.IsInSameOrNoContainer(entity))
{
break;
}
globalVerb.Activate(userEntity, entity);
@@ -92,6 +100,12 @@ namespace Content.Server.GameObjects.EntitySystems
var userEntity = player.AttachedEntity;
if (userEntity == null)
{
Logger.Warning($"{nameof(UseVerb)} called by player {player} with no attached entity.");
return;
}
var data = new List<VerbsResponseMessage.NetVerbData>();
//Get verbs, component dependent.
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
@@ -99,6 +113,9 @@ namespace Content.Server.GameObjects.EntitySystems
if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
continue;
if (verb.BlockedByContainers && !userEntity.IsInSameOrNoContainer(entity))
continue;
var verbData = verb.GetData(userEntity, component);
if (verbData.IsInvisible)
continue;
@@ -113,6 +130,9 @@ namespace Content.Server.GameObjects.EntitySystems
if (globalVerb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
continue;
if (globalVerb.BlockedByContainers && !userEntity.IsInSameOrNoContainer(entity))
continue;
var verbData = globalVerb.GetData(userEntity, entity);
if (verbData.IsInvisible)
continue;

View File

@@ -1,5 +1,7 @@
using Content.Shared.GameObjects.Components.Mobs;
using System;
using Content.Shared.GameObjects.Components.Mobs;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
@@ -22,6 +24,15 @@ namespace Content.Shared.GameObjects.EntitySystems
public const float ExamineRangeSquared = ExamineRange * ExamineRange;
protected const float ExamineDetailsRange = 3f;
private static bool IsInDetailsRange(IEntity examiner, IEntity entity)
{
return Get<SharedInteractionSystem>()
.InRangeUnobstructed(examiner.Transform.MapPosition, entity.Transform.MapPosition,
ExamineDetailsRange, predicate: entity0 => entity0 == examiner || entity0 == entity,
ignoreInsideBlocker: true) &&
examiner.IsInSameOrNoContainer(entity);
}
[Pure]
protected static bool CanExamine(IEntity examiner, IEntity examined)
{
@@ -40,9 +51,16 @@ namespace Content.Shared.GameObjects.EntitySystems
return false;
}
Func<IEntity, bool> predicate = entity => entity == examiner || entity == examined;
if (ContainerHelpers.TryGetContainer(examiner, out var container))
{
predicate += entity => entity == container.Owner;
}
return Get<SharedInteractionSystem>()
.InRangeUnobstructed(examiner.Transform.MapPosition, examined.Transform.MapPosition,
ExamineRange, predicate: entity => entity == examiner || entity == examined, ignoreInsideBlocker:true);
ExamineRange, predicate: predicate, ignoreInsideBlocker:true);
}
public static FormattedMessage GetExamineText(IEntity entity, IEntity examiner)
@@ -60,15 +78,11 @@ namespace Content.Shared.GameObjects.EntitySystems
message.PushColor(Color.DarkGray);
var inDetailsRange = Get<SharedInteractionSystem>()
.InRangeUnobstructed(examiner.Transform.MapPosition, entity.Transform.MapPosition,
ExamineDetailsRange, predicate: entity0 => entity0 == examiner || entity0 == entity, ignoreInsideBlocker: true);
//Add component statuses from components that report one
foreach (var examineComponent in entity.GetAllComponents<IExamine>())
{
var subMessage = new FormattedMessage();
examineComponent.Examine(subMessage, inDetailsRange);
examineComponent.Examine(subMessage, IsInDetailsRange(examiner, entity));
if (subMessage.Tags.Count == 0)
continue;

View File

@@ -20,6 +20,12 @@ namespace Content.Shared.GameObjects.Verbs
/// </summary>
public virtual bool RequireInteractionRange => true;
/// <summary>
/// If true, this verb requires both the user and the entity on which
/// this verb resides to be in the same container or no container.
/// </summary>
public virtual bool BlockedByContainers => true;
/// <summary>
/// Gets the visible verb data for the user.
/// </summary>

View File

@@ -20,6 +20,12 @@ namespace Content.Shared.GameObjects.Verbs
/// </summary>
public virtual bool RequireInteractionRange => true;
/// <summary>
/// If true, this verb requires both the user and the entity on which
/// this verb resides to be in the same container or no container.
/// </summary>
public virtual bool BlockedByContainers => true;
/// <summary>
/// Gets the visible verb data for the user.
/// </summary>