Esempio n. 1
0
        public static void DamageLegsUntilIncapableOfMoving(Pawn p)
        {
            HediffDef def = Rand.Element <HediffDef>(HediffDefOf.Scratch, HediffDefOf.Bruise, HediffDefOf.Bite, HediffDefOf.Cut);
            int       num = 0;

            while (p.health.capacities.CapableOf(PawnCapacityDefOf.Moving) && num < 300)
            {
                num++;
                IEnumerable <BodyPartRecord> source = from x in p.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined)
                                                      where x.def.tags.Contains("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);
                if (p.health.WouldDieAfterAddingHediff(def, bodyPartRecord, (float)num2))
                {
                    break;
                }
                Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(def, p, bodyPartRecord);
                hediff_Injury.Severity = (float)num2;
                p.health.AddHediff(hediff_Injury, null, null);
            }
        }
Esempio n. 2
0
        private static void GiveRandomSurgeryInjuries(Pawn p, int totalDamage, BodyPartRecord operatedPart)
        {
            IEnumerable <BodyPartRecord> source;

            if (operatedPart == null)
            {
                source = from x in p.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)
                         where !x.def.conceptual
                         select x;
            }
            else
            {
                source = from x in p.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)
                         where !x.def.conceptual
                         select x into pa
                         where pa == operatedPart || pa.parent == operatedPart || (operatedPart != null && operatedPart.parent == pa)
                         select pa;
            }
            source = from x in source
                     where HealthUtility.GetMinHealthOfPartsWeWantToAvoidDestroying(x, p) >= 2f
                     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.5f + 1f
                         select x;
            }
            while (totalDamage > 0 && source.Any <BodyPartRecord>())
            {
                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 < 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)
                {
                    break;
                }
                DamageDef      damageDef = Rand.Element <DamageDef>(DamageDefOf.Cut, DamageDefOf.Scratch, DamageDefOf.Stab, DamageDefOf.Crush);
                Thing          p2        = p;
                DamageDef      def       = damageDef;
                float          amount    = (float)num;
                BodyPartRecord hitPart   = bodyPartRecord;
                p2.TakeDamage(new DamageInfo(def, amount, 0f, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                totalDamage -= num;
            }
        }
Esempio n. 3
0
        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;
            }
        }