/// <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); } } }
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)); } }
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); }
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); }
public override IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) { IEnumerable <BodyPartRecord> parts = pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null); using (IEnumerator <BodyPartRecord> enumerator = parts.GetEnumerator()) { while (enumerator.MoveNext()) { BodyPartRecord part = enumerator.Current; if (pawn.health.hediffSet.HasDirectlyAddedPartFor(part) && pawn.health.hediffSet.hediffs.Any((Hediff d) => !(d is Hediff_AddedPartSystem) && d.Part == part)) { if (!pawn.health.hediffSet.AncestorHasDirectlyAddedParts(part)) { yield return(part); } } else if (MedicalRecipesUtility.IsCleanAndDroppable(pawn, part) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(part)) { yield return(part); } else if (part != pawn.RaceProps.body.corePart && part.def.canSuggestAmputation && pawn.health.hediffSet.hediffs.Any((Hediff d) => !(d is Hediff_Injury) && d.def.isBad && d.Visible && d.Part == part)) { yield return(part); } } } yield break; }
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)); }
public static IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn) { IEnumerable <BodyPartRecord> parts = pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null); using (IEnumerator <BodyPartRecord> enumerator = parts.GetEnumerator()) { while (enumerator.MoveNext()) { BodyPartRecord part = enumerator.Current; var check1 = pawn.health.hediffSet.hediffs.Any((Hediff d) => !d.def.HasComp(typeof(HediffComp_PartSystem)) && d.Part == part); var check2 = pawn.health.hediffSet.hediffs.Any((Hediff d) => !(d is Hediff_SurgerySupport) && d.Part == part); var check3 = pawn.health.hediffSet.hediffs.Any((Hediff d) => !(d is Hediff_Injury || d is Hediff_SurgerySupport) && d.def.isBad && d.Visible && d.Part == part); if (pawn.health.hediffSet.HasDirectlyAddedPartFor(part) && check1 && check2) { if (!pawn.health.hediffSet.AncestorHasDirectlyAddedParts(part)) { yield return(part); } } else if (MedicalRecipesUtility.IsCleanAndDroppable(pawn, part) && !pawn.health.hediffSet.AncestorHasDirectlyAddedParts(part)) { yield return(part); } else if (part != pawn.RaceProps.body.corePart && part.def.canSuggestAmputation && check3) { yield return(part); } } } yield break; }
static void ApplyOnPawnPostfix(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { if (MedicalRecipesUtility.IsCleanAndDroppable(pawn, part) && bill.recipe.addsHediff != null) { pawn.health.AddHediff(bill.recipe.addsHediff, part); } }
/// <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; }
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)); } }
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)); } }
public override IEnumerable <BodyPartRecord> GetPartsToApplyOn( Pawn pawn, RecipeDef recipe) => MedicalRecipesUtility.GetFixedPartsToApplyOn(recipe, pawn, (Func <BodyPartRecord, bool>)(record => pawn.health.hediffSet.GetNotMissingParts().Contains <BodyPartRecord>(record) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(record) && !pawn.health.hediffSet.hediffs.Any <Hediff>((Predicate <Hediff>)(x => { if (x.Part != record) { return(false); } return(x.def == recipe.addsHediff); }))));
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; } } } } } }
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); } }
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); }
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); } }
public override IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) { return(MedicalRecipesUtility.GetFixedPartsToApplyOn(recipe, pawn, delegate(BodyPartRecord record) { if (!pawn.health.hediffSet.GetNotMissingParts().Contains(record)) { return false; } if (pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(record)) { return false; } return (!pawn.health.hediffSet.hediffs.Any((Hediff x) => x.Part == record && (x.def == recipe.addsHediff || !recipe.CompatibleWithHediff(x.def)))) ? true : false; })); }
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 IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) { return(MedicalRecipesUtility.GetFixedPartsToApplyOn(recipe, pawn, delegate(BodyPartRecord record) { IEnumerable <Hediff> source = pawn.health.hediffSet.hediffs.Where((Hediff x) => x.Part == record); if (source.Count() == 1 && source.First().def == recipe.addsHediff) { return false; } if (record.parent != null && !pawn.health.hediffSet.GetNotMissingParts().Contains(record.parent)) { return false; } return (!pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(record) || pawn.health.hediffSet.HasDirectlyAddedPartFor(record)) ? true : false; })); }
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); } } }
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); } }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { bool flag1 = pawn.health.hediffSet.hediffs.Any((Hediff d) => (d is Hediff_AddedPartModule) && d.Part == 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); } if (flag1) { pawn.health.RestorePart(part, null, true); Hediff_BodyPartModule hediff_BodyPartModule = (Hediff_BodyPartModule)HediffMaker.MakeHediff(MSE_HediffDefOf.MSE_BodyPartModule, pawn, null); hediff_BodyPartModule.Part = part; pawn.health.hediffSet.AddDirect(hediff_BodyPartModule, null, null); } else { 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 (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null) { Faction faction1 = pawn.Faction; Faction faction2 = billDoer.Faction; int goodwillChange = -20; string reason = "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort); GlobalTargetInfo?lookTarget = new GlobalTargetInfo?(pawn); faction1.TryAffectGoodwillWith(faction2, goodwillChange, true, true, reason, lookTarget); } }
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); } }
/// <summary> /// If the part is clean it returns it as item /// </summary> /// <param name="pawn">The pawn from which to check if the parts are ok</param> /// <param name="part">The part to drop as item</param> /// <returns>The Thing corresponding to the part if it is clean, with eventual subparts</returns> public static Thing MakeNaturalPartIfClean(Pawn pawn, BodyPartRecord part) { if (MedicalRecipesUtility.IsCleanAndDroppable(pawn, part)) { Thing item = ThingMaker.MakeThing(part.def.spawnThingOnRemoved); if (item is ThingWithComps itemWithComps) { AddSubparts(ref itemWithComps, pawn, part); } return(item); } else { return(null); } }
public override IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) { // don't add natural parts to prosthetics return (MedicalRecipesUtility.GetFixedPartsToApplyOn(recipe, pawn, ( BodyPartRecord record ) => // part has some hediff pawn.health.hediffSet.hediffs.Any(( Hediff x ) => x.Part == record) // parent is not missing && (record.parent == null || pawn.health.hediffSet.GetNotMissingParts().Contains(record.parent)) // parent is not an added part or is not solid (mainly for mutant arms and legs) && (record.parent == null || !pawn.health.hediffSet.HasDirectlyAddedPartFor(record.parent) || !record.parent.def.IsSolid(record.parent, pawn.health.hediffSet.hediffs)) // is compatible with parent && !recipe.HasRestrictionsForPart(record, pawn.health.hediffSet) // part shouldn't be ignored && !pawn.health.hediffSet.PartShouldBeIgnored(record))); }
public override IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) { return(MedicalRecipesUtility.GetFixedPartsToApplyOn(recipe, pawn, delegate(BodyPartRecord record) { IEnumerable <Hediff> alreadyPresent = from x in pawn.health.hediffSet.hediffs where x.Part == record where x.def == recipe.addsHediff select x; return // hediff not already present !alreadyPresent.Any() // has something to attach to && (record.parent == null || pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null).Contains(record.parent)) // is compatible with parent && !recipe.HasRestrictionsForPart(record, pawn.health.hediffSet) // part shouldn't be ignored && !pawn.health.hediffSet.PartShouldBeIgnored(record); })); }
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); } } } }
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)); } }
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); } }
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); } }