public override bool CanHappen(string msg, Viewer viewer) { foreach (Pawn pawn in Find.ColonistBar.GetColonistsInOrder().Where(p => !p.Dead)) { if (IncidentSettings.HealAll.FairFights && pawn.mindState.lastAttackTargetTick > 0 && Find.TickManager.TicksGame < pawn.mindState.lastAttackTargetTick + 1800) { continue; } object result = HealHelper.GetPawnHealable(pawn); switch (result) { case Hediff hediff: _healQueue.Add(hediff); break; case BodyPartRecord record: _restoreQueue.Add(new Pair <Pawn, BodyPartRecord>(pawn, record)); break; } } return(_healQueue.Any(i => i != null) || _restoreQueue.Any(i => i.Second != null)); }
private static bool TryProcessColonist([NotNull] Pawn pawn) { if (pawn.Dead) { pawn.TryResurrect(); return(true); } if (!(HealHelper.GetPawnHealable(pawn) is { } injury)) { return(false); } switch (injury) { case Hediff hediff: pawn.health.RemoveHediff(hediff); return(true); case BodyPartRecord record: pawn.health.RestorePart(record); return(true); } return(false); }
public override void Execute() { var healed = 0; var iterations = 0; while (true) { if (!Viewer.CanAfford(storeIncident.cost)) { break; } object healable = HealHelper.GetPawnHealable(_pawn); if (healable == null) { break; } healed = Heal(healable, healed); iterations += 1; if (iterations < 500) { continue; } TkUtils.Logger.Warn("Exceeded the maximum number of iterations during full heal."); break; } MessageHelper.SendConfirmation( Viewer.username, healed > 1 ? "TKUtils.FullHeal.CompletePlural".LocalizeKeyed(healed.ToString("N0")) : "TKUtils.FullHeal.Complete".Localize() ); Current.Game.letterStack.ReceiveLetter( "TKUtils.FullHealLetter.Title".Localize(), "TKUtils.FullHealLetter.Description".LocalizeKeyed(Viewer.username), LetterDefOf.PositiveEvent, _pawn ); }
private static bool TryProcessAnimal([NotNull] Pawn pawn) { if (pawn.mindState.mentalStateHandler.CurStateDef == MentalStateDefOf.Manhunter) { pawn.ClearMind(); return(true); } if (pawn.mindState.mentalStateHandler.CurStateDef == MentalStateDefOf.ManhunterPermanent) { pawn.Kill(new DamageInfo(DamageDefOf.Burn, 100000, 1f, category: DamageInfo.SourceCategory.ThingOrUnknown)); return(true); } if (pawn.Dead) { pawn.TryResurrect(); return(true); } if (!(HealHelper.GetPawnHealable(pawn) is { } injury)) { return(false); } switch (injury) { case Hediff hediff: pawn.health.RemoveHediff(hediff); return(true); case BodyPartRecord record: pawn.health.RestorePart(record); return(true); } return(false); }
public override bool CanHappen(string msg, Viewer viewer) { List <Pawn> pawns = Find.ColonistBar.GetColonistsInOrder() .Where(p => !p.Dead) .Where( pawn => !IncidentSettings.HealRandom.FairFights || (pawn.mindState.lastAttackTargetTick > 0 && Find.TickManager.TicksGame <= pawn.mindState.lastAttackTargetTick + 1800) ) .ToList(); if (!pawns.Select(p => new Pair <Pawn, object>(p, HealHelper.GetPawnHealable(p))).Where(r => r.Second != null).TryRandomElement(out Pair <Pawn, object> random)) { return(false); } if (random.First == null || random.Second == null) { return(false); } _target = random.First; switch (random.Second) { case Hediff hediff: _toHeal = hediff; break; case BodyPartRecord record: _toRestore = record; break; } return(_target != null && (_toHeal != null || _toRestore != null)); }