コード例 #1
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = !PawnGenerator.IsBeingGenerated(pawn) && IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (CheckSurgeryFailCustom(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map);
                if (flag && flag2 && part.def.spawnThingOnRemoved != null)
                {
                    ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
                }
                if (flag2)
                {
                    ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(recipe.addsHediff.label));
                }
            }
            else if (pawn.Map != null)
            {
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, pawn.Position, pawn.Map);
            }
            else
            {
                pawn.health.RestorePart(part);
            }
            pawn.health.AddHediff(recipe.addsHediff, part);
        }
コード例 #2
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            // part = brain
            var spine = pawn.health.hediffSet.GetSpine();

            bool isClean     = MedicalRecipesUtility.IsClean(pawn, part);
            bool isViolation = IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }

                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                GenSpawn.Spawn(AutomataRaceDefOf.PN_Brain, billDoer.Position, billDoer.Map);
            }

            pawn.TakeDamage(new DamageInfo(DamageDefOf.SurgicalCut, 99999f, 999f, -1f, null, part));
            pawn.health.AddHediff(HediffDefOf.MissingBodyPart, spine, new DamageInfo(DamageDefOf.SurgicalCut, 99999f, 999f, -1f, null, spine));

            if (isClean)
            {
                if (pawn.Dead)
                {
                    ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting);
                }
                ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
            }
            if (isViolation)
            {
                ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort));
            }
        }
        /// <summary>
        /// Generates a list of all Things that can be dropped from a part and its subparts
        /// </summary>
        /// <param name="pawn">Pawn from which to check hediffs</param>
        /// <param name="part">From where to look for hediffs</param>
        /// <param name="pos">Position where to drop natural subparts</param>
        /// <param name="map">Map where to drop natural subparts</param>
        /// <returns>All Things that hediffs from part and childparts can drop, with subparts inserted into the correct parent</returns>
        public static IEnumerable <Thing> MakeThingsFromHediffs(Pawn pawn, BodyPartRecord part, IntVec3 pos, Map map)
        {
            // stop if the part is missing
            if (!pawn.health.hediffSet.GetNotMissingParts().Contains(part))
            {
                yield break;
            }

            /// Things that can be made from all subPart hediffs
            List <Thing> subThings = new List <Thing>();

            foreach (BodyPartRecord subPart in part.GetDirectChildParts())                  // for each subpart
            {
                if (!MedicalRecipesUtility.IsClean(pawn, part))                             // If parent is not clean
                {
                    MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, subPart, pos, map); // try to make natural parts out of children
                }

                // add each thing coming from the child hediffs
                subThings.AddRange(MakeThingsFromHediffs(pawn, subPart, pos, map));
            }

            // for every thing makeable from hediffs on this part: add subparts if possible then return it
            List <Thing> items = new List <Thing>();

            foreach (Hediff hediff in from x in pawn.health.hediffSet.hediffs
                     where x.Part == part
                     select x)                              // for every hediff on the part
            {
                if (hediff.def.spawnThingOnRemoved != null) // if it spawns an item
                {
                    Thing item = ThingMaker.MakeThing(hediff.def.spawnThingOnRemoved);

                    if (item is ThingWithComps itemWithComps)   // compose if possible
                    {
                        AddSubparts(itemWithComps, subThings);
                    }

                    items.Add(item);
                }
            }

            // merge siblings
            for (int i = items.Count - 1; i >= 0; i--)
            {
                if (items[i] is ThingWithComps)
                {
                    AddSubparts(items[i] as ThingWithComps, items, false);
                }
            }

            // return all
            foreach (Thing item in items.Concat(subThings))
            {
                yield return(item);
            }

            yield break;
        }
コード例 #4
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            MedicalRecipesUtility.IsClean(pawn, part);
            bool flag = this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                List <Hediff> hediffs = new List <Hediff>();
                hediffs.Clear();
                string textHediffs = string.Empty;
                foreach (Hediff tempHediff in pawn.health.hediffSet.hediffs)
                {
                    if (tempHediff is Hediff_Implant && tempHediff.Part == part && tempHediff.Visible && !(tempHediff is Hediff_AddedPart))
                    {
                        textHediffs += "*" + tempHediff.LabelCap;
                        hediffs.Add(tempHediff);
                    }
                }
                if (!hediffs.NullOrEmpty())
                {
                    if (PawnUtility.ShouldSendNotificationAbout(pawn) || PawnUtility.ShouldSendNotificationAbout(billDoer))
                    {
                        Messages.Message("PolarisMessageSuccessfullyRemovedImplants".Translate(billDoer.LabelShort, pawn.LabelShort, textHediffs), pawn, MessageTypeDefOf.PositiveEvent);
                    }
                    for (int i = hediffs.Count - 1; i >= 0; i--)
                    {
                        pawn.health.RemoveHediff(hediffs[i]);
                        if (hediffs[i].def.spawnThingOnRemoved != null)
                        {
                            if (hediffs[i] is Hediff_ImplantWithLevel levelHediff)
                            {
                                int count = levelHediff.level;
                                for (int j = 0; j < count; j++)
                                {
                                    GenSpawn.Spawn(hediffs[i].def.spawnThingOnRemoved, billDoer.Position, billDoer.Map, WipeMode.Vanish);
                                }
                            }
                            else
                            {
                                GenSpawn.Spawn(hediffs[i].def.spawnThingOnRemoved, billDoer.Position, billDoer.Map, WipeMode.Vanish);
                            }

                            /*Thing thing = ThingMaker.MakeThing(hediffs[i].def.spawnThingOnRemoved);
                             * GenPlace.TryPlaceThing(thing, pawn.Position, pawn.Map, ThingPlaceMode.Near);*/
                        }
                    }
                }
            }
            if (flag)
            {
                base.ReportViolation(pawn, billDoer, pawn.FactionOrExtraHomeFaction, -70, "GoodwillChangedReason_RemovedImplant".Translate(part.LabelShort));
            }
        }
コード例 #5
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            MedicalRecipesUtility.IsClean(pawn, part);
            bool flag = IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                if (!pawn.health.hediffSet.GetNotMissingParts().Contains(part))
                {
                    return;
                }

                var hediff = pawn.health.hediffSet.GetFirstHediffOfDef(AlteredCarbonDefOf.AC_CorticalStack) as Hediff_CorticalStack;
                if (hediff != null)
                {
                    if (hediff.def.spawnThingOnRemoved != null)
                    {
                        var corticalStack = ThingMaker.MakeThing(hediff.def.spawnThingOnRemoved) as CorticalStack;
                        hediff.SavePawn(pawn);
                        corticalStack.SavePawnFromHediff(hediff);
                        corticalStack.gender = hediff.gender;
                        corticalStack.race   = hediff.race;
                        //if (hediff.stackGroupID == 0)
                        //{
                        //	corticalStack.stackGroupID = ACUtils.ACTracker.GetStackGroupID(corticalStack);
                        //}
                        GenPlace.TryPlaceThing(corticalStack, billDoer.Position, billDoer.Map, ThingPlaceMode.Near);
                        if (ACUtils.ACTracker.stacksIndex == null)
                        {
                            ACUtils.ACTracker.stacksIndex = new Dictionary <string, CorticalStack>();
                        }
                        ACUtils.ACTracker.stacksIndex[pawn.ThingID + pawn.Name] = corticalStack;
                        ACUtils.ACTracker.ReplacePawnWithStack(pawn, corticalStack);
                        ACUtils.ACTracker.RegisterSleeve(pawn, hediff.stackGroupID);
                        //Log.Message("corticalStack.stackGroupID: " + corticalStack.stackGroupID, true);
                        //Log.Message("hediff.stackGroupID: " + hediff.stackGroupID, true);
                    }
                    ACUtils.ACTracker.deadPawns.Add(pawn);
                    var head = pawn.health.hediffSet.GetNotMissingParts().FirstOrDefault((BodyPartRecord x) => x.def == BodyPartDefOf.Head);
                    if (head != null)
                    {
                        pawn.TakeDamage(new DamageInfo(DamageDefOf.SurgicalCut, 99999f, 999f, -1f, null, head));
                    }
                    pawn.health.RemoveHediff(hediff);
                }
            }
            if (flag)
            {
                ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_RemovedImplant".Translate(part.LabelShort));
            }
        }
コード例 #6
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = !PawnGenerator.IsBeingGenerated(pawn) && IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);

                if (flag && flag2 && part.def.spawnThingOnRemoved != null)
                {
                    ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn, billDoer);
                }
                if (flag2)
                {
                    ReportViolation(pawn, billDoer, pawn.HomeFaction, -70);
                }
                if (ModsConfig.IdeologyActive)
                {
                    Find.HistoryEventsManager.RecordEvent(new HistoryEvent(HistoryEventDefOf.InstalledProsthetic, billDoer.Named(HistoryEventArgsNames.Doer)));
                }
            }

            else
            {
                pawn.health.RestorePart(part);
            }
            pawn.health.AddHediff(recipe.addsHediff, part);

            if (recipe?.addsHediff != null && ingredients != null)
            {
                var hediff = pawn.health?.hediffSet?.hediffs?.FindLast(x => x.def == recipe.addsHediff);

                if (hediff != null)
                {
                    var comp = hediff.TryGetComp <HediffCompImplantQuality>();
                    if (comp != null)
                    {
                        foreach (var ingredient in ingredients)
                        {
                            if (ingredient != null && hediff.def.spawnThingOnRemoved == ingredient.def && ingredient.TryGetQuality(out var qualityCategory))
                            {
                                comp.quality = qualityCategory;
                                comp.SelectSeverity(qualityCategory);
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
            static void SpawnNaturalPartIfCleanPostfix(ref Thing __result, Pawn pawn, BodyPartRecord part, IntVec3 pos, Map map)
            {
                bool isOrganTransplant         = false;
                bool shouldDropTransplantOrgan = false;
                int  badHediffCount            = 0;

                foreach (Hediff currHediff in pawn.health.hediffSet.hediffs)
                {
                    if (currHediff.Part == part)
                    {
                        QEEMod.TryLog("Hediff on this body part: " + currHediff.def.defName + " isBad: " + currHediff.def.isBad);
                        if (currHediff.def == QEHediffDefOf.QE_OrganRejection)
                        {
                            isOrganTransplant = true;
                        }
                        else if (currHediff.def.isBad)
                        {
                            badHediffCount++;
                        }
                    }
                }

                //if the only hediff on bodypart is organ rejection, that organ should spawn
                //vanilla game would not spawn it, because part hediffs > 0
                if (isOrganTransplant && badHediffCount == 0 && part.def.spawnThingOnRemoved != null)
                {
                    shouldDropTransplantOrgan = true;
                }

                QEEMod.TryLog("shouldDropTransplantOrgan: " + shouldDropTransplantOrgan + " [isOrganTransplant: " +
                              isOrganTransplant + " " + part.LabelShort + " bad hediffs: " + badHediffCount + "]");

                //spawn a biological arm when a shoulder is removed with a healthy arm attached
                if (part.LabelShort == "shoulder")
                {
                    foreach (BodyPartRecord childPart in part.parts)
                    {
                        bool isHealthy = MedicalRecipesUtility.IsClean(pawn, childPart);
                        QEEMod.TryLog("body part: " + childPart.LabelShort + " defName: " + childPart.def.defName +
                                      " healthy: " + isHealthy);

                        if (childPart.def == BodyPartDefOf.Arm && isHealthy && (shouldDropTransplantOrgan = true ||
                                                                                                            isOrganTransplant == false))
                        {
                            QEEMod.TryLog("Spawn natural arm from shoulder replacement");
                            __result = GenSpawn.Spawn(QEThingDefOf.QE_Organ_Arm, pos, map);
                        }
                    }
                }
                else if (shouldDropTransplantOrgan)
                {
                    __result = GenSpawn.Spawn(part.def.spawnThingOnRemoved, pos, map);
                }
            }
コード例 #8
0
        public static bool IsChildrenClean(Pawn pawn, BodyPartRecord part)
        {
            IEnumerable <BodyPartRecord> allChildParts = HarmonyPatches.GetAllChildParts(part);

            foreach (BodyPartRecord bodyPartRecord in allChildParts)
            {
                if (!MedicalRecipesUtility.IsClean(pawn, bodyPartRecord))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #9
0
        public override IEnumerable <BodyPartRecord> GetPartsToApplyOn(
            Pawn pawn,
            RecipeDef recipeDef
            )
        {
            IEnumerable <BodyPartRecord> parts =
                pawn.health.hediffSet.GetNotMissingParts(tag: Defs_Rimworld.EyeTag);

            foreach (BodyPartRecord part in parts.DefaultIfEmpty())
            {
                if (!pawn.health.hediffSet.HasDirectlyAddedPartFor(part) &&
                    MedicalRecipesUtility.IsClean(pawn, part))
                {
                    yield return(part);
                }
            }
        }
コード例 #10
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag1 = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
                {
                    billDoer,
                    pawn
                });
                MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, part, billDoer.Position, billDoer.Map);
                MedicalRecipesUtility.SpawnThingsFromHediffs(pawn, part, billDoer.Position, billDoer.Map);
            }

            DamageDef surgicalCut      = DamageDefOf.SurgicalCut;
            float     amount           = 99999f;
            float     armorPenetration = 999f;

            pawn.TakeDamage(new DamageInfo(surgicalCut, amount, armorPenetration, -1f, null, part, null, DamageInfo.SourceCategory.ThingOrUnknown, null));

            if (flag1)
            {
                if (pawn.Dead)
                {
                    ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting);
                }
                ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
            }

            if (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null)
            {
                Faction          faction        = pawn.Faction;
                Faction          faction2       = billDoer.Faction;
                int              goodwillChange = -15;
                string           reason         = "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort);
                GlobalTargetInfo?lookTarget     = new GlobalTargetInfo?(pawn);
                faction.TryAffectGoodwillWith(faction2, goodwillChange, true, true, reason, lookTarget);
            }
        }
コード例 #11
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            base.ApplyOnPawn(pawn, part, billDoer, ingredients, bill);

            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
                {
                    billDoer,
                    pawn
                });
                Thing md = ThingMaker.MakeThing(WTH_DefOf.WTH_ExtractedBrainData);
                md.stackCount = 3 + pawn.skills.GetSkill(SkillDefOf.Intellectual).Level;
                GenPlace.TryPlaceThing(md, pawn.Position, pawn.Map, ThingPlaceMode.Near);
            }
            DamageDef surgicalCut      = DamageDefOf.SurgicalCut;
            float     amount           = 99999f;
            float     armorPenetration = 999f;

            pawn.TakeDamage(new DamageInfo(surgicalCut, amount, armorPenetration, -1f, null, part, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
            if (flag)
            {
                if (pawn.Dead)
                {
                    ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting);
                }
                ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
            }
            if (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null)
            {
                Faction          arg_120_0      = pawn.Faction;
                Faction          faction        = billDoer.Faction;
                int              goodwillChange = -15;
                string           reason         = "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort);
                GlobalTargetInfo?lookTarget     = new GlobalTargetInfo?(pawn);
                arg_120_0.TryAffectGoodwillWith(faction, goodwillChange, true, true, reason, lookTarget);
            }
        }
コード例 #12
0
            static void SpawnNaturalPartIfCleanPostfix(ref Thing __result, Pawn pawn, BodyPartRecord part, IntVec3 pos, Map map)
            {
                //spawn a biological arm when a shoulder is removed with a healthy arm attached (e.g. from installing a prosthetic on a healthy arm)
                if (part.LabelShort == "shoulder")
                {
                    foreach (BodyPartRecord childPart in part.parts)
                    {
                        bool isHealthy = MedicalRecipesUtility.IsClean(pawn, childPart);
                        QEEMod.TryLog("body part: " + childPart.LabelShort + " IsClean: " + isHealthy);

                        if (childPart.def == BodyPartDefOf.Arm && isHealthy)
                        {
                            QEEMod.TryLog("Spawn natural arm from shoulder replacement");
                            __result = GenSpawn.Spawn(QEThingDefOf.QE_Organ_Arm, pos, map);
                        }
                    }
                }
            }
コード例 #13
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            MedicalRecipesUtility.IsClean(pawn, part);
            bool flag = IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                if (!pawn.health.hediffSet.GetNotMissingParts().Contains(part))
                {
                    return;
                }

                var hediff = pawn.health.hediffSet.GetFirstHediffOfDef(AlteredCarbonDefOf.AC_CorticalStack) as Hediff_CorticalStack;
                if (hediff != null)
                {
                    if (hediff.def.spawnThingOnRemoved != null)
                    {
                        var corticalStack = ThingMaker.MakeThing(hediff.def.spawnThingOnRemoved) as CorticalStack;
                        hediff.SavePawn(pawn);
                        corticalStack.SavePawnFromHediff(hediff);
                        corticalStack.gender = hediff.gender;
                        GenPlace.TryPlaceThing(corticalStack, billDoer.Position, billDoer.Map, ThingPlaceMode.Near);
                        if (ACUtils.ACTracker.stacksIndex == null)
                        {
                            ACUtils.ACTracker.stacksIndex = new Dictionary <string, CorticalStack>();
                        }
                        ACUtils.ACTracker.stacksIndex[pawn.ThingID + pawn.Name] = corticalStack;
                        ACUtils.ACTracker.RegisterSleeve(pawn);
                        ACUtils.ACTracker.ReplacePawnWithStack(pawn, corticalStack);
                    }
                    pawn.health.RemoveHediff(hediff);
                    ACUtils.ACTracker.deadPawns.Add(pawn);
                }
            }
            if (flag)
            {
                ReportViolation(pawn, billDoer, pawn.FactionOrExtraHomeFaction, -70, "GoodwillChangedReason_RemovedImplant".Translate(part.LabelShort));
            }
        }
コード例 #14
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            // START VANILLA CODE (couldn't know if the surgery was successfull)

            bool partIsClean = MedicalRecipesUtility.IsClean(pawn, part);
            bool isViolation = !PawnGenerator.IsBeingGenerated(pawn) && this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
                {
                    billDoer,
                    pawn
                });
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map);
                if (partIsClean && isViolation && part.def.spawnThingOnRemoved != null)
                {
                    ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
                }
                if (isViolation)
                {
                    base.ReportViolation(pawn, billDoer, pawn.FactionOrExtraHomeFaction, -70, "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(this.recipe.addsHediff.label));
                }
            }
            else if (pawn.Map != null)
            {
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, pawn.Position, pawn.Map);
            }
            else
            {
                pawn.health.RestorePart(part, null, true);
            }
            pawn.health.AddHediff(this.recipe.addsHediff, part, null, null);

            // END VANILLA CODE

            if (!ingredients.NullOrEmpty())
            {
                // iterate over non null CompIncludedChildParts in ingredients
                foreach (CompIncludedChildParts compChildParts in
                         from x in ingredients
                         let comp = x.TryGetComp <CompIncludedChildParts>() // take the comp
                                    where comp?.IncludedParts != null
                                    select comp)
                {
                    compChildParts.RecursiveInstallation(pawn, part);
                }
            }
            else
            {
                foreach (CompProperties_IncludedChildParts compProp in
                         (this.recipe.fixedIngredientFilter?.AllowedThingDefs ?? Enumerable.Empty <ThingDef>())
                         .Select(td => td.GetCompProperties <CompProperties_IncludedChildParts>())
                         .Where(c => c != null))
                {
                    compProp.RecursiveDefInstallation(pawn, part);
                }
            }
        }
コード例 #15
0
        // Token: 0x06001463 RID: 5219 RVA: 0x0009DD5C File Offset: 0x0009C15C
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
                {
                    billDoer,
                    pawn
                });
                if (PawnUtility.ShouldSendNotificationAbout(pawn) || PawnUtility.ShouldSendNotificationAbout(billDoer))
                {
                    string text;
                    if (!this.recipe.successfullyRemovedHediffMessage.NullOrEmpty())
                    {
                        text = string.Format(this.recipe.successfullyRemovedHediffMessage, billDoer.LabelShort, pawn.LabelShort);
                    }
                    else
                    {
                        text = "MessageSuccessfullyRemovedHediff".Translate(billDoer.LabelShort, pawn.LabelShort, this.recipe.removesHediff.label.Named("HEDIFF"), billDoer.Named("SURGEON"), pawn.Named("PATIENT"));
                    }
                    Messages.Message(text, pawn, MessageTypeDefOf.PositiveEvent, true);
                }
            }
            Hediff hediff = pawn.health.hediffSet.hediffs.Find((Hediff x) => x.def == this.recipe.removesHediff && x.Part == part);

            if (hediff != null)
            {
                pawn.health.RemoveHediff(hediff);
                DamageDef surgicalCut      = DamageDefOf.SurgicalCut;
                float     amount           = 99999f;
                float     armorPenetration = 999f;
                pawn.TakeDamage(new DamageInfo(surgicalCut, amount, armorPenetration, -1f, null, part, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                if (flag)
                {
                    if (pawn.Dead)
                    {
                        ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting);
                    }
                    ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
                }
                if (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null)
                {
                    Faction          faction        = pawn.Faction;
                    Faction          faction2       = billDoer.Faction;
                    int              goodwillChange = -15;
                    string           reason         = "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort);
                    GlobalTargetInfo?lookTarget     = new GlobalTargetInfo?(pawn);
                    faction.TryAffectGoodwillWith(faction2, goodwillChange, true, true, reason, lookTarget);
                }
            }

            /*
             * bool flag = MedicalRecipesUtility.IsClean(pawn, part);
             * bool flag2 = this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);
             * if (billDoer != null)
             * {
             *  if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
             *  {
             *      return;
             *  }
             *  TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
             *  {
             *      billDoer,
             *      pawn
             *  });
             *  MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, part, billDoer.Position, billDoer.Map);
             *  MedicalRecipesUtility.SpawnThingsFromHediffs(pawn, part, billDoer.Position, billDoer.Map);
             * }
             * DamageDef surgicalCut = DamageDefOf.SurgicalCut;
             * float amount = 99999f;
             * float armorPenetration = 999f;
             * pawn.TakeDamage(new DamageInfo(surgicalCut, amount, armorPenetration, -1f, null, part, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
             * if (flag)
             * {
             *  if (pawn.Dead)
             *  {
             *      ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting);
             *  }
             *  ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
             * }
             * if (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null)
             * {
             *  Faction faction = pawn.Faction;
             *  Faction faction2 = billDoer.Faction;
             *  int goodwillChange = -15;
             *  string reason = "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort);
             *  GlobalTargetInfo? lookTarget = new GlobalTargetInfo?(pawn);
             *  faction.TryAffectGoodwillWith(faction2, goodwillChange, true, true, reason, lookTarget);
             * }
             */
        }