Esempio n. 1
0
        public static void DamageUntilDead(Pawn p)
        {
            HediffSet hediffSet = p.health.hediffSet;
            int       num       = 0;

            while (!p.Dead && num < 200 && HealthUtility.HittablePartsViolence(hediffSet).Any <BodyPartRecord>())
            {
                num++;
                BodyPartRecord bodyPartRecord = HealthUtility.HittablePartsViolence(hediffSet).RandomElementByWeight((BodyPartRecord x) => x.coverageAbs);
                int            num2           = Rand.RangeInclusive(8, 25);
                DamageDef      damageDef;
                if (bodyPartRecord.depth == BodyPartDepth.Outside)
                {
                    damageDef = HealthUtility.RandomViolenceDamageType();
                }
                else
                {
                    damageDef = DamageDefOf.Blunt;
                }
                DamageDef      def              = damageDef;
                float          amount           = (float)num2;
                float          armorPenetration = 999f;
                BodyPartRecord hitPart          = bodyPartRecord;
                DamageInfo     dinfo            = new DamageInfo(def, amount, armorPenetration, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null);
                p.TakeDamage(dinfo);
            }
            if (!p.Dead)
            {
                Log.Error(p + " not killed during GiveInjuriesToKill", false);
            }
        }
Esempio n. 2
0
        public static void DamageUntilDowned(Pawn p)
        {
            if (p.health.Downed)
            {
                return;
            }
            HediffSet hediffSet = p.health.hediffSet;

            p.health.forceIncap = true;
            IEnumerable <BodyPartRecord> source = from x in HealthUtility.HittablePartsViolence(hediffSet)
                                                  where !p.health.hediffSet.hediffs.Any((Hediff y) => y.Part == x && y.CurStage != null && y.CurStage.partEfficiencyOffset < 0f)
                                                  select x;
            int num = 0;

            while (num < 300 && !p.Downed && source.Any <BodyPartRecord>())
            {
                num++;
                BodyPartRecord bodyPartRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs);
                int            num2           = Mathf.RoundToInt(hediffSet.GetPartHealth(bodyPartRecord)) - 3;
                if (num2 >= 8)
                {
                    DamageDef damageDef;
                    if (bodyPartRecord.depth == BodyPartDepth.Outside)
                    {
                        damageDef = HealthUtility.RandomViolenceDamageType();
                    }
                    else
                    {
                        damageDef = DamageDefOf.Blunt;
                    }
                    int       num3 = Rand.RangeInclusive(Mathf.RoundToInt((float)num2 * 0.65f), num2);
                    HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(damageDef, p, bodyPartRecord);
                    if (!p.health.WouldDieAfterAddingHediff(hediffDefFromDamage, bodyPartRecord, (float)num3))
                    {
                        DamageDef      def     = damageDef;
                        int            amount  = num3;
                        BodyPartRecord hitPart = bodyPartRecord;
                        DamageInfo     dinfo   = new DamageInfo(def, amount, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown);
                        dinfo.SetAllowDamagePropagation(false);
                        p.TakeDamage(dinfo);
                    }
                }
            }
            if (p.Dead)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine(p + " died during GiveInjuriesToForceDowned");
                for (int i = 0; i < p.health.hediffSet.hediffs.Count; i++)
                {
                    stringBuilder.AppendLine("   -" + p.health.hediffSet.hediffs[i].ToString());
                }
                Log.Error(stringBuilder.ToString());
            }
            p.health.forceIncap = false;
        }
Esempio n. 3
0
        public static void DamageLegsUntilIncapableOfMoving(Pawn p, bool allowBleedingWounds = true)
        {
            int num = 0;

            p.health.forceIncap = true;
            while (p.health.capacities.CapableOf(PawnCapacityDefOf.Moving) && num < 300)
            {
                num++;
                IEnumerable <BodyPartRecord> source = from x in p.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)
                                                      where x.def.tags.Contains(BodyPartTagDefOf.MovingLimbCore) && p.health.hediffSet.GetPartHealth(x) >= 2f
                                                      select x;
                if (!source.Any <BodyPartRecord>())
                {
                    break;
                }
                BodyPartRecord bodyPartRecord = source.RandomElement <BodyPartRecord>();
                float          maxHealth      = bodyPartRecord.def.GetMaxHealth(p);
                float          partHealth     = p.health.hediffSet.GetPartHealth(bodyPartRecord);
                int            min            = Mathf.Clamp(Mathf.RoundToInt(maxHealth * 0.12f), 1, (int)partHealth - 1);
                int            max            = Mathf.Clamp(Mathf.RoundToInt(maxHealth * 0.27f), 1, (int)partHealth - 1);
                int            num2           = Rand.RangeInclusive(min, max);
                DamageDef      damageDef;
                if (!allowBleedingWounds && bodyPartRecord.def.bleedRate > 0f)
                {
                    damageDef = DamageDefOf.Blunt;
                }
                else
                {
                    damageDef = HealthUtility.RandomViolenceDamageType();
                }
                HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(damageDef, p, bodyPartRecord);
                if (p.health.WouldDieAfterAddingHediff(hediffDefFromDamage, bodyPartRecord, (float)num2))
                {
                    break;
                }
                DamageDef      def              = damageDef;
                float          amount           = (float)num2;
                float          armorPenetration = 999f;
                BodyPartRecord hitPart          = bodyPartRecord;
                DamageInfo     dinfo            = new DamageInfo(def, amount, armorPenetration, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null);
                dinfo.SetAllowDamagePropagation(false);
                p.TakeDamage(dinfo);
            }
            p.health.forceIncap = false;
        }