private void ObserveSurroundingThings()
        {
            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Sight) || pawn.needs.mood == null)
            {
                return;
            }
            Map map = pawn.Map;

            for (int i = 0; (float)i < 100f; i++)
            {
                IntVec3 intVec = pawn.Position + GenRadial.RadialPattern[i];
                if (!intVec.InBounds(map) || !GenSight.LineOfSight(intVec, pawn.Position, map, skipFirstCell: true))
                {
                    continue;
                }
                List <Thing> thingList = intVec.GetThingList(map);
                for (int j = 0; j < thingList.Count; j++)
                {
                    IThoughtGiver thoughtGiver = thingList[j] as IThoughtGiver;
                    if (thoughtGiver != null)
                    {
                        Thought_Memory thought_Memory = thoughtGiver.GiveObservedThought();
                        if (thought_Memory != null)
                        {
                            pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory);
                        }
                    }
                }
            }
        }
示例#2
0
 public override void Notify_QuestSignalReceived(Signal signal)
 {
     base.Notify_QuestSignalReceived(signal);
     if (!(signal.tag == inSignal) || pawn == null || pawn.needs == null)
     {
         return;
     }
     if (count.HasValue)
     {
         for (int i = 0; i < count.Value; i++)
         {
             Thought_Memory thought_Memory = pawn.needs.mood.thoughts.memories.Memories.FirstOrDefault((Thought_Memory m) => def == m.def && (otherPawn == null || m.otherPawn == otherPawn));
             if (thought_Memory != null)
             {
                 pawn.needs.mood.thoughts.memories.RemoveMemory(thought_Memory);
                 continue;
             }
             break;
         }
     }
     else if (otherPawn == null)
     {
         pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(def);
     }
     else
     {
         pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDefWhereOtherPawnIs(def, otherPawn);
     }
 }
 private void ObserveSurroundingThings()
 {
     if (this.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Sight))
     {
         Map map = this.pawn.Map;
         int num = 0;
         while ((float)num < 100f)
         {
             IntVec3 intVec = this.pawn.Position + GenRadial.RadialPattern[num];
             if (intVec.InBounds(map))
             {
                 if (GenSight.LineOfSight(intVec, this.pawn.Position, map, true, null, 0, 0))
                 {
                     List <Thing> thingList = intVec.GetThingList(map);
                     for (int i = 0; i < thingList.Count; i++)
                     {
                         IThoughtGiver thoughtGiver = thingList[i] as IThoughtGiver;
                         if (thoughtGiver != null)
                         {
                             Thought_Memory thought_Memory = thoughtGiver.GiveObservedThought();
                             if (thought_Memory != null)
                             {
                                 this.pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory, null);
                             }
                         }
                     }
                 }
             }
             num++;
         }
     }
 }
 public void RemoveMemory(Thought_Memory th)
 {
     if (!this.memories.Remove(th))
     {
         Log.Warning("Tried to remove memory thought of def " + th.def.defName + " but it's not here.");
     }
 }
示例#5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(BedInd);
            this.FailOnDespawnedOrNull(PartnerInd);
            this.FailOn(() => !Partner.health.capacities.CanBeAwake);
            this.KeepLyingDown(BedInd);
            yield return(Toils_Bed.ClaimBedIfNonMedical(BedInd));

            yield return(Toils_Bed.GotoBed(BedInd));

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                if (Partner.CurJob == null || Partner.CurJob.def != JobDefOf.Lovin)
                {
                    Job newJob = JobMaker.MakeJob(JobDefOf.Lovin, pawn, Bed);
                    Partner.jobs.StartJob(newJob, JobCondition.InterruptForced);
                    ticksLeft = (int)(2500f * Mathf.Clamp(Rand.Range(0.1f, 1.1f), 0.1f, 2f));
                }
                else
                {
                    ticksLeft = 9999999;
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil);

            Toil toil2 = Toils_LayDown.LayDown(BedInd, hasBed: true, lookForOtherJobs: false, canSleep: false, gainRestAndHealth: false);

            toil2.FailOn(() => Partner.CurJob == null || Partner.CurJob.def != JobDefOf.Lovin);
            toil2.AddPreTickAction(delegate
            {
                ticksLeft--;
                if (ticksLeft <= 0)
                {
                    ReadyForNextToil();
                }
                else if (pawn.IsHashIntervalTick(100))
                {
                    MoteMaker.ThrowMetaIcon(pawn.Position, pawn.Map, ThingDefOf.Mote_Heart);
                }
            });
            toil2.AddFinishAction(delegate
            {
                Thought_Memory thought_Memory = (Thought_Memory)ThoughtMaker.MakeThought(ThoughtDefOf.GotSomeLovin);
                if ((pawn.health != null && pawn.health.hediffSet != null && pawn.health.hediffSet.hediffs.Any((Hediff h) => h.def == HediffDefOf.LoveEnhancer)) || (Partner.health != null && Partner.health.hediffSet != null && Partner.health.hediffSet.hediffs.Any((Hediff h) => h.def == HediffDefOf.LoveEnhancer)))
                {
                    thought_Memory.moodPowerFactor = 1.5f;
                }
                if (pawn.needs.mood != null)
                {
                    pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory, Partner);
                }
                pawn.mindState.canLovinTick = Find.TickManager.TicksGame + GenerateRandomMinTicksToNextLovin(pawn);
            });
            toil2.socialMode = RandomSocialMode.Off;
            yield return(toil2);
        }
示例#6
0
        private void AddNuzzledThought(Pawn initiator, Pawn recipient)
        {
            Thought_Memory newThought = (Thought_Memory)ThoughtMaker.MakeThought(ThoughtDefOf.Nuzzled);

            if (recipient.needs.mood != null)
            {
                recipient.needs.mood.thoughts.memories.TryGainMemory(newThought);
            }
        }
示例#7
0
        public static Thought_Memory MakeThought(ThoughtDef def, int forcedStage)
        {
            Thought_Memory thought_Memory = (Thought_Memory)Activator.CreateInstance(def.ThoughtClass);

            thought_Memory.def = def;
            thought_Memory.SetForcedStage(forcedStage);
            thought_Memory.Init();
            return(thought_Memory);
        }
示例#8
0
        public override bool GroupsWith(Thought other)
        {
            Thought_Memory thought_Memory = other as Thought_Memory;

            if (thought_Memory == null)
            {
                return(false);
            }
            return(base.GroupsWith(other) && (otherPawn == thought_Memory.otherPawn || LabelCap == thought_Memory.LabelCap));
        }
示例#9
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(this.BedInd);
            this.FailOnDespawnedOrNull(this.PartnerInd);
            this.FailOn(() => !this.Partner.health.capacities.CanBeAwake);
            this.KeepLyingDown(this.BedInd);
            yield return(Toils_Bed.ClaimBedIfNonMedical(this.BedInd, TargetIndex.None));

            yield return(Toils_Bed.GotoBed(this.BedInd));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (this.Partner.CurJob == null || this.Partner.CurJob.def != JobDefOf.Lovin)
                    {
                        Job newJob = new Job(JobDefOf.Lovin, this.pawn, this.Bed);
                        this.Partner.jobs.StartJob(newJob, JobCondition.InterruptForced, null, false, true, null, null, false);
                        this.ticksLeft = (int)(2500f * Mathf.Clamp(Rand.Range(0.1f, 1.1f), 0.1f, 2f));
                    }
                    else
                    {
                        this.ticksLeft = 9999999;
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            Toil doLovin = Toils_LayDown.LayDown(this.BedInd, true, false, false, false);

            doLovin.FailOn(() => this.Partner.CurJob == null || this.Partner.CurJob.def != JobDefOf.Lovin);
            doLovin.AddPreTickAction(delegate
            {
                this.ticksLeft--;
                if (this.ticksLeft <= 0)
                {
                    base.ReadyForNextToil();
                }
                else if (this.pawn.IsHashIntervalTick(100))
                {
                    MoteMaker.ThrowMetaIcon(this.pawn.Position, this.pawn.Map, ThingDefOf.Mote_Heart);
                }
            });
            doLovin.AddFinishAction(delegate
            {
                Thought_Memory newThought = (Thought_Memory)ThoughtMaker.MakeThought(ThoughtDefOf.GotSomeLovin);
                this.pawn.needs.mood.thoughts.memories.TryGainMemory(newThought, this.Partner);
                this.pawn.mindState.canLovinTick = Find.TickManager.TicksGame + this.GenerateRandomMinTicksToNextLovin(this.pawn);
            });
            doLovin.socialMode = RandomSocialMode.Off;
            yield return(doLovin);

            yield break;
        }
示例#10
0
 public void RemoveMemoriesWhereOtherPawnIs(Pawn otherPawn)
 {
     while (true)
     {
         Thought_Memory thought_Memory = memories.Find((Thought_Memory x) => x.otherPawn == otherPawn);
         if (thought_Memory == null)
         {
             break;
         }
         RemoveMemory(thought_Memory);
     }
 }
示例#11
0
 public void RemoveMemoriesOfDefWhereOtherPawnIs(ThoughtDef def, Pawn otherPawn)
 {
     while (true)
     {
         Thought_Memory thought_Memory = this.memories.Find((Thought_Memory x) => x.def == def && x.otherPawn == otherPawn);
         if (thought_Memory == null)
         {
             break;
         }
         this.RemoveMemory(thought_Memory);
     }
 }
 public void RemoveMemoriesWhereOtherPawnIs(Pawn otherPawn)
 {
     for (;;)
     {
         Thought_Memory thought_Memory = this.memories.Find((Thought_Memory x) => x.otherPawn == otherPawn);
         if (thought_Memory == null)
         {
             break;
         }
         this.RemoveMemory(thought_Memory);
     }
 }
        public void TryGainMemoryFast(ThoughtDef mem)
        {
            Thought_Memory firstMemoryOfDef = this.GetFirstMemoryOfDef(mem);

            if (firstMemoryOfDef != null)
            {
                firstMemoryOfDef.Renew();
            }
            else
            {
                this.TryGainMemory(mem, null);
            }
        }
        public int NumMemoriesInGroup(Thought_Memory group)
        {
            int num = 0;

            for (int i = 0; i < this.memories.Count; i++)
            {
                if (this.memories[i].GroupsWith(group))
                {
                    num++;
                }
            }
            return(num);
        }
 public void RemoveMemoriesWhereOtherPawnIs(Pawn otherPawn)
 {
     while (true)
     {
         Thought_Memory thought_Memory = this.memories.Find((Thought_Memory x) => x.otherPawn == otherPawn);
         if (thought_Memory != null)
         {
             this.RemoveMemory(thought_Memory);
             continue;
         }
         break;
     }
 }
        private static void AddInteractionThought(Pawn pawn, Pawn otherPawn, ThoughtDef thoughtDef)
        {
            float          statValue      = otherPawn.GetStatValue(StatDefOf.SocialImpact, true);
            Thought_Memory thought_Memory = (Thought_Memory)ThoughtMaker.MakeThought(thoughtDef);

            thought_Memory.moodPowerFactor = statValue;
            Thought_MemorySocial thought_MemorySocial = thought_Memory as Thought_MemorySocial;

            if (thought_MemorySocial != null)
            {
                thought_MemorySocial.opinionOffset *= statValue;
            }
            pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory, otherPawn);
        }
        public IndividualThoughtToAdd(ThoughtDef thoughtDef, Pawn addTo, Pawn otherPawn = null, float moodPowerFactor = 1f, float opinionOffsetFactor = 1f)
        {
            this.addTo     = addTo;
            this.otherPawn = otherPawn;
            this.thought   = (Thought_Memory)ThoughtMaker.MakeThought(thoughtDef);
            this.thought.moodPowerFactor = moodPowerFactor;
            this.thought.otherPawn       = otherPawn;
            Thought_MemorySocial thought_MemorySocial = this.thought as Thought_MemorySocial;

            if (thought_MemorySocial != null)
            {
                thought_MemorySocial.opinionOffset *= opinionOffsetFactor;
            }
        }
 private void RemoveExpiredMemories()
 {
     for (int num = this.memories.Count - 1; num >= 0; num--)
     {
         Thought_Memory thought_Memory = this.memories[num];
         if (thought_Memory.ShouldDiscard)
         {
             this.RemoveMemory(thought_Memory);
             if (thought_Memory.def.nextThought != null)
             {
                 this.TryGainMemory(thought_Memory.def.nextThought, null);
             }
         }
     }
 }
        public void GetAllMoodThoughts(List <Thought> outThoughts)
        {
            outThoughts.Clear();
            List <Thought_Memory> list = memories.Memories;

            for (int i = 0; i < list.Count; i++)
            {
                Thought_Memory thought_Memory = list[i];
                if (thought_Memory.MoodOffset() != 0f)
                {
                    outThoughts.Add(thought_Memory);
                }
            }
            situational.AppendMoodThoughts(outThoughts);
        }
        public Thought_Memory OldestMemoryOfDef(ThoughtDef def)
        {
            Thought_Memory result = null;
            int            num    = -9999;

            for (int i = 0; i < this.memories.Count; i++)
            {
                Thought_Memory thought_Memory = this.memories[i];
                if (thought_Memory.def == def && thought_Memory.age > num)
                {
                    result = thought_Memory;
                    num    = thought_Memory.age;
                }
            }
            return(result);
        }
        public Thought_Memory OldestMemoryInGroup(Thought_Memory group)
        {
            Thought_Memory result = null;
            int            num    = -9999;

            for (int i = 0; i < this.memories.Count; i++)
            {
                Thought_Memory thought_Memory = this.memories[i];
                if (thought_Memory.GroupsWith(group) && thought_Memory.age > num)
                {
                    result = thought_Memory;
                    num    = thought_Memory.age;
                }
            }
            return(result);
        }
 public void RemoveMemoriesOfDefIf(ThoughtDef def, Func <Thought_Memory, bool> predicate)
 {
     if (!def.IsMemory)
     {
         Log.Warning(def + " is not a memory thought.", false);
         return;
     }
     for (;;)
     {
         Thought_Memory thought_Memory = this.memories.Find((Thought_Memory x) => x.def == def && predicate(x));
         if (thought_Memory == null)
         {
             break;
         }
         this.RemoveMemory(thought_Memory);
     }
 }
示例#23
0
 public void RemoveMemoriesOfDef(ThoughtDef def)
 {
     if (!def.IsMemory)
     {
         Log.Warning(def + " is not a memory thought.");
         return;
     }
     while (true)
     {
         Thought_Memory thought_Memory = this.memories.Find((Thought_Memory x) => x.def == def);
         if (thought_Memory == null)
         {
             break;
         }
         this.RemoveMemory(thought_Memory);
     }
 }
示例#24
0
        public virtual bool TryMergeWithExistingMemory(out bool showBubble)
        {
            ThoughtHandler thoughts = pawn.needs.mood.thoughts;

            if (thoughts.memories.NumMemoriesInGroup(this) >= def.stackLimit)
            {
                Thought_Memory thought_Memory = thoughts.memories.OldestMemoryInGroup(this);
                if (thought_Memory != null)
                {
                    showBubble = (thought_Memory.age > thought_Memory.def.DurationTicks / 2);
                    thought_Memory.Renew();
                    return(true);
                }
            }
            showBubble = true;
            return(false);
        }
示例#25
0
 public void RemoveMemoriesOfDefIf(ThoughtDef def, Func <Thought_Memory, bool> predicate)
 {
     if (!def.IsMemory)
     {
         Log.Warning(def + " is not a memory thought.");
         return;
     }
     while (true)
     {
         Thought_Memory thought_Memory = memories.Find((Thought_Memory x) => x.def == def && predicate(x));
         if (thought_Memory != null)
         {
             RemoveMemory(thought_Memory);
             continue;
         }
         break;
     }
 }
示例#26
0
        public override bool GroupsWith(Thought other)
        {
            Thought_Memory thought_Memory = other as Thought_Memory;

            if (thought_Memory == null)
            {
                return(false);
            }
            if (base.GroupsWith(other))
            {
                if (otherPawn != thought_Memory.otherPawn)
                {
                    return(LabelCap == thought_Memory.LabelCap);
                }
                return(true);
            }
            return(false);
        }
        public Thought RandomBreakupReason(Pawn initiator, Pawn recipient)
        {
            List <Thought_Memory> list = (from m in initiator.needs.mood.thoughts.memories.Memories
                                          where m != null && m.otherPawn == recipient && m.CurStage != null && m.CurStage.baseOpinionOffset < 0f
                                          select m).ToList <Thought_Memory>();

            if (list.Count == 0)
            {
                return(null);
            }
            float          worstMemoryOpinionOffset = list.Max((Thought_Memory m) => - m.CurStage.baseOpinionOffset);
            Thought_Memory result = null;

            (from m in list
             where - m.CurStage.baseOpinionOffset >= worstMemoryOpinionOffset / 2f
             select m).TryRandomElementByWeight((Thought_Memory m) => - m.CurStage.baseOpinionOffset, out result);
            return(result);
        }
示例#28
0
 public void RemoveMemoriesOfDef(ThoughtDef def)
 {
     if (!def.IsMemory)
     {
         Log.Warning(string.Concat(def, " is not a memory thought."));
         return;
     }
     while (true)
     {
         Thought_Memory thought_Memory = memories.Find((Thought_Memory x) => x.def == def);
         if (thought_Memory != null)
         {
             RemoveMemory(thought_Memory);
             continue;
         }
         break;
     }
 }
        public Thought RandomBreakupReason(Pawn initiator, Pawn recipient)
        {
            if (initiator.needs.mood == null)
            {
                return(null);
            }
            List <Thought_Memory> list = initiator.needs.mood.thoughts.memories.Memories.Where((Thought_Memory m) => m != null && m.otherPawn == recipient && m.CurStage != null && m.CurStage.baseOpinionOffset < 0f).ToList();

            if (list.Count == 0)
            {
                return(null);
            }
            float          worstMemoryOpinionOffset = list.Max((Thought_Memory m) => 0f - m.CurStage.baseOpinionOffset);
            Thought_Memory result = null;

            list.Where((Thought_Memory m) => 0f - m.CurStage.baseOpinionOffset >= worstMemoryOpinionOffset / 2f).TryRandomElementByWeight((Thought_Memory m) => 0f - m.CurStage.baseOpinionOffset, out result);
            return(result);
        }
示例#30
0
 public void RemoveMemoriesOfDef(ThoughtDef def)
 {
     if (!def.IsMemory)
     {
         Log.Warning(def + " is not a memory thought.", false);
     }
     else
     {
         for (;;)
         {
             Thought_Memory thought_Memory = this.memories.Find((Thought_Memory x) => x.def == def);
             if (thought_Memory == null)
             {
                 break;
             }
             this.RemoveMemory(thought_Memory);
         }
     }
 }