internal void Notify_PawnKilled(DamageInfo?dinfo, Map mapBeforeDeath) { foreach (Pawn potentiallyRelatedPawn in this.PotentiallyRelatedPawns) { if (!potentiallyRelatedPawn.Dead && potentiallyRelatedPawn.needs.mood != null) { potentiallyRelatedPawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty(); } } this.RemoveMySpouseMarriageRelatedThoughts(); if (this.everSeenByPlayer && !PawnGenerator.IsBeingGenerated(this.pawn)) { if (this.pawn.RaceProps.Animal) { this.SendBondedAnimalDiedLetter(mapBeforeDeath); } else { this.AffectBondedAnimalsOnMyDeath(); } } if (this.relativeInvolvedInRescueQuest != null && !this.relativeInvolvedInRescueQuest.Dead && this.relativeInvolvedInRescueQuest.needs.mood != null) { Messages.Message("MessageFailedToRescueRelative".Translate(this.pawn.LabelShort, this.relativeInvolvedInRescueQuest.LabelShort), this.relativeInvolvedInRescueQuest, MessageTypeDefOf.PawnDeath); this.relativeInvolvedInRescueQuest.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.FailedToRescueRelative, this.pawn); } this.relativeInvolvedInRescueQuest = null; }
public static void TryGiveThoughts(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind) { try { if (PawnGenerator.IsBeingGenerated(victim) || Current.ProgramState != ProgramState.Playing) { return; } GetThoughts(victim, dinfo, thoughtsKind, tmpIndividualThoughtsToAdd, tmpAllColonistsThoughts); for (int i = 0; i < tmpIndividualThoughtsToAdd.Count; i++) { tmpIndividualThoughtsToAdd[i].Add(); } if (tmpAllColonistsThoughts.Any()) { foreach (Pawn allMapsCaravansAndTravelingTransportPods_Alive_Colonist in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_Colonists) { if (allMapsCaravansAndTravelingTransportPods_Alive_Colonist != victim) { for (int j = 0; j < tmpAllColonistsThoughts.Count; j++) { tmpAllColonistsThoughts[j].Add(allMapsCaravansAndTravelingTransportPods_Alive_Colonist); } } } } tmpIndividualThoughtsToAdd.Clear(); tmpAllColonistsThoughts.Clear(); } catch (Exception arg) { Log.Error("Could not give thoughts: " + arg); } }
public void Notify_MemberDied(Pawn member, DamageInfo?dinfo, bool wasWorldPawn, Map map) { if (IsPlayer) { return; } if (!wasWorldPawn && !PawnGenerator.IsBeingGenerated(member) && Current.ProgramState == ProgramState.Playing && map != null && map.IsPlayerHome && !this.HostileTo(OfPlayer)) { if (dinfo.HasValue && dinfo.Value.Category == DamageInfo.SourceCategory.Collapse) { bool canSendMessage = MessagesRepeatAvoider.MessageShowAllowed("FactionRelationAdjustmentCrushed-" + Name, 5f); TryAffectGoodwillWith(OfPlayer, member.RaceProps.Humanlike ? (-25) : (-15), canSendMessage, canSendHostilityLetter: true, "GoodwillChangedReason_PawnCrushed".Translate(member.LabelShort, member), new TargetInfo(member.Position, map)); } else if (dinfo.HasValue && (dinfo.Value.Instigator == null || dinfo.Value.Instigator.Faction == null)) { Pawn pawn = dinfo.Value.Instigator as Pawn; if (pawn == null || !pawn.RaceProps.Animal || pawn.mindState.mentalStateHandler.CurStateDef != MentalStateDefOf.ManhunterPermanent) { TryAffectGoodwillWith(OfPlayer, member.RaceProps.Humanlike ? (-5) : (-3), canSendMessage: true, canSendHostilityLetter: true, "GoodwillChangedReason_PawnDied".Translate(member.LabelShort, member), member); } } } if (member == leader) { Notify_LeaderDied(); } }
public static bool ShouldSendNotificationAbout(Pawn p) { if (Current.ProgramState != ProgramState.Playing) { return(false); } if (PawnGenerator.IsBeingGenerated(p)) { return(false); } if (p.IsWorldPawn() && (!p.IsCaravanMember() || !p.GetCaravan().IsPlayerControlled) && !PawnUtility.IsTravelingInTransportPodWorldObject(p) && p.Corpse.DestroyedOrNull()) { return(false); } if (p.Faction != Faction.OfPlayer) { if (p.HostFaction != Faction.OfPlayer) { return(false); } if (p.RaceProps.Humanlike && p.guest.Released && !p.Downed && !p.InBed()) { return(false); } if (p.CurJob != null && p.CurJob.exitMapOnArrival && !PrisonBreakUtility.IsPrisonBreaking(p)) { return(false); } } return(true); }
public void Notify_MemberDied(Pawn member, DamageInfo?dinfo, bool wasWorldPawn, Map map) { if (!this.IsPlayer) { if (!wasWorldPawn && !PawnGenerator.IsBeingGenerated(member) && Current.ProgramState == ProgramState.Playing && map != null && map.IsPlayerHome && !this.HostileTo(Faction.OfPlayer)) { if (dinfo.HasValue && dinfo.Value.Category == DamageInfo.SourceCategory.Collapse) { float num = (float)(member.RaceProps.body.corePart.def.GetMaxHealth(member) * 1.2999999523162842 * 0.5 * -1.0); if (this.AffectGoodwillWith(Faction.OfPlayer, num) && MessagesRepeatAvoider.MessageShowAllowed("FactionRelationAdjustmentCrushed-" + this.Name, 5f)) { Messages.Message("MessageFactionPawnCrushed".Translate(this.Name, Mathf.RoundToInt(num)), member, MessageTypeDefOf.NegativeEvent); } } else if (dinfo.HasValue && (dinfo.Value.Instigator == null || dinfo.Value.Instigator.Faction == null)) { float num2 = (float)(member.RaceProps.body.corePart.def.GetMaxHealth(member) * 1.2999999523162842 * 0.10000000149011612 * -1.0); if (this.AffectGoodwillWith(Faction.OfPlayer, num2)) { Messages.Message("MessageFactionPawnLost".Translate(this.Name, member.NameStringShort, Mathf.RoundToInt(num2)), member, MessageTypeDefOf.NegativeEvent); } } } if (member == this.leader) { this.Notify_LeaderDied(); } } }
/// <summary> Notify this faction that one of their pawns has been transformed. </summary> public static void Notify_MemberTransformed([NotNull] this Faction faction, [NotNull] Pawn member, [NotNull] Pawn animal, bool wasWorldPawn, [CanBeNull] Map map) { if (faction == null) { throw new ArgumentNullException(nameof(faction)); } if (member == null) { throw new ArgumentNullException(nameof(member)); } if (animal == null) { throw new ArgumentNullException(nameof(animal)); } if (faction.IsPlayer) { return; } if (!wasWorldPawn && !PawnGenerator.IsBeingGenerated(member) && (Current.ProgramState == ProgramState.Playing && map != null) && (map.IsPlayerHome && !faction.HostileTo(Faction.OfPlayer))) //check that mirrors that in Faction Notify_MemberDied { var reason = GOODWILL_LABEL.Translate(member.LabelShort.Named(MEMBER_LABEL) , animal.def.LabelCap.Named(ANIMAL_SPECIES) ); // the first arg will be the former pawn, the second the animal faction.TryAffectGoodwillWith(Faction.OfPlayer, TRANSFORMED_RELATIONSHIP_OFFSET, reason: reason); } if (member == faction.leader) { Notify_LeaderTransformed(faction, animal); } }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { bool isViolation = !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 }); if (isViolation) { base.ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(this.recipe.addsHediff.label)); } } foreach (Hediff_ModuleAdded module in from x in pawn.health.hediffSet.GetHediffs <Hediff_ModuleAdded>() where x.Part == part select x) { // spawn thing if possible if (module.def.spawnThingOnRemoved != null && pawn?.Map != null) { GenPlace.TryPlaceThing(ThingMaker.MakeThing(module.def.spawnThingOnRemoved), pawn.Position, pawn.Map, ThingPlaceMode.Near); } // remove hediff pawn.health.RemoveHediff(module); } }
/// <summary>called after this instance is added to the pawn.</summary> /// <param name="dinfo">The dinfo.</param> public override void PostAdd(DamageInfo?dinfo) // After the hediff has been applied. { base.PostAdd(dinfo); // Do the inherited method. if (PawnGenerator.IsBeingGenerated(pawn) || !pawn.Spawned) //if the pawn is still being generated do not update graphics until it's done { _waitingForUpdate = true; return; } UpdatePawnInfo(); foreach (Hediff_AddedMutation otherMutation in pawn.health.hediffSet.hediffs.OfType <Hediff_AddedMutation>()) { try { if (Blocks((MutationDef)otherMutation.def, otherMutation.Part)) { otherMutation.shouldRemove = true; //don't actually remove the hediffs, just mark them for removal } } catch (InvalidCastException e) //just pretty up the error message a bit and continue on { Log.Error($"could not cast {otherMutation.def.defName} of type {otherMutation.def.GetType().Name} to {nameof(MutationDef)}!\n{e}"); } } }
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); }
public void Notify_MemberDied(Pawn member, DamageInfo?dinfo, bool wasWorldPawn, Map map) { if (this.IsPlayer) { return; } if (!wasWorldPawn && !PawnGenerator.IsBeingGenerated(member) && Current.ProgramState == ProgramState.Playing && map != null && map.IsPlayerHome && !this.HostileTo(Faction.OfPlayer)) { if (dinfo.HasValue && dinfo.Value.Category == DamageInfo.SourceCategory.Collapse) { bool flag = MessagesRepeatAvoider.MessageShowAllowed("FactionRelationAdjustmentCrushed-" + this.Name, 5f); Faction ofPlayer = Faction.OfPlayer; int goodwillChange = (!member.RaceProps.Humanlike) ? -15 : -25; bool canSendMessage = flag; string reason = "GoodwillChangedReason_PawnCrushed".Translate(member.LabelShort, member); this.TryAffectGoodwillWith(ofPlayer, goodwillChange, canSendMessage, true, reason, new GlobalTargetInfo?(new TargetInfo(member.Position, map, false))); } else if (dinfo.HasValue && (dinfo.Value.Instigator == null || dinfo.Value.Instigator.Faction == null)) { Faction ofPlayer = Faction.OfPlayer; int goodwillChange = (!member.RaceProps.Humanlike) ? -3 : -5; string reason = "GoodwillChangedReason_PawnDied".Translate(member.LabelShort, member); GlobalTargetInfo?lookTarget = new GlobalTargetInfo?(member); this.TryAffectGoodwillWith(ofPlayer, goodwillChange, true, true, reason, lookTarget); } } if (member == this.leader) { this.Notify_LeaderDied(); } }
static bool Prefix(ref Faction __instance, Pawn member, DamageInfo?dinfo, bool wasWorldPawn, Map map) { if (member.Faction.def.defName == "PColony" && !wasWorldPawn && !PawnGenerator.IsBeingGenerated(member) && map != null && map.IsPlayerHome && !__instance.HostileTo(Faction.OfPlayer)) { FactionFC faction = Find.World.GetComponent <FactionFC>(); if (!faction.hasPolicy(FCPolicyDefOf.pacifist) && dinfo != null) { if (dinfo.Value.Category == DamageInfo.SourceCategory.Collapse) { faction.GainUnrestForReason(new Message("DeathOfFactionPawn".Translate(), MessageTypeDefOf.PawnDeath), 5d); faction.GainHappiness(-5d); } else if (dinfo.Value.Instigator?.Faction == Find.FactionManager.OfPlayer) { faction.GainUnrestForReason(new Message("DeathOfFactionPawn".Translate(), MessageTypeDefOf.PawnDeath), 5d); faction.GainHappiness(-5d); } } //return false to stop from continuing method return(false); } return(true); }
public static void TryGiveThoughts(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind) { try { if (!PawnGenerator.IsBeingGenerated(victim) && Current.ProgramState == ProgramState.Playing) { PawnDiedOrDownedThoughtsUtility.GetThoughts(victim, dinfo, thoughtsKind, PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd, PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts); for (int i = 0; i < PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd.Count; i++) { PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd[i].Add(); } if (PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts.Any()) { foreach (Pawn allMapsCaravansAndTravelingTransportPods_Colonist in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Colonists) { if (allMapsCaravansAndTravelingTransportPods_Colonist != victim) { for (int j = 0; j < PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts.Count; j++) { ThoughtDef def = PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts[j]; allMapsCaravansAndTravelingTransportPods_Colonist.needs.mood.thoughts.memories.TryGainMemory(def, null); } } } } PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd.Clear(); PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts.Clear(); } } catch (Exception arg) { Log.Error("Could not give thoughts: " + arg); } }
public void CheckAppendBondedAnimalDiedInfo(ref string letter, ref string label) { if (pawn.RaceProps.Animal && everSeenByPlayer && !PawnGenerator.IsBeingGenerated(pawn)) { Predicate <Pawn> isAffected = delegate(Pawn x) { if (x.Dead) { return(false); } if (x.RaceProps.Humanlike && x.story.traits.HasTrait(TraitDefOf.Psychopath)) { return(false); } return(true); }; int num = 0; for (int i = 0; i < directRelations.Count; i++) { if (directRelations[i].def == PawnRelationDefOf.Bond && isAffected(directRelations[i].otherPawn)) { num++; } } string text; switch (num) { case 0: return; case 1: { Pawn firstDirectRelationPawn = GetFirstDirectRelationPawn(PawnRelationDefOf.Bond, (Pawn x) => isAffected(x)); text = "LetterPartBondedAnimalDied".Translate(pawn.LabelDefinite(), firstDirectRelationPawn.LabelShort, pawn.Named("ANIMAL"), firstDirectRelationPawn.Named("HUMAN")).CapitalizeFirst(); break; } default: { StringBuilder stringBuilder = new StringBuilder(); for (int j = 0; j < directRelations.Count; j++) { if (directRelations[j].def == PawnRelationDefOf.Bond && isAffected(directRelations[j].otherPawn)) { stringBuilder.AppendLine(" - " + directRelations[j].otherPawn.LabelShort); } } text = "LetterPartBondedAnimalDiedMulti".Translate(stringBuilder.ToString().TrimEndNewlines()); break; } } label = label + " (" + "LetterLabelSuffixBondedAnimalDied".Translate() + ")"; if (!letter.NullOrEmpty()) { letter += "\n\n"; } letter += text; } }
/// <summary>called after this instance is removed from the pawn</summary> public override void PostRemoved() { base.PostRemoved(); if (!PawnGenerator.IsBeingGenerated(pawn)) { pawn.GetMutationTracker()?.NotifyMutationRemoved(this); } }
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; } } } } } }
/// <summary>called after this instance is added to the pawn.</summary> /// <param name="dinfo">The dinfo.</param> public override void PostAdd(DamageInfo?dinfo) // After the hediff has been applied. { base.PostAdd(dinfo); // Do the inherited method. if (PawnGenerator.IsBeingGenerated(pawn) || !pawn.Spawned) //if the pawn is still being generated do not update graphics until it's done { _waitingForUpdate = true; return; } UpdatePawnInfo(); }
public void CheckAppendBondedAnimalDiedInfo(ref string letter, ref string label) { if (!this.pawn.RaceProps.Animal || !this.everSeenByPlayer || PawnGenerator.IsBeingGenerated(this.pawn)) { return; } Predicate <Pawn> isAffected = (Pawn x) => !x.Dead && (!x.RaceProps.Humanlike || !x.story.traits.HasTrait(TraitDefOf.Psychopath)); int num = 0; for (int i = 0; i < this.directRelations.Count; i++) { if (this.directRelations[i].def == PawnRelationDefOf.Bond && isAffected(this.directRelations[i].otherPawn)) { num++; } } if (num == 0) { return; } string str; if (num == 1) { Pawn firstDirectRelationPawn = this.GetFirstDirectRelationPawn(PawnRelationDefOf.Bond, (Pawn x) => isAffected(x)); str = "LetterPartBondedAnimalDied".Translate(new object[] { this.pawn.LabelDefinite(), firstDirectRelationPawn.LabelShort }).CapitalizeFirst(); } else { StringBuilder stringBuilder = new StringBuilder(); for (int j = 0; j < this.directRelations.Count; j++) { if (this.directRelations[j].def == PawnRelationDefOf.Bond && isAffected(this.directRelations[j].otherPawn)) { stringBuilder.AppendLine(" - " + this.directRelations[j].otherPawn.LabelShort); } } str = "LetterPartBondedAnimalDiedMulti".Translate(new object[] { stringBuilder.ToString().TrimEndNewlines() }); } label = label + " (" + "LetterLabelSuffixBondedAnimalDied".Translate() + ")"; if (!letter.NullOrEmpty()) { letter += "\n\n"; } letter += str; }
/// <summary> /// Determines whether this pawn is loading or spawning. /// </summary> /// <param name="pawn">The pawn.</param> /// <returns> /// <c>true</c> if this pawn is loading or spawning ; otherwise, <c>false</c>. /// </returns> public static bool IsLoadingOrSpawning([NotNull] this Pawn pawn) { if (PawnGenerator.IsBeingGenerated(pawn)) { return(true); } if (pawn.health == null || pawn.mindState?.inspirationHandler == null || pawn.needs == null) { return(true); } return(false); }
public static void Notify_PawnKilled(Pawn_RelationsTracker __instance, DamageInfo?dinfo, Map mapBeforeDeath) { foreach (Pawn potentiallyRelatedPawn in __instance.PotentiallyRelatedPawns) { if (!potentiallyRelatedPawn.Dead && potentiallyRelatedPawn.needs.mood != null) { potentiallyRelatedPawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty(); } } RemoveMySpouseMarriageRelatedThoughts(__instance); if (__instance.everSeenByPlayer && !PawnGenerator.IsBeingGenerated(pawn(__instance)) && !pawn(__instance).RaceProps.Animal) { AffectBondedAnimalsOnMyDeath(__instance); } __instance.Notify_FailedRescueQuest(); }
internal void Notify_PawnKilled(DamageInfo?dinfo, Map mapBeforeDeath) { foreach (Pawn potentiallyRelatedPawn in PotentiallyRelatedPawns) { if (!potentiallyRelatedPawn.Dead && potentiallyRelatedPawn.needs.mood != null) { potentiallyRelatedPawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty(); } } RemoveMySpouseMarriageRelatedThoughts(); if (everSeenByPlayer && !PawnGenerator.IsBeingGenerated(pawn) && !pawn.RaceProps.Animal) { AffectBondedAnimalsOnMyDeath(); } Notify_FailedRescueQuest(); }
public static bool PreFix(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind) { try { if (!PawnGenerator.IsBeingGenerated(victim) && Current.ProgramState == ProgramState.Playing) { // This is the main redirection for our patches switch (thoughtsKind) { case PawnDiedOrDownedThoughtsKind.Downed: // There is potential here, simply wasted. return(false); case PawnDiedOrDownedThoughtsKind.Died: // Let's see if this works; I hope it does. // It works. // Refer to PostFix_Pawn_Kill // Handler_PawnDied.HandlePawnDied(victim, dinfo); return(false); case PawnDiedOrDownedThoughtsKind.BanishedToDie: Handler_PawnBanished.HandlePawnBanished(victim, true); return(false); case PawnDiedOrDownedThoughtsKind.Banished: Handler_PawnBanished.HandlePawnBanished(victim, false); return(false); case PawnDiedOrDownedThoughtsKind.Lost: // Refer to PostFix_Pawn_PreKidnapped return(false); default: // This shouldn't happen. You should check things again. throw new InvalidOperationException(); } } } catch (Exception arg) { Log.Error( "[V1024-DESYNC] Could not give thought, falling back to vanilla thought-giving procedures: " + arg); } return(true); }
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 override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { bool isViolation = !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 }); if (isViolation) { base.ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(this.recipe.addsHediff.label)); } } pawn.health.AddHediff(this.recipe.addsHediff, part, null, null); }
private string GetCriticalPawnReason(Pawn pawn) { if (pawn.Discarded) { return(null); } if (PawnUtility.EverBeenColonistOrTameAnimal(pawn) && pawn.RaceProps.Humanlike) { return("Colonist"); } if (PawnGenerator.IsBeingGenerated(pawn)) { return("Generating"); } if (PawnUtility.IsFactionLeader(pawn)) { return("FactionLeader"); } if (PawnUtility.IsKidnappedPawn(pawn)) { return("Kidnapped"); } if (pawn.IsCaravanMember()) { return("CaravanMember"); } if (PawnUtility.IsTravelingInTransportPodWorldObject(pawn)) { return("TransportPod"); } if (PawnUtility.ForSaleBySettlement(pawn)) { return("ForSale"); } if (Find.WorldPawns.ForcefullyKeptPawns.Contains(pawn)) { return("ForceKept"); } if (pawn.SpawnedOrAnyParentSpawned) { return("Spawned"); } if (!pawn.Corpse.DestroyedOrNull()) { return("CorpseExists"); } if (pawn.RaceProps.Humanlike && Current.ProgramState == ProgramState.Playing) { if (Find.PlayLog.AnyEntryConcerns(pawn)) { return("InPlayLog"); } if (Find.BattleLog.AnyEntryConcerns(pawn)) { return("InBattleLog"); } } if (Current.ProgramState == ProgramState.Playing && Find.TaleManager.AnyActiveTaleConcerns(pawn)) { return("InActiveTale"); } if (QuestUtility.IsReservedByQuestOrQuestBeingGenerated(pawn)) { return("ReservedByQuest"); } return(null); }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { // START VANILLA CODE (couldn't know if the surgery was successfull) bool partIsClean = MedicalRecipesUtility.IsClean(pawn, part); bool isViolation = !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); if (partIsClean && isViolation && part.def.spawnThingOnRemoved != null) { ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn); } if (isViolation) { base.ReportViolation(pawn, billDoer, pawn.FactionOrExtraHomeFaction, -70, "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(this.recipe.addsHediff.label)); } } 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); // END VANILLA CODE if (!ingredients.NullOrEmpty()) { // iterate over non null CompIncludedChildParts in ingredients foreach (CompIncludedChildParts compChildParts in from x in ingredients let comp = x.TryGetComp <CompIncludedChildParts>() // take the comp where comp?.IncludedParts != null select comp) { compChildParts.RecursiveInstallation(pawn, part); } } else { foreach (CompProperties_IncludedChildParts compProp in (this.recipe.fixedIngredientFilter?.AllowedThingDefs ?? Enumerable.Empty <ThingDef>()) .Select(td => td.GetCompProperties <CompProperties_IncludedChildParts>()) .Where(c => c != null)) { compProp.RecursiveDefInstallation(pawn, part); } } }
internal static void _GiveThoughtsForPawnDied(Pawn victim, DamageInfo?dinfo, Hediff hediff) { if (PawnGenerator.IsBeingGenerated(victim) || Current.ProgramState != ProgramState.MapPlaying) { return; } bool flag1 = dinfo.HasValue && dinfo.Value.Def == DamageDefOf.ExecutionCut || hediff != null && (hediff.def == HediffDefOf.Euthanasia || hediff.def == HediffDefOf.ShutDown); bool flag2 = victim.IsPrisonerOfColony && !PrisonBreakUtility.IsPrisonBreaking(victim) && !victim.InAggroMentalState; if (!victim.RaceProps.Humanlike) { return; } if (dinfo.HasValue && dinfo.Value.Def.externalViolence && dinfo.Value.Instigator != null) { Pawn pawn = dinfo.Value.Instigator as Pawn; if (pawn != null && !pawn.Dead && (pawn.needs.mood != null && pawn.story != null)) { pawn.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOf.KilledHumanlikeBloodlust, (Pawn)null); if (victim.Faction.HostileTo(pawn.Faction) && !flag1 && !flag2) { pawn.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.KilledHumanlikeEnemy, (Pawn)null); } } } List <Pawn> allPawnsSpawned = Find.MapPawns.AllPawnsSpawned; for (int index = 0; index < allPawnsSpawned.Count; ++index) { Pawn p = allPawnsSpawned[index]; if (p.needs.mood != null && !flag1 && (p.MentalStateDef != MentalStateDefOf.SocialFighting || ((MentalState_SocialFighting)p.MentalState).otherPawn != victim)) { if (victim.Spawned && (p.Position.InHorDistOf(victim.Position, 12f) && GenSight.LineOfSight(victim.Position, p.Position, false) && (p.Awake() && p.health.capacities.CapableOf(PawnCapacityDefOf.Sight)))) { if (!p.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !p.story.traits.HasTrait(TraitDefOf.Psychopath) && !p.story.traits.HasTrait(TraitDefOf.Bloodlust)) { if (((p.GetHashCode() ^ (GenDate.DayOfYear + GenDate.CurrentYear + (int)(GenDate.CurrentDayPercent * 5) * 60) * 391) % 1000) == 0) { p.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized)); p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.RecentlyDesensitized, (Pawn)null); } } if (p.Faction == victim.Faction) { p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOf.WitnessedDeathAlly, (Pawn)null); p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.WitnessedDeathAllyBleedingHeart, (Pawn)null); } else { p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOf.WitnessedDeathNonAlly, (Pawn)null); p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.WitnessedDeathNonAllyBleedingHeart, (Pawn)null); } if (p.relations.FamilyByBlood.Contains <Pawn>(victim)) { p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOf.WitnessedDeathFamily, (Pawn)null); } p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOf.WitnessedDeathBloodlust, (Pawn)null); } else if (victim.Faction == Faction.OfPlayer && victim.Faction == p.Faction && victim.HostFaction != p.Faction) { p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOf.KnowColonistDied, (Pawn)null); } if (flag2 && p.Faction == Faction.OfPlayer && !p.IsPrisoner) { p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOf.KnowPrisonerDiedInnocent, (Pawn)null); p.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.KnowPrisonerDiedInnocentBleedingHeart, (Pawn)null); } } } }
public void Notify_PawnKilled() { if (!PawnGenerator.IsBeingGenerated(pawn) && AllTitlesForReading.Count != 0) { bool flag = false; StringBuilder stringBuilder = new StringBuilder(); try { stringBuilder.AppendLine("LetterTitleInheritance_Base".Translate(pawn.Named("PAWN"))); stringBuilder.AppendLine(); foreach (RoyalTitle item in AllTitlesForReading) { if (item.def.canBeInherited) { if (pawn.IsFreeColonist && !pawn.IsQuestLodger()) { flag = true; } if (item.def.TryInherit(pawn, item.faction, out RoyalTitleInheritanceOutcome outcome)) { if (outcome.HeirHasTitle && !outcome.heirTitleHigher) { stringBuilder.AppendLine("LetterTitleInheritance_AsReplacement".Translate(pawn.Named("PAWN"), item.faction.Named("FACTION"), outcome.heir.Named("HEIR"), item.def.GetLabelFor(pawn).Named("TITLE"), outcome.heirCurrentTitle.GetLabelFor(outcome.heir).Named("REPLACEDTITLE")).CapitalizeFirst().Resolve()); stringBuilder.AppendLine(); } else if (outcome.heirTitleHigher) { stringBuilder.AppendLine("LetterTitleInheritance_NoEffectHigherTitle".Translate(pawn.Named("PAWN"), item.faction.Named("FACTION"), outcome.heir.Named("HEIR"), item.def.GetLabelFor(pawn).Named("TITLE"), outcome.heirCurrentTitle.GetLabelFor(outcome.heir).Named("HIGHERTITLE")).CapitalizeFirst().Resolve()); stringBuilder.AppendLine(); } else { stringBuilder.AppendLine("LetterTitleInheritance_WasInherited".Translate(pawn.Named("PAWN"), item.faction.Named("FACTION"), outcome.heir.Named("HEIR"), item.def.GetLabelFor(pawn).Named("TITLE")).CapitalizeFirst().Resolve()); stringBuilder.AppendLine(); } if (!outcome.heirTitleHigher) { RoyalTitle titleLocal = item; tmpInheritedTitles.Add(delegate { outcome.heir.royalty.SetTitle(titleLocal.faction, titleLocal.def, grantRewards: true, rewardsOnlyForNewestTitle: true); titleLocal.wasInherited = true; }); if (outcome.heir.IsFreeColonist && !outcome.heir.IsQuestLodger()) { flag = true; } } } else { stringBuilder.AppendLine("LetterTitleInheritance_NoHeirFound".Translate(pawn.Named("PAWN"), item.def.GetLabelFor(pawn).Named("TITLE"), item.faction.Named("FACTION")).CapitalizeFirst().Resolve()); } } } if (stringBuilder.Length > 0 && flag) { Find.LetterStack.ReceiveLetter("LetterTitleInheritance".Translate(), stringBuilder.ToString().TrimEndNewlines(), LetterDefOf.PositiveEvent); } foreach (Action tmpInheritedTitle in tmpInheritedTitles) { tmpInheritedTitle(); } } finally { tmpInheritedTitles.Clear(); } } }