Fix verbs in-hand.
Properly this time.
This commit is contained in:
@@ -207,11 +207,10 @@ namespace Content.Client.GameObjects.EntitySystems
|
|||||||
//Get verbs, component dependent.
|
//Get verbs, component dependent.
|
||||||
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
|
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
|
||||||
{
|
{
|
||||||
if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(user, entity))
|
if (!VerbUtility.VerbAccessChecks(user, entity, verb))
|
||||||
continue;
|
{
|
||||||
|
|
||||||
if (verb.BlockedByContainers && !user.IsInSameOrNoContainer(entity))
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var verbData = verb.GetData(user, component);
|
var verbData = verb.GetData(user, component);
|
||||||
|
|
||||||
@@ -232,11 +231,10 @@ namespace Content.Client.GameObjects.EntitySystems
|
|||||||
//Get global verbs. Visible for all entities regardless of their components.
|
//Get global verbs. Visible for all entities regardless of their components.
|
||||||
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
|
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
|
||||||
{
|
{
|
||||||
if (globalVerb.RequireInteractionRange && !VerbUtility.InVerbUseRange(user, entity))
|
if (!VerbUtility.VerbAccessChecks(user, entity, globalVerb))
|
||||||
continue;
|
{
|
||||||
|
|
||||||
if (globalVerb.BlockedByContainers && !user.IsInSameOrNoContainer(entity))
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var verbData = globalVerb.GetData(user, entity);
|
var verbData = globalVerb.GetData(user, entity);
|
||||||
|
|
||||||
|
|||||||
@@ -51,12 +51,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
|
if (!VerbUtility.VerbAccessChecks(userEntity, entity, verb))
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verb.BlockedByContainers && !userEntity.IsInSameOrNoContainer(entity))
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -72,13 +67,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalVerb.RequireInteractionRange &&
|
if (!VerbUtility.VerbAccessChecks(userEntity, entity, globalVerb))
|
||||||
!VerbUtility.InVerbUseRange(userEntity, entity))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (globalVerb.BlockedByContainers && !userEntity.IsInSameOrNoContainer(entity))
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -110,19 +99,9 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
//Get verbs, component dependent.
|
//Get verbs, component dependent.
|
||||||
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
|
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
|
||||||
{
|
{
|
||||||
if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
|
if (!VerbUtility.VerbAccessChecks(userEntity, entity, verb))
|
||||||
continue;
|
|
||||||
|
|
||||||
if (verb.BlockedByContainers)
|
|
||||||
{
|
{
|
||||||
if (!userEntity.IsInSameOrNoContainer(entity))
|
continue;
|
||||||
{
|
|
||||||
if (!ContainerHelpers.TryGetContainer(entity, out var container) ||
|
|
||||||
container.Owner != userEntity)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var verbData = verb.GetData(userEntity, component);
|
var verbData = verb.GetData(userEntity, component);
|
||||||
@@ -136,11 +115,10 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
//Get global verbs. Visible for all entities regardless of their components.
|
//Get global verbs. Visible for all entities regardless of their components.
|
||||||
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
|
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
|
||||||
{
|
{
|
||||||
if (globalVerb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
|
if (!VerbUtility.VerbAccessChecks(userEntity, entity, globalVerb))
|
||||||
continue;
|
{
|
||||||
|
|
||||||
if (globalVerb.BlockedByContainers && !userEntity.IsInSameOrNoContainer(entity))
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var verbData = globalVerb.GetData(userEntity, entity);
|
var verbData = globalVerb.GetData(userEntity, entity);
|
||||||
if (verbData.IsInvisible)
|
if (verbData.IsInvisible)
|
||||||
|
|||||||
@@ -12,20 +12,8 @@ namespace Content.Shared.GameObjects.Verbs
|
|||||||
/// To add a global verb to all entities,
|
/// To add a global verb to all entities,
|
||||||
/// define it and mark it with <see cref="GlobalVerbAttribute"/>
|
/// define it and mark it with <see cref="GlobalVerbAttribute"/>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public abstract class GlobalVerb
|
public abstract class GlobalVerb : VerbBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// If true, this verb requires the user to be within
|
|
||||||
/// <see cref="VerbUtility.InteractionRange"/> meters from the entity on which this verb resides.
|
|
||||||
/// </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>
|
/// <summary>
|
||||||
/// Gets the visible verb data for the user.
|
/// Gets the visible verb data for the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -12,21 +12,8 @@ namespace Content.Shared.GameObjects.Verbs
|
|||||||
/// and mark it with <see cref="VerbAttribute"/>
|
/// and mark it with <see cref="VerbAttribute"/>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public abstract class Verb
|
public abstract class Verb : VerbBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// If true, this verb requires the user to be inside within
|
|
||||||
/// <see cref="VerbUtility.InteractionRange"/> meters from the entity on which this verb resides.
|
|
||||||
/// </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.
|
|
||||||
/// OR the user can be the entity's container
|
|
||||||
/// </summary>
|
|
||||||
public virtual bool BlockedByContainers => true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the visible verb data for the user.
|
/// Gets the visible verb data for the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
18
Content.Shared/GameObjects/Verbs/VerbBase.cs
Normal file
18
Content.Shared/GameObjects/Verbs/VerbBase.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace Content.Shared.GameObjects.Verbs
|
||||||
|
{
|
||||||
|
public abstract class VerbBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// If true, this verb requires the user to be inside within
|
||||||
|
/// <see cref="VerbUtility.InteractionRange"/> meters from the entity on which this verb resides.
|
||||||
|
/// </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.
|
||||||
|
/// OR the user can be the entity's container
|
||||||
|
/// </summary>
|
||||||
|
public virtual bool BlockedByContainers => true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
@@ -50,6 +51,21 @@ namespace Content.Shared.GameObjects.Verbs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool VerbAccessChecks(IEntity user, IEntity target, VerbBase verb)
|
||||||
|
{
|
||||||
|
if (verb.RequireInteractionRange && !InVerbUseRange(user, target))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verb.BlockedByContainers && !VerbContainerCheck(user, target))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool InVerbUseRange(IEntity user, IEntity target)
|
public static bool InVerbUseRange(IEntity user, IEntity target)
|
||||||
{
|
{
|
||||||
var distanceSquared = (user.Transform.WorldPosition - target.Transform.WorldPosition)
|
var distanceSquared = (user.Transform.WorldPosition - target.Transform.WorldPosition)
|
||||||
@@ -60,5 +76,19 @@ namespace Content.Shared.GameObjects.Verbs
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool VerbContainerCheck(IEntity user, IEntity target)
|
||||||
|
{
|
||||||
|
if (!user.IsInSameOrNoContainer(target))
|
||||||
|
{
|
||||||
|
if (!ContainerHelpers.TryGetContainer(target, out var container) ||
|
||||||
|
container.Owner != user)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user