예제 #1
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;
            }
        }