/// <summary> /// preform the requested transform /// </summary> /// <param name="request">The request.</param> /// <returns></returns> protected override TransformedPawnSingle TransformImpl(TransformationRequest request) { Pawn original = request.originals[0]; if (request.addMutationToOriginal) { TryAddMutationsToPawn(original, request.cause, request.outputDef); } var reactionStatus = original.GetFormerHumanReactionStatus(); float newAge = TransformerUtility.ConvertAge(original, request.outputDef.race.race); Faction faction; faction = GetFaction(request, original); Gender newGender = TransformerUtility.GetTransformedGender(original, request.forcedGender, request.forcedGenderChance); var pRequest = FormerHumanUtilities.CreateSapientAnimalRequest(request.outputDef, original, faction, fixedGender: newGender); Pawn animalToSpawn = PawnGenerator.GeneratePawn(pRequest); //make the temp pawn animalToSpawn.needs.food.CurLevel = original.needs.food.CurLevel; // Copies the original pawn's food need to the animal's. animalToSpawn.needs.rest.CurLevel = original.needs.rest.CurLevel; // Copies the original pawn's rest need to the animal's. animalToSpawn.Name = original.Name; // Copies the original pawn's name to the animal's. float sapienceLevel = request.forcedSapienceLevel ?? GetSapienceLevel(original, animalToSpawn); if (request.forcedFaction == null && original.Faction != faction && original.Faction != animalToSpawn.Faction && FormerHumanUtilities.GetQuantizedSapienceLevel(sapienceLevel) <= SapienceLevel.MostlySapient) { //set the faction to the original's if mostly sapient or above animalToSpawn.SetFaction(original.Faction); } GiveTransformedPawnSapienceState(animalToSpawn, sapienceLevel); FormerHumanUtilities.InitializeTransformedPawn(original, animalToSpawn, sapienceLevel); //use a normal distribution? Pawn spawnedAnimal = SpawnAnimal(original, animalToSpawn); // Spawns the animal into the map. ReactionsHelper.OnPawnTransforms(original, animalToSpawn, reactionStatus); //this needs to happen before MakeSapientAnimal because that removes relations var rFaction = request.factionResponsible ?? GetFactionResponsible(original); var inst = new TransformedPawnSingle(request.transformedTick) { original = original, animal = spawnedAnimal, factionResponsible = rFaction, reactionStatus = reactionStatus }; if (original.Spawned) { for (var i = 0; i < 10; i++) // Create a cloud of magic. { IntermittentMagicSprayer.ThrowMagicPuffDown(spawnedAnimal.Position.ToVector3(), spawnedAnimal.MapHeld); IntermittentMagicSprayer.ThrowMagicPuffUp(spawnedAnimal.Position.ToVector3(), spawnedAnimal.MapHeld); } } if (request.tale != null) // If a tale was provided, push it to the tale recorder. { TaleRecorder.RecordTale(request.tale, original, animalToSpawn); } Faction oFaction = original.FactionOrExtraMiniOrHomeFaction; Map oMap = original.Map; //apply any other post tf effects ApplyPostTfEffects(original, animalToSpawn, request); TransformerUtility .CleanUpHumanPawnPostTf(original, request.cause); //now clean up the original pawn (remove apparel, drop'em, ect) //notify the faction that their member has been transformed oFaction?.Notify_MemberTransformed(original, animalToSpawn, oMap == null, oMap); if (!request.noLetter && reactionStatus == FormerHumanReactionStatus.Colonist || reactionStatus == FormerHumanReactionStatus.Prisoner) //only send the letter for colonists and prisoners { SendLetter(request, original, spawnedAnimal); } if (original.Spawned) { original.DeSpawn(); // Remove the original pawn from the current map. } DebugLogUtils.Assert(!PrisonBreakUtility.CanParticipateInPrisonBreak(original), $"{original.Name} has been cleaned up and de-spawned but can still participate in prison breaks"); return(inst); }
public static bool HostileTo(ref bool __result, Thing a, Thing b) { if (a == null || b == null) { __result = false; return(false); } if (a.Destroyed || b.Destroyed || a == b) { __result = false; return(false); } if ((a.Faction == null && a.TryGetComp <CompCauseGameCondition>() != null) || (b.Faction == null && b.TryGetComp <CompCauseGameCondition>() != null)) { __result = true; return(false); } Pawn pawn = a as Pawn; Pawn pawn2 = b as Pawn; __result = (pawn?.MentalState != null && pawn.MentalState.ForceHostileTo(b)) || (pawn2?.MentalState != null && pawn2.MentalState.ForceHostileTo(a)) || (pawn != null && pawn2 != null && (IsPredatorHostileTo(pawn, pawn2) || IsPredatorHostileTo(pawn2, pawn))) || ((a.Faction != null && pawn2 != null && pawn2.HostFaction == a.Faction && (pawn?.HostFaction == null) && PrisonBreakUtility.IsPrisonBreaking(pawn2)) || (b.Faction != null && pawn != null && pawn.HostFaction == b.Faction && (pawn2?.HostFaction == null) && PrisonBreakUtility.IsPrisonBreaking(pawn))) || ((a.Faction == null || pawn2 == null || pawn2.HostFaction != a.Faction) && (b.Faction == null || pawn == null || pawn.HostFaction != b.Faction) && (pawn == null || !pawn.IsPrisoner || pawn2 == null || !pawn2.IsPrisoner) && (pawn == null || pawn2 == null || ((!pawn.IsPrisoner || pawn.HostFaction != pawn2.HostFaction || PrisonBreakUtility.IsPrisonBreaking(pawn)) && (!pawn2.IsPrisoner || pawn2.HostFaction != pawn.HostFaction || PrisonBreakUtility.IsPrisonBreaking(pawn2)))) && (pawn == null || pawn2 == null || ((pawn.HostFaction == null || pawn2.Faction == null || pawn.HostFaction.HostileTo(pawn2.Faction) || PrisonBreakUtility.IsPrisonBreaking(pawn)) && (pawn2.HostFaction == null || pawn.Faction == null || pawn2.HostFaction.HostileTo(pawn.Faction) || PrisonBreakUtility.IsPrisonBreaking(pawn2)))) && (a.Faction == null || !a.Faction.IsPlayer || pawn2 == null || !pawn2.mindState.WillJoinColonyIfRescued) && (b.Faction == null || !b.Faction.IsPlayer || pawn == null || !pawn.mindState.WillJoinColonyIfRescued) && ((pawn != null && pawn.Faction == null && pawn.RaceProps.Humanlike && b.Faction != null && b.Faction.def.hostileToFactionlessHumanlikes) || (pawn2 != null && pawn2.Faction == null && pawn2.RaceProps.Humanlike && a.Faction != null && a.Faction.def.hostileToFactionlessHumanlikes) || (a.Faction != null && b.Faction != null && a.Faction.HostileTo(b.Faction)))); return(false); }
public static Pawn FindPrisoner(Pawn pawn) { if (!pawn.Spawned) { return(null); } JailbreakerMentalStateUtility.tmpPrisoners.Clear(); List <Pawn> allPawnsSpawned = pawn.Map.mapPawns.AllPawnsSpawned; for (int i = 0; i < allPawnsSpawned.Count; i++) { Pawn pawn2 = allPawnsSpawned[i]; if (pawn2.IsPrisoner && pawn2.HostFaction == pawn.Faction && pawn2 != pawn && !pawn2.Downed && !pawn2.InMentalState && !pawn2.IsBurning() && pawn2.Awake() && pawn2.guest.PrisonerIsSecure && PrisonBreakUtility.CanParticipateInPrisonBreak(pawn2) && pawn.CanReach(pawn2, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn)) { JailbreakerMentalStateUtility.tmpPrisoners.Add(pawn2); } } if (!JailbreakerMentalStateUtility.tmpPrisoners.Any <Pawn>()) { return(null); } Pawn result = JailbreakerMentalStateUtility.tmpPrisoners.RandomElement <Pawn>(); JailbreakerMentalStateUtility.tmpPrisoners.Clear(); return(result); }
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); } } } }