public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = !PawnGenerator.IsBeingGenerated(pawn) && IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map);
                if (flag && flag2 && part.def.spawnThingOnRemoved != null)
                {
                    ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
                }
                if (flag2)
                {
                    ReportViolation(pawn, billDoer, pawn.FactionOrExtraHomeFaction, -70, "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(recipe.addsHediff.label));
                }
            }
            else if (pawn.Map != null)
            {
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, pawn.Position, pawn.Map);
            }
            else
            {
                pawn.health.RestorePart(part);
            }
            pawn.health.AddHediff(recipe.addsHediff, part);
        }
示例#2
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, part, billDoer.Position, billDoer.Map);
                MedicalRecipesUtility.SpawnThingsFromHediffs(pawn, part, billDoer.Position, billDoer.Map);
            }
            pawn.TakeDamage(new DamageInfo(DamageDefOf.SurgicalCut, 99999f, 999f, -1f, null, part));
            if (flag)
            {
                if (pawn.Dead)
                {
                    ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting);
                }
                ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
            }
            if (flag2)
            {
                ReportViolation(pawn, billDoer, pawn.FactionOrExtraHomeFaction, -70, "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort));
            }
        }
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, part, billDoer.Position, billDoer.Map);
                MedicalRecipesUtility.SpawnThingsFromHediffs(pawn, part, billDoer.Position, billDoer.Map);
            }
            DamageDef surgicalCut = DamageDefOf.SurgicalCut;
            int       amount      = 99999;

            pawn.TakeDamage(new DamageInfo(surgicalCut, amount, -1f, null, part, null, DamageInfo.SourceCategory.ThingOrUnknown));
            if (flag)
            {
                if (pawn.Dead)
                {
                    ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting);
                }
                else
                {
                    ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
                }
            }
            if (flag2)
            {
                pawn.Faction.AffectGoodwillWith(billDoer.Faction, -20f);
            }
        }
示例#4
0
            internal void <> m__0()
            {
                Pawn actor = this.layDown.actor;

                actor.pather.StopDead();
                JobDriver curDriver = actor.jobs.curDriver;

                if (this.hasBed)
                {
                    Building_Bed t = (Building_Bed)actor.CurJob.GetTarget(this.bedOrRestSpotIndex).Thing;
                    if (!t.OccupiedRect().Contains(actor.Position))
                    {
                        Log.Error("Can't start LayDown toil because pawn is not in the bed. pawn=" + actor, false);
                        actor.jobs.EndCurrentJob(JobCondition.Errored, true);
                        return;
                    }
                    actor.jobs.posture = PawnPosture.LayingInBed;
                }
                else
                {
                    actor.jobs.posture = PawnPosture.LayingOnGroundNormal;
                }
                curDriver.asleep = false;
                if (actor.mindState.applyBedThoughtsTick == 0)
                {
                    actor.mindState.applyBedThoughtsTick    = Find.TickManager.TicksGame + Rand.Range(2500, 10000);
                    actor.mindState.applyBedThoughtsOnLeave = false;
                }
                if (actor.ownership != null && actor.CurrentBed() != actor.ownership.OwnedBed)
                {
                    ThoughtUtility.RemovePositiveBedroomThoughts(actor);
                }
            }
        private Thought_Situational TryCreateThought(ThoughtDef def)
        {
            Thought_Situational thought_Situational = null;

            try
            {
                if (!ThoughtUtility.CanGetThought(pawn, def))
                {
                    return(null);
                }
                if (!def.Worker.CurrentState(pawn).ActiveFor(def))
                {
                    return(null);
                }
                thought_Situational      = (Thought_Situational)ThoughtMaker.MakeThought(def);
                thought_Situational.pawn = pawn;
                thought_Situational.RecalculateState();
                return(thought_Situational);
            }
            catch (Exception ex)
            {
                Log.Error("Exception while recalculating " + def + " thought state for pawn " + pawn + ": " + ex);
                return(thought_Situational);
            }
        }
示例#6
0
        private Thought_SituationalSocial TryCreateSocialThought(ThoughtDef def, Pawn otherPawn)
        {
            Thought_SituationalSocial thought_SituationalSocial = null;

            try
            {
                if (!ThoughtUtility.CanGetThought_NewTemp(pawn, def))
                {
                    return(null);
                }
                if (!def.Worker.CurrentSocialState(pawn, otherPawn).ActiveFor(def))
                {
                    return(null);
                }
                thought_SituationalSocial           = (Thought_SituationalSocial)ThoughtMaker.MakeThought(def);
                thought_SituationalSocial.pawn      = pawn;
                thought_SituationalSocial.otherPawn = otherPawn;
                thought_SituationalSocial.RecalculateState();
                return(thought_SituationalSocial);
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat("Exception while recalculating ", def, " thought state for pawn ", pawn, ": ", ex));
                return(thought_SituationalSocial);
            }
        }
        private Thought_Situational TryCreateThought(ThoughtDef def)
        {
            Thought_Situational thought_Situational = null;

            try
            {
                if (!ThoughtUtility.CanGetThought(this.pawn, def))
                {
                    return(null);
                }
                if (!def.Worker.CurrentState(this.pawn).ActiveFor(def))
                {
                    return(null);
                }
                thought_Situational      = (Thought_Situational)ThoughtMaker.MakeThought(def);
                thought_Situational.pawn = this.pawn;
                thought_Situational.RecalculateState();
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Exception while recalculating ",
                    def,
                    " thought state for pawn ",
                    this.pawn,
                    ": ",
                    ex
                }), false);
            }
            return(thought_Situational);
        }
示例#8
0
 public override float MoodOffset()
 {
     if (ThoughtUtility.ThoughtNullified(pawn, def))
     {
         return(0f);
     }
     return(base.MoodOffset() * moodPowerFactor);
 }
 public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
 {
     if (IsViolationOnPawn(pawn, part, Faction.OfPlayer))
     {
         ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -100, "GoodwillChangedReason_EuthanizedPawn".Translate(pawn.Named("PAWN")));
     }
     ExecutionUtility.DoExecutionByCut(billDoer, pawn);
     ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.GenericHumane);
 }
 public static bool CanGetThought(Pawn pawn, ThoughtDef def)
 {
     try
     {
         if (!def.validWhileDespawned && !pawn.Spawned && !def.IsMemory)
         {
             return(false);
         }
         if (def.nullifyingTraits != null)
         {
             for (int i = 0; i < def.nullifyingTraits.Count; i++)
             {
                 if (pawn.story.traits.HasTrait(def.nullifyingTraits[i]))
                 {
                     return(false);
                 }
             }
         }
         if (!def.requiredTraits.NullOrEmpty <TraitDef>())
         {
             bool flag = false;
             for (int j = 0; j < def.requiredTraits.Count; j++)
             {
                 if (pawn.story.traits.HasTrait(def.requiredTraits[j]))
                 {
                     if (!def.RequiresSpecificTraitsDegree || def.requiredTraitsDegree == pawn.story.traits.DegreeOfTrait(def.requiredTraits[j]))
                     {
                         flag = true;
                         break;
                     }
                 }
             }
             if (!flag)
             {
                 return(false);
             }
         }
         if (def.nullifiedIfNotColonist && !pawn.IsColonist)
         {
             return(false);
         }
         if (ThoughtUtility.IsSituationalThoughtNullifiedByHediffs(def, pawn))
         {
             return(false);
         }
         if (ThoughtUtility.IsThoughtNullifiedByOwnTales(def, pawn))
         {
             return(false);
         }
     }
     finally
     {
     }
     return(true);
 }
 public virtual float OpinionOffset()
 {
     if (ThoughtUtility.ThoughtNullified(pawn, def))
     {
         return(0f);
     }
     if (ShouldDiscard)
     {
         return(0f);
     }
     return(opinionOffset * AgeFactor);
 }
 public override float OpinionOffset()
 {
     if (ThoughtUtility.ThoughtNullified(pawn, def))
     {
         return(0f);
     }
     if (ShouldDiscard)
     {
         return(0f);
     }
     return(Mathf.Min(opinionOffset, def.maxCumulatedOpinionOffset));
 }
示例#13
0
 protected override Job TryGiveJob(Pawn pawn)
 {
     if (!pawn.guest.PrisonerIsSecure || pawn.apparel == null)
     {
         return(null);
     }
     if (ThoughtUtility.CanGetThought_NewTemp(pawn, ThoughtDefOf.ClothedNudist, checkIfNullified: true) && pawn.AmbientTemperature >= pawn.SafeTemperatureRange().min)
     {
         return(null);
     }
     if (pawn.royalty != null && pawn.royalty.AllTitlesInEffectForReading.Count > 0)
     {
         RoyalTitleDef def = pawn.royalty.MostSeniorTitle.def;
         if (def != null && def.requiredApparel != null)
         {
             for (int i = 0; i < def.requiredApparel.Count; i++)
             {
                 if (!def.requiredApparel[i].IsMet(pawn))
                 {
                     Apparel apparel = FindGarmentSatisfyingTitleRequirement(pawn, def.requiredApparel[i]);
                     if (apparel != null)
                     {
                         Job job = JobMaker.MakeJob(JobDefOf.Wear, apparel);
                         job.ignoreForbidden = true;
                         return(job);
                     }
                 }
             }
         }
     }
     if (!pawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.Legs))
     {
         Apparel apparel2 = FindGarmentCoveringPart(pawn, BodyPartGroupDefOf.Legs);
         if (apparel2 != null)
         {
             Job job2 = JobMaker.MakeJob(JobDefOf.Wear, apparel2);
             job2.ignoreForbidden = true;
             return(job2);
         }
     }
     if (!pawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.Torso))
     {
         Apparel apparel3 = FindGarmentCoveringPart(pawn, BodyPartGroupDefOf.Torso);
         if (apparel3 != null)
         {
             Job job3 = JobMaker.MakeJob(JobDefOf.Wear, apparel3);
             job3.ignoreForbidden = true;
             return(job3);
         }
     }
     return(null);
 }
示例#14
0
        public virtual float OpinionOffset()
        {
            if (ThoughtUtility.ThoughtNullified(pawn, def))
            {
                return(0f);
            }
            float num = base.CurStage.baseOpinionOffset;

            if (def.effectMultiplyingStat != null)
            {
                num *= pawn.GetStatValue(def.effectMultiplyingStat) * otherPawn.GetStatValue(def.effectMultiplyingStat);
            }
            return(num);
        }
示例#15
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnAggroMentalState(TargetIndex.A);
            yield return(Toils_Interpersonal.GotoPrisoner(pawn, Victim, PrisonerInteractionModeDefOf.Execution).FailOn(() => !Victim.IsPrisonerOfColony || !Victim.guest.PrisonerIsSecure));

            Toil execute = new Toil();

            execute.initAction = delegate
            {
                ExecutionUtility.DoExecutionByCut(execute.actor, Victim);
                ThoughtUtility.GiveThoughtsForPawnExecuted(Victim, PawnExecutionKind.GenericBrutal);
                TaleRecorder.RecordTale(TaleDefOf.ExecutedPrisoner, pawn, Victim);
            };
            execute.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(execute);
        }
示例#16
0
        public override float MoodOffset()
        {
            if (ThoughtUtility.ThoughtNullified(pawn, def))
            {
                return(0f);
            }
            if (ShouldDiscard)
            {
                return(0f);
            }
            float num       = base.MoodOffset();
            float num2      = Mathf.Lerp(-1f, 1f, harmonizer.pawn.needs.mood.CurLevel);
            float statValue = harmonizer.pawn.GetStatValue(StatDefOf.PsychicSensitivity);

            return(num * num2 * statValue);
        }
        public override float MoodOffset()
        {
            if (ThoughtUtility.ThoughtNullified(pawn, def))
            {
                return(0f);
            }
            QuestPart_SituationalThought questPart_SituationalThought = ((ThoughtWorker_QuestPart)def.Worker).FindQuestPart(pawn);

            if (questPart_SituationalThought == null)
            {
                return(0f);
            }
            float x = (float)TicksSinceQuestUnmet(questPart_SituationalThought) / 60000f;

            return(Mathf.RoundToInt(MoodOffsetFromUnmetDaysCurve.Evaluate(x)));
        }
        public static float ApparelScoreRaw(Pawn pawn, Apparel ap)
        {
            float num  = 0.1f;
            float num2 = ap.GetStatValue(StatDefOf.ArmorRating_Sharp, true) + ap.GetStatValue(StatDefOf.ArmorRating_Blunt, true);

            num += num2;
            if (ap.def.useHitPoints)
            {
                float x = (float)ap.HitPoints / (float)ap.MaxHitPoints;
                num *= JobGiver_OptimizeApparel.HitPointsPercentScoreFactorCurve.Evaluate(x);
            }
            num += ap.GetSpecialApparelScoreOffset();
            float num3 = 1f;

            if (JobGiver_OptimizeApparel.neededWarmth == NeededWarmth.Warm)
            {
                float statValue = ap.GetStatValue(StatDefOf.Insulation_Cold, true);
                num3 *= JobGiver_OptimizeApparel.InsulationColdScoreFactorCurve_NeedWarm.Evaluate(statValue);
            }
            num *= num3;
            if (ap.WornByCorpse && (pawn == null || ThoughtUtility.CanGetThought(pawn, ThoughtDefOf.DeadMansApparel)))
            {
                num = (float)(num - 0.5);
                if (num > 0.0)
                {
                    num = (float)(num * 0.10000000149011612);
                }
            }
            if (ap.Stuff == ThingDefOf.Human.race.leatherDef)
            {
                if (pawn == null || ThoughtUtility.CanGetThought(pawn, ThoughtDefOf.HumanLeatherApparelSad))
                {
                    num = (float)(num - 0.5);
                    if (num > 0.0)
                    {
                        num = (float)(num * 0.10000000149011612);
                    }
                }
                if (pawn != null && ThoughtUtility.CanGetThought(pawn, ThoughtDefOf.HumanLeatherApparelHappy))
                {
                    num = (float)(num + 0.11999999731779099);
                }
            }
            return(num);
        }
示例#19
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
                {
                    billDoer,
                    pawn
                });
                MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, part, billDoer.Position, billDoer.Map);
                MedicalRecipesUtility.SpawnThingsFromHediffs(pawn, part, billDoer.Position, billDoer.Map);
            }
            DamageDef surgicalCut      = DamageDefOf.SurgicalCut;
            float     amount           = 99999f;
            float     armorPenetration = 999f;

            pawn.TakeDamage(new DamageInfo(surgicalCut, amount, armorPenetration, -1f, null, part, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
            if (flag)
            {
                if (pawn.Dead)
                {
                    ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting);
                }
                ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
            }
            if (flag2 && pawn.Faction != null && billDoer.Faction != null)
            {
                Faction faction        = pawn.Faction;
                Faction faction2       = billDoer.Faction;
                int     goodwillChange = -15;
                string  reason         = "GoodwillChangedReason_RemovedBodyPart".Translate(new object[]
                {
                    part.LabelShort
                });
                GlobalTargetInfo?lookTarget = new GlobalTargetInfo?(pawn);
                faction.TryAffectGoodwillWith(faction2, goodwillChange, true, true, reason, lookTarget);
            }
        }
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = !PawnGenerator.IsBeingGenerated(pawn) && this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
                {
                    billDoer,
                    pawn
                });
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map);
            }
            else if (pawn.Map != null)
            {
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, pawn.Position, pawn.Map);
            }
            else
            {
                pawn.health.RestorePart(part, null, true);
            }
            pawn.health.AddHediff(this.recipe.addsHediff, part, null, null);
            if (flag && flag2 && part.def.spawnThingOnRemoved != null)
            {
                ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
            }
            if (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null)
            {
                Faction faction        = pawn.Faction;
                Faction faction2       = billDoer.Faction;
                int     goodwillChange = -15;
                string  reason         = "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(new object[]
                {
                    this.recipe.addsHediff.label
                });
                GlobalTargetInfo?lookTarget = new GlobalTargetInfo?(pawn);
                faction.TryAffectGoodwillWith(faction2, goodwillChange, true, true, reason, lookTarget);
            }
        }
 public void TryGainMemory(Thought_Memory newThought, Pawn otherPawn = null)
 {
     if (ThoughtUtility.CanGetThought(this.pawn, newThought.def))
     {
         if (newThought is Thought_MemorySocial && newThought.otherPawn == null && otherPawn == null)
         {
             Log.Error("Can't gain social thought " + newThought.def + " because its otherPawn is null and otherPawn passed to this method is also null. Social thoughts must have otherPawn.");
         }
         else
         {
             newThought.pawn      = this.pawn;
             newThought.otherPawn = otherPawn;
             bool flag = default(bool);
             if (!newThought.TryMergeWithExistingMemory(out flag))
             {
                 this.memories.Add(newThought);
             }
             if (newThought.def.stackLimitPerPawn >= 0)
             {
                 while (this.NumMemoriesInGroup(newThought) > newThought.def.stackLimitPerPawn)
                 {
                     this.RemoveMemory(this.OldestMemoryInGroup(newThought));
                 }
             }
             if (newThought.def.stackLimit >= 0)
             {
                 while (this.NumMemoriesOfDef(newThought.def) > newThought.def.stackLimit)
                 {
                     this.RemoveMemory(this.OldestMemoryOfDef(newThought.def));
                 }
             }
             if (newThought.def.thoughtToMake != null)
             {
                 this.TryGainMemory(newThought.def.thoughtToMake, newThought.otherPawn);
             }
             if (flag && newThought.def.showBubble && this.pawn.Spawned)
             {
                 MoteMaker.MakeMoodThoughtBubble(this.pawn, newThought);
             }
         }
     }
 }
        public override float OpinionOffset()
        {
            if (ThoughtUtility.ThoughtNullified(pawn, def))
            {
                return(0f);
            }
            Tale latestTale = Find.TaleManager.GetLatestTale(def.taleDef, otherPawn);

            if (latestTale != null)
            {
                float num = 1f;
                if (latestTale.def.type == TaleType.Expirable)
                {
                    float value = (float)latestTale.AgeTicks / (latestTale.def.expireDays * 60000f);
                    num = Mathf.InverseLerp(1f, def.lerpOpinionToZeroAfterDurationPct, value);
                }
                return(base.CurStage.baseOpinionOffset * num);
            }
            return(0f);
        }
示例#23
0
 public void TryGainMemory(Thought_Memory newThought, Pawn otherPawn = null)
 {
     if (!ThoughtUtility.CanGetThought(pawn, newThought.def))
     {
         return;
     }
     if (newThought is Thought_MemorySocial && newThought.otherPawn == null && otherPawn == null)
     {
         Log.Error("Can't gain social thought " + newThought.def + " because its otherPawn is null and otherPawn passed to this method is also null. Social thoughts must have otherPawn.");
         return;
     }
     newThought.pawn      = pawn;
     newThought.otherPawn = otherPawn;
     if (!newThought.TryMergeWithExistingMemory(out bool showBubble))
     {
         memories.Add(newThought);
     }
     if (newThought.def.stackLimitForSameOtherPawn >= 0)
     {
         while (NumMemoriesInGroup(newThought) > newThought.def.stackLimitForSameOtherPawn)
         {
             RemoveMemory(OldestMemoryInGroup(newThought));
         }
     }
     if (newThought.def.stackLimit >= 0)
     {
         while (NumMemoriesOfDef(newThought.def) > newThought.def.stackLimit)
         {
             RemoveMemory(OldestMemoryOfDef(newThought.def));
         }
     }
     if (newThought.def.thoughtToMake != null)
     {
         TryGainMemory(newThought.def.thoughtToMake, newThought.otherPawn);
     }
     if (showBubble && newThought.def.showBubble && pawn.Spawned && PawnUtility.ShouldSendNotificationAbout(pawn))
     {
         MoteMaker.MakeMoodThoughtBubble(pawn, newThought);
     }
 }
示例#24
0
        public virtual float MoodOffset()
        {
            if (CurStage == null)
            {
                Log.Error("CurStage is null while ShouldDiscard is false on " + def.defName + " for " + pawn);
                return(0f);
            }
            if (ThoughtUtility.ThoughtNullified(pawn, def))
            {
                return(0f);
            }
            float num = BaseMoodOffset;

            if (def.effectMultiplyingStat != null)
            {
                num *= pawn.GetStatValue(def.effectMultiplyingStat);
            }
            if (def.Worker != null)
            {
                num *= def.Worker.MoodMultiplier(pawn);
            }
            return(num);
        }
示例#25
0
        public static Toil LayDown(TargetIndex bedOrRestSpotIndex, bool hasBed, bool lookForOtherJobs, bool canSleep = true, bool gainRestAndHealth = true)
        {
            Toil layDown = new Toil();

            layDown.initAction = delegate
            {
                Pawn actor3 = layDown.actor;
                actor3.pather.StopDead();
                JobDriver curDriver3 = actor3.jobs.curDriver;
                if (hasBed)
                {
                    if (!((Building_Bed)actor3.CurJob.GetTarget(bedOrRestSpotIndex).Thing).OccupiedRect().Contains(actor3.Position))
                    {
                        Log.Error("Can't start LayDown toil because pawn is not in the bed. pawn=" + actor3);
                        actor3.jobs.EndCurrentJob(JobCondition.Errored);
                        return;
                    }
                    actor3.jobs.posture = PawnPosture.LayingInBed;
                }
                else
                {
                    actor3.jobs.posture = PawnPosture.LayingOnGroundNormal;
                }
                curDriver3.asleep = false;
                if (actor3.mindState.applyBedThoughtsTick == 0)
                {
                    actor3.mindState.applyBedThoughtsTick    = Find.TickManager.TicksGame + Rand.Range(2500, 10000);
                    actor3.mindState.applyBedThoughtsOnLeave = false;
                }
                if (actor3.ownership != null && actor3.CurrentBed() != actor3.ownership.OwnedBed)
                {
                    ThoughtUtility.RemovePositiveBedroomThoughts(actor3);
                }
                actor3.GetComp <CompCanBeDormant>()?.ToSleep();
            };
            layDown.tickAction = delegate
            {
                Pawn         actor2       = layDown.actor;
                Job          curJob       = actor2.CurJob;
                JobDriver    curDriver2   = actor2.jobs.curDriver;
                Building_Bed building_Bed = (Building_Bed)curJob.GetTarget(bedOrRestSpotIndex).Thing;
                actor2.GainComfortFromCellIfPossible();
                if (!curDriver2.asleep)
                {
                    if (canSleep && ((actor2.needs.rest != null && actor2.needs.rest.CurLevel < RestUtility.FallAsleepMaxLevel(actor2)) || curJob.forceSleep))
                    {
                        curDriver2.asleep = true;
                    }
                }
                else if (!canSleep)
                {
                    curDriver2.asleep = false;
                }
                else if ((actor2.needs.rest == null || actor2.needs.rest.CurLevel >= RestUtility.WakeThreshold(actor2)) && !curJob.forceSleep)
                {
                    curDriver2.asleep = false;
                }
                if (curDriver2.asleep && gainRestAndHealth && actor2.needs.rest != null)
                {
                    float restEffectiveness = (building_Bed == null || !building_Bed.def.statBases.StatListContains(StatDefOf.BedRestEffectiveness)) ? StatDefOf.BedRestEffectiveness.valueIfMissing : building_Bed.GetStatValue(StatDefOf.BedRestEffectiveness);
                    actor2.needs.rest.TickResting(restEffectiveness);
                }
                if (actor2.mindState.applyBedThoughtsTick != 0 && actor2.mindState.applyBedThoughtsTick <= Find.TickManager.TicksGame)
                {
                    ApplyBedThoughts(actor2);
                    actor2.mindState.applyBedThoughtsTick   += 60000;
                    actor2.mindState.applyBedThoughtsOnLeave = true;
                }
                if (actor2.IsHashIntervalTick(100) && !actor2.Position.Fogged(actor2.Map))
                {
                    if (curDriver2.asleep)
                    {
                        MoteMaker.ThrowMetaIcon(actor2.Position, actor2.Map, ThingDefOf.Mote_SleepZ);
                    }
                    if (gainRestAndHealth && actor2.health.hediffSet.GetNaturallyHealingInjuredParts().Any())
                    {
                        MoteMaker.ThrowMetaIcon(actor2.Position, actor2.Map, ThingDefOf.Mote_HealingCross);
                    }
                }
                if (actor2.ownership != null && building_Bed != null && !building_Bed.Medical && !building_Bed.OwnersForReading.Contains(actor2))
                {
                    if (actor2.Downed)
                    {
                        actor2.Position = CellFinder.RandomClosewalkCellNear(actor2.Position, actor2.Map, 1);
                    }
                    actor2.jobs.EndCurrentJob(JobCondition.Incompletable);
                }
                else if (lookForOtherJobs && actor2.IsHashIntervalTick(211))
                {
                    actor2.jobs.CheckForJobOverride();
                }
            };
            layDown.defaultCompleteMode = ToilCompleteMode.Never;
            if (hasBed)
            {
                layDown.FailOnBedNoLongerUsable(bedOrRestSpotIndex);
            }
            layDown.AddFinishAction(delegate
            {
                Pawn actor          = layDown.actor;
                JobDriver curDriver = actor.jobs.curDriver;
                if (actor.mindState.applyBedThoughtsOnLeave)
                {
                    ApplyBedThoughts(actor);
                }
                curDriver.asleep = false;
            });
            return(layDown);
        }
        public static float ApparelScoreRaw(Pawn pawn, Apparel ap)
        {
            float num  = 0.1f;
            float num2 = ap.GetStatValue(StatDefOf.ArmorRating_Sharp) + ap.GetStatValue(StatDefOf.ArmorRating_Blunt);

            num += num2;
            if (ap.def.useHitPoints)
            {
                float x = (float)ap.HitPoints / (float)ap.MaxHitPoints;
                num *= HitPointsPercentScoreFactorCurve.Evaluate(x);
            }
            num += ap.GetSpecialApparelScoreOffset();
            float num3 = 1f;

            if (neededWarmth == NeededWarmth.Warm)
            {
                float statValue = ap.GetStatValue(StatDefOf.Insulation_Cold);
                num3 *= InsulationColdScoreFactorCurve_NeedWarm.Evaluate(statValue);
            }
            num *= num3;
            if (ap.WornByCorpse && (pawn == null || ThoughtUtility.CanGetThought_NewTemp(pawn, ThoughtDefOf.DeadMansApparel, checkIfNullified: true)))
            {
                num -= 0.5f;
                if (num > 0f)
                {
                    num *= 0.1f;
                }
            }
            if (ap.Stuff == ThingDefOf.Human.race.leatherDef)
            {
                if (pawn == null || ThoughtUtility.CanGetThought_NewTemp(pawn, ThoughtDefOf.HumanLeatherApparelSad, checkIfNullified: true))
                {
                    num -= 0.5f;
                    if (num > 0f)
                    {
                        num *= 0.1f;
                    }
                }
                if (pawn != null && ThoughtUtility.CanGetThought_NewTemp(pawn, ThoughtDefOf.HumanLeatherApparelHappy, checkIfNullified: true))
                {
                    num += 0.12f;
                }
            }
            if (pawn != null && !ap.def.apparel.CorrectGenderForWearing(pawn.gender))
            {
                num *= 0.01f;
            }
            if (pawn != null && pawn.royalty != null && pawn.royalty.AllTitlesInEffectForReading.Count > 0)
            {
                tmpAllowedApparels.Clear();
                tmpRequiredApparels.Clear();
                tmpBodyPartGroupsWithRequirement.Clear();
                QualityCategory qualityCategory = QualityCategory.Awful;
                foreach (RoyalTitle item in pawn.royalty.AllTitlesInEffectForReading)
                {
                    if (item.def.requiredApparel != null)
                    {
                        for (int i = 0; i < item.def.requiredApparel.Count; i++)
                        {
                            tmpAllowedApparels.AddRange(item.def.requiredApparel[i].AllAllowedApparelForPawn(pawn, ignoreGender: false, includeWorn: true));
                            tmpRequiredApparels.AddRange(item.def.requiredApparel[i].AllRequiredApparelForPawn(pawn, ignoreGender: false, includeWorn: true));
                            tmpBodyPartGroupsWithRequirement.AddRange(item.def.requiredApparel[i].bodyPartGroupsMatchAny);
                        }
                    }
                    if ((int)item.def.requiredMinimumApparelQuality > (int)qualityCategory)
                    {
                        qualityCategory = item.def.requiredMinimumApparelQuality;
                    }
                }
                bool num4 = ap.def.apparel.bodyPartGroups.Any((BodyPartGroupDef bp) => tmpBodyPartGroupsWithRequirement.Contains(bp));
                if (ap.TryGetQuality(out QualityCategory qc) && (int)qc < (int)qualityCategory)
                {
                    num *= 0.25f;
                }
                if (num4)
                {
                    foreach (ThingDef tmpRequiredApparel in tmpRequiredApparels)
                    {
                        tmpAllowedApparels.Remove(tmpRequiredApparel);
                    }
                    if (tmpAllowedApparels.Contains(ap.def))
                    {
                        num *= 10f;
                    }
                    if (tmpRequiredApparels.Contains(ap.def))
                    {
                        num *= 25f;
                    }
                }
            }
            return(num);
        }
示例#27
0
        public static Toil LayDown(TargetIndex bedOrRestSpotIndex, bool hasBed, bool lookForOtherJobs, bool canSleep = true, bool gainRestAndHealth = true)
        {
            Toil layDown = new Toil();

            layDown.initAction = delegate
            {
                Pawn actor = layDown.actor;
                actor.pather.StopDead();
                JobDriver curDriver = actor.jobs.curDriver;
                if (hasBed)
                {
                    Building_Bed t = (Building_Bed)actor.CurJob.GetTarget(bedOrRestSpotIndex).Thing;
                    if (!t.OccupiedRect().Contains(actor.Position))
                    {
                        Log.Error("Can't start LayDown toil because pawn is not in the bed. pawn=" + actor);
                        actor.jobs.EndCurrentJob(JobCondition.Errored, true);
                        return;
                    }
                    curDriver.layingDown = LayingDownState.LayingInBed;
                }
                else
                {
                    curDriver.layingDown = LayingDownState.LayingSurface;
                }
                curDriver.asleep = false;
                if (actor.mindState.applyBedThoughtsTick == 0)
                {
                    actor.mindState.applyBedThoughtsTick    = Find.TickManager.TicksGame + Rand.Range(2500, 10000);
                    actor.mindState.applyBedThoughtsOnLeave = false;
                }
                if (actor.ownership != null && actor.CurrentBed() != actor.ownership.OwnedBed)
                {
                    ThoughtUtility.RemovePositiveBedroomThoughts(actor);
                }
            };
            layDown.tickAction = delegate
            {
                Pawn         actor        = layDown.actor;
                Job          curJob       = actor.CurJob;
                JobDriver    curDriver    = actor.jobs.curDriver;
                Building_Bed building_Bed = (Building_Bed)curJob.GetTarget(bedOrRestSpotIndex).Thing;
                actor.GainComfortFromCellIfPossible();
                if (!curDriver.asleep)
                {
                    if (canSleep && ((actor.needs.rest != null && actor.needs.rest.CurLevel < RestUtility.FallAsleepMaxLevel(actor)) || curJob.forceSleep))
                    {
                        curDriver.asleep = true;
                    }
                }
                else if (!canSleep)
                {
                    curDriver.asleep = false;
                }
                else if ((actor.needs.rest == null || actor.needs.rest.CurLevel >= RestUtility.WakeThreshold(actor)) && !curJob.forceSleep)
                {
                    curDriver.asleep = false;
                }
                if (curDriver.asleep && gainRestAndHealth && actor.needs.rest != null)
                {
                    float num;
                    if (building_Bed != null && building_Bed.def.statBases.StatListContains(StatDefOf.BedRestEffectiveness))
                    {
                        num = building_Bed.GetStatValue(StatDefOf.BedRestEffectiveness, true);
                    }
                    else
                    {
                        num = 0.8f;
                    }
                    float num2 = RestUtility.PawnHealthRestEffectivenessFactor(actor);
                    num = 0.7f * num + 0.3f * num * num2;
                    actor.needs.rest.TickResting(num);
                }
                if (actor.mindState.applyBedThoughtsTick != 0 && actor.mindState.applyBedThoughtsTick <= Find.TickManager.TicksGame)
                {
                    Toils_LayDown.ApplyBedThoughts(actor);
                    actor.mindState.applyBedThoughtsTick   += 60000;
                    actor.mindState.applyBedThoughtsOnLeave = true;
                }
                if (actor.IsHashIntervalTick(100) && !actor.Position.Fogged(actor.Map))
                {
                    if (curDriver.asleep)
                    {
                        MoteMaker.ThrowMetaIcon(actor.Position, actor.Map, ThingDefOf.Mote_SleepZ);
                    }
                    if (gainRestAndHealth && actor.health.hediffSet.GetNaturallyHealingInjuredParts().Any <BodyPartRecord>())
                    {
                        MoteMaker.ThrowMetaIcon(actor.Position, actor.Map, ThingDefOf.Mote_HealingCross);
                    }
                }
                if (actor.ownership != null && building_Bed != null && !building_Bed.Medical && !building_Bed.owners.Contains(actor))
                {
                    if (actor.Downed)
                    {
                        actor.Position = CellFinder.RandomClosewalkCellNear(actor.Position, actor.Map, 1, null);
                    }
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                    return;
                }
                if (lookForOtherJobs && actor.IsHashIntervalTick(211))
                {
                    actor.jobs.CheckForJobOverride();
                    return;
                }
            };
            layDown.defaultCompleteMode = ToilCompleteMode.Never;
            if (hasBed)
            {
                layDown.FailOnBedNoLongerUsable(bedOrRestSpotIndex);
            }
            layDown.AddFinishAction(delegate
            {
                Pawn actor          = layDown.actor;
                JobDriver curDriver = actor.jobs.curDriver;
                if (actor.mindState.applyBedThoughtsOnLeave)
                {
                    Toils_LayDown.ApplyBedThoughts(actor);
                }
                curDriver.layingDown = LayingDownState.NotLaying;
                curDriver.asleep     = false;
            });
            return(layDown);
        }
 public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
 {
     pawn.health.AddHediff(base.recipe.addsHediff, part, null);
     ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.GenericHumane);
 }
 public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
 {
     ExecutionUtility.DoExecutionByCut(billDoer, pawn);
     ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.GenericHumane);
 }