Пример #1
0
        public static async Task <Tuple <DbRef, ObjectBase> > MatchObjectAsync([CanBeNull] Player player, [NotNull] ICacheClient redis, [CanBeNull] string text, CancellationToken cancellationToken)
        {
            // Did they provide a DbRef?
            DbRef reference;

            if (DbRef.TryParse(text, out reference))
            {
                // Only return the reference if the object exists.
                var lookup = await ObjectBase.GetAsync(redis, reference, cancellationToken);

                return(lookup == null
                    ? new Tuple <DbRef, ObjectBase>(DbRef.FailedMatch, null)
                    : new Tuple <DbRef, ObjectBase>(reference, lookup));
            }

            // Is it a special pronoun?
            if (string.Compare(text, "me", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                return(player == null
                    ? new Tuple <DbRef, ObjectBase>(DbRef.FailedMatch, null)
                    : new Tuple <DbRef, ObjectBase>(player.DbRef, player));
            }

            if (string.Compare(text, "here", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                return(player == null || player.Location.Equals(DbRef.Nothing)
                    ? new Tuple <DbRef, ObjectBase>(DbRef.FailedMatch, null)
                    : new Tuple <DbRef, ObjectBase>(player.Location, await ObjectBase.GetAsync(redis, player.Location, cancellationToken)));
            }

            return(await MatchTypeAsync <ObjectBase>(player, redis, text, cancellationToken));
        }