public static void GainJoyFromConstant(this Pawn pawn, float amountPerHour, JoyKindDef def) { if (pawn.needs != null && pawn.needs.joy != null) { pawn.needs.joy.GainJoy(amountPerHour * 0.000144f, def); } }
public void Notify_JoyKindDisabled(JoyKindDef joyKind) { try { if (curJob != null && curJob.def.joyKind == joyKind) { tmpJobsToDequeue.Add(curJob); } foreach (QueuedJob item in jobQueue) { if (item.job.def.joyKind == joyKind) { tmpJobsToDequeue.Add(item.job); } } foreach (Job item2 in tmpJobsToDequeue) { EndCurrentOrQueuedJob(item2, JobCondition.InterruptForced); } } finally { tmpJobsToDequeue.Clear(); } }
public static void ApplyThoughts(Pawn listener, JoyKindDef joyKindDef) { if (joyKindDef != JoyKindDefOf_Music.Music) { return; } var thought = PerformanceManager.GetThoughtDef(MusicQuality); if (thought == null) { return; } var caravan = listener.GetCaravan(); var audience = new List <Pawn>(); foreach (var pawn in caravan.pawns) { if (!pawn.NonHumanlikeOrWildMan() && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Hearing) && pawn.Awake()) { audience.Add(pawn); } } #if DEBUG Verse.Log.Message(string.Format("Giving memory of {0} to {1} pawns (caravan)", thought.stages[0].label, audience.Count())); #endif foreach (var audienceMember in audience) { audienceMember.needs.mood.thoughts.memories.TryGainMemory(thought); } }
private static void Prefix(Pawn ___pawn, ref float amount, JoyKindDef joyKind) { if (___pawn.InspirationDef == VSIE_DefOf.VSIE_Party_Frenzy && amount > 0) { amount *= 2f; } }
public static void Notify_CaravanMemberIngestedFood(Pawn p, ThingDef foodDef) { if (p.Dead || p.needs.joy == null) { return; } if (foodDef.ingestible.nutrition <= 0f) { return; } bool flag = false; List <Pawn> pawnsListForReading = p.GetCaravan().PawnsListForReading; for (int i = 0; i < pawnsListForReading.Count; i++) { if (pawnsListForReading[i] != p && pawnsListForReading[i].RaceProps.Humanlike && !pawnsListForReading[i].Downed && !pawnsListForReading[i].InMentalState) { if (p.IsPrisoner == pawnsListForReading[i].IsPrisoner) { flag = true; break; } } } JoyKindDef joyKind = (!flag) ? JoyKindDefOf.Meditative : Rand.Element <JoyKindDef>(JoyKindDefOf.Meditative, JoyKindDefOf.Social); p.needs.joy.GainJoy(0.5f, joyKind); }
public float Ingested(Pawn ingester, float nutritionWanted) { if (this.Destroyed) { Log.Error(ingester + " ingested destroyed thing " + this); return(0f); } if (!this.IngestibleNow) { Log.Error(ingester + " ingested IngestibleNow=false thing " + this); return(0f); } ingester.mindState.lastIngestTick = Find.TickManager.TicksGame; if (this.def.ingestible.outcomeDoers != null) { for (int i = 0; i < this.def.ingestible.outcomeDoers.Count; i++) { this.def.ingestible.outcomeDoers[i].DoIngestionOutcome(ingester, this); } } if (ingester.needs.mood != null) { List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(ingester, this, this.def); for (int j = 0; j < list.Count; j++) { ingester.needs.mood.thoughts.memories.TryGainMemory(list[j], null); } } if (ingester.IsColonist && FoodUtility.IsHumanlikeMeatOrHumanlikeCorpse(this)) { TaleRecorder.RecordTale(TaleDefOf.AteRawHumanlikeMeat, ingester); } int num = default(int); float result = default(float); this.IngestedCalculateAmounts(ingester, nutritionWanted, out num, out result); if (!ingester.Dead && ingester.needs.joy != null && Mathf.Abs(this.def.ingestible.joy) > 9.9999997473787516E-05 && num > 0) { JoyKindDef joyKind = (this.def.ingestible.joyKind == null) ? JoyKindDefOf.Gluttonous : this.def.ingestible.joyKind; ingester.needs.joy.GainJoy((float)num * this.def.ingestible.joy, joyKind); } if (ingester.IsCaravanMember()) { CaravanPawnsNeedsUtility.Notify_CaravanMemberIngestedFood(ingester, this.def); } if (num > 0) { if (num == this.stackCount) { this.Destroy(DestroyMode.Vanish); } else { this.SplitOff(num); } } this.PostIngested(ingester); return(result); }
protected override IEnumerable <Toil> MakeNewToils() { // TargetIndex.A is the window glower // TargetIndex.B is the window Building_Window window = TargetB.Thing as Building_Window; // Set fail conditions this.FailOnDespawnedOrNull(TargetIndex.A); this.FailOnDestroyedOrNull(TargetIndex.B); // Reserve the window glower yield return(Toils_Reserve.Reserve(TargetIndex.A)); // Go to the window yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell)); // Look out the window Toil low = new Toil(); JoyKindDef joyKind = LocalDefOf.WIN_LookOutWindow.joyKind; low.socialMode = RandomSocialMode.Normal; low.initAction = () => { low.handlingFacing = true; }; low.tickAction = () => { base.WatchTickAction(); pawn.needs.joy.GainJoy(Mathf.Max(window.WindowViewBeauty, 0.1f) * 0.000576f, joyKind); pawn.rotationTracker.FaceCell(TargetB.Cell); }; low.defaultCompleteMode = ToilCompleteMode.Delay; low.defaultDuration = job.def.joyDuration; low.AddFinishAction(() => { // Create the basic memory Thought_Memory thought_Memory = (Thought_Memory)ThoughtMaker.MakeThought(LocalDefOf.WIN_LookedOutWindowRegular); // Create a temp list of thoughts the pawn has List <Thought> tmpThoughts = new List <Thought>();; pawn.needs.mood.thoughts.GetAllMoodThoughts(tmpThoughts); // Scan through the thoughts for (int t = 0; t < tmpThoughts.Count; t++) { // If the pawn has cabin fever, change the memory if (tmpThoughts[t].def.defName == "CabinFever") { thought_Memory = (Thought_Memory)ThoughtMaker.MakeThought(LocalDefOf.WIN_LookedOutWindowCabinFever); // If the pawn has serious cabin fever, give a better memory if (tmpThoughts[t].CurStageIndex == 1) { thought_Memory.moodPowerFactor = 1.5f; } } } // Try to add the memory pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory); }); yield return(low); }
internal static void GainJoy_Patch(Need_Joy __instance, JoyKindDef joyKind, Pawn ___pawn) { if (joyKind == JoyKindDefOf.Social && ___pawn.ageTracker.CurLifeStageIndex <= AgeStage.Toddler) { // Unlike NeedJoy.GainJoy, Notify_JoyGained does not check that amount > 0 // We can abuse this to keep babies' tolerance for social joy at zero. __instance.tolerances.Notify_JoyGained(__instance.tolerances[joyKind] * 0.65f * -1, JoyKindDefOf.Social); } }
public float Ingested(Pawn ingester, float nutritionWanted) { if (Destroyed) { Log.Error(ingester + " ingested destroyed thing " + this); return(0f); } if (!IngestibleNow) { Log.Error(ingester + " ingested IngestibleNow=false thing " + this); return(0f); } ingester.mindState.lastIngestTick = Find.TickManager.TicksGame; if (def.ingestible.outcomeDoers != null) { for (int i = 0; i < def.ingestible.outcomeDoers.Count; i++) { def.ingestible.outcomeDoers[i].DoIngestionOutcome(ingester, this); } } if (ingester.needs.mood != null) { List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(ingester, this, def); for (int j = 0; j < list.Count; j++) { ingester.needs.mood.thoughts.memories.TryGainMemory(list[j]); } } if (ingester.IsColonist && FoodUtility.IsHumanlikeMeatOrHumanlikeCorpse(this)) { TaleRecorder.RecordTale(TaleDefOf.AteRawHumanlikeMeat, ingester); } IngestedCalculateAmounts(ingester, nutritionWanted, out int numTaken, out float nutritionIngested); if (!ingester.Dead && ingester.needs.joy != null && Mathf.Abs(def.ingestible.joy) > 0.0001f && numTaken > 0) { JoyKindDef joyKind = (def.ingestible.joyKind == null) ? JoyKindDefOf.Gluttonous : def.ingestible.joyKind; ingester.needs.joy.GainJoy((float)numTaken * def.ingestible.joy, joyKind); } if (ingester.RaceProps.Humanlike && Rand.Chance(this.GetStatValue(StatDefOf.FoodPoisonChanceFixedHuman) * Find.Storyteller.difficulty.foodPoisonChanceFactor)) { FoodUtility.AddFoodPoisoningHediff(ingester, this, FoodPoisonCause.DangerousFoodType); } if (numTaken > 0) { if (numTaken == stackCount) { Destroy(); } else { SplitOff(numTaken); } } PostIngested(ingester); return(nutritionIngested); }
public static void Notify_CaravanMemberIngestedFood(Pawn p, float nutritionIngested) { if (!p.Dead && p.needs.joy != null) { if (nutritionIngested > 0f) { Pawn pawn = BestCaravanPawnUtility.FindBestEntertainingPawnFor(p.GetCaravan(), p); JoyKindDef joyKind = (pawn == null) ? JoyKindDefOf.Meditative : Rand.Element <JoyKindDef>(JoyKindDefOf.Meditative, JoyKindDefOf.Social); float amount = 0.2f * Mathf.Min(nutritionIngested / p.needs.food.MaxLevel, 1f); p.needs.joy.GainJoy(amount, joyKind); } } }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDespawnedNullOrForbidden(TargetIndex.A); this.FailOnNotCasualInterruptible(TargetIndex.A); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch)); yield return(Toils_Interpersonal.WaitToBeAbleToInteract(pawn)); Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).socialMode = RandomSocialMode.Off; Toils_General.WaitWith(TargetIndex.A, TalkDuration, useProgressBar: false, maintainPosture: true).socialMode = RandomSocialMode.Off; yield return(Toils_General.Do(delegate { Pawn recipient = (Pawn)pawn.CurJob.targetA.Thing; if (pawn.def == InternalDefOf.GR_Mancat) { pawn.interactions.TryInteractWith(recipient, InternalDefOf.GR_UwUTalkingToHumans); if (Rand.Chance(0.1f)) { if (recipient.needs?.mood?.thoughts?.memories?.GetFirstMemoryOfDef(InternalDefOf.GR_Uwuchat) == null) { recipient.needs?.mood?.thoughts?.memories?.TryGainMemory(InternalDefOf.GR_DisgustingUwuchat, pawn); } } else { if (recipient.needs?.mood?.thoughts?.memories?.GetFirstMemoryOfDef(InternalDefOf.GR_DisgustingUwuchat) == null) { recipient.needs?.mood?.thoughts?.memories?.TryGainMemory(InternalDefOf.GR_Uwuchat); } if (!recipient.Dead && recipient.needs.joy != null) { JoyKindDef joyKind = JoyKindDefOf.Social; recipient.needs.joy.GainJoy(0.15f, joyKind); } } } else { pawn.interactions.TryInteractWith(recipient, InternalDefOf.GR_TalkingToHumans); if (!recipient.Dead && recipient.needs.joy != null) { JoyKindDef joyKind = JoyKindDefOf.Social; recipient.needs.joy.GainJoy(0.1f, joyKind); } } })); }
public static void Notify_CaravanMemberIngestedFood(Pawn p, ThingDef foodDef) { if (!p.Dead && p.needs.joy != null && !(foodDef.ingestible.nutrition <= 0.0)) { bool flag = false; List <Pawn> pawnsListForReading = p.GetCaravan().PawnsListForReading; int num = 0; while (num < pawnsListForReading.Count) { if (pawnsListForReading[num] == p || !pawnsListForReading[num].RaceProps.Humanlike || pawnsListForReading[num].Downed || pawnsListForReading[num].InMentalState || p.IsPrisoner != pawnsListForReading[num].IsPrisoner) { num++; continue; } flag = true; break; } JoyKindDef joyKind = (!flag) ? JoyKindDefOf.Meditative : Rand.Element(JoyKindDefOf.Meditative, JoyKindDefOf.Social); p.needs.joy.GainJoy(0.5f, joyKind); } }
public float Ingested(Pawn ingester, float nutritionWanted) { if (Destroyed) { Log.Error(string.Concat(ingester, " ingested destroyed thing ", this)); return(0f); } if (!IngestibleNow) { Log.Error(string.Concat(ingester, " ingested IngestibleNow=false thing ", this)); return(0f); } ingester.mindState.lastIngestTick = Find.TickManager.TicksGame; if (ingester.needs.mood != null) { List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(ingester, this, def); for (int i = 0; i < list.Count; i++) { ingester.needs.mood.thoughts.memories.TryGainMemory(list[i]); } } if (ingester.needs.drugsDesire != null) { ingester.needs.drugsDesire.Notify_IngestedDrug(this); } if (ingester.IsColonist && FoodUtility.IsHumanlikeMeatOrHumanlikeCorpse(this)) { TaleRecorder.RecordTale(TaleDefOf.AteRawHumanlikeMeat, ingester); } IngestedCalculateAmounts(ingester, nutritionWanted, out var numTaken, out var nutritionIngested); if (!ingester.Dead && ingester.needs.joy != null && Mathf.Abs(def.ingestible.joy) > 0.0001f && numTaken > 0) { JoyKindDef joyKind = ((def.ingestible.joyKind != null) ? def.ingestible.joyKind : JoyKindDefOf.Gluttonous); ingester.needs.joy.GainJoy((float)numTaken * def.ingestible.joy, joyKind); } if (ingester.RaceProps.Humanlike && Rand.Chance(this.GetStatValue(StatDefOf.FoodPoisonChanceFixedHuman) * FoodUtility.GetFoodPoisonChanceFactor(ingester))) { FoodUtility.AddFoodPoisoningHediff(ingester, this, FoodPoisonCause.DangerousFoodType); } bool flag = false; if (numTaken > 0) { if (stackCount == 0) { Log.Error(string.Concat(this, " stack count is 0.")); } if (numTaken == stackCount) { flag = true; } else { SplitOff(numTaken); } } PrePostIngested(ingester); if (flag) { ingester.carryTracker.innerContainer.Remove(this); } if (def.ingestible.outcomeDoers != null) { for (int j = 0; j < def.ingestible.outcomeDoers.Count; j++) { def.ingestible.outcomeDoers[j].DoIngestionOutcome(ingester, this); } } if (flag) { Destroy(); } PostIngested(ingester); return(nutritionIngested); }
public static float Ingested(this Thing thing, Pawn ingester, float nutritionWanted, BodyPartRecord targetPart) { if (thing.Destroyed) { Log.Error(ingester + " ingested destroyed thing " + thing); return(0f); } if (!thing.IngestibleNow) { Log.Error(ingester + " ingested IngestibleNow=false thing " + thing); return(0f); } Corpse corpse = thing as Corpse; if (corpse == null) { Log.Error(ingester + " ingested NonCorpse thing " + thing); return(0f); } ingester.mindState.lastIngestTick = Find.TickManager.TicksGame; if (ingester.needs.mood != null) { List <FoodUtility.ThoughtFromIngesting> list = FoodUtility.ThoughtsFromIngesting(ingester, thing, thing.def); for (int i = 0; i < list.Count; i++) { ingester.needs.mood.thoughts.memories.TryGainMemory(list[i].thought, null); } } if (ingester.needs.drugsDesire != null) { ingester.needs.drugsDesire.Notify_IngestedDrug(thing); } if (ingester.IsColonist && FoodUtility.IsHumanlikeCorpseOrHumanlikeMeat(thing, thing.def)) { TaleRecorder.RecordTale(TaleDefOf.AteRawHumanlikeMeat, new object[] { ingester }); } corpse.IngestedCalculateAmounts(ingester, targetPart, out int num, out float result); /* * MethodInfo dynMethod = thing.GetType().GetMethod("IngestedCalculateAmounts", * BindingFlags.NonPublic | BindingFlags.Instance); * object[] parameters = new object[] { ingester, nutritionWanted, null, null }; * dynMethod.Invoke(thing, parameters); * // Log.Message(thing+" eaten by "+ingester+" nutritionWanted: "+ nutritionWanted + " num: " + parameters[2] + " result: " + parameters[3]); * num = (int)parameters[2]; * result = (float)parameters[3]; * // thing.IngestedCalculateAmounts(ingester, nutritionWanted, out num, out result); */ if (!ingester.Dead && ingester.needs.joy != null && Mathf.Abs(thing.def.ingestible.joy) > 0.0001f && num > 0) { JoyKindDef joyKind = (thing.def.ingestible.joyKind != null) ? thing.def.ingestible.joyKind : JoyKindDefOf.Gluttonous; ingester.needs.joy.GainJoy((float)num * thing.def.ingestible.joy, joyKind); } if (ingester.RaceProps.Humanlike && Rand.Chance(thing.GetStatValue(StatDefOf.FoodPoisonChanceFixedHuman, true) * FoodUtility.GetFoodPoisonChanceFactor(ingester))) { FoodUtility.AddFoodPoisoningHediff(ingester, thing, FoodPoisonCause.DangerousFoodType); } bool flag = false; if (num > 0) { if (thing.stackCount == 0) { Log.Error(thing + " stack count is 0."); } if (num == thing.stackCount) { flag = true; } else { thing.SplitOff(num); } } MethodInfo dynMethod2 = thing.GetType().GetMethod("PrePostIngested", BindingFlags.NonPublic | BindingFlags.Instance); dynMethod2.Invoke(thing, new object[] { ingester }); // thing.PrePostIngested(ingester); if (flag) { ingester.carryTracker.innerContainer.Remove(thing); } if (thing.def.ingestible.outcomeDoers != null) { for (int j = 0; j < thing.def.ingestible.outcomeDoers.Count; j++) { thing.def.ingestible.outcomeDoers[j].DoIngestionOutcome(ingester, thing); } } if (flag) { thing.Destroy(DestroyMode.Vanish); } MethodInfo dynMethod3 = thing.GetType().GetMethod("PostIngested", BindingFlags.NonPublic | BindingFlags.Instance); dynMethod3.Invoke(thing, new object[] { ingester }); // thing.PostIngested(ingester); return(result); }
internal float <> m__0(JoyKindDef x) { return(1f - Mathf.Clamp01(this.pawn.needs.joy.tolerances[x])); }