private void UseVerb(UseVerbMessage use) { var channel = use.NetChannel; if (channel == null) { return; } if (!_entityManager.TryGetEntity(use.EntityUid, out var entity)) { return; } var session = _playerManager.GetSessionByChannel(channel); var userEntity = session.AttachedEntity; foreach (var(component, verb) in VerbUtility.GetVerbs(entity)) { if ($"{component.GetType()}:{verb.GetType()}" != use.VerbKey) { continue; } if (verb.RequireInteractionRange) { var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition) .LengthSquared; if (distanceSquared > VerbUtility.InteractionRangeSquared) { break; } } verb.Activate(userEntity, component); break; } foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly())) { if (globalVerb.GetType().ToString() != use.VerbKey) { continue; } if (globalVerb.RequireInteractionRange) { var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition) .LengthSquared; if (distanceSquared > VerbUtility.InteractionRangeSquared) { break; } } globalVerb.Activate(userEntity, entity); break; } }
private void UseVerb(UseVerbMessage use, EntitySessionEventArgs eventArgs) { if (!_entityManager.TryGetEntity(use.EntityUid, out var entity)) { return; } 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) { continue; } if (!VerbUtility.VerbAccessChecks(userEntity, entity, verb)) { break; } verb.Activate(userEntity, component); break; } foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly())) { if (globalVerb.GetType().ToString() != use.VerbKey) { continue; } if (!VerbUtility.VerbAccessChecks(userEntity, entity, globalVerb)) { break; } globalVerb.Activate(userEntity, entity); break; } }