public static void DamageTest() { ThingDef thingDef = ThingDef.Named("Bullet_BoltActionRifle"); PawnKindDef slave = PawnKindDefOf.Slave; Faction faction = FactionUtility.DefaultFactionFrom(slave.defaultFactionType); DamageInfo dinfo = new DamageInfo(thingDef.projectile.damageDef, thingDef.projectile.GetDamageAmount(null), thingDef.projectile.GetArmorPenetration(null)); dinfo.SetIgnoreInstantKillProtection(ignore: true); int num = 0; int num2 = 0; DefMap <BodyPartDef, int> defMap = new DefMap <BodyPartDef, int>(); for (int i = 0; i < 500; i++) { Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(slave, faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: true)); List <BodyPartDef> list = (from hd in pawn.health.hediffSet.GetMissingPartsCommonAncestors() select hd.Part.def).ToList(); for (int j = 0; j < 2; j++) { pawn.TakeDamage(dinfo); if (pawn.Dead) { num++; break; } } List <BodyPartDef> list2 = (from hd in pawn.health.hediffSet.GetMissingPartsCommonAncestors() select hd.Part.def).ToList(); if (list2.Count > list.Count) { num2++; foreach (BodyPartDef item in list2) { defMap[item]++; } foreach (BodyPartDef item2 in list) { defMap[item2]--; } } Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Damage test"); stringBuilder.AppendLine("Hit " + 500 + " " + slave.label + "s with " + 2 + "x " + thingDef.label + " (" + thingDef.projectile.GetDamageAmount(null) + " damage) each. Results:"); stringBuilder.AppendLine("Killed: " + num + " / " + 500 + " (" + ((float)num / 500f).ToStringPercent() + ")"); stringBuilder.AppendLine("Part losers: " + num2 + " / " + 500 + " (" + ((float)num2 / 500f).ToStringPercent() + ")"); stringBuilder.AppendLine("Parts lost:"); foreach (BodyPartDef allDef in DefDatabase <BodyPartDef> .AllDefs) { if (defMap[allDef] > 0) { stringBuilder.AppendLine(" " + allDef.label + ": " + defMap[allDef]); } } Log.Message(stringBuilder.ToString()); }
public static void HitsToKill() { var data = DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.race != null).Select(delegate(ThingDef x) { int num = 0; int num2 = 0; for (int i = 0; i < 15; i++) { Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(x.race.AnyPawnKind, null, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: true)); for (int j = 0; j < 1000; j++) { DamageInfo dinfo = new DamageInfo(DamageDefOf.Crush, 10f); dinfo.SetIgnoreInstantKillProtection(ignore: true); pawn.TakeDamage(dinfo); if (pawn.Destroyed) { num += j + 1; break; } } if (!pawn.Destroyed) { Log.Error("Could not kill pawn " + pawn.ToStringSafe()); } if (pawn.health.ShouldBeDeadFromLethalDamageThreshold()) { num2++; } if (Find.WorldPawns.Contains(pawn)) { Find.WorldPawns.RemovePawn(pawn); } Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard); } float hits = (float)num / 15f; return(new { Race = x, Hits = hits, DiedDueToDamageThreshold = num2 }); }).ToDictionary(x => x.Race); DebugTables.MakeTablesDialog(from d in DefDatabase <ThingDef> .AllDefs where d.race != null orderby d.race.baseHealthScale descending select d, new TableDataGetter <ThingDef>("defName", (ThingDef d) => d.defName), new TableDataGetter <ThingDef>("10 damage hits", (ThingDef d) => data[d].Hits.ToString("F0")), new TableDataGetter <ThingDef>("died due to\ndam. thresh.", (ThingDef d) => data[d].DiedDueToDamageThreshold + "/" + 15), new TableDataGetter <ThingDef>("mech", (ThingDef d) => (!d.race.IsMechanoid) ? "" : "mech")); }
private static void KillFactionLeader() { Pawn leader = Find.FactionManager.AllFactions.Where((Faction x) => x.leader != null).RandomElement().leader; int num = 0; while (!leader.Dead) { if (++num > 1000) { Log.Warning("Could not kill faction leader."); break; } DamageInfo dinfo = new DamageInfo(DamageDefOf.Bullet, 30f, 999f); dinfo.SetIgnoreInstantKillProtection(ignore: true); leader.TakeDamage(dinfo); } }
public static void DamageUntilDead(Pawn p) { HediffSet hediffSet = p.health.hediffSet; int num = 0; while (!p.Dead && num < 200 && HittablePartsViolence(hediffSet).Any()) { num++; BodyPartRecord bodyPartRecord = HittablePartsViolence(hediffSet).RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Rand.RangeInclusive(8, 25); DamageDef def = ((bodyPartRecord.depth != BodyPartDepth.Outside) ? DamageDefOf.Blunt : RandomViolenceDamageType()); DamageInfo dinfo = new DamageInfo(def, num2, 999f, -1f, null, bodyPartRecord); dinfo.SetIgnoreInstantKillProtection(ignore: true); p.TakeDamage(dinfo); } if (!p.Dead) { Log.Error(string.Concat(p, " not killed during GiveInjuriesToKill")); } }