예제 #1
0
        // gets the best DialogEntry based on an NPC.
        public DialogEntry GetBestEntry(Character npc)
        {
            DialogEntry result = null;

            foreach (var entries in Entries
                     .Where(x => x.Criterion != null)
                     .GroupBy(x => x.Criterion.Priority)
                     .OrderByDescending(x => x.Key))
            {
                var available = entries
                                .Where(x => x.Criterion?.Judge?.Invoke(npc) ?? true);

                if (!available.Any())
                {
                    continue;
                }

                result = Randomizer.Choose(available);
                break;
            }

            if (result == null)
            {
                var generic = Entries.Where(x => x.Criterion == null);

                if (!generic.Any())
                {
                    throw new System.Exception("Could not find any available entries.");
                }

                return(Randomizer.Choose(generic));
            }

            return(result);
        }
예제 #2
0
 public Dialog(string id, DialogType type, DialogTone tone, DialogEntry entry, params DialogEntry[] rest)
 {
     Id      = id;
     Type    = type;
     Tone    = tone;
     Entries = rest.Prepend(entry);
 }