public static void TryGiveThoughts(IEnumerable <Pawn> victims, PawnDiedOrDownedThoughtsKind thoughtsKind) { foreach (Pawn victim in victims) { PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(victim, null, thoughtsKind); } }
public static void BuildMoodThoughtsListString(IEnumerable <Pawn> victims, PawnDiedOrDownedThoughtsKind thoughtsKind, StringBuilder sb, string individualThoughtsHeader, string allColonistsThoughtsHeader, string victimLabelKey) { foreach (Pawn pawn in victims) { PawnDiedOrDownedThoughtsUtility.GetThoughts(pawn, null, thoughtsKind, PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd, PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts); if (PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd.Any <IndividualThoughtToAdd>() || PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts.Any <ThoughtDef>()) { if (sb.Length > 0) { sb.AppendLine(); sb.AppendLine(); } string text = pawn.KindLabel.CapitalizeFirst() + " " + pawn.LabelShort; if (victimLabelKey.NullOrEmpty()) { sb.Append(text + ":"); } else { sb.Append(victimLabelKey.Translate(new object[] { text })); } PawnDiedOrDownedThoughtsUtility.BuildMoodThoughtsListString(pawn, null, thoughtsKind, sb, individualThoughtsHeader, allColonistsThoughtsHeader); } } }
public static void Banish(Pawn pawn, int tile = -1) { if (pawn.Faction != Faction.OfPlayer && pawn.HostFaction != Faction.OfPlayer) { Log.Warning("Tried to banish " + pawn + " but he's neither a colonist, tame animal, nor prisoner."); } else { if (tile == -1) { tile = pawn.Tile; } bool flag = PawnBanishUtility.WouldBeLeftToDie(pawn, tile); PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(pawn, null, (PawnDiedOrDownedThoughtsKind)((!flag) ? 1 : 2)); Caravan caravan = pawn.GetCaravan(); if (caravan != null) { CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawn, caravan.PawnsListForReading, null); caravan.RemovePawn(pawn); if (flag) { if (Rand.Value < 0.800000011920929) { pawn.Kill(null, null); } else { PawnBanishUtility.HealIfPossible(pawn); } } if (pawn.guest != null) { pawn.guest.SetGuestStatus(null, false); } if (pawn.Faction == Faction.OfPlayer) { Faction newFaction = default(Faction); if (Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction(out newFaction, pawn.Faction != null && (int)pawn.Faction.def.techLevel >= 3, false, TechLevel.Undefined)) { pawn.SetFaction(newFaction, null); } else { pawn.SetFaction(Faction.OfSpacer, null); } } } else { if (pawn.guest != null) { pawn.guest.SetGuestStatus(null, false); } if (pawn.Faction == Faction.OfPlayer) { pawn.SetFaction(Faction.OfSpacer, null); } } } }
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 static void Banish(Pawn pawn, int tile = -1) { if (pawn.Faction != Faction.OfPlayer && pawn.HostFaction != Faction.OfPlayer) { Log.Warning(string.Concat("Tried to banish ", pawn, " but he's neither a colonist, tame animal, nor prisoner.")); return; } if (tile == -1) { tile = pawn.Tile; } bool flag = WouldBeLeftToDie(pawn, tile); if (!pawn.IsQuestLodger()) { PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(pawn, null, (!flag) ? PawnDiedOrDownedThoughtsKind.Banished : PawnDiedOrDownedThoughtsKind.BanishedToDie); } Caravan caravan = pawn.GetCaravan(); if (caravan != null) { CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawn, caravan.PawnsListForReading); caravan.RemovePawn(pawn); if (flag) { if (Rand.Value < 0.8f) { pawn.Kill(null, null); } else { HealIfPossible(pawn); } } } if (pawn.guest != null) { pawn.guest.SetGuestStatus(null); } if (pawn.Faction == Faction.OfPlayer) { if (!pawn.Spawned && Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction_NewTemp(out var faction, pawn.Faction != null && (int)pawn.Faction.def.techLevel >= 3)) { if (pawn.Faction != faction) { pawn.SetFaction(faction); } } else if (pawn.Faction != null) { pawn.SetFaction(null); } }
public static void GetThoughts(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind, List <IndividualThoughtToAdd> outIndividualThoughts, List <ThoughtDef> outAllColonistsThoughts) { outIndividualThoughts.Clear(); outAllColonistsThoughts.Clear(); if (victim.RaceProps.Humanlike) { PawnDiedOrDownedThoughtsUtility.AppendThoughts_ForHumanlike(victim, dinfo, thoughtsKind, outIndividualThoughts, outAllColonistsThoughts); } if (victim.relations != null && victim.relations.everSeenByPlayer) { PawnDiedOrDownedThoughtsUtility.AppendThoughts_Relations(victim, dinfo, thoughtsKind, outIndividualThoughts, outAllColonistsThoughts); } }
public void RemoveKidnappedPawn(Pawn pawn) { if (kidnappedPawns.Remove(pawn)) { if (pawn.Faction == Faction.OfPlayer) { PawnDiedOrDownedThoughtsUtility.RemoveLostThoughts(pawn); } } else { Log.Warning("Tried to remove kidnapped pawn " + pawn + " but he's not here."); } }
public static string GetBanishPawnDialogText(Pawn banishedPawn) { StringBuilder stringBuilder = new StringBuilder(); bool flag = PawnBanishUtility.WouldBeLeftToDie(banishedPawn, banishedPawn.Tile); stringBuilder.Append("ConfirmBanishPawnDialog".Translate(banishedPawn.Label)); if (flag) { stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.Append("ConfirmBanishPawnDialog_LeftToDie".Translate(banishedPawn.LabelShort).CapitalizeFirst()); } List <ThingWithComps> list = (banishedPawn.equipment == null) ? null : banishedPawn.equipment.AllEquipmentListForReading; List <Apparel> list2 = (banishedPawn.apparel == null) ? null : banishedPawn.apparel.WornApparel; ThingOwner <Thing> thingOwner = (banishedPawn.inventory == null || !PawnBanishUtility.WillTakeInventoryIfBanished(banishedPawn)) ? null : banishedPawn.inventory.innerContainer; if (!list.NullOrEmpty() || !list2.NullOrEmpty() || !thingOwner.NullOrEmpty()) { stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.Append("ConfirmBanishPawnDialog_Items".Translate(banishedPawn.LabelShort).CapitalizeFirst().AdjustedFor(banishedPawn)); stringBuilder.AppendLine(); if (list != null) { for (int i = 0; i < list.Count; i++) { stringBuilder.AppendLine(); stringBuilder.Append(" - " + list[i].LabelCap); } } if (list2 != null) { for (int j = 0; j < list2.Count; j++) { stringBuilder.AppendLine(); stringBuilder.Append(" - " + list2[j].LabelCap); } } if (thingOwner != null) { for (int k = 0; k < thingOwner.Count; k++) { stringBuilder.AppendLine(); stringBuilder.Append(" - " + thingOwner[k].LabelCap); } } } PawnDiedOrDownedThoughtsUtility.BuildMoodThoughtsListString(banishedPawn, null, (PawnDiedOrDownedThoughtsKind)((!flag) ? 1 : 2), stringBuilder, "\n\n" + "ConfirmBanishPawnDialog_IndividualThoughts".Translate(banishedPawn.LabelShort), "\n\n" + "ConfirmBanishPawnDialog_AllColonistsThoughts".Translate()); return(stringBuilder.ToString()); }
public static void BuildMoodThoughtsListString(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind, StringBuilder sb, string individualThoughtsHeader, string allColonistsThoughtsHeader) { PawnDiedOrDownedThoughtsUtility.GetThoughts(victim, dinfo, thoughtsKind, PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd, PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts); if (PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts.Any <ThoughtDef>()) { if (!allColonistsThoughtsHeader.NullOrEmpty()) { sb.Append(allColonistsThoughtsHeader); sb.AppendLine(); } for (int i = 0; i < PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts.Count; i++) { ThoughtDef thoughtDef = PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts[i]; if (sb.Length > 0) { sb.AppendLine(); } sb.Append(" - " + thoughtDef.stages[0].label.CapitalizeFirst() + " " + Mathf.RoundToInt(thoughtDef.stages[0].baseMoodEffect).ToStringWithSign()); } } if (PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd.Any((IndividualThoughtToAdd x) => x.thought.MoodOffset() != 0f)) { if (!individualThoughtsHeader.NullOrEmpty()) { sb.Append(individualThoughtsHeader); } foreach (IGrouping <Pawn, IndividualThoughtToAdd> grouping in from x in PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd where x.thought.MoodOffset() != 0f group x by x.addTo) { if (sb.Length > 0) { sb.AppendLine(); sb.AppendLine(); } string value = grouping.Key.KindLabel.CapitalizeFirst() + " " + grouping.Key.LabelShort; sb.Append(value); sb.Append(":"); foreach (IndividualThoughtToAdd individualThoughtToAdd in grouping) { sb.AppendLine(); sb.Append(" " + individualThoughtToAdd.LabelCap); } } } }
public void Kidnap(Pawn pawn, Pawn kidnapper) { if (kidnappedPawns.Contains(pawn)) { Log.Error("Tried to kidnap already kidnapped pawn " + pawn); return; } if (pawn.Faction == faction) { Log.Error("Tried to kidnap pawn with the same faction: " + pawn); return; } pawn.PreKidnapped(kidnapper); if (pawn.Spawned) { pawn.DeSpawn(); } kidnappedPawns.Add(pawn); if (!Find.WorldPawns.Contains(pawn)) { Find.WorldPawns.PassToWorld(pawn); if (!Find.WorldPawns.Contains(pawn)) { Log.Error("WorldPawns discarded kidnapped pawn."); kidnappedPawns.Remove(pawn); } } if (pawn.Faction == Faction.OfPlayer) { PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(pawn, null, PawnDiedOrDownedThoughtsKind.Lost); BillUtility.Notify_ColonistUnavailable(pawn); if (kidnapper != null) { Find.LetterStack.ReceiveLetter("LetterLabelPawnsKidnapped".Translate(pawn.Named("PAWN")), "LetterPawnsKidnapped".Translate(pawn.Named("PAWN"), kidnapper.Faction.Named("FACTION")), LetterDefOf.NegativeEvent); } } QuestUtility.SendQuestTargetSignals(pawn.questTags, "Kidnapped", this.Named("SUBJECT"), kidnapper.Named("KIDNAPPER")); Find.GameEnder.CheckOrUpdateGameOver(); }
private static void AppendThoughts_ForHumanlike(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind, List <IndividualThoughtToAdd> outIndividualThoughts, List <ThoughtDef> outAllColonistsThoughts) { bool flag = dinfo != null && dinfo.Value.Def.execution; bool flag2 = victim.IsPrisonerOfColony && !victim.guilt.IsGuilty && !victim.InAggroMentalState; bool flag3 = dinfo != null && dinfo.Value.Def.externalViolence && dinfo.Value.Instigator != null && dinfo.Value.Instigator is Pawn; if (flag3) { Pawn pawn = (Pawn)dinfo.Value.Instigator; if (!pawn.Dead && pawn.needs.mood != null && pawn.story != null && pawn != victim) { if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died) { outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KilledHumanlikeBloodlust, pawn, null, 1f, 1f)); } if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died && victim.HostileTo(pawn)) { if (victim.Faction != null && PawnUtility.IsFactionLeader(victim) && victim.Faction.HostileTo(pawn.Faction)) { outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.DefeatedHostileFactionLeader, pawn, victim, 1f, 1f)); } } } } if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died && !flag) { foreach (Pawn pawn2 in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive) { if (pawn2 != victim && pawn2.needs.mood != null) { if (pawn2.MentalStateDef != MentalStateDefOf.SocialFighting || ((MentalState_SocialFighting)pawn2.MentalState).otherPawn != victim) { if (PawnDiedOrDownedThoughtsUtility.Witnessed(pawn2, victim)) { if (pawn2.Faction == victim.Faction) { outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathAlly, pawn2, null, 1f, 1f)); } else if (victim.Faction == null || !victim.Faction.HostileTo(pawn2.Faction)) { outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathNonAlly, pawn2, null, 1f, 1f)); } if (pawn2.relations.FamilyByBlood.Contains(victim)) { outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathFamily, pawn2, null, 1f, 1f)); } outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathBloodlust, pawn2, null, 1f, 1f)); } else if (victim.Faction == Faction.OfPlayer && victim.Faction == pawn2.Faction && victim.HostFaction != pawn2.Faction) { outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KnowColonistDied, pawn2, victim, 1f, 1f)); } if (flag2 && pawn2.Faction == Faction.OfPlayer && !pawn2.IsPrisoner) { outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KnowPrisonerDiedInnocent, pawn2, victim, 1f, 1f)); } } } } } if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Banished && victim.IsColonist) { outAllColonistsThoughts.Add(ThoughtDefOf.ColonistBanished); } if (thoughtsKind == PawnDiedOrDownedThoughtsKind.BanishedToDie) { if (victim.IsColonist) { outAllColonistsThoughts.Add(ThoughtDefOf.ColonistBanishedToDie); } else if (victim.IsPrisonerOfColony) { outAllColonistsThoughts.Add(ThoughtDefOf.PrisonerBanishedToDie); } } }
public static void Resurrect(Pawn pawn) { if (!pawn.Dead) { Log.Error("Tried to resurrect a pawn who is not dead: " + pawn.ToStringSafe <Pawn>(), false); return; } if (pawn.Discarded) { Log.Error("Tried to resurrect a discarded pawn: " + pawn.ToStringSafe <Pawn>(), false); return; } Corpse corpse = pawn.Corpse; bool flag = false; IntVec3 loc = IntVec3.Invalid; Map map = null; if (corpse != null) { flag = corpse.Spawned; loc = corpse.Position; map = corpse.Map; corpse.InnerPawn = null; corpse.Destroy(DestroyMode.Vanish); } if (flag && pawn.IsWorldPawn()) { Find.WorldPawns.RemovePawn(pawn); } pawn.ForceSetStateToUnspawned(); PawnComponentsUtility.CreateInitialComponents(pawn); pawn.health.Notify_Resurrected(); if (pawn.Faction != null && pawn.Faction.IsPlayer) { if (pawn.workSettings != null) { pawn.workSettings.EnableAndInitialize(); } Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(pawn, PopAdaptationEvent.GainedColonist); } if (flag) { GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish); for (int i = 0; i < 10; i++) { MoteMaker.ThrowAirPuffUp(pawn.DrawPos, map); } if (pawn.Faction != null && pawn.Faction != Faction.OfPlayer && pawn.HostileTo(Faction.OfPlayer)) { LordMaker.MakeNewLord(pawn.Faction, new LordJob_AssaultColony(pawn.Faction, true, true, false, false, true), pawn.Map, Gen.YieldSingle <Pawn>(pawn)); } if (pawn.apparel != null) { List <Apparel> wornApparel = pawn.apparel.WornApparel; for (int j = 0; j < wornApparel.Count; j++) { wornApparel[j].Notify_PawnResurrected(); } } } PawnDiedOrDownedThoughtsUtility.RemoveDiedThoughts(pawn); }