Add global verbs (#400)
* Add support for global verbs These are verbs that are visible for all entities, regardless of their components. This works by adding a new class `GlobalVerb` and a new attribute `GlobalVerbAttribute`. It works in the same way as current verbs, except you can put the verbs class definition anywhere instead of inside a component. Also moved VerbUtility into it's own file since it now has functions for both verbs and global verbs. * Add view variables verb as an example of global verbs * Implement suggested changes Implemented some suggested changes from code review: - Remove unneeded attribute from `GlobalVerb` - Added some useful attributes to `GlobalVerbAttribute` - Moved constants used by both `Verb` and `GlobalVerb` into `VerbUtility` * Reduce duplicate code in VerbSystem (client & server) Greatly reduced the amount of duplicate code for handling component verbs and global verbs separately. * Update engine submodule Need this so client side permissions checks are available.
This commit is contained in:
committed by
Pieter-Jan Briers
parent
e4f3ea7798
commit
6497cdf8ff
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.EntitySystemMessages;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
@@ -50,20 +51,12 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
var userEntity = session.AttachedEntity;
|
||||
|
||||
var data = new List<VerbsResponseMessage.VerbData>();
|
||||
//Get verbs, component dependent.
|
||||
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
|
||||
{
|
||||
if (verb.RequireInteractionRange)
|
||||
{
|
||||
var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition)
|
||||
.LengthSquared;
|
||||
if (distanceSquared > Verb.InteractionRangeSquared)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var vis = verb.GetVisibility(userEntity, component);
|
||||
if(vis == VerbVisibility.Invisible)
|
||||
if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
|
||||
continue;
|
||||
if(VerbUtility.IsVerbInvisible(verb, userEntity, component, out var vis))
|
||||
continue;
|
||||
|
||||
// TODO: These keys being giant strings is inefficient as hell.
|
||||
@@ -71,6 +64,17 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
$"{component.GetType()}:{verb.GetType()}",
|
||||
vis == VerbVisibility.Visible));
|
||||
}
|
||||
//Get global verbs. Visible for all entities regardless of their components.
|
||||
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
|
||||
{
|
||||
if (globalVerb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
|
||||
continue;
|
||||
if(VerbUtility.IsVerbInvisible(globalVerb, userEntity, entity, out var vis))
|
||||
continue;
|
||||
|
||||
data.Add(new VerbsResponseMessage.VerbData(globalVerb.GetText(userEntity, entity),
|
||||
globalVerb.GetType().ToString(), vis == VerbVisibility.Visible));
|
||||
}
|
||||
|
||||
var response = new VerbsResponseMessage(data, req.EntityUid);
|
||||
RaiseNetworkEvent(response, channel);
|
||||
@@ -99,7 +103,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition)
|
||||
.LengthSquared;
|
||||
if (distanceSquared > Verb.InteractionRangeSquared)
|
||||
if (distanceSquared > VerbUtility.InteractionRangeSquared)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user