public override float OpinionOffset() { if (ThoughtUtility.ThoughtNullified(pawn, def)) { return(0f); } Predicate <Tale_DoublePawn> validator = delegate(Tale_DoublePawn tale) { return(otherPawn == tale.secondPawnData?.pawn && OpinionOf(tale.firstPawnData.pawn) >= 20); }; Tale latestTale = VSIE_Utils.GetLatestDoublePawnTale(def.taleDef, validator); 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); } var value2 = base.CurStage.baseOpinionOffset * num; return(value2); } return(0f); }
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 (CheckSurgeryFailCustom(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.FactionOrExtraMiniOrHomeFaction, -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); }
private static void ApplyHumanLeatherScoring(Pawn pawn, Thing apparel, ref float score) { if (apparel.Stuff != ThingDefOf.Human.race.leatherDef) { return; } if (ThoughtUtility.CanGetThought_NewTemp(pawn, ThoughtDefOf.HumanLeatherApparelSad)) { #if DEBUG Log.Message("OutfitManager: Penalizing human leather apparel", true); #endif score -= HumanLeatherScorePenalty; if (score > 0f) { score *= HumanLeatherScoreFactor; } } if (ThoughtUtility.CanGetThought_NewTemp(pawn, ThoughtDefOf.HumanLeatherApparelHappy)) { #if DEBUG Log.Message("OutfitManager: Promoting human leather apparel", true); #endif score += HumanLeatherScoreBonus; } }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { // part = brain var spine = pawn.health.hediffSet.GetSpine(); bool isClean = MedicalRecipesUtility.IsClean(pawn, part); bool isViolation = IsViolationOnPawn(pawn, part, Faction.OfPlayer); if (billDoer != null) { if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill)) { return; } TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); GenSpawn.Spawn(AutomataRaceDefOf.PN_Brain, billDoer.Position, billDoer.Map); } pawn.TakeDamage(new DamageInfo(DamageDefOf.SurgicalCut, 99999f, 999f, -1f, null, part)); pawn.health.AddHediff(HediffDefOf.MissingBodyPart, spine, new DamageInfo(DamageDefOf.SurgicalCut, 99999f, 999f, -1f, null, spine)); if (isClean) { if (pawn.Dead) { ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting); } ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn); } if (isViolation) { ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort)); } }
public static Thought_Memory GetSubstitute([NotNull] this Thought_Memory memory, [NotNull] Pawn pawn) { IEnumerable <ThoughtGroupDefExtension> tGroups = memory.def.modExtensions.MakeSafe().OfType <ThoughtGroupDefExtension>(); foreach (ThoughtDef thoughtDef in tGroups.SelectMany(g => g.thoughts)) { if (ThoughtUtility.CanGetThought(pawn, thoughtDef)) { int forcedStage = Mathf.Min(memory.CurStageIndex, thoughtDef.stages.Count - 1); if (forcedStage != memory.CurStageIndex) { Log.Warning($"in memory {memory.def.defName}, substituted thought {thoughtDef.defName} does not the same number of stages\noriginal:{memory.def.stages.Count} sub:{thoughtDef.stages.Count}"); } Thought_Memory newMemory = ThoughtMaker.MakeThought(thoughtDef, forcedStage); if (newMemory == null) { Log.Error($"in thought {memory.def.defName} group, thought {thoughtDef.defName} is not a memory"); continue; } return(newMemory); } } return(memory); }
static bool Prefix(ref Pawn ___pawn, ref Building_Bed ___intOwnedBed) { UnassignAllBedsIfDead(___pawn); if (!Helpers.ShouldRunForPawn(___pawn)) { return(true); } var isInShuttle = !___pawn.Spawned && ___pawn.SpawnedParentOrMe?.Label?.Contains("shuttle") == true; if (isInShuttle) { ___intOwnedBed = null; ThoughtUtility.RemovePositiveBedroomThoughts(___pawn); return(true); } // NOTE: If the bed is unclaimed (typically deconstructed/replaced) on another map this will cause the pawn // to unclaim the bed on CurrentMap. Since UnclaimBed doesn't specify bed we have to guess, and since it's // called from a bunch of places in vanilla (plus whatever from mods) I'd rather just take the occasional // unwanted unclaim instead of trying to patch everywhere. // Temporarily replace pawns owned bed on their map with the bed owned on the current map ClaimBedOnMapIfExists(___pawn, Find.CurrentMap, ref ___intOwnedBed); return(true); }
public override float OpinionOffset() { if (ThoughtUtility.ThoughtNullified(pawn, def)) { return(0f); } return(LovePartnerRelationUtility.IncestOpinionOffsetFor(otherPawn, pawn)); }
private void ApplyThought(Pawn thoughtReceiver, Pawn thoughtTarget, string defName) { var thought = ThoughtDef.Named(defName); if (ThoughtUtility.CanGetThought(thoughtReceiver, thought)) { thoughtReceiver.needs.mood.thoughts.memories.TryGainMemory((Thought_Memory)ThoughtMaker.MakeThought(thought), thoughtTarget); } }
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); if (flag && flag2 && part.def.spawnThingOnRemoved != null) { ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn, billDoer); } if (flag2) { ReportViolation(pawn, billDoer, pawn.HomeFaction, -70); } if (ModsConfig.IdeologyActive) { Find.HistoryEventsManager.RecordEvent(new HistoryEvent(HistoryEventDefOf.InstalledProsthetic, billDoer.Named(HistoryEventArgsNames.Doer))); } } else { pawn.health.RestorePart(part); } pawn.health.AddHediff(recipe.addsHediff, part); if (recipe?.addsHediff != null && ingredients != null) { var hediff = pawn.health?.hediffSet?.hediffs?.FindLast(x => x.def == recipe.addsHediff); if (hediff != null) { var comp = hediff.TryGetComp <HediffCompImplantQuality>(); if (comp != null) { foreach (var ingredient in ingredients) { if (ingredient != null && hediff.def.spawnThingOnRemoved == ingredient.def && ingredient.TryGetQuality(out var qualityCategory)) { comp.quality = qualityCategory; comp.SelectSeverity(qualityCategory); break; } } } } } }
public static bool TryGainMemory(MemoryThoughtHandler __instance, Thought_Memory newThought, Pawn otherPawn = null) { if (!ThoughtUtility.CanGetThought_NewTemp(__instance.pawn, newThought.def)) { return(false); } if (newThought is Thought_MemorySocial && newThought.otherPawn == null && otherPawn == null) { Log.Error(string.Concat("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(false); } newThought.pawn = __instance.pawn; newThought.otherPawn = otherPawn; if (!newThought.TryMergeWithExistingMemory(out bool showBubble)) { lock (__instance) { List <Thought_Memory> newMemories = new List <Thought_Memory>(__instance.Memories) { newThought }; memoriesFieldRef(__instance) = newMemories; } } if (newThought.def.stackLimitForSameOtherPawn >= 0) { while (__instance.NumMemoriesInGroup(newThought) > newThought.def.stackLimitForSameOtherPawn) { __instance.RemoveMemory(__instance.OldestMemoryInGroup(newThought)); } } if (newThought.def.stackLimit >= 0) { while (__instance.NumMemoriesOfDef(newThought.def) > newThought.def.stackLimit) { __instance.RemoveMemory(__instance.OldestMemoryOfDef(newThought.def)); } } if (newThought.def.thoughtToMake != null) { __instance.TryGainMemory(newThought.def.thoughtToMake, newThought.otherPawn); } if (showBubble && newThought.def.showBubble && __instance.pawn.Spawned && PawnUtility.ShouldSendNotificationAbout(__instance.pawn)) { MoteMaker.MakeMoodThoughtBubble(__instance.pawn, newThought); } return(false); }
public static void UnclaimBeds(Pawn pawn, IEnumerable <Building_Bed> beds, ref Building_Bed ___intOwnedBed) { foreach (var bed in beds) { bed?.CompAssignableToPawn?.ForceRemovePawn(pawn); if (pawn.ownership?.OwnedBed == bed) { ___intOwnedBed = null; ThoughtUtility.RemovePositiveBedroomThoughts(pawn); } } }
public static float ApparelScoreRaw(Pawn pawn, Apparel apparel, NeededWarmth neededWarmth = NeededWarmth.Any) { var outfit = pawn.outfits.CurrentOutfit as ExtendedOutfit; if (outfit == null) { Log.ErrorOnce("Outfitted :: Not an ExtendedOutfit, something went wrong.", 399441); return(0f); } float score = 0.1f + ApparelScoreRawPriorities(pawn, apparel, outfit); if (outfit.AutoWorkPriorities) { score += ApparelScoreAutoWorkPriorities(pawn, apparel); } if (apparel.def.useHitPoints) { float x = (float)apparel.HitPoints / apparel.MaxHitPoints; score *= HitPointsPercentScoreFactorCurve.Evaluate(x); } score += apparel.GetSpecialApparelScoreOffset(); score += ApparelScoreRawInsulation(pawn, apparel, outfit, neededWarmth); if (outfit.PenaltyWornByCorpse && apparel.WornByCorpse && ThoughtUtility.CanGetThought(pawn, ThoughtDefOf.DeadMansApparel)) { score -= 0.5f; if (score > 0f) { score *= 0.1f; } } if (apparel.Stuff == ThingDefOf.Human.race.leatherDef) { if (ThoughtUtility.CanGetThought(pawn, ThoughtDefOf.HumanLeatherApparelSad)) { score -= 0.5f; if (score > 0f) { score *= 0.1f; } } if (ThoughtUtility.CanGetThought(pawn, ThoughtDefOf.HumanLeatherApparelHappy)) { score += 0.12f; } } return(score); }
public override float OpinionOffset() { if (ThoughtUtility.ThoughtNullified(pawn, def)) { return(0f); } if (otherPawn.story.traits.HasTrait(MyDefOf.MLRP_BronyTrait)) { return(25f); } return(0f); }
public static bool HasSocialSituationalThought(Pawn pawn, Pawn other, ThoughtDef thought) { if (!ThoughtUtility.CanGetThought(pawn, thought)) { return(false); } ThoughtState thoughtState = thought.Worker.CurrentSocialState(pawn, other); if (thoughtState.Active) { return(true); } return(false); }
public static ThoughtDef GetSubstitute([NotNull] this ThoughtDef def, [NotNull] Pawn pawn) { IEnumerable <ThoughtGroupDefExtension> tGroups = def.modExtensions.MakeSafe().OfType <ThoughtGroupDefExtension>(); foreach (ThoughtDef thoughtDef in tGroups.SelectMany(g => g.thoughts)) { if (ThoughtUtility.CanGetThought(pawn, thoughtDef)) //take the first one that matches { return(thoughtDef); } } //no matches found return(def); }
/// <summary> /// Try to give this pawn a new memory. <br /> /// If pawn does not have needs/mood/thoughts ect this call does nothing. /// </summary> /// <param name="pawn">The pawn.</param> /// <param name="thought">The thought.</param> /// <param name="otherPawn">The other pawn.</param> /// <param name="respectTraits">if ThoughtUtility.CanGetThought should be checked before giving the thought</param> /// <exception cref="ArgumentNullException">pawn</exception> public static void TryGainMemory([NotNull] this Pawn pawn, Thought_Memory thought, Pawn otherPawn = null, bool respectTraits = true) //move extension methods elsewhere? { if (pawn == null) { throw new ArgumentNullException(nameof(pawn)); } if (respectTraits && !ThoughtUtility.CanGetThought(pawn, thought.def)) { return; } pawn.needs?.mood?.thoughts?.memories?.TryGainMemory(thought, otherPawn); }
private static void ClaimBedOnMapIfExists(Pawn ___pawn, Map map, ref Building_Bed ___intOwnedBed) { var pawnBedsOnMap = Helpers.PawnBedsOnMap(___pawn, map); if (pawnBedsOnMap.Any()) { var bed = pawnBedsOnMap.First(); ___intOwnedBed = bed; if (bed.CompAssignableToPawn != null && !bed.CompAssignableToPawn.AssignedPawnsForReading.Contains(___pawn)) { bed.CompAssignableToPawn.ForceAddPawn(___pawn); } ThoughtUtility.RemovePositiveBedroomThoughts(___pawn); } }
private static void ApplyTaintedScoring(Pawn pawn, Apparel apparel, ExtendedOutfit outfit, ref float score) { if (!outfit.PenalizeTaintedApparel || !apparel.WornByCorpse || !ThoughtUtility.CanGetThought_NewTemp(pawn, ThoughtDefOf.DeadMansApparel)) { return; } #if DEBUG Log.Message("OutfitManager: Penalizing tainted apparel", true); #endif score -= TaintedApparelScorePenalty; if (score > 0f) { score *= TaintedApparelScoreFactor; } }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { bool flag1 = 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 (flag1) { if (pawn.Dead) { ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting); } 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_RemovedBodyPart".Translate(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) { base.ApplyOnPawn(pawn, part, billDoer, ingredients, 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 }); Thing md = ThingMaker.MakeThing(WTH_DefOf.WTH_ExtractedBrainData); md.stackCount = 3 + pawn.skills.GetSkill(SkillDefOf.Intellectual).Level; GenPlace.TryPlaceThing(md, pawn.Position, pawn.Map, ThingPlaceMode.Near); } 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 != null && billDoer.Faction != null) { Faction arg_120_0 = pawn.Faction; Faction faction = billDoer.Faction; int goodwillChange = -15; string reason = "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort); GlobalTargetInfo?lookTarget = new GlobalTargetInfo?(pawn); arg_120_0.TryAffectGoodwillWith(faction, goodwillChange, true, true, reason, lookTarget); } }
public override float OpinionOffset() { if (ThoughtUtility.ThoughtNullified(pawn, def)) { return(0f); } int num = otherPawn.story.traits.DegreeOfTrait(TraitDefOf.Industriousness); if (num > 0) { return(0f); } return(num switch { 0 => - 5f, -1 => - 20f, _ => - 30f, });
public override float OpinionOffset() { if (ThoughtUtility.ThoughtNullified(pawn, def)) { return(0f); } int num = pawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire); if (otherPawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire) >= 0) { return(0f); } if (num == 1) { return(-20f); } return(-30f); }
public override void ApplyOnPawn(Pawn p, BodyPartRecord part, Pawn doer, List <Thing> ingredients, Bill bill) { var har = is_harvest(p, part); base.ApplyOnPawn(p, part, doer, ingredients, bill); if (har) { if (!p.Dead) { ThoughtUtility.GiveThoughtsForPawnOrganHarvested(p); } else { ThoughtUtility.GiveThoughtsForPawnExecuted(p, PawnExecutionKind.OrganHarvesting); } } }
private void DoSocialImpact(Pawn victim) { var isPrisoner = victim.IsPrisonerOfColony; var giveThought = AllowToolUtility.PawnIsFriendly(victim); if (giveThought) { ThoughtUtility.GiveThoughtsForPawnExecuted(victim, PawnExecutionKind.GenericBrutal); } if (victim.RaceProps != null && victim.RaceProps.intelligence == Intelligence.Animal) { pawn.records.Increment(RecordDefOf.AnimalsSlaughtered); } if (isPrisoner) { TaleRecorder.RecordTale(TaleDefOf.ExecutedPrisoner, pawn, victim); } }
public override void GameConditionTick() { base.GameConditionTick(); if (!firstTick) { return; } firstTick = false; var affectedPawns = new List <Pawn>(); foreach (var map in AffectedMaps) { affectedPawns.AddRange(map.mapPawns.FreeColonistsAndPrisoners); //Add a wolf pack var wolfType = map.mapTemperature.OutdoorTemp > 0f ? PawnKindDef.Named("Wolf_Timber") : PawnKindDef.Named("Wolf_Arctic"); RCellFinder.TryFindRandomPawnEntryCell(out var loc, map, CellFinder.EdgeRoadChance_Animal); var numberOfWolves = Rand.Range(3, 6); for (var i = 0; i < numberOfWolves; i++) { var newWolf = PawnGenerator.GeneratePawn(wolfType); GenSpawn.Spawn(newWolf, loc, map); } } foreach (var pawn in affectedPawns) { if (ThoughtUtility.CanGetThought(pawn, HPLDefOf.HPLovecraft_SawBloodMoonSad)) { pawn.needs.mood.thoughts.memories.TryGainMemory(HPLDefOf.HPLovecraft_SawBloodMoonSad); continue; } if (ThoughtUtility.CanGetThought(pawn, HPLDefOf.HPLovecraft_SawBloodMoonHappy)) { pawn.needs.mood.thoughts.memories.TryGainMemory(HPLDefOf.HPLovecraft_SawBloodMoonHappy); } } }
public override void GameConditionTick() { base.GameConditionTick(); if (firstTick) { foreach (Pawn pawn in Map.mapPawns.FreeColonistsAndPrisoners) { if (ThoughtUtility.CanGetThought(pawn, HPLDefOf.HPLovecraft_SawBloodMoonSad)) { pawn.needs.mood.thoughts.memories.TryGainMemory(HPLDefOf.HPLovecraft_SawBloodMoonSad); } else if (ThoughtUtility.CanGetThought(pawn, HPLDefOf.HPLovecraft_SawBloodMoonHappy)) { pawn.needs.mood.thoughts.memories.TryGainMemory(HPLDefOf.HPLovecraft_SawBloodMoonHappy); } } firstTick = false; } }
private static void CanGetThoughtPostfix([NotNull] Pawn pawn, [NotNull] ThoughtDef def, ref bool __result) { var tracker = pawn.GetAspectTracker(); if (tracker != null) { foreach (Aspect aspect in tracker) { if (aspect.NullifiedThoughts.Contains(def)) { __result = false; break; } } } var tGroup = def.GetModExtension <ThoughtGroupDefExtension>(); if (tGroup != null && !__result) { //if the default thought is invalid and it has a thought group extension check if any of the specific thoughts are valid foreach (ThoughtDef tGroupThought in tGroup.thoughts) { if (tGroupThought.HasModExtension <ThoughtGroupDefExtension>()) { Log.Warning($"thought in {def.defName} has thought {tGroupThought.defName} with thought group extension! this is not currently supported as it may cause infinite recursion"); continue; } if (ThoughtUtility.CanGetThought_NewTemp(pawn, tGroupThought)) { __result = true; return; } } } if (__result) { __result = def.IsValidFor(pawn); } }
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, new object[] { pawn, Victim }); }; execute.defaultCompleteMode = ToilCompleteMode.Instant; yield return(execute); }
public static void GainSocialThought(Pawn initiator, Pawn target, ThoughtDef thoughtDef) { if (!ThoughtUtility.CanGetThought(target, thoughtDef)) { return; } float impact = initiator.GetStatValue(StatDefOf.SocialImpact); var thoughtMemory = (Thought_Memory)ThoughtMaker.MakeThought(thoughtDef); thoughtMemory.moodPowerFactor = impact; var thoughtSocialMemory = thoughtMemory as Thought_MemorySocial; if (thoughtSocialMemory != null) { thoughtSocialMemory.opinionOffset *= impact; } target.needs.mood.thoughts.memories.TryGainMemory(thoughtMemory, initiator); }
static bool Prefix(Building_Bed newBed, Pawn_Ownership __instance, ref Pawn ___pawn, ref Building_Bed ___intOwnedBed) { if (newBed == null || newBed.Medical || !Helpers.ShouldRunForPawn(___pawn) || (newBed.OwnersForReading != null && newBed.OwnersForReading.Contains(___pawn) && ___pawn.ownership?.OwnedBed == newBed)) { return(true); } // Remove other pawn to make room in bed var pawn = ___pawn; if (newBed.OwnersForReading?.Count == newBed.SleepingSlotsCount && !newBed.OwnersForReading.Any(p => p == pawn) && newBed.OwnersForReading.Count > 0) { var pawnToRemove = newBed.OwnersForReading.LastOrDefault(); pawnToRemove?.ownership?.UnclaimBed(); } // Unclaim bed if pawn already has one on the map of the new bed var pawnBeds = Helpers.PawnBedsOnMap(___pawn, newBed.Map); if (pawnBeds.Any()) { Helpers.UnclaimBeds(___pawn, pawnBeds, ref ___intOwnedBed); } // Claim new bed newBed.CompAssignableToPawn.ForceAddPawn(___pawn); // ... but only assign it if the pawn is on the same map if (___pawn.Map == newBed.Map) { ___intOwnedBed = newBed; ThoughtUtility.RemovePositiveBedroomThoughts(___pawn); } return(false); }