Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Render this to a look command (what something sees when it 'look's at this
        /// </summary>
        /// <returns>the output strings</returns>
        public ILexicalParagraph RenderToVisible(IEntity viewer)
        {
            short strength = GetVisibleDelta(viewer);

            ISensoryEvent me = GetSelf(MessagingType.Visible, strength);

            LexicalContext collectiveContext = new LexicalContext(viewer)
            {
                Determinant = true,
                Perspective = NarrativePerspective.SecondPerson,
                Plural      = false,
                Position    = LexicalPosition.Near,
                Tense       = LexicalTense.Present
            };

            LexicalContext discreteContext = new LexicalContext(viewer)
            {
                Determinant = true,
                Perspective = NarrativePerspective.ThirdPerson,
                Plural      = false,
                Position    = LexicalPosition.Attached,
                Tense       = LexicalTense.Present
            };

            Lexica verb = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "leads", collectiveContext);

            me.Event.TryModify(verb);

            return(new LexicalParagraph(me));
        }
Ejemplo n.º 3
0
        private static IDictata FocusFindWord(IEnumerable <IDictata> possibleWords, LexicalContext context, IDictataPhrase basePhrase)
        {
            if (context.Language == null)
            {
                context.Language = basePhrase.Language;
            }

            possibleWords = possibleWords.Where(word => word != null && word.Language == context.Language && word.GetLexeme().SuitableForUse);

            if (context.Severity + context.Elegance + context.Quality == 0)
            {
                List <Tuple <IDictata, int> > rankedWords = new List <Tuple <IDictata, int> >();
                int baseRanking = GetSynonymRanking(basePhrase, context);

                rankedWords.AddRange(possibleWords.Select(word => new Tuple <IDictata, int>(word, GetSynonymRanking(word, context))));

                if (baseRanking > rankedWords.Max(phrase => phrase.Item2))
                {
                    return(null);
                }

                return(rankedWords.OrderByDescending(pair => pair.Item2).Select(pair => pair.Item1).FirstOrDefault());
            }

            return(GetRelatedWord(basePhrase, possibleWords, context.Severity, context.Elegance, context.Quality));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Put it in the cache
        /// </summary>
        /// <returns>success status</returns>
        public override bool PersistToCache()
        {
            try
            {
                LexicalContext collectiveContext = new LexicalContext(null)
                {
                    Determinant = true,
                    Perspective = NarrativePerspective.ThirdPerson,
                    Plural      = false,
                    Position    = LexicalPosition.None,
                    Tense       = LexicalTense.Present
                };

                List <IDictata> dictatas = new List <IDictata>
                {
                    new Dictata(new Lexica(LexicalType.ProperNoun, GrammaticalType.Subject, Name, collectiveContext))
                };
                dictatas.AddRange(Descriptives.Select(desc => desc.Event.GetDictata()));

                foreach (IDictata dictata in dictatas)
                {
                    LexicalProcessor.VerifyLexeme(dictata.GetLexeme());
                }

                TemplateCache.Add(this);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex, LogChannels.SystemWarnings);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
 private static int GetSynonymRanking(IDictataPhrase word, LexicalContext context)
 {
     return((word.Positional == context.Position ? 5 : 0) +
            (word.Tense == context.Tense ? 5 : 0) +
            (word.Perspective == context.Perspective ? 5 : 0) +
            ((context.GenderForm == null || word.Feminine == context.GenderForm?.Feminine) ? 10 : 0) +
            (context.Semantics.Any() ? word.Semantics.Count(wrd => context.Semantics.Contains(wrd)) * 10 : 0));
 }
Ejemplo n.º 6
0
        public static IDictataPhrase GetSynonymPhrase(IDictata baseWord, LexicalContext context)
        {
            if (baseWord == null)
            {
                return(null);
            }

            return(FocusFindPhrase(baseWord.PhraseSynonyms.ToList(), context, baseWord));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Render this as being show inside a container
        /// </summary>
        /// <param name="viewer">The entity looking</param>
        /// <returns>the output strings</returns>
        public ILexicalParagraph RenderAsContents(IEntity viewer, MessagingType[] sensoryTypes)
        {
            if (sensoryTypes == null || sensoryTypes.Count() == 0)
            {
                sensoryTypes = new MessagingType[] { MessagingType.Audible, MessagingType.Olefactory, MessagingType.Psychic, MessagingType.Tactile, MessagingType.Taste, MessagingType.Visible };
            }

            IList <ISensoryEvent> Messages = new List <ISensoryEvent>();

            //Self becomes the first sense in the list
            foreach (MessagingType sense in sensoryTypes)
            {
                ISensoryEvent me = GetSelf(sense);
                switch (sense)
                {
                case MessagingType.Audible:
                case MessagingType.Olefactory:
                case MessagingType.Psychic:
                case MessagingType.Tactile:
                case MessagingType.Taste:
                    continue;

                case MessagingType.Visible:
                    me.Strength = GetVisibleDelta(viewer);

                    me.TryModify(GetVisibleDescriptives(viewer));

                    me.Event.Context = new LexicalContext(viewer)
                    {
                        Determinant = true,
                        Perspective = NarrativePerspective.None,
                        Plural      = false,
                        Position    = LexicalPosition.InsideOf,
                        Tense       = LexicalTense.Present
                    };

                    LexicalContext skyContext = new LexicalContext(viewer)
                    {
                        Determinant = true,
                        Perspective = NarrativePerspective.None,
                        Plural      = false,
                        Position    = LexicalPosition.None,
                        Tense       = LexicalTense.Present
                    };

                    me.TryModify(new Lexica(LexicalType.Noun, GrammaticalType.DirectObject, "sky", skyContext));
                    break;
                }

                if (me.Event.Modifiers.Count() > 0)
                {
                    Messages.Add(me);
                }
            }

            return(new LexicalParagraph(Messages));
        }
Ejemplo n.º 8
0
        public static IDictata GetSynonym(IDictata baseWord, LexicalContext context)
        {
            if (baseWord == null)
            {
                return(baseWord);
            }

            return(FocusFindWord(baseWord.Synonyms.ToList(), context, baseWord));
        }
Ejemplo n.º 9
0
        public static IDictataPhrase GetSynonymPhrase(IDictataPhrase basePhrase, LexicalContext context)
        {
            if (basePhrase == null)
            {
                return(basePhrase);
            }

            return(FocusFindPhrase(basePhrase.PhraseSynonyms.ToList(), context, basePhrase));
        }
Ejemplo n.º 10
0
        public static IDictata GetSynonym(IDictataPhrase basePhrase, LexicalContext context)
        {
            if (basePhrase == null)
            {
                return(null);
            }

            return(FocusFindWord(basePhrase.Synonyms.ToList(), context, basePhrase));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Render this to a look command (what something sees when it 'look's at this
        /// </summary>
        /// <returns>the output strings</returns>
        public override ILexicalParagraph RenderToVisible(IEntity viewer)
        {
            short strength = GetVisibleDelta(viewer);

            IPathwayTemplate bS = Template <IPathwayTemplate>();
            ISensoryEvent    me = GetSelf(MessagingType.Visible, strength);

            if (bS.Descriptives.Any())
            {
                foreach (ISensoryEvent desc in bS.Descriptives)
                {
                    me.Event.TryModify(desc.Event);
                }
            }
            else
            {
                LexicalContext collectiveContext = new LexicalContext(viewer)
                {
                    Determinant = true,
                    Perspective = NarrativePerspective.SecondPerson,
                    Plural      = false,
                    Position    = LexicalPosition.Near,
                    Tense       = LexicalTense.Present
                };

                LexicalContext discreteContext = new LexicalContext(viewer)
                {
                    Determinant = true,
                    Perspective = NarrativePerspective.ThirdPerson,
                    Plural      = false,
                    Position    = LexicalPosition.Attached,
                    Tense       = LexicalTense.Present
                };

                Lexica verb = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "leads", collectiveContext);

                //Fallback to using names
                if (DirectionType == MovementDirectionType.None)
                {
                    Lexica origin = new Lexica(LexicalType.Noun, GrammaticalType.DirectObject, Origin.TemplateName, discreteContext);
                    origin.TryModify(new Lexica(LexicalType.Noun, GrammaticalType.IndirectObject, Destination.TemplateName, discreteContext));
                    verb.TryModify(origin);
                }
                else
                {
                    Lexica direction = new Lexica(LexicalType.Noun, GrammaticalType.DirectObject, DirectionType.ToString(), discreteContext);
                    Lexica origin    = new Lexica(LexicalType.Noun, GrammaticalType.IndirectObject, Origin.TemplateName, discreteContext);
                    origin.TryModify(new Lexica(LexicalType.Noun, GrammaticalType.IndirectObject, Destination.TemplateName, discreteContext));
                    direction.TryModify(origin);
                }

                me.Event.TryModify(verb);
            }

            return(new LexicalParagraph(me));
        }
Ejemplo n.º 12
0
        public Lexica(LexicalType type, GrammaticalType role, string phrase, IEntity origin, IEntity observer)
        {
            Type   = type;
            Phrase = phrase;
            Role   = role;

            Modifiers = new HashSet <ILexica>();

            LexicalProcessor.VerifyLexeme(this);
            Context = BuildContext(origin, observer);
        }
Ejemplo n.º 13
0
        public Lexica(LexicalType type, GrammaticalType role, string phrase, LexicalContext context)
        {
            Type   = type;
            Phrase = phrase;
            Role   = role;

            Modifiers = new HashSet <ILexica>();

            LexicalProcessor.VerifyLexeme(this);
            Context = context.Clone();
        }
Ejemplo n.º 14
0
        public Lexica(LexicalType type, GrammaticalType role, string phrase, LexicalContext context)
        {
            Type   = type;
            Phrase = phrase;
            Role   = role;

            Modifiers = new HashSet <ILexica>();

            Context = context.Clone();
            GetDictata();
        }
Ejemplo n.º 15
0
        public Lexica(LexicalType type, GrammaticalType role, string phrase, IEntity origin, IEntity observer)
        {
            Type   = type;
            Phrase = phrase;
            Role   = role;

            Modifiers = new HashSet <ILexica>();

            Context = BuildContext(origin, observer);
            GetDictata();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Unpack the sentences/lexica
        /// </summary>
        /// <param name="overridingContext">Context to override the lexica with</param>
        public void Unpack(LexicalContext overridingContext = null)
        {
            //Clean them out
            List <ILexicalSentence> sentences = new List <ILexicalSentence>();

            foreach (ISensoryEvent sensoryEvent in Events)
            {
                sentences.AddRange(sensoryEvent.Unpack(overridingContext));
            }

            Sentences = sentences;
        }
Ejemplo n.º 17
0
        public static IDictataPhrase GetPhrase(LexicalContext context)
        {
            if (context.Language == null)
            {
                IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld));

                context.Language = globalConfig.BaseLanguage;
            }

            IEnumerable <IDictataPhrase> possibleWords = ConfigDataCache.GetAll <IDictataPhrase>().Where(dict => dict.Language == context.Language && dict.SuitableForUse);

            return(possibleWords.OrderByDescending(word => GetSynonymRanking(word, context)).FirstOrDefault());
        }
Ejemplo n.º 18
0
        public virtual ILexicalParagraph RenderResourceCollection(IEntity viewer, int amount)
        {
            LexicalContext collectiveContext = new LexicalContext(viewer)
            {
                Determinant = true,
                Perspective = NarrativePerspective.SecondPerson,
                Plural      = false,
                Position    = LexicalPosition.Around,
                Tense       = LexicalTense.Present
            };

            ISensoryEvent me = GetImmediateDescription(viewer, MessagingType.Visible);

            me.TryModify(new Lexica(LexicalType.Adjective, GrammaticalType.Descriptive, amount.ToString(), collectiveContext));

            return(new LexicalParagraph(me));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Get the string version of all the contained messages
        /// </summary>
        /// <param name="target">The entity type to select the messages of</param>
        /// <returns>Everything unpacked</returns>
        public string Unpack(TargetEntity target, LexicalContext overridingContext = null)
        {
            switch (target)
            {
            case TargetEntity.Destination:
                return(string.Join(" ", ToDestination.Select(msg => msg.Describe(overridingContext))));

            case TargetEntity.Origin:
                return(string.Join(" ", ToOrigin.Select(msg => msg.Describe(overridingContext))));

            case TargetEntity.Subject:
                return(string.Join(" ", ToSubject.Select(msg => msg.Describe(overridingContext))));

            case TargetEntity.Target:
                return(string.Join(" ", ToTarget.Select(msg => msg.Describe(overridingContext))));
            }

            return(string.Join(" ", ToActor.Select(msg => msg.Describe(overridingContext))));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Add language translations for this
        /// </summary>
        public void FillLanguages()
        {
            IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld));

            //Don't do this if: we have no config, translation is turned off or lacking in the azure key, the language is not a human-ui language
            //it isn't an approved language, the word is a proper noun or the language isnt the base language at all
            if (globalConfig == null || !globalConfig.TranslationActive || string.IsNullOrWhiteSpace(globalConfig.AzureTranslationKey) ||
                !Language.UIOnly || !Language.SuitableForUse || ContainedTypes().Contains(LexicalType.ProperNoun) || Language != globalConfig.BaseLanguage)
            {
                return;
            }

            IEnumerable <ILanguage> otherLanguages = ConfigDataCache.GetAll <ILanguage>().Where(lang => lang != Language && lang.SuitableForUse && lang.UIOnly);

            foreach (ILanguage language in otherLanguages)
            {
                short  formGrouping = -1;
                string newName      = string.Empty;

                Lexeme newLexeme = new Lexeme()
                {
                    Language = language
                };

                foreach (IDictata word in WordForms)
                {
                    LexicalContext context = new LexicalContext(null)
                    {
                        Language    = language,
                        Perspective = word.Perspective,
                        Tense       = word.Tense,
                        Position    = word.Positional,
                        Determinant = word.Determinant,
                        Plural      = word.Plural,
                        Possessive  = word.Possessive,
                        Elegance    = word.Elegance,
                        Quality     = word.Quality,
                        Semantics   = word.Semantics,
                        Severity    = word.Severity,
                        GenderForm  = new Gender()
                        {
                            Feminine = word.Feminine
                        }
                    };

                    IDictata translatedWord = Thesaurus.GetSynonym(word, context);

                    //no linguistic synonym
                    if (translatedWord == this)
                    {
                        string newWord = Thesaurus.GetTranslatedWord(globalConfig.AzureTranslationKey, Name, Language, language);

                        if (!string.IsNullOrWhiteSpace(newWord))
                        {
                            newName        = newWord;
                            newLexeme.Name = newName;

                            Dictata newDictata = new Dictata(newWord, formGrouping++)
                            {
                                Elegance       = word.Elegance,
                                Severity       = word.Severity,
                                Quality        = word.Quality,
                                Determinant    = word.Determinant,
                                Plural         = word.Plural,
                                Perspective    = word.Perspective,
                                Feminine       = word.Feminine,
                                Positional     = word.Positional,
                                Possessive     = word.Possessive,
                                Semantics      = word.Semantics,
                                Antonyms       = word.Antonyms,
                                Synonyms       = word.Synonyms,
                                PhraseAntonyms = word.PhraseAntonyms,
                                PhraseSynonyms = word.PhraseSynonyms,
                                Tense          = word.Tense,
                                WordType       = word.WordType
                            };

                            newDictata.Synonyms = new HashSet <IDictata>(word.Synonyms)
                            {
                                word
                            };
                            word.Synonyms = new HashSet <IDictata>(word.Synonyms)
                            {
                                newDictata
                            };
                            newLexeme.AddNewForm(newDictata);
                        }
                    }
                }

                if (newLexeme.WordForms.Count() > 0)
                {
                    newLexeme.SystemSave();
                    newLexeme.PersistToCache();
                }
            }

            SystemSave();
            PersistToCache();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Render this in a short descriptive style
        /// </summary>
        /// <param name="viewer">The entity looking</param>
        /// <returns>the output strings</returns>
        public override ILexicalParagraph GetFullDescription(IEntity viewer, MessagingType[] sensoryTypes = null)
        {
            if (sensoryTypes == null || sensoryTypes.Count() == 0)
            {
                sensoryTypes = new MessagingType[] { MessagingType.Audible, MessagingType.Olefactory, MessagingType.Psychic, MessagingType.Tactile, MessagingType.Taste, MessagingType.Visible };
            }

            LexicalContext collectiveContext = new LexicalContext(viewer)
            {
                Determinant = true,
                Perspective = NarrativePerspective.SecondPerson,
                Plural      = false,
                Position    = LexicalPosition.None,
                Tense       = LexicalTense.Present
            };

            LexicalContext discreteContext = new LexicalContext(viewer)
            {
                Determinant = false,
                Perspective = NarrativePerspective.ThirdPerson,
                Plural      = false,
                Position    = LexicalPosition.Far,
                Tense       = LexicalTense.Present
            };

            //Self becomes the first sense in the list
            List <ISensoryEvent> sensoryOutput = new List <ISensoryEvent>();

            foreach (MessagingType sense in sensoryTypes)
            {
                ISensoryEvent me = GetSelf(sense);
                switch (sense)
                {
                case MessagingType.Audible:
                    me.Strength = GetAudibleDelta(viewer);

                    IEnumerable <ISensoryEvent> aDescs = GetAudibleDescriptives(viewer);

                    if (aDescs.Count() == 0)
                    {
                        continue;
                    }

                    me.TryModify(aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                    ILexica uberSounds = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "hear", collectiveContext);
                    uberSounds.TryModify(aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                    foreach (ISensoryEvent desc in aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                    {
                        Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext);
                        newDesc.TryModify(desc.Event.Modifiers);

                        uberSounds.TryModify(newDesc);
                    }

                    if (uberSounds.Modifiers.Any())
                    {
                        me.TryModify(uberSounds);
                    }

                    break;

                case MessagingType.Olefactory:
                    me.Strength = GetOlefactoryDelta(viewer);

                    IEnumerable <ISensoryEvent> oDescs = GetOlefactoryDescriptives(viewer);

                    if (oDescs.Count() == 0)
                    {
                        continue;
                    }

                    me.TryModify(oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                    ILexica uberSmells = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "smell", collectiveContext);
                    uberSmells.TryModify(oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                    foreach (ISensoryEvent desc in oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                    {
                        Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext);
                        newDesc.TryModify(desc.Event.Modifiers);

                        uberSmells.TryModify(newDesc);
                    }

                    if (uberSmells.Modifiers.Any())
                    {
                        me.TryModify(uberSmells);
                    }

                    break;

                case MessagingType.Psychic:
                    me.Strength = GetPsychicDelta(viewer);

                    IEnumerable <ISensoryEvent> pDescs = GetPsychicDescriptives(viewer);

                    if (pDescs.Count() == 0)
                    {
                        continue;
                    }

                    me.TryModify(pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                    Lexica collectivePsy = new Lexica(LexicalType.Pronoun, GrammaticalType.Subject, "you", collectiveContext);

                    ILexica uberPsy = collectivePsy.TryModify(LexicalType.Verb, GrammaticalType.Verb, "sense");
                    uberPsy.TryModify(pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                    foreach (ISensoryEvent desc in pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                    {
                        Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext);
                        newDesc.TryModify(desc.Event.Modifiers);

                        uberPsy.TryModify(newDesc);
                    }

                    if (uberPsy.Modifiers.Any())
                    {
                        me.TryModify(collectivePsy);
                    }

                    break;

                case MessagingType.Taste:
                    continue;

                case MessagingType.Tactile:
                    me.Strength = GetTactileDelta(viewer);

                    //Add the temperature
                    me.TryModify(LexicalType.Verb, GrammaticalType.Verb, "feels").TryModify(new Lexica[] {
                        new Lexica(LexicalType.Adjective, GrammaticalType.Descriptive, MeteorologicalUtilities.ConvertHumidityToType(EffectiveHumidity()).ToString(), collectiveContext),
                        new Lexica(LexicalType.Adjective, GrammaticalType.Descriptive, MeteorologicalUtilities.ConvertTemperatureToType(EffectiveTemperature()).ToString(), collectiveContext)
                    });

                    break;

                case MessagingType.Visible:
                    me.Strength = GetVisibleDelta(viewer);

                    IEnumerable <ISensoryEvent> vDescs = GetVisibleDescriptives(viewer);

                    if (vDescs.Count() > 0)
                    {
                        me.TryModify(vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                        Lexica collectiveSight = new Lexica(LexicalType.Pronoun, GrammaticalType.Subject, "you", collectiveContext);

                        ILexica uberSight = collectiveSight.TryModify(LexicalType.Verb, GrammaticalType.Verb, "see");
                        uberSight.TryModify(vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                        foreach (ISensoryEvent desc in vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                        {
                            Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext);
                            newDesc.TryModify(desc.Event.Modifiers);

                            uberSight.TryModify(newDesc);
                        }

                        if (uberSight.Modifiers.Any())
                        {
                            me.TryModify(collectiveSight);
                        }
                    }

                    //Describe the size and population of this zone
                    DimensionalSizeDescription zoneSize = GeographicalUtilities.ConvertSizeToType(GetModelDimensions(), GetType());

                    me.TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, zoneSize.ToString());

                    //Render people in the zone
                    CrowdSizeDescription populationSize = GeographicalUtilities.GetCrowdSize(GetContents <IMobile>().Count());

                    string crowdSize = "abandoned";
                    if ((short)populationSize > (short)zoneSize)
                    {
                        crowdSize = "crowded";
                    }
                    else if (populationSize > CrowdSizeDescription.Intimate)
                    {
                        crowdSize = "sparsely populated";
                    }

                    me.TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, crowdSize);

                    break;
                }

                if (me != null)
                {
                    sensoryOutput.Add(me);
                }
            }

            foreach (ICelestial celestial in GetVisibileCelestials(viewer))
            {
                sensoryOutput.AddRange(celestial.RenderAsContents(viewer, sensoryTypes).Events);
            }

            foreach (IWeatherEvent wEvent in WeatherEvents)
            {
                sensoryOutput.AddRange(wEvent.RenderAsContents(viewer, sensoryTypes).Events);
            }

            foreach (INaturalResourceSpawn <IFlora> resource in FloraNaturalResources)
            {
                sensoryOutput.AddRange(resource.Resource.RenderResourceCollection(viewer, resource.RateFactor).Events);
            }

            foreach (INaturalResourceSpawn <IFauna> resource in FaunaNaturalResources)
            {
                sensoryOutput.AddRange(resource.Resource.RenderResourceCollection(viewer, resource.RateFactor).Events);
            }

            foreach (INaturalResourceSpawn <IMineral> resource in MineralNaturalResources)
            {
                sensoryOutput.AddRange(resource.Resource.RenderResourceCollection(viewer, resource.RateFactor).Events);
            }

            //render our locales out
            foreach (ILocale locale in LiveCache.GetAll <ILocale>().Where(loc => loc.ParentLocation?.TemplateId == TemplateId))
            {
                sensoryOutput.AddRange(locale.RenderAsContents(viewer, sensoryTypes).Events);
            }

            //render our locales out
            foreach (IPathway path in GetPathways())
            {
                sensoryOutput.AddRange(path.RenderAsContents(viewer, sensoryTypes).Events);
            }

            return(new LexicalParagraph(sensoryOutput));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Render this as being show inside a container
        /// </summary>
        /// <param name="viewer">The entity looking</param>
        /// <returns>the output strings</returns>
        public override ILexicalParagraph RenderAsContents(IEntity viewer, MessagingType[] sensoryTypes)
        {
            if (sensoryTypes == null || sensoryTypes.Count() == 0)
            {
                sensoryTypes = new MessagingType[] { MessagingType.Audible, MessagingType.Olefactory, MessagingType.Psychic, MessagingType.Tactile, MessagingType.Taste, MessagingType.Visible };
            }

            LexicalContext collectiveContext = new LexicalContext(viewer)
            {
                Determinant = true,
                Perspective = NarrativePerspective.SecondPerson,
                Plural      = false,
                Position    = LexicalPosition.None,
                Tense       = LexicalTense.Present
            };

            LexicalContext discreteContext = new LexicalContext(viewer)
            {
                Determinant = false,
                Perspective = NarrativePerspective.ThirdPerson,
                Plural      = false,
                Position    = LexicalPosition.Far,
                Tense       = LexicalTense.Present
            };

            List <ISensoryEvent> sensoryOutput = new List <ISensoryEvent>();

            foreach (MessagingType sense in sensoryTypes)
            {
                SensoryEvent me        = new SensoryEvent(new Lexica(LexicalType.Pronoun, GrammaticalType.Subject, "you", collectiveContext), 0, sense);
                ILexica      senseVerb = null;
                IEnumerable <ISensoryEvent> senseDescs = Enumerable.Empty <ISensoryEvent>();

                switch (sense)
                {
                case MessagingType.Audible:
                    me.Strength = GetAudibleDelta(viewer);

                    senseVerb = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "hear", collectiveContext);

                    IEnumerable <ISensoryEvent> audibleDescs = GetAudibleDescriptives(viewer);

                    if (audibleDescs.Count() == 0)
                    {
                        continue;
                    }

                    ISensoryEvent audibleNoun = null;
                    if (!audibleDescs.Any(desc => desc.Event.Role == GrammaticalType.DirectObject))
                    {
                        audibleNoun = new SensoryEvent(new Lexica(LexicalType.Noun, GrammaticalType.DirectObject, "noise", discreteContext), me.Strength, sense);
                    }
                    else
                    {
                        audibleNoun = audibleDescs.FirstOrDefault(desc => desc.Event.Role == GrammaticalType.DirectObject);
                    }

                    audibleNoun.TryModify(audibleDescs.Where(desc => desc.Event.Role == GrammaticalType.Descriptive));
                    senseDescs = new List <ISensoryEvent>()
                    {
                        audibleNoun
                    };
                    break;

                case MessagingType.Olefactory:
                    me.Strength = GetOlefactoryDelta(viewer);

                    senseVerb = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "smell", collectiveContext);

                    IEnumerable <ISensoryEvent> smellDescs = GetOlefactoryDescriptives(viewer);

                    if (smellDescs.Count() == 0)
                    {
                        continue;
                    }

                    ISensoryEvent smellNoun = null;
                    if (!smellDescs.Any(desc => desc.Event.Role == GrammaticalType.DirectObject))
                    {
                        smellNoun = new SensoryEvent(new Lexica(LexicalType.Noun, GrammaticalType.DirectObject, "odor", discreteContext), me.Strength, sense);
                    }
                    else
                    {
                        smellNoun = smellDescs.FirstOrDefault(desc => desc.Event.Role == GrammaticalType.DirectObject);
                    }

                    smellNoun.TryModify(smellDescs.Where(desc => desc.Event.Role == GrammaticalType.Descriptive));
                    senseDescs = new List <ISensoryEvent>()
                    {
                        smellNoun
                    };
                    break;

                case MessagingType.Psychic:
                    me.Strength = GetPsychicDelta(viewer);

                    senseVerb = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "sense", collectiveContext);

                    IEnumerable <ISensoryEvent> psyDescs = GetPsychicDescriptives(viewer);

                    if (psyDescs.Count() == 0)
                    {
                        continue;
                    }

                    ISensoryEvent psyNoun = null;
                    if (!psyDescs.Any(desc => desc.Event.Role == GrammaticalType.DirectObject))
                    {
                        psyNoun = new SensoryEvent(new Lexica(LexicalType.Noun, GrammaticalType.DirectObject, "presence", discreteContext), me.Strength, sense);
                    }
                    else
                    {
                        psyNoun = psyDescs.FirstOrDefault(desc => desc.Event.Role == GrammaticalType.DirectObject);
                    }

                    psyNoun.TryModify(psyDescs.Where(desc => desc.Event.Role == GrammaticalType.Descriptive));
                    senseDescs = new List <ISensoryEvent>()
                    {
                        psyNoun
                    };
                    break;

                case MessagingType.Tactile:
                case MessagingType.Taste:
                    continue;

                case MessagingType.Visible:
                    me.Strength = GetVisibleDelta(viewer);

                    senseVerb = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "see", collectiveContext);

                    IEnumerable <ISensoryEvent> seeDescs = GetVisibleDescriptives(viewer);

                    if (seeDescs.Count() == 0)
                    {
                        continue;
                    }

                    ISensoryEvent seeNoun = null;
                    if (!seeDescs.Any(desc => desc.Event.Role == GrammaticalType.DirectObject))
                    {
                        seeNoun = new SensoryEvent(new Lexica(LexicalType.Noun, GrammaticalType.DirectObject, "thing", discreteContext), me.Strength, sense);
                    }
                    else
                    {
                        seeNoun = seeDescs.FirstOrDefault(desc => desc.Event.Role == GrammaticalType.DirectObject);
                    }

                    seeNoun.TryModify(seeDescs.Where(desc => desc.Event.Role == GrammaticalType.Descriptive));
                    senseDescs = new List <ISensoryEvent>()
                    {
                        seeNoun
                    };
                    break;
                }

                if (senseVerb != null && senseDescs.Count() > 0)
                {
                    IEnumerable <ILexica> senseEvents = senseDescs.Select(desc => desc.Event);

                    foreach (ILexica evt in senseEvents)
                    {
                        evt.Context = discreteContext;
                        senseVerb.TryModify(evt);
                    }

                    me.TryModify(senseVerb);
                    sensoryOutput.Add(me);
                }
            }

            return(new LexicalParagraph(sensoryOutput));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Render a natural resource collection to a viewer
        /// </summary>
        /// <param name="viewer">the entity looking</param>
        /// <param name="amount">How much of it there is</param>
        /// <returns>a view string</returns>
        public override ILexicalParagraph RenderResourceCollection(IEntity viewer, int amount)
        {
            if (amount <= 0)
            {
                return(new LexicalParagraph());
            }

            LexicalContext collectiveContext = new LexicalContext(viewer)
            {
                Determinant = false,
                Perspective = NarrativePerspective.SecondPerson,
                Plural      = false,
                Position    = LexicalPosition.None,
                Tense       = LexicalTense.Present
            };

            LexicalContext discreteContext = new LexicalContext(viewer)
            {
                Determinant = false,
                Perspective = NarrativePerspective.ThirdPerson,
                Plural      = false,
                Position    = LexicalPosition.Attached,
                Tense       = LexicalTense.Present
            };
            string sizeWord;

            if (amount < 20)
            {
                sizeWord = "sparse";
            }
            else if (amount < 50)
            {
                sizeWord = "small";
            }
            else if (amount < 200)
            {
                sizeWord = "";
            }
            else
            {
                sizeWord = "vast";
            }

            SensoryEvent observer = new SensoryEvent(new Lexica(LexicalType.Pronoun, GrammaticalType.Subject, "you", collectiveContext), 0, MessagingType.Visible)
            {
                Strength = GetVisibleDelta(viewer)
            };

            SensoryEvent collectiveNoun = new SensoryEvent(new Lexica(LexicalType.Noun, GrammaticalType.DirectObject, "forest", collectiveContext),
                                                           GetVisibleDelta(viewer), MessagingType.Visible);

            ISensoryEvent me = GetSelf(MessagingType.Visible, GetVisibleDelta(viewer));

            me.Event.Role = GrammaticalType.Descriptive;

            collectiveNoun.TryModify(me);

            SensoryEvent senseVerb = new SensoryEvent(new Lexica(LexicalType.Verb, GrammaticalType.Verb, "see", collectiveContext), me.Strength, MessagingType.Visible);

            if (!string.IsNullOrWhiteSpace(sizeWord))
            {
                collectiveNoun.TryModify(new Lexica(LexicalType.Adjective, GrammaticalType.Descriptive, sizeWord, discreteContext));
            }

            senseVerb.TryModify(collectiveNoun);
            observer.TryModify(senseVerb);

            return(new LexicalParagraph(observer));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Render this in a short descriptive style
        /// </summary>
        /// <param name="viewer">The entity looking</param>
        /// <returns>the output strings</returns>
        public override ILexicalParagraph GetFullDescription(IEntity viewer, MessagingType[] sensoryTypes = null)
        {
            if (sensoryTypes == null || sensoryTypes.Count() == 0)
            {
                sensoryTypes = new MessagingType[] { MessagingType.Audible, MessagingType.Olefactory, MessagingType.Psychic, MessagingType.Tactile, MessagingType.Taste, MessagingType.Visible };
            }

            LexicalContext collectiveContext = new LexicalContext(viewer)
            {
                Determinant = true,
                Perspective = NarrativePerspective.SecondPerson,
                Plural      = false,
                Position    = LexicalPosition.Around,
                Tense       = LexicalTense.Present
            };

            LexicalContext discreteContext = new LexicalContext(viewer)
            {
                Determinant = true,
                Perspective = NarrativePerspective.ThirdPerson,
                Plural      = false,
                Position    = LexicalPosition.Attached,
                Tense       = LexicalTense.Present
            };

            //Self becomes the first sense in the list
            List <ISensoryEvent> messages = new List <ISensoryEvent>();

            foreach (MessagingType sense in sensoryTypes)
            {
                ISensoryEvent me = GetSelf(sense);

                switch (sense)
                {
                case MessagingType.Audible:
                    me.Strength = GetAudibleDelta(viewer);

                    IEnumerable <ISensoryEvent> aDescs = GetAudibleDescriptives(viewer);

                    me.TryModify(aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                    ILexica uberSounds = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "hear", collectiveContext);
                    uberSounds.TryModify(aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                    foreach (ISensoryEvent desc in aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                    {
                        Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.Subject, desc.Event.Phrase, discreteContext);
                        newDesc.TryModify(desc.Event.Modifiers);

                        me.TryModify(newDesc);
                    }

                    if (uberSounds.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject))
                    {
                        me.TryModify(uberSounds);
                    }

                    break;

                case MessagingType.Olefactory:
                    me.Strength = GetOlefactoryDelta(viewer);

                    IEnumerable <ISensoryEvent> oDescs = GetOlefactoryDescriptives(viewer);

                    me.TryModify(oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                    Lexica uberSmells = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "smell", collectiveContext);
                    uberSmells.TryModify(oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                    foreach (ISensoryEvent desc in oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                    {
                        Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext);
                        newDesc.TryModify(desc.Event.Modifiers);

                        uberSmells.TryModify(newDesc);
                    }

                    if (uberSmells.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject))
                    {
                        me.TryModify(uberSmells);
                    }

                    break;

                case MessagingType.Psychic:
                    me.Strength = GetPsychicDelta(viewer);

                    IEnumerable <ISensoryEvent> pDescs = GetPsychicDescriptives(viewer);

                    me.TryModify(pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                    Lexica collectivePsy = new Lexica(LexicalType.Pronoun, GrammaticalType.Subject, "you", collectiveContext);

                    ILexica uberPsy = collectivePsy.TryModify(LexicalType.Verb, GrammaticalType.Verb, "sense");
                    uberPsy.TryModify(pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                    foreach (ISensoryEvent desc in pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                    {
                        Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext);
                        newDesc.TryModify(desc.Event.Modifiers);

                        uberPsy.TryModify(newDesc);
                    }

                    if (uberPsy.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject))
                    {
                        me.TryModify(collectivePsy);
                    }

                    break;

                case MessagingType.Taste:
                    me.Strength = GetTasteDelta(viewer);

                    IEnumerable <ISensoryEvent> taDescs = GetTasteDescriptives(viewer);

                    me.TryModify(taDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                    Lexica uberTaste = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "taste", collectiveContext);
                    uberTaste.TryModify(taDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                    foreach (ISensoryEvent desc in taDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                    {
                        Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext);
                        newDesc.TryModify(desc.Event.Modifiers);

                        uberTaste.TryModify(newDesc);
                    }

                    if (uberTaste.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject))
                    {
                        me.TryModify(uberTaste);
                    }

                    break;

                case MessagingType.Tactile:
                    me.Strength = GetTactileDelta(viewer);

                    IEnumerable <ISensoryEvent> tDescs = GetOlefactoryDescriptives(viewer);

                    me.TryModify(tDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                    Lexica uberTouch = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "feel", collectiveContext);
                    uberTouch.TryModify(tDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                    foreach (ISensoryEvent desc in tDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                    {
                        Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext);
                        newDesc.TryModify(desc.Event.Modifiers);

                        uberTouch.TryModify(newDesc);
                    }

                    if (uberTouch.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject))
                    {
                        me.TryModify(uberTouch);
                    }

                    break;

                case MessagingType.Visible:
                    me.Strength = GetVisibleDelta(viewer);

                    IEnumerable <ISensoryEvent> vDescs = GetVisibleDescriptives(viewer);

                    me.TryModify(vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive));

                    Lexica uberSight = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "appears", collectiveContext);
                    uberSight.TryModify(vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event));

                    foreach (ISensoryEvent desc in vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject))
                    {
                        Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext);
                        newDesc.TryModify(desc.Event.Modifiers);

                        uberSight.TryModify(newDesc);
                    }

                    if (uberSight.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject))
                    {
                        me.TryModify(uberSight);
                    }

                    //Describe the size and population of this zone
                    DimensionalSizeDescription objectSize = GeographicalUtilities.ConvertSizeToType(GetModelDimensions(), GetType());

                    me.TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, objectSize.ToString());

                    //Render people in the zone
                    ObjectContainmentSizeDescription bulgeSizeAdjective = GeographicalUtilities.GetObjectContainmentSize(GetContents <IInanimate>().Sum(obj => obj.GetModelVolume()), GetModelVolume());

                    me.TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, bulgeSizeAdjective.ToString());

                    break;
                }

                messages.Add(me);
            }

            return(new LexicalParagraph(messages));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Create a narrative description from this
        /// </summary>
        /// <returns>A long description</returns>
        public string Describe(LexicalContext overridingContext = null)
        {
            if (!string.IsNullOrWhiteSpace(Override))
            {
                return(Override);
            }

            StringBuilder sb = new StringBuilder();

            if (Sentences.Count == 0 || overridingContext != null)
            {
                Unpack(overridingContext);
            }

            List <int> removedSentences            = new List <int>();
            List <ILexicalSentence> finalSentences = new List <ILexicalSentence>();

            for (int i = 0; i < Sentences.Count(); i++)
            {
                if (removedSentences.Contains(i))
                {
                    continue;
                }

                ILexicalSentence sentence = Sentences[i];
                for (int n = i + 1; n < Sentences.Count(); n++)
                {
                    if (removedSentences.Contains(n))
                    {
                        continue;
                    }

                    ILexicalSentence secondSentence = Sentences[n];
                    foreach (SentenceComplexityRule complexityRule in sentence.Language.ComplexityRules)
                    {
                        short match = complexityRule.MatchesRule(sentence, secondSentence, overridingContext.Elegance);

                        if (match != 0)
                        {
                            finalSentences.Add(CombineSentences(sentence, secondSentence, complexityRule, match));
                            removedSentences.Add(i);
                            removedSentences.Add(n);

                            //Short circut the outer for loop
                            n = Sentences.Count();
                            break;
                        }
                    }
                }

                if (!removedSentences.Contains(i))
                {
                    finalSentences.Add(sentence);
                }
            }

            foreach (ILexicalSentence sentence in finalSentences)
            {
                sb.Append(sentence.Describe() + " ");
            }

            if (sb.Length > 0)
            {
                sb.Length -= 1;
            }

            return(sb.ToString());
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Wraps sending messages to the connected descriptor
        /// </summary>
        /// <param name="strings">the output</param>
        /// <returns>success status</returns>
        public bool SendOutput(IEnumerable <string> strings)
        {
            //TODO: Stop hardcoding this but we have literally no sense of injury/self status yet
            SelfStatus self = new SelfStatus
            {
                Body = new BodyStatus
                {
                    Health  = _currentPlayer.CurrentHealth == 0 ? 100 : 100 / (2M * _currentPlayer.CurrentHealth),
                    Stamina = _currentPlayer.CurrentStamina,
                    Overall = OverallStatus.Excellent,
                    Anatomy = new AnatomicalPart[] {
                        new AnatomicalPart {
                            Name    = "Arm",
                            Overall = OverallStatus.Good,
                            Wounds  = new string[] {
                                "Light scrape"
                            }
                        },
                        new AnatomicalPart {
                            Name    = "Leg",
                            Overall = OverallStatus.Excellent,
                            Wounds  = new string[] {
                            }
                        }
                    }
                },
                CurrentActivity = _currentPlayer.CurrentAction,
                Balance         = _currentPlayer.Balance.ToString(),
                CurrentArt      = _currentPlayer.LastAttack?.Name ?? "",
                CurrentCombo    = _currentPlayer.LastCombo?.Name ?? "",
                CurrentTarget   = _currentPlayer.GetTarget() == null ? ""
                                                                   : _currentPlayer.GetTarget() == _currentPlayer
                                                                        ? "Your shadow"
                                                                        : _currentPlayer.GetTarget().GetDescribableName(_currentPlayer),
                CurrentTargetHealth = _currentPlayer.GetTarget() == null || _currentPlayer.GetTarget() == _currentPlayer ? double.PositiveInfinity
                                                                        : _currentPlayer.GetTarget().CurrentHealth == 0 ? 100 : 100 / (2 * _currentPlayer.CurrentHealth),
                Position  = _currentPlayer.StancePosition.ToString(),
                Stance    = _currentPlayer.Stance,
                Stagger   = _currentPlayer.Stagger.ToString(),
                Qualities = string.Join("", _currentPlayer.Qualities.Where(quality => quality.Visible).Select(quality => string.Format("<div class='qualityRow'><span>{0}</span><span>{1}</span></div>", quality.Name, quality.Value))),
                CurrentTargetQualities = _currentPlayer.GetTarget() == null || _currentPlayer.GetTarget() == _currentPlayer ? ""
                                                                            : string.Join("", _currentPlayer.GetTarget().Qualities.Where(quality => quality.Visible).Select(quality => string.Format("<div class='qualityRow'><span>{0}</span><span>{1}</span></div>", quality.Name, quality.Value))),
                Mind = new MindStatus
                {
                    Overall = OverallStatus.Excellent,
                    States  = new string[]
                    {
                        "Fearful"
                    }
                }
            };

            IGlobalPosition currentLocation  = _currentPlayer.CurrentLocation;
            IContains       currentContainer = currentLocation.CurrentLocation();
            IZone           currentZone      = currentContainer.CurrentLocation.CurrentZone;
            ILocale         currentLocale    = currentLocation.CurrentLocale;
            IRoom           currentRoom      = currentLocation.CurrentRoom;
            IGaia           currentWorld     = currentZone.GetWorld();

            IEnumerable <string> pathways  = Enumerable.Empty <string>();
            IEnumerable <string> inventory = Enumerable.Empty <string>();
            IEnumerable <string> populace  = Enumerable.Empty <string>();
            string locationDescription     = string.Empty;

            LexicalContext lexicalContext = new LexicalContext(_currentPlayer)
            {
                Language    = _currentPlayer.Template <IPlayerTemplate>().Account.Config.UILanguage,
                Perspective = NarrativePerspective.SecondPerson,
                Position    = LexicalPosition.Near
            };

            Message toCluster = new Message(currentContainer.RenderToVisible(_currentPlayer));

            if (currentContainer != null)
            {
                pathways            = ((ILocation)currentContainer).GetPathways().Select(data => data.GetDescribableName(_currentPlayer));
                inventory           = currentContainer.GetContents <IInanimate>().Select(data => data.GetDescribableName(_currentPlayer));
                populace            = currentContainer.GetContents <IMobile>().Where(player => !player.Equals(_currentPlayer)).Select(data => data.GetDescribableName(_currentPlayer));
                locationDescription = toCluster.Unpack(TargetEntity.Actor, lexicalContext);
            }

            LocalStatus local = new LocalStatus
            {
                ZoneName            = currentZone?.TemplateName,
                LocaleName          = currentLocale?.TemplateName,
                RoomName            = currentRoom?.TemplateName,
                Inventory           = inventory.ToArray(),
                Populace            = populace.ToArray(),
                Exits               = pathways.ToArray(),
                LocationDescriptive = locationDescription
            };

            //The next two are mostly hard coded, TODO, also fix how we get the map as that's an admin thing
            ExtendedStatus extended = new ExtendedStatus
            {
                Horizon = new string[]
                {
                    "A hillside",
                    "A dense forest"
                },
                VisibleMap = currentLocation.CurrentRoom == null ? string.Empty : currentLocation.CurrentRoom.RenderCenteredMap(3, true)
            };

            string timeOfDayString = string.Format("The hour of {0} in the day of {1} in {2} in the year of {3}", currentWorld.CurrentTimeOfDay.Hour
                                                   , currentWorld.CurrentTimeOfDay.Day
                                                   , currentWorld.CurrentTimeOfDay.MonthName()
                                                   , currentWorld.CurrentTimeOfDay.Year);

            string sun              = "0";
            string moon             = "0";
            string visibilityString = "5";
            Tuple <string, string, string[]> weatherTuple = new Tuple <string, string, string[]>("", "", new string[] { });

            if (currentZone != null)
            {
                Tuple <PrecipitationAmount, PrecipitationType, HashSet <WeatherType> > forecast = currentZone.CurrentForecast();
                weatherTuple = new Tuple <string, string, string[]>(forecast.Item1.ToString(), forecast.Item2.ToString(), forecast.Item3.Select(wt => wt.ToString()).ToArray());

                visibilityString = currentZone.GetCurrentLuminosity().ToString();

                if (currentWorld != null)
                {
                    IEnumerable <ICelestial> bodies = currentZone.GetVisibileCelestials(_currentPlayer);
                    ICelestial theSun  = bodies.FirstOrDefault(cest => cest.Name.Equals("sun", StringComparison.InvariantCultureIgnoreCase));
                    ICelestial theMoon = bodies.FirstOrDefault(cest => cest.Name.Equals("moon", StringComparison.InvariantCultureIgnoreCase));

                    if (theSun != null)
                    {
                        ICelestialPosition celestialPosition = currentWorld.CelestialPositions.FirstOrDefault(celest => celest.CelestialObject == theSun);

                        sun = AstronomicalUtilities.GetCelestialLuminosityModifier(celestialPosition.CelestialObject, celestialPosition.Position, currentWorld.PlanetaryRotation
                                                                                   , currentWorld.OrbitalPosition, currentZone.Template <IZoneTemplate>().Hemisphere, currentWorld.Template <IGaiaTemplate>().RotationalAngle).ToString();
                    }

                    if (theMoon != null)
                    {
                        ICelestialPosition celestialPosition = currentWorld.CelestialPositions.FirstOrDefault(celest => celest.CelestialObject == theMoon);

                        moon = AstronomicalUtilities.GetCelestialLuminosityModifier(celestialPosition.CelestialObject, celestialPosition.Position, currentWorld.PlanetaryRotation
                                                                                    , currentWorld.OrbitalPosition, currentZone.Template <IZoneTemplate>().Hemisphere, currentWorld.Template <IGaiaTemplate>().RotationalAngle).ToString();
                    }
                }
            }

            EnvironmentStatus environment = new EnvironmentStatus
            {
                Sun         = sun,
                Moon        = moon,
                Visibility  = visibilityString,
                Weather     = weatherTuple,
                Temperature = currentZone.EffectiveTemperature().ToString(),
                Humidity    = currentZone.EffectiveHumidity().ToString(),
                TimeOfDay   = timeOfDayString
            };

            OutputStatus outputFormat = new OutputStatus
            {
                Occurrence  = EncapsulateOutput(strings),
                Self        = self,
                Local       = local,
                Extended    = extended,
                Environment = environment
            };

            Send(Utility.SerializationUtility.Serialize(outputFormat));

            return(true);
        }
Ejemplo n.º 27
0
 public WordsController(LexicalContext db)
 {
     _db = db;
 }
Ejemplo n.º 28
0
        private static IDictataPhrase FocusFindPhrase(IEnumerable <IDictataPhrase> possiblePhrases, LexicalContext context, IDictataPhrase basePhrase)
        {
            if (context.Language == null)
            {
                context.Language = basePhrase.Language;
            }

            possiblePhrases = possiblePhrases.Where(phrase => phrase != null && phrase.Language == context.Language && phrase.SuitableForUse);

            if (context.Severity + context.Elegance + context.Quality == 0)
            {
                List <Tuple <IDictataPhrase, int> > rankedPhrases = new List <Tuple <IDictataPhrase, int> >
                {
                    new Tuple <IDictataPhrase, int>(basePhrase, GetSynonymRanking(basePhrase, context))
                };

                rankedPhrases.AddRange(possiblePhrases.Select(phrase => new Tuple <IDictataPhrase, int>(phrase, GetSynonymRanking(phrase, context))));

                return(rankedPhrases.OrderByDescending(pair => pair.Item2).Select(pair => pair.Item1).FirstOrDefault());
            }

            return(GetRelatedPhrase(basePhrase, possiblePhrases, context.Severity, context.Elegance, context.Quality));
        }
Ejemplo n.º 29
0
 public Lexica()
 {
     Modifiers = new HashSet <ILexica>();
     Context   = new LexicalContext(null);
 }
Ejemplo n.º 30
0
        private static IDictata GetObscuredWord(IDictata word, IEnumerable <IDictata> possibleWords, short obscureStrength)
        {
            if (word == null || possibleWords.Count() == 0 || obscureStrength == 0)
            {
                return(word);
            }

            //try to downgrade word
            Dictionary <IDictata, int> rankedWords = new Dictionary <IDictata, int>();

            foreach (IDictata possibleWord in possibleWords)
            {
                int rating = Math.Abs(word.Quality + (Math.Abs(obscureStrength) * -1) - possibleWord.Quality);

                rankedWords.Add(possibleWord, rating);
            }

            KeyValuePair <IDictata, int> closestWord = rankedWords.OrderBy(pair => pair.Value).FirstOrDefault();
            IDictata newWord = closestWord.Key;

            LexicalType[] descriptiveWordTypes = new LexicalType[] { LexicalType.Adjective, LexicalType.Adverb };
            LexicalType[] remainderWordTypes   = new LexicalType[] { LexicalType.Verb, LexicalType.Preposition, LexicalType.Conjunction, LexicalType.Article };
            LexicalType[] nounWordTypes        = new LexicalType[] { LexicalType.Pronoun, LexicalType.ProperNoun, LexicalType.Noun };
            if (newWord != null)
            {
                //Adjectives/adverbs/articles get eaten
                if (descriptiveWordTypes.Contains(newWord.WordType))
                {
                    newWord = null;
                }

                //if it's a verb or preposition or structural leave it alone
                if (remainderWordTypes.Contains(newWord.WordType))
                {
                    newWord = word;
                }

                //pronouns become "it"
                if (nounWordTypes.Contains(newWord.WordType))
                {
                    LexicalContext itContext = new LexicalContext(null)
                    {
                        Determinant = false,
                        Plural      = false,
                        Possessive  = false,
                        Tense       = LexicalTense.None,
                        Language    = word.Language,
                        Perspective = NarrativePerspective.None
                    };

                    newWord = GetWord(itContext, LexicalType.Pronoun);
                }

                //TODO: if it's a noun try to downgrade it to a shape or single aspect
            }
            else
            {
                newWord = word;
            }

            return(newWord);
        }