public Dialog_QuestDialog(QuestPawn quester, Pawn speaker)
 {
     QuestPawn  = quester;
     Speaker    = speaker;
     forcePause = true;
     doCloseX   = true;
 }
Beispiel #2
0
 public void RemoveQuestPawn(QuestPawn questPawn)
 {
     if (QuestPawns.Contains(questPawn))
     {
         QuestPawns.Remove(questPawn);
     }
 }
Beispiel #3
0
        public virtual void TakeQuestByQuester(QuestPawn quester, bool notify = true)
        {
            ShowInConsole = true;

            if (notify)
            {
                Find.LetterStack.ReceiveLetter(QuestsManager.Communications.MakeQuestLetter(this, "TakeQuestFromPawnLetter".Translate(CardLabel), "TakeQuestFromPawnLetterDesc".Translate(CardLabel, Description)));
            }

            quester.Quests.Remove(this);
        }
Beispiel #4
0
        public override void GameComponentTick()
        {
            base.GameComponentTick();

            if (communications != null)
            {
                if (Find.TickManager.TicksGame % 500 == 0)
                {
                    for (int i = 0; i < communications.QuestPawns.Count; i++)
                    {
                        QuestPawn questPawn = communications.QuestPawns[i];

                        if (questPawn.Pawn == null || questPawn.Pawn.IsPrisoner || questPawn.Pawn.Faction.PlayerRelationKind == RimWorld.FactionRelationKind.Hostile || (WorldPawnsUtility.IsWorldPawn(questPawn.Pawn) && !questPawn.WorldQuester) || questPawn.Pawn.Dead || questPawn.Pawn.Destroyed)
                        {
                            questPawn.Destroy();
                        }
                    }
                }

                for (int i = 0; i < communications.Quests.Count; i++)
                {
                    Quest quest = communications.Quests[i];
                    try
                    {
                        quest.Tick();
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"Exception ticking quest {quest.id} --> {ex}");
                    }
                }

                for (int i = 0; i < communications.Components.Count; i++)
                {
                    var component = communications.Components[i];

                    try
                    {
                        component.Tick();
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"Exception ticking component {component.id} --> {ex}");
                    }
                }

                Communications.FactionManager.Tick();
            }
        }
Beispiel #5
0
        public void AddQuestPawn(Pawn pawn, CommunicationDialog dialog)
        {
            pawn.GetQuestPawn(out QuestPawn questPawn);
            if (questPawn != null)
            {
                if (!questPawn.Dialogs.Contains(dialog))
                {
                    questPawn.Dialogs.Add(dialog);
                }
            }
            else
            {
                questPawn      = new QuestPawn();
                questPawn.Pawn = pawn;
                questPawn.Dialogs.Add(dialog);

                QuestPawns.Add(questPawn);
            }
        }
Beispiel #6
0
        public void AddQuestPawn(Pawn pawn, Quest quest)
        {
            pawn.GetQuestPawn(out QuestPawn questPawn);
            if (questPawn != null)
            {
                if (!questPawn.Quests.Contains(quest))
                {
                    questPawn.Quests.Add(quest);
                }
            }
            else
            {
                questPawn      = new QuestPawn();
                questPawn.Pawn = pawn;
                questPawn.Quests.Add(quest);

                QuestPawns.Add(questPawn);
            }
        }
Beispiel #7
0
 public static bool GetQuestPawn(this Pawn pawn, out QuestPawn questPawn)
 {
     questPawn = QuestsManager.Communications.QuestPawns.FirstOrDefault(p => p.Pawn == pawn);
     return(questPawn != null);
 }
Beispiel #8
0
        public static bool TryGiveRandomQuestTo(Pawn pawn, int giveCount)
        {
            try
            {
                if (pawn == null)
                {
                    Log.Error($"Error: pawn is null");
                    return(false);
                }

                Dictionary <IncidentDef, int> lastFireTicks = Find.World.StoryState.lastFireTicks;

                if (lastFireTicks == null)
                {
                    Log.Warning($"Error: lastFireTicks world is null");
                    return(false);
                }

                int ticksGame = Find.TickManager.TicksGame;

                List <QuestDef> allQuests = DefDatabase <QuestDef> .AllDefsListForReading;

                if (allQuests.Count < giveCount)
                {
                    return(false);
                }

                List <QuestDef> allQuestsToFire = new List <QuestDef>();

                QuestPawn questPawn = null;
                pawn.GetQuestPawn(out questPawn);

                foreach (var potentialQuest in allQuests)
                {
                    if (potentialQuest.Incident == null)
                    {
                        continue;
                    }

                    if (lastFireTicks.TryGetValue(potentialQuest.Incident, out int value))
                    {
                        float num = (float)(ticksGame - value) / 60000f;
                        if (num < potentialQuest.Incident.minRefireDays)
                        {
                            continue;
                        }
                    }

                    if (QuestsManager.Communications.Quests.Any(q => q.RelatedQuestDef == potentialQuest && q.Faction == pawn.Faction))
                    {
                        continue;
                    }

                    if (questPawn != null)
                    {
                        if (questPawn.Quests.Any(q => q.RelatedQuestDef == potentialQuest))
                        {
                            continue;
                        }
                    }

                    allQuestsToFire.Add(potentialQuest);
                }

                if (allQuestsToFire.Count == 0)
                {
                    return(false);
                }

                for (int i = 0; i < giveCount; i++)
                {
                    if (allQuestsToFire.Count == 0)
                    {
                        return(true);
                    }

                    if (allQuestsToFire.TryRandomElementByWeight(w => w.Commonality, out QuestDef result))
                    {
                        TryGiveQuestTo(pawn, result);
                        allQuestsToFire.Remove(result);
                    }
                }
                return(false);
            }catch (Exception ex)
            {
                Log.Message($"Error while giving quest --> {ex}");

                return(false);
            }
        }