Beispiel #1
0
 public void GenerateQuest(QuestEntity entity, StringField group, DomainType domainType, WorldModel worldModel, bool requireReturnToComplete,
                           List <QuestContent> rewardsUIContents, List <RewardSystem> rewardSystems, List <Quest> existingQuests, GeneratedQuestDelegate generatedQuest,
                           UrgentFactSelectionMode goalSelectionMode)
 {
     if (entity == null || domainType == null || worldModel == null)
     {
         return;
     }
     coroutine = entity.StartCoroutine(GenerateQuestCoroutine(entity, group, domainType, worldModel, requireReturnToComplete,
                                                              rewardsUIContents, rewardSystems, existingQuests, generatedQuest, goalSelectionMode));
 }
Beispiel #2
0
        private IEnumerator GenerateQuestCoroutine(QuestEntity entity, StringField group, DomainType domainType, WorldModel worldModel, bool requireReturnToComplete,
                                                   List <QuestContent> rewardsUIContents, List <RewardSystem> rewardSystems, List <Quest> existingQuests, GeneratedQuestDelegate generatedQuest,
                                                   UrgentFactSelectionMode goalSelectionMode)
        {
            this.cancel     = false;
            this.entity     = entity;
            this.group      = group;
            this.domainType = domainType;
            this.worldModel = worldModel;
            this.requireReturnToComplete = requireReturnToComplete;
            this.rewardsUIContents       = rewardsUIContents;
            this.rewardSystems           = rewardSystems;
            this.ignoreList        = GenerateIgnoreList(existingQuests);
            this.goalSelectionMode = goalSelectionMode;
            masterStepList         = new List <PlanStep>();
            goal = null;
            plan = null;
            Quest quest = null;

            worldModel.observer = new Fact(domainType, entity.entityType, 1);
            yield return(DetermineGoal());

            if (!(cancel || goal == null))
            {
                yield return(GeneratePlan());

                if (!(cancel || plan == null))
                {
                    BackfillMinimumCounterValues();
                    if (detailedDebug)
                    {
                        LogPlan(plan);
                    }
                    quest = planToQuestBuilder.ConvertPlanToQuest(entity, group, goal, motive, plan, requireReturnToComplete, rewardsUIContents, rewardSystems);
                }
            }
            generatedQuest(quest);
        }
        /// <summary>
        /// Computes the world model's urgency.
        /// </summary>
        /// <param name="factSelectionMode">Method by which to compute fact urgency.</param>
        /// <param name="mostUrgentFacts">Gets set to a list of most-urgent facts in the world model.</param>
        /// <param name="ignoreList">Ignore entities named in this list when computing urgency.</param>
        /// <param name="numTopFactsToChoose">Maximum number of most-urgent facts to return in mostUrgentFacts.</param>
        /// <param name="debug">If true, logs details of this function's operation.</param>
        /// <returns>The cumulative urgency of all facts in the world model.</returns>
        public float ComputeUrgency(UrgentFactSelectionMode factSelectionMode, out Fact[] mostUrgentFacts, string[] ignoreList = null, bool debug = false)
        {
            var   mostUrgentFactsList = new List <Fact>(); // Maintained in ascending urgency, up to factionSelectMode.max facts.
            Fact  mostUrgentFact      = null;
            int   maxUrgentFacts      = factSelectionMode.max;
            float cumulativeUrgency   = 0;
            float minTopUrgency       = Mathf.NegativeInfinity; // Urgency of least-urgent fact in mostUrgentFacts[].
            var   debugInfo           = QuestMachine.debug ? "WORLD MODEL: (observer:" + observer.entityType.name + ")\n" : string.Empty;

            for (int i = 0; i < facts.Count; i++)
            {
                var fact = facts[i];
                if (fact == null || fact.entityType == null)
                {
                    continue;
                }
                if (ShouldIgnore(fact.entityType.name, ignoreList))
                {
                    continue;
                }
                observed = fact;
                var urgency = GetFactUrgency(fact);
                urgency            = factSelectionMode.AdjustUrgency(urgency);
                fact.urgency       = urgency;
                cumulativeUrgency += urgency;
                if (urgency > 0 && (mostUrgentFactsList.Count < maxUrgentFacts || urgency > minTopUrgency))
                {
                    if (mostUrgentFactsList.Count >= maxUrgentFacts)
                    {
                        mostUrgentFactsList.RemoveAt(0);
                    }
                    var added = false;
                    for (int j = 0; j < mostUrgentFactsList.Count; j++)
                    {
                        if (mostUrgentFactsList[j].urgency > urgency)
                        {
                            mostUrgentFactsList.Insert(j, fact);
                            added = true;
                            break;
                        }
                    }
                    if (!added)
                    {
                        mostUrgentFactsList.Add(fact);
                    }
                    mostUrgentFact = fact;
                    minTopUrgency  = mostUrgentFactsList[0].urgency;
                }
                if (debug)
                {
                    debugInfo += string.Format("Domain:{0}, EntityType:{1}, Count:{2}\n", new object[] { fact.domainType.name, fact.entityType.name, fact.count });
                    debugInfo += string.Format("   Urgency:{0}\n", new object[] { urgency });
                }
            }
            mostUrgentFact = (mostUrgentFactsList.Count > 0) ? mostUrgentFactsList[mostUrgentFactsList.Count - 1] : null;
            if (debug)
            {
                if (mostUrgentFact != null)
                {
                    debugInfo += string.Format("MOST URGENT: Domain:{0}, EntityType:{1}, Count:{2}, Urgency:{3}\n", new object[] { mostUrgentFact.domainType.name, mostUrgentFact.entityType.name, mostUrgentFact.count, minTopUrgency });
                }
                debugInfo += string.Format("CUMULATIVE URGENCY: {0}", new object[] { cumulativeUrgency });
                Debug.Log(debugInfo);
            }
            mostUrgentFacts = mostUrgentFactsList.ToArray();
            return(cumulativeUrgency);
        }