public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
 {
     if (billDoer != null)
     {
         if (base.CheckSurgeryFailAndroid(billDoer, pawn, ingredients, part, bill))
         {
             return;
         }
         TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
         {
             billDoer,
             pawn
         });
         MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map);
     }
     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);
 }
Esempio n. 2
0
        /// <summary>
        /// Copy of vanilla's Recipe_InstallNaturalBodyPart.GetPartsToApplyOn() plus the addition of code that respects the addsHediff node
        /// in the recipe (vanilla does not). The addsHediff node is currently used in the RBSE compatibility patch to add organ rejection.
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="part"></param>
        /// <param name="billDoer"></param>
        /// <param name="ingredients"></param>
        /// <param name="bill"></param>
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            if (billDoer != null && !CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
            {
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map);
            }

            //add any hediffs in the <addsHediff> element of the recipe, after surgery involving natural body parts completes.
            if (bill.recipe.addsHediff != null && CompatibilityTracker.RBSEActive && RBSECompat.GetOrganRejectionSetting() == true)
            {
                if (part.LabelShort == "shoulder")
                {
                    //add hediff to arm bodypart
                    foreach (BodyPartRecord childPart in part.parts)
                    {
                        if (childPart.def == BodyPartDefOf.Arm)
                        {
                            QEEMod.TryLog("Adding hediff " + bill.recipe.addsHediff.label + " to installed BodyPart " + childPart.Label);
                            pawn.health.AddHediff(bill.recipe.addsHediff, childPart);
                            return;
                        }
                    }

                    QEEMod.TryLog("No arm found in shoulder replacement!");
                }
                else
                {
                    QEEMod.TryLog("Adding hediff " + bill.recipe.addsHediff.label + " to installed BodyPart " + part.Label);
                    pawn.health.AddHediff(bill.recipe.addsHediff, part);
                }
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public static bool TryRegrowProsthetic(this HediffComp_Regeneration RegenHComp, HediffDef ProstheticHediff)
        {
            if (ProstheticHediff == null)
            {
                return(false);
            }

            Pawn           p   = RegenHComp.Pawn;
            BodyPartRecord BPR = RegenHComp.currentHediff.Part;

            Tools.Warn(p.LabelShort + " TryRegrowProsthetic - hediffdef: " + ProstheticHediff?.defName + "; BP: " + BPR?.Label);

            float BPRMaxHealth      = BPR.def.GetMaxHealth(RegenHComp.Pawn);
            float PawnBodyPartRatio = BPRMaxHealth / RegenHComp.BodyPartsHealthSum;

            MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(p, BPR, p.Position, p.Map);
            p.health.AddHediff(ProstheticHediff, BPR);

            if (RegenHComp.HasLimits)
            {
                RegenHComp.TreatmentPerformedQuality += PawnBodyPartRatio * 10;
            }

            return(p.health.hediffSet.HasHediff(ProstheticHediff, BPR));
        }
Esempio n. 5
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients,
                                         Bill bill)
        {
            TaleRecorder.RecordTale(TaleDefOf.DidSurgery, (object)billDoer, (object)pawn);

            var missingParts = BodyPartRecordsMissing(pawn);

            foreach (var record in missingParts)
            {
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, record, billDoer.Position,
                                                                          billDoer.Map);
            }
        }
Esempio n. 6
0
 public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
 {
     if (billDoer != null)
     {
         if (base.CheckSurgeryFailAndroid(billDoer, pawn, ingredients, part, bill))
         {
             return;
         }
         TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
         {
             billDoer,
             pawn
         });
         MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map);
     }
 }
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            CompHediffStorage comp = ingredients.Select(x => x.TryGetComp <CompHediffStorage>()).Where(x => x != null).RandomElementWithFallback();

            if (comp == null)
            {
                return;
            }
            if (billDoer == null)
            {
                return;
            }

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

            TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
            {
                billDoer,
                pawn
            });
            MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map);
            if (IsViolationOnPawn(pawn, part, Faction.OfPlayer))
            {
                ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
                ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(comp.parent.def.label));
            }

            for (int i = 0; i < comp.hediffs.Count; i++)
            {
                var            hediff        = comp.hediffs[i];
                var            installedPart = comp.parts[i];
                BodyPartRecord target        = pawn.RaceProps.body.AllParts.Where(x => x.def == installedPart && HealthHelper.IsParent(part, x)).FirstOrDefault();

                hediff.pawn = pawn;
                pawn.health.AddHediff(hediff, target, null, null);
            }
        }
Esempio n. 8
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)

            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);
            }

            // END VANILLA CODE
            else if (pawn.Map != null)
            {
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, pawn.Position, pawn.Map);
            }
            else
            {
                pawn.health.RestorePart(part, null, true);
            }

            // iterate over non null CompIncludedChildParts in ingredients
            foreach (CompIncludedChildParts compChildParts
                     in from x in ingredients
                     where x is ThingWithComps                                           // out of every thingwithcomps ingredient
                     let comp = (x as ThingWithComps).GetComp <CompIncludedChildParts>() // take the comp
                                where comp?.IncludedParts != null
                                select comp)
            {
                compChildParts.RecursiveInstallation(pawn, part);
            }
        }
Esempio n. 9
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);
                }
            }
        }