private void TrySatisfyPawnNeeds(Pawn pawn) { if (pawn.Dead) { return; } List <Need> allNeeds = pawn.needs.AllNeeds; for (int i = 0; i < allNeeds.Count; i++) { Need need = allNeeds[i]; Need_Rest need_Rest = need as Need_Rest; Need_Food need_Food = need as Need_Food; Need_Chemical need_Chemical = need as Need_Chemical; Need_Joy need_Joy = need as Need_Joy; if (need_Rest != null) { TrySatisfyRestNeed(pawn, need_Rest); } else if (need_Food != null) { TrySatisfyFoodNeed(pawn, need_Food); } else if (need_Chemical != null) { TrySatisfyChemicalNeed(pawn, need_Chemical); } else if (need_Joy != null) { TrySatisfyJoyNeed(pawn, need_Joy); } } }
protected override Job TryGiveJob(Pawn pawn) { if (pawn != null && pawn.Map != null && pawn.health != null && pawn.health.hediffSet != null && pawn.health.hediffSet.HasHediff(TorannMagicDefOf.TM_ChiHD) && !pawn.Drafted) { if (pawn.InBed() || HealthAIUtility.ShouldSeekMedicalRest(pawn) || !(pawn.GetPosture() == PawnPosture.Standing)) { return(null); } Need_Joy curJoy = pawn.needs.joy; if (curJoy == null) { return(null); } if (curJoy.CurLevel >= .8f) { return(null); } CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>(); if (comp != null) { MightPower mightPower = comp.MightData.MightPowersM.FirstOrDefault <MightPower>((MightPower x) => x.abilityDef == TorannMagicDefOf.TM_Meditate); if (mightPower == null) { return(null); } if (!mightPower.AutoCast) { return(null); } Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_ChiHD); PawnAbility ability = pawn.GetComp <CompAbilityUserMight>().AbilityData.Powers.FirstOrDefault((PawnAbility x) => x.Def == TorannMagicDefOf.TM_Meditate); if (ability.CooldownTicksLeft > 0 || hediff.Severity >= 70) { return(null); } Building_Bed building_Bed = pawn.ownership.OwnedBed; if (building_Bed != null) { if (building_Bed.GetRoom() != null && !building_Bed.GetRoom().PsychologicallyOutdoors) { List <IntVec3> roomCells = building_Bed.GetRoom().Cells.ToList(); for (int i = 0; i < roomCells.Count; i++) { if (roomCells[i].IsValid && roomCells[i].Walkable(pawn.Map) && roomCells[i].GetFirstBuilding(pawn.Map) == null) { return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, roomCells[i])); } } } } return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, pawn.Position)); } } return(null); }
private static void TrySatisfyPawnNeeds(Pawn pawn, Caravan caravan) { if (!pawn.Dead) { List <Need> allNeeds = pawn.needs.AllNeeds; for (int i = 0; i < allNeeds.Count; i++) { Need need = allNeeds[i]; Need_Rest need_Rest = need as Need_Rest; Need_Food need_Food = need as Need_Food; Need_Chemical need_Chemical = need as Need_Chemical; Need_Joy need_Joy = need as Need_Joy; if (need_Rest != null) { CaravanPawnsNeedsUtility.TrySatisfyRestNeed(pawn, need_Rest, caravan); } else if (need_Food != null) { CaravanPawnsNeedsUtility.TrySatisfyFoodNeed(pawn, need_Food, caravan); } else if (need_Chemical != null) { CaravanPawnsNeedsUtility.TrySatisfyChemicalNeed(pawn, need_Chemical, caravan); } else if (need_Joy != null) { CaravanPawnsNeedsUtility.TrySatisfyJoyNeed(pawn, need_Joy, caravan); } } } }
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); } }
private static void TrySatisfyJoyNeed(Pawn pawn, Need_Joy joy, Caravan caravan) { float currentJoyGainPerTick = CaravanPawnsNeedsUtility.GetCurrentJoyGainPerTick(pawn, caravan); if (currentJoyGainPerTick > 0f) { joy.GainJoy(currentJoyGainPerTick, JoyKindDefOf.Social); } }
private void TrySatisfyJoyNeed(Pawn pawn, Need_Joy joy) { if (pawn.IsHashIntervalTick(1250)) { float currentJoyGainPerTick = GetCurrentJoyGainPerTick(pawn); if (!(currentJoyGainPerTick <= 0f)) { currentJoyGainPerTick *= 1250f; tmpAvailableJoyKinds.Clear(); GetAvailableJoyKindsFor(pawn, tmpAvailableJoyKinds); if (tmpAvailableJoyKinds.TryRandomElementByWeight((JoyKindDef x) => 1f - Mathf.Clamp01(pawn.needs.joy.tolerances[x]), out JoyKindDef result)) { joy.GainJoy(currentJoyGainPerTick, result); tmpAvailableJoyKinds.Clear(); } } } }
private void TrySatisfyJoyNeed(Pawn pawn, Need_Joy joy) { if (pawn.IsHashIntervalTick(1250)) { float num = this.GetCurrentJoyGainPerTick(pawn); if (num <= 0f) { return; } num *= 1250f; Caravan_NeedsTracker.tmpAvailableJoyKinds.Clear(); this.GetAvailableJoyKindsFor(pawn, Caravan_NeedsTracker.tmpAvailableJoyKinds); JoyKindDef joyKind; if (!Caravan_NeedsTracker.tmpAvailableJoyKinds.TryRandomElementByWeight((JoyKindDef x) => 1f - Mathf.Clamp01(pawn.needs.joy.tolerances[x]), out joyKind)) { return; } joy.GainJoy(num, joyKind); Caravan_NeedsTracker.tmpAvailableJoyKinds.Clear(); } }
private void TrySatisfyPawnNeeds(Pawn pawn) { if (pawn.Dead) { return; } List <Need> allNeeds = pawn.needs.AllNeeds; for (int i = 0; i < allNeeds.Count; i++) { Need need = allNeeds[i]; Need_Rest need_Rest = need as Need_Rest; Need_Food need_Food = need as Need_Food; Need_Chemical need_Chemical = need as Need_Chemical; Need_Joy need_Joy = need as Need_Joy; if (need_Rest != null) { TrySatisfyRestNeed(pawn, need_Rest); } else if (need_Food != null) { TrySatisfyFoodNeed(pawn, need_Food); } else if (need_Chemical != null) { TrySatisfyChemicalNeed(pawn, need_Chemical); } else if (need_Joy != null) { TrySatisfyJoyNeed(pawn, need_Joy); } } Pawn_PsychicEntropyTracker psychicEntropy = pawn.psychicEntropy; if (psychicEntropy.Psylink != null) { TryGainPsyfocus(psychicEntropy); } }