コード例 #1
0
        private IDictata GetExistingMeaning(string word, LexicalType wordType = LexicalType.Noun)
        {
            List <string> allContext = new List <string>();

            //Get all local nouns
            allContext.AddRange(_currentPlace.GetContents <IInanimate>().SelectMany(thing => thing.Keywords));
            allContext.AddRange(_currentPlace.GetContents <IMobile>().SelectMany(thing => thing.Keywords));
            allContext.AddRange(_currentPlace.Keywords);
            allContext.AddRange(_actor.Keywords);

            IDictata existingMeaning = null;

            //It's a thing we can see
            if (allContext.Contains(word))
            {
                existingMeaning = new Dictata()
                {
                    Name = word, WordType = LexicalType.ProperNoun
                };
            }
            else
            {
                //TODO: We need to discriminate based on lexical type as well, we could have multiple of the same word with different types
                if (_currentDictionary.Any(dict => dict.Name.Equals(word, StringComparison.InvariantCultureIgnoreCase)))
                {
                    existingMeaning = _currentDictionary.FirstOrDefault(dict => dict.Name.Equals(word, StringComparison.InvariantCultureIgnoreCase))?.GetForm(wordType);
                }
            }

            return(existingMeaning);
        }
コード例 #2
0
        /// <summary>
        /// Build out the context object
        /// </summary>
        /// <param name="entity">the subject</param>
        private LexicalContext BuildContext(IEntity entity, IEntity observer)
        {
            LexicalContext context = new LexicalContext(observer);

            bool      specific       = true;
            ILocation entityLocation = entity?.CurrentLocation?.CurrentLocation();

            if (entityLocation != null)
            {
                Type type = entity.GetType();

                //We're looking for more things with the same template id (ie based on the same thing, like more than one wolf or sword)
                if (type == typeof(IInanimate))
                {
                    specific = !entityLocation.GetContents <IInanimate>().Any(item => item != entity && item.TemplateId == entity.TemplateId);
                }
                else if (type == typeof(INonPlayerCharacter))
                {
                    specific           = !entityLocation.GetContents <INonPlayerCharacter>().Any(item => item != entity && item.TemplateId == entity.TemplateId);
                    context.GenderForm = ((INonPlayerCharacter)entity).Gender;
                }
                else if (type == typeof(IPlayer))
                {
                    context.GenderForm = ((IPlayer)entity).Gender;
                }
            }

            context.Determinant = specific;

            return(context);
        }