Пример #1
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;
            }
        }