private static void GiveRandomSurgeryInjuries(Pawn p, int totalDamage, BodyPartRecord operatedPart) { IEnumerable <BodyPartRecord> source = (operatedPart != null) ? (from x in p.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined) where !x.def.isConceptual select x into pa where pa == operatedPart || pa.parent == operatedPart || (operatedPart != null && operatedPart.parent == pa) select pa) : p.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined).Where((BodyPartRecord x) => !x.def.isConceptual); source = from x in source where HealthUtility.GetMinHealthOfPartsWeWantToAvoidDestroying(x, p) >= 2.0 select x; BodyPartRecord brain = p.health.hediffSet.GetBrain(); if (brain != null) { float maxBrainHealth = brain.def.GetMaxHealth(p); source = from x in source where x != brain || p.health.hediffSet.GetPartHealth(x) >= maxBrainHealth * 0.5 + 1.0 select x; } while (totalDamage > 0 && source.Any()) { BodyPartRecord bodyPartRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); float partHealth = p.health.hediffSet.GetPartHealth(bodyPartRecord); int num = Mathf.Max(3, GenMath.RoundRandom(partHealth * Rand.Range(0.5f, 1f))); float minHealthOfPartsWeWantToAvoidDestroying = HealthUtility.GetMinHealthOfPartsWeWantToAvoidDestroying(bodyPartRecord, p); if (minHealthOfPartsWeWantToAvoidDestroying - (float)num < 1.0) { num = Mathf.RoundToInt((float)(minHealthOfPartsWeWantToAvoidDestroying - 1.0)); } if (bodyPartRecord == brain && partHealth - (float)num < brain.def.GetMaxHealth(p) * 0.5) { num = Mathf.Max(Mathf.RoundToInt((float)(partHealth - brain.def.GetMaxHealth(p) * 0.5)), 1); } if (num > 0) { DamageDef damageDef = Rand.Element(DamageDefOf.Cut, DamageDefOf.Scratch, DamageDefOf.Stab, DamageDefOf.Crush); Pawn pawn = p; DamageDef def = damageDef; int amount = num; BodyPartRecord hitPart = bodyPartRecord; pawn.TakeDamage(new DamageInfo(def, amount, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown)); totalDamage -= num; continue; } break; } }
public int GetDamageAmountAt(IntVec3 c) { int result; if (!this.damageFalloff) { result = this.damAmount; } else { float t = c.DistanceTo(base.Position) / this.radius; int a = GenMath.RoundRandom(Mathf.Lerp((float)this.damAmount, (float)this.damAmount * 0.2f, t)); result = Mathf.Max(a, 1); } return(result); }
public virtual IEnumerable <Thing> ButcherProducts(Pawn butcher, float efficiency) { if (this.def.butcherProducts != null) { for (int i = 0; i < this.def.butcherProducts.Count; i++) { ThingDefCountClass ta = this.def.butcherProducts[i]; int count = GenMath.RoundRandom((float)ta.count * efficiency); if (count > 0) { Thing t = ThingMaker.MakeThing(ta.thingDef, null); t.stackCount = count; yield return(t); } } } }
private static void ApplyArmor(ref float damAmount, float armorRating, Thing armorThing, DamageDef damageDef) { float num; float num2; if ((double)armorRating <= 0.5) { num = armorRating; num2 = 0f; } else if (armorRating < 1f) { num = 0.5f; num2 = armorRating - 0.5f; } else { num = 0.5f + (armorRating - 1f) * 0.25f; num2 = 0.5f + (armorRating - 1f) * 0.25f; } if (num > 0.9f) { num = 0.9f; } if (num2 > 0.9f) { num2 = 0.9f; } float num3; if (Rand.Value < num2) { num3 = damAmount; } else { num3 = damAmount * num; } if (armorThing != null) { float f = damAmount * 0.25f; armorThing.TakeDamage(new DamageInfo(damageDef, GenMath.RoundRandom(f), -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown)); } damAmount -= num3; }
public override void OnIntervalPassed(Pawn pawn, Hediff cause) { float ambientTemperature = pawn.AmbientTemperature; FloatRange floatRange = pawn.ComfortableTemperatureRange(); FloatRange floatRange2 = pawn.SafeTemperatureRange(); HediffSet hediffSet = pawn.health.hediffSet; Hediff firstHediffOfDef = hediffSet.GetFirstHediffOfDef(hediff); if (ambientTemperature > floatRange2.max) { float x = ambientTemperature - floatRange2.max; x = TemperatureOverageAdjustmentCurve.Evaluate(x); float a = x * 6.45E-05f; a = Mathf.Max(a, 0.000375f); HealthUtility.AdjustSeverity(pawn, hediff, a); } else if (firstHediffOfDef != null && ambientTemperature < floatRange.max) { float value = firstHediffOfDef.Severity * 0.027f; value = Mathf.Clamp(value, 0.0015f, 0.015f); firstHediffOfDef.Severity -= value; } if (!pawn.Dead && pawn.IsNestedHashIntervalTick(60, 420)) { float num = floatRange.max + 150f; if (ambientTemperature > num) { float x2 = ambientTemperature - num; x2 = TemperatureOverageAdjustmentCurve.Evaluate(x2); int num2 = Mathf.Max(GenMath.RoundRandom(x2 * 0.06f), 3); DamageInfo dinfo = new DamageInfo(DamageDefOf.Burn, (float)num2); dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside); pawn.TakeDamage(dinfo); if (pawn.Faction == Faction.OfPlayer) { Find.TickManager.slower.SignalForceNormalSpeed(); if (MessagesRepeatAvoider.MessageShowAllowed("PawnBeingBurned", 60f)) { Messages.Message("MessagePawnBeingBurned".Translate(pawn.LabelShort, pawn).CapitalizeFirst(), pawn, MessageTypeDefOf.ThreatSmall); } } pawn.GetLord()?.ReceiveMemo(MemoPawnBurnedByAir); } } }
public virtual IEnumerable <Thing> ButcherProducts(Pawn butcher, float efficiency) { if (def.butcherProducts == null) { yield break; } for (int i = 0; i < def.butcherProducts.Count; i++) { ThingDefCountClass thingDefCountClass = def.butcherProducts[i]; int num = GenMath.RoundRandom((float)thingDefCountClass.count * efficiency); if (num > 0) { Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef); thing.stackCount = num; yield return(thing); } } }
public override void Destroy(DestroyMode mode = DestroyMode.Vanish) { if (mode == DestroyMode.Cancel) { for (int i = 0; i < ingredients.Count; i++) { int num = GenMath.RoundRandom((float)ingredients[i].stackCount * 0.75f); if (num > 0) { ingredients[i].stackCount = num; GenPlace.TryPlaceThing(ingredients[i], base.Position, base.Map, ThingPlaceMode.Near); } } ingredients.Clear(); } base.Destroy(mode); BoundBill = null; }
private static void GiveRandomSurgeryInjuries(Pawn p, int totalDamage, BodyPartRecord operatedPart) { IEnumerable <BodyPartRecord> source = (operatedPart != null) ? (from x in p.health.hediffSet.GetNotMissingParts() where !x.def.conceptual select x into pa where pa == operatedPart || pa.parent == operatedPart || (operatedPart != null && operatedPart.parent == pa) select pa) : (from x in p.health.hediffSet.GetNotMissingParts() where !x.def.conceptual select x); source = source.Where((BodyPartRecord x) => GetMinHealthOfPartsWeWantToAvoidDestroying(x, p) >= 2f); BodyPartRecord brain = p.health.hediffSet.GetBrain(); if (brain != null) { float maxBrainHealth = brain.def.GetMaxHealth(p); source = source.Where((BodyPartRecord x) => x != brain || p.health.hediffSet.GetPartHealth(x) >= maxBrainHealth * 0.5f + 1f); } while (totalDamage > 0 && source.Any()) { BodyPartRecord bodyPartRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); float partHealth = p.health.hediffSet.GetPartHealth(bodyPartRecord); int num = Mathf.Max(3, GenMath.RoundRandom(partHealth * Rand.Range(0.5f, 1f))); float minHealthOfPartsWeWantToAvoidDestroying = GetMinHealthOfPartsWeWantToAvoidDestroying(bodyPartRecord, p); if (minHealthOfPartsWeWantToAvoidDestroying - (float)num < 1f) { num = Mathf.RoundToInt(minHealthOfPartsWeWantToAvoidDestroying - 1f); } if (bodyPartRecord == brain && partHealth - (float)num < brain.def.GetMaxHealth(p) * 0.5f) { num = Mathf.Max(Mathf.RoundToInt(partHealth - brain.def.GetMaxHealth(p) * 0.5f), 1); } if (num > 0) { DamageDef def = Rand.Element(DamageDefOf.Cut, DamageDefOf.Scratch, DamageDefOf.Stab, DamageDefOf.Crush); DamageInfo dinfo = new DamageInfo(def, num, 0f, -1f, null, bodyPartRecord); dinfo.SetIgnoreArmor(ignoreArmor: true); p.TakeDamage(dinfo); totalDamage -= num; continue; } break; } }
private static void ApplyArmor(ref float damAmount, float armorRating, Thing armorThing, DamageDef damageDef) { float num; float num2; if ((double)armorRating <= 0.5) { num = armorRating; num2 = 0f; } else if (armorRating < 1.0) { num = 0.5f; num2 = (float)(armorRating - 0.5); } else { num = (float)(0.5 + (armorRating - 1.0) * 0.25); num2 = (float)(0.5 + (armorRating - 1.0) * 0.25); } if (num > 0.89999997615814209) { num = 0.9f; } if (num2 > 0.89999997615814209) { num2 = 0.9f; } float num3 = (!(Rand.Value < num2)) ? (damAmount * num) : damAmount; if (armorThing != null) { float f = (float)(damAmount * 0.25); armorThing.TakeDamage(new DamageInfo(damageDef, GenMath.RoundRandom(f), -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown)); } damAmount -= num3; }
private static void DropRoofInCellPhaseOne(IntVec3 c, Map map, List <Thing> outCrushedThings) { RoofDef roofDef = map.roofGrid.RoofAt(c); if (roofDef == null) { return; } if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable) { for (int i = 0; i < 2; i++) { List <Thing> thingList = c.GetThingList(map); for (int j = thingList.Count - 1; j >= 0; j--) { Thing thing = thingList[j]; RoofCollapserImmediate.TryAddToCrushedThingsList(thing, outCrushedThings); Pawn pawn = thing as Pawn; DamageInfo dinfo; if (pawn != null) { DamageDef crush = DamageDefOf.Crush; float amount = 99999f; float armorPenetration = 999f; BodyPartRecord brain = pawn.health.hediffSet.GetBrain(); dinfo = new DamageInfo(crush, amount, armorPenetration, -1f, null, brain, null, DamageInfo.SourceCategory.Collapse, null); } else { dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null); dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null; if (i == 0 && pawn != null) { battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling, null); Find.BattleLog.Add(battleLogEntry_DamageTaken); } thing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_DamageTaken); if (!thing.Destroyed && thing.def.destroyable) { thing.Kill(new DamageInfo?(new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null)), null); } } } } else { List <Thing> thingList2 = c.GetThingList(map); for (int k = thingList2.Count - 1; k >= 0; k--) { Thing thing2 = thingList2[k]; if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn) { RoofCollapserImmediate.TryAddToCrushedThingsList(thing2, outCrushedThings); float num = (float)RoofCollapserImmediate.ThinRoofCrushDamageRange.RandomInRange; if (thing2.def.building != null) { num *= thing2.def.building.roofCollapseDamageMultiplier; } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null; if (thing2 is Pawn) { battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken((Pawn)thing2, RulePackDefOf.DamageEvent_Ceiling, null); Find.BattleLog.Add(battleLogEntry_DamageTaken2); } DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, (float)GenMath.RoundRandom(num), 0f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null); dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); thing2.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_DamageTaken2); } } } if (roofDef.collapseLeavingThingDef != null) { Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map, WipeMode.Vanish); if (thing3.def.rotatable) { thing3.Rotation = Rot4.Random; } } for (int l = 0; l < 1; l++) { Vector3 vector = c.ToVector3Shifted(); vector += Gen.RandomHorizontalVector(0.6f); MoteMaker.ThrowDustPuff(vector, map, 2f); } }
private static void DropRoofInCellPhaseOne(IntVec3 c, Map map, List <Thing> outCrushedThings) { RoofDef roofDef = map.roofGrid.RoofAt(c); if (roofDef == null) { return; } if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable) { for (int i = 0; i < 2; i++) { List <Thing> thingList = c.GetThingList(map); for (int num = thingList.Count - 1; num >= 0; num--) { Thing thing = thingList[num]; TryAddToCrushedThingsList(thing, outCrushedThings); Pawn pawn = thing as Pawn; DamageInfo dinfo; if (pawn != null) { dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, pawn.health.hediffSet.GetBrain(), null, DamageInfo.SourceCategory.Collapse); } else { dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse); dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null; if (i == 0 && pawn != null) { battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling); Find.BattleLog.Add(battleLogEntry_DamageTaken); } thing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_DamageTaken); if (!thing.Destroyed && thing.def.destroyable) { thing.Kill(new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse)); } } } } else { List <Thing> thingList2 = c.GetThingList(map); for (int num2 = thingList2.Count - 1; num2 >= 0; num2--) { Thing thing2 = thingList2[num2]; if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn) { TryAddToCrushedThingsList(thing2, outCrushedThings); float num3 = ThinRoofCrushDamageRange.RandomInRange; if (thing2.def.building != null) { num3 *= thing2.def.building.roofCollapseDamageMultiplier; } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null; if (thing2 is Pawn) { battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken((Pawn)thing2, RulePackDefOf.DamageEvent_Ceiling); Find.BattleLog.Add(battleLogEntry_DamageTaken2); } DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, GenMath.RoundRandom(num3), 0f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse); dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); thing2.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_DamageTaken2); } } } if (roofDef.collapseLeavingThingDef != null) { Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map); if (thing3.def.rotatable) { thing3.Rotation = Rot4.Random; } } for (int j = 0; j < 1; j++) { MoteMaker.ThrowDustPuff(c.ToVector3Shifted() + Gen.RandomHorizontalVector(0.6f), map, 2f); } }
public static void PerformBattleRoyale(IEnumerable <PawnKindDef> kindsEnumerable) { if (!ArenaUtility.ValidateArenaCapability()) { return; } List <PawnKindDef> kinds = kindsEnumerable.ToList <PawnKindDef>(); Dictionary <PawnKindDef, float> ratings = new Dictionary <PawnKindDef, float>(); foreach (PawnKindDef pawnKindDef in kinds) { ratings[pawnKindDef] = EloUtility.CalculateRating(pawnKindDef.combatPower, 1500f, 60f); } int currentFights = 0; int completeFights = 0; Current.Game.GetComponent <GameComponent_DebugTools>().AddPerFrameCallback(delegate { if (currentFights >= 15) { return(false); } PawnKindDef lhsDef = kinds.RandomElement <PawnKindDef>(); PawnKindDef rhsDef = kinds.RandomElement <PawnKindDef>(); float num = EloUtility.CalculateExpectation(ratings[lhsDef], ratings[rhsDef]); float num2 = 1f - num; float num3 = num; float num4 = Mathf.Min(num2, num3); num2 /= num4; num3 /= num4; float num5 = Mathf.Max(num2, num3); if (num5 > 40f) { return(false); } float num6 = 40f / num5; float num7 = (float)Math.Exp((double)Rand.Range(0f, (float)Math.Log((double)num6))); num2 *= num7; num3 *= num7; List <PawnKindDef> lhs = Enumerable.Repeat <PawnKindDef>(lhsDef, GenMath.RoundRandom(num2)).ToList <PawnKindDef>(); List <PawnKindDef> rhs = Enumerable.Repeat <PawnKindDef>(rhsDef, GenMath.RoundRandom(num3)).ToList <PawnKindDef>(); currentFights++; ArenaUtility.BeginArenaFight(lhs, rhs, delegate(ArenaUtility.ArenaResult result) { currentFights--; completeFights++; if (result.winner != ArenaUtility.ArenaResult.Winner.Other) { float value = ratings[lhsDef]; float value2 = ratings[rhsDef]; float kfactor = 8f * Mathf.Pow(0.5f, Time.realtimeSinceStartup / 900f); EloUtility.Update(ref value, ref value2, 0.5f, (float)((result.winner != ArenaUtility.ArenaResult.Winner.Lhs) ? 0 : 1), kfactor); ratings[lhsDef] = value; ratings[rhsDef] = value2; Log.Message(string.Format("Scores after {0} trials:\n\n{1}", completeFights, (from v in ratings orderby v.Value select string.Format(" {0}: {1}->{2} (rating {2})", new object[] { v.Key.label, v.Key.combatPower, EloUtility.CalculateLinearScore(v.Value, 1500f, 60f).ToString("F0"), v.Value.ToString("F0") })).ToLineList(null)), false); } }); return(false); }); }
private static object RoundRandom(object[] args) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; return((double)GenMath.RoundRandom(Convert.ToSingle(args[0], invariantCulture))); }
private static void DropRoofInCellPhaseOne(IntVec3 c, Map map) { RoofDef roofDef = map.roofGrid.RoofAt(c); if (roofDef != null) { if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable) { for (int i = 0; i < 2; i++) { List <Thing> thingList = c.GetThingList(map); for (int num = thingList.Count - 1; num >= 0; num--) { Thing thing = thingList[num]; map.roofCollapseBuffer.Notify_Crushed(thing); Pawn pawn = thing as Pawn; DamageInfo dinfo = default(DamageInfo); if (pawn != null) { DamageDef crush = DamageDefOf.Crush; int amount = 99999; BodyPartRecord brain = pawn.health.hediffSet.GetBrain(); dinfo = new DamageInfo(crush, amount, -1f, null, brain, null, DamageInfo.SourceCategory.Collapse); } else { dinfo = new DamageInfo(DamageDefOf.Crush, 99999, -1f, null, null, null, DamageInfo.SourceCategory.Collapse); dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null; if (i == 0 && pawn != null) { battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling, null); Find.BattleLog.Add(battleLogEntry_DamageTaken); } thing.TakeDamage(dinfo).InsertIntoLog(battleLogEntry_DamageTaken); if (!thing.Destroyed && thing.def.destroyable) { thing.Destroy(DestroyMode.Vanish); } } } } else { List <Thing> thingList2 = c.GetThingList(map); for (int num2 = thingList2.Count - 1; num2 >= 0; num2--) { Thing thing2 = thingList2[num2]; if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn) { map.roofCollapseBuffer.Notify_Crushed(thing2); float num3 = (float)RoofCollapserImmediate.ThinRoofCrushDamageRange.RandomInRange; if (thing2.def.building != null) { num3 *= thing2.def.building.roofCollapseDamageMultiplier; } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null; if (thing2 is Pawn) { battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken(thing2 as Pawn, RulePackDefOf.DamageEvent_Ceiling, null); Find.BattleLog.Add(battleLogEntry_DamageTaken2); } DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, GenMath.RoundRandom(num3), -1f, null, null, null, DamageInfo.SourceCategory.Collapse); dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); thing2.TakeDamage(dinfo2).InsertIntoLog(battleLogEntry_DamageTaken2); } } } if (roofDef.collapseLeavingThingDef != null) { Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map); if (thing3.def.rotatable) { thing3.Rotation = Rot4.Random; } } for (int j = 0; j < 1; j++) { Vector3 a = c.ToVector3Shifted(); a += Gen.RandomHorizontalVector(0.6f); MoteMaker.ThrowDustPuff(a, map, 2f); } } }