public void TryForceFleeCowards() { foreach (var pawn in cowards) { if (pawn.Map != null && Rand.Chance(0.1f)) { Log.Message(" - TryForceFleeCowards - var enemies = pawn.Map.attackTargetsCache?.GetPotentialTargetsFor(pawn)?.Where(x => x.Thing.Position.DistanceTo(pawn.Position) < 15f)?.Select(y => y.Thing); - 3", true); var enemies = pawn.Map.attackTargetsCache?.GetPotentialTargetsFor(pawn)?.Where(x => x.Thing.Position.DistanceTo(pawn.Position) < 15f)?.Select(y => y.Thing); Log.Message(" - TryForceFleeCowards - if (enemies?.Count() > 0) - 4", true); if (enemies?.Count() > 0) { Log.Message(" - TryForceFleeCowards - TraitUtils.MakeFlee(pawn, enemies.OrderBy(x => x.Position.DistanceTo(pawn.Position)).First(), 15, enemies.ToList()); - 5", true); TraitUtils.MakeFlee(pawn, enemies.OrderBy(x => x.Position.DistanceTo(pawn.Position)).First(), 15, enemies.ToList()); Log.Message(" - TryForceFleeCowards - Messages.Message(\"VTE.PawnCowardlyFlees\".Translate(pawn.Named(\"PAWN\")), pawn, MessageTypeDefOf.NeutralEvent, historical: false); - 6", true); Messages.Message("VTE.PawnCowardlyFlees".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NeutralEvent, historical: false); } } } }
public void TryForceFleeCowards() { if (cowards is null) { PreInit(); } foreach (var pawn in cowards) { if (pawn?.Map != null && !pawn.Downed && !pawn.Dead && Rand.Chance(0.1f)) { var enemies = pawn.Map.attackTargetsCache?.GetPotentialTargetsFor(pawn)?.Where(x => (x is Pawn pawnEnemy && !pawnEnemy.Dead && !pawnEnemy.Downed || !(x.Thing is Pawn) && x.Thing.DestroyedOrNull()) && x.Thing.Position.DistanceTo(pawn.Position) < 15f && GenSight.LineOfSight(x.Thing.Position, pawn.Position, pawn.Map))?.Select(y => y.Thing); if (enemies?.Count() > 0) { if (pawn.Faction == Faction.OfPlayer) { TraitUtils.MakeFlee(pawn, enemies.OrderBy(x => x.Position.DistanceTo(pawn.Position)).First(), 15, enemies.ToList()); Messages.Message("VTE.PawnCowardlyFlees".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NeutralEvent, historical: false); } else if (pawn.Faction != null) { TraitUtils.MakeExit(pawn); if (pawn.HostileTo(Faction.OfPlayer)) { Messages.Message("VTE.PawnCowardlyExitMapHostile".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NeutralEvent, historical: false); } else if (pawn.Faction.RelationKindWith(Faction.OfPlayer) == FactionRelationKind.Ally) { Messages.Message("VTE.PawnCowardlyExitMapAlly".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NeutralEvent, historical: false); } else { Messages.Message("VTE.PawnCowardlyExitMapNeutral".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NeutralEvent, historical: false); } } } } } }