public bool TryAddPawnForModification(Pawn pawn, RecipeDef recipeDef) { if ((!pawn.IsHacked() || (pawn.IsHacked() && pawn.Faction != Faction.OfPlayer))) { Bill_Medical bill = new Bill_Medical(recipeDef); IEnumerable <BodyPartRecord> bodyparts = RecipeUtility.GetPartsToApplyOn(pawn, bill.recipe); if (bodyparts.Count() == 0) { return(false); } if (pawn.health.surgeryBills.FirstShouldDoNow == null || pawn.health.surgeryBills.FirstShouldDoNow.recipe != WTH_DefOf.WTH_HackMechanoid) { pawn.health.surgeryBills.AddBill(bill); bill.Part = bodyparts.First(); } } Need_Power powerNeed = pawn.needs.TryGetNeed <Need_Power>(); if (powerNeed != null) { //discharge mech battery so pawns can work safely. powerNeed.CurLevel = 0; } pawn.jobs.TryTakeOrderedJob(new Job(WTH_DefOf.WTH_Mechanoid_Rest, this)); if (pawn.jobs.curDriver != null) { pawn.jobs.posture = PawnPosture.LayingInBed; } return(true); }
public bool TryAddPawnForModification(Pawn pawn, RecipeDef recipeDef) { Bill_Medical bill = new Bill_Medical(recipeDef); IEnumerable <BodyPartRecord> bodyparts = RecipeUtility.GetPartsToApplyOn(pawn, bill.recipe); if (pawn.health.surgeryBills.FirstShouldDoNow == null || pawn.health.surgeryBills.FirstShouldDoNow.recipe != WTH_DefOf.WTH_HackMechanoid && pawn.health.surgeryBills.FirstShouldDoNow.recipe != WTH_DefOf.WTH_InduceEmergencySignal) { pawn.health.surgeryBills.AddBill(bill); bill.Part = bodyparts.FirstOrDefault(); } /* * Need_Power powerNeed = pawn.needs.TryGetNeed<Need_Power>(); * if (powerNeed != null) * { * //discharge mech battery so pawns can work safely. * powerNeed.CurLevel = 0; * } */ pawn.jobs.StartJob(new Job(WTH_DefOf.WTH_Mechanoid_Rest, this), JobCondition.InterruptForced); if (pawn.jobs.curDriver != null) { pawn.jobs.posture = PawnPosture.LayingInBed; } return(true); }
static void Postfix(Bill_Medical __instance, ref bool __result) { Pawn pawn = Traverse.Create(__instance).Property("GiverPawn").GetValue <Pawn>(); if (__instance.recipe == WTH_DefOf.WTH_HackMechanoid && pawn.OnHackingTable() && !((Building_HackingTable)pawn.CurrentBed()).HasPowerNow()) { __result = false; } }
public static bool Affects(this Bill_Medical bill, PawnCapacityDef capacity) { if (bill?.recipe == null) { return(false); } return(bill.recipe.AddsHediffThatAffects(capacity, -1) || bill.recipe.AdministersDrugThatAffects(capacity, -1) || bill.recipe.addsHediff.IsAddedPart() && bill.Part.Affects(capacity)); }
public void addSurgeryIfNotAlready(List <Pawn> pawns, SurgeryOption surgery) { foreach (Pawn pawn in pawns) { if (canPawnGetSurgery(pawn, surgery) && !doesPawnAlreadyHaveSurgery(pawn, surgery)) { Bill_Medical bm = new Bill_Medical(surgery.recipe); pawn.BillStack.AddBill(bm); bm.Part = surgery.part; } } }
private Job GetMedicalBillJob(Pawn meeseeks, CompMeeseeksMemory memory, SavedJob savedJob, SavedTargetInfo jobTarget, ref JobAvailability jobAvailabilty) { Bill_Medical bill = jobTarget.bill as Bill_Medical; Job job = null; if (jobTarget != null && jobTarget.HasThing && !jobTarget.ThingDestroyed && jobTarget.Thing is Pawn && !(jobTarget.Thing as Pawn).Dead) { Pawn targetPawn = jobTarget.Thing as Pawn; if (targetPawn == null || targetPawn.Dead || !bill.CompletableEver) { bill.deleted = true; jobAvailabilty = JobAvailability.Complete; } else { MeeseeksBillStorage billStorage = Current.Game.World.GetComponent <MeeseeksBillStorage>(); BillStack billStack = targetPawn.BillStack; jobAvailabilty = JobAvailability.Delayed; if (targetPawn.UsableForBillsAfterFueling() && meeseeks.CanReserve(targetPawn, 1, -1, null, true)) { List <ThingCount> chosenIngredients = new List <ThingCount>(); // Screw you I need this function bool result = (bool)typeof(WorkGiver_DoBill).GetMethod("TryFindBestBillIngredients", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { bill, meeseeks, targetPawn, chosenIngredients }); if (result) { Job haulOffJob; job = WorkGiver_DoBill.TryStartNewDoBillJob(meeseeks, bill, targetPawn, chosenIngredients, out haulOffJob); bill.billStack.billGiver = targetPawn as IBillGiver; } if (job == null) { jobAvailabilty = JobAvailability.Delayed; } else { jobAvailabilty = JobAvailability.Available; } } } } else { bill.deleted = true; jobAvailabilty = JobAvailability.Complete; } return(job); }
// Token: 0x06000043 RID: 67 RVA: 0x00004CA0 File Offset: 0x00002EA0 private static bool GenAdminOption(Pawn patient, RecipeDef recipe, BodyPartRecord part = null) { bool result = false; if (patient != null) { Bill_Medical bill_Medical = new Bill_Medical(recipe); patient.BillStack.AddBill(bill_Medical); result = true; bill_Medical.Part = part; if (recipe.conceptLearned != null) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(recipe.conceptLearned, KnowledgeAmount.Total); } Pawn patient2 = patient; Map map = patient2?.Map; if (map != null) { if (!map.mapPawns.FreeColonists.Any((Pawn col) => recipe.PawnSatisfiesSkillRequirements(col))) { Bill.CreateNoPawnsWithSkillDialog(recipe); } if (!RestUtility.InBed(patient) && patient.RaceProps.IsFlesh) { if (patient.RaceProps.Humanlike) { if (!GenCollection.Any(map.listerBuildings.allBuildingsColonist, (Building x) => x is Building_Bed bed && RestUtility.CanUseBedEver(patient, x.def) && bed.Medical)) { Messages.Message(Translator.Translate("MessageNoMedicalBeds"), patient, MessageTypeDefOf.CautionInput, false); } } else if (!GenCollection.Any <Building>(map.listerBuildings.allBuildingsColonist, (Building x) => x is Building_Bed && RestUtility.CanUseBedEver(patient, x.def))) { Messages.Message(Translator.Translate("MessageNoAnimalBeds"), patient, MessageTypeDefOf.CautionInput, false); } } if (patient.Faction != null && !patient.Faction.def.hidden && !FactionUtility.HostileTo(patient.Faction, Faction.OfPlayer) && recipe.Worker.IsViolationOnPawn(patient, part, Faction.OfPlayer)) { Messages.Message(TranslatorFormattedStringExtensions.Translate("MessageMedicalOperationWillAngerFaction", patient.Faction), patient, MessageTypeDefOf.CautionInput, false); } ThingDef minRequiredMedicine = MSAddDrugBill.GetMinRequiredMedicine(recipe); if (minRequiredMedicine != null && patient.playerSettings != null && !MedicalCareUtility.AllowsMedicine(patient.playerSettings.medCare, minRequiredMedicine)) { Messages.Message(TranslatorFormattedStringExtensions.Translate("MessageTooLowMedCare", minRequiredMedicine.label, patient.LabelShort, MedicalCareUtility.GetLabel(patient.playerSettings.medCare), NamedArgumentUtility.Named(patient, "PAWN")), patient, MessageTypeDefOf.CautionInput, false); } } } return(result); }
//Bill_Medical public static bool Notify_DoBillStarted_Debug(Bill_Medical __instance, Pawn billDoer) { if (__instance.recipe == VampDefOf.ROMV_ExtractBloodPack || __instance.recipe == VampDefOf.ROMV_ExtractBloodVial || __instance.recipe == VampDefOf.ROMV_ExtractBloodWine) { //Pawn GiverPawn = (Pawn)AccessTools.Method(typeof(Bill_Medical), "get_GiverPawn").Invoke(__instance, null); //if (!GiverPawn.Dead && __instance.recipe.anesthetize && HealthUtility.TryAnesthetize(GiverPawn)) //{ //} return(false); } return(true); }
public bool doesPawnAlreadyHaveSurgery(Pawn pawn, SurgeryOption surgery) { foreach (Bill b in pawn.BillStack.Bills) { if (b is Bill_Medical) { Bill_Medical existing = (Bill_Medical)b; if (existing.recipe == surgery.recipe) { if (existing.Part == surgery.part) { return(true); } } } } return(false); }
public static void Postfix(Bill_Medical __instance, Pawn billDoer) { CompMeeseeksMemory meeseeksMemory = billDoer.GetComp <CompMeeseeksMemory>(); if (meeseeksMemory != null) { foreach (SavedTargetInfo jobTarget in meeseeksMemory.jobTargets) { if (jobTarget.bill != null && !jobTarget.bill.deleted) { Bill_Medical billMedical = jobTarget.bill as Bill_Medical; if (billMedical != null && billMedical.GiverPawn == __instance.GiverPawn && billMedical.Part == __instance.Part && billMedical.recipe.defName == __instance.recipe.defName) { jobTarget.bill.deleted = true; return; } } } } }
// Token: 0x06001467 RID: 5223 RVA: 0x0009C970 File Offset: 0x0009AD70 private float GetAverageMedicalPotency(List <Thing> ingredients, Bill bill) { Bill_Medical bill_Medical = bill as Bill_Medical; ThingDef thingDef; if (bill_Medical != null) { thingDef = bill_Medical.consumedInitialMedicineDef; } else { thingDef = null; } int num = 0; float num2 = 0f; if (thingDef != null) { num++; num2 += thingDef.GetStatValueAbstract(StatDefOf.MedicalPotency, null); } for (int i = 0; i < ingredients.Count; i++) { Medicine medicine = ingredients[i] as Medicine; if (medicine != null) { num += medicine.stackCount; num2 += medicine.GetStatValue(StatDefOf.MedicalPotency, true) * (float)medicine.stackCount; } } if (num == 0) { return(1f); } return(num2 / (float)num); }
static void Prefix(Bill_Medical __instance, Pawn billDoer) { Pawn pawn = Traverse.Create(__instance).Property("GiverPawn").GetValue <Pawn>(); if (__instance.recipe == WTH_DefOf.WTH_InduceEmergencySignal) { bool shouldCancel = false; if (Base.Instance.EmergencySignalRaidInbound()) { Messages.Message("WTH_Message_EmergencySignalRaidInbound".Translate(), new RimWorld.Planet.GlobalTargetInfo(pawn.Position, pawn.Map), MessageTypeDefOf.RejectInput); shouldCancel = true; } else if (Base.Instance.EmergencySignalRaidCoolingDown()) { Messages.Message("WTH_Message_EmgergencySignalRaidCoolingDown".Translate(), new RimWorld.Planet.GlobalTargetInfo(pawn.Position, pawn.Map), MessageTypeDefOf.RejectInput); shouldCancel = true; } if (shouldCancel) { __instance.billStack.Delete(__instance); billDoer.jobs.EndCurrentJob(Verse.AI.JobCondition.Incompletable); } } }
public float DrawMedOperationsTab(Rect leftRect, Pawn pawn, Thing thingForMedBills, float curY) { curY += 2f; Func <List <FloatMenuOption> > recipeOptionsMaker = delegate { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (RecipeDef current in thingForMedBills.def.AllRecipes) { if (current.AvailableNow) { IEnumerable <ThingDef> enumerable = current.PotentiallyMissingIngredients(null); if (!enumerable.Any((ThingDef x) => x.isBodyPartOrImplant)) { IEnumerable <BodyPartRecord> partsToApplyOn = current.Worker.GetPartsToApplyOn(pawn, current); if (partsToApplyOn.Any <BodyPartRecord>()) { foreach (BodyPartRecord current2 in partsToApplyOn) { RecipeDef localRecipe = current; BodyPartRecord localPart = current2; string text; if (localRecipe == RecipeDefOf.RemoveBodyPart) { text = RimWorld.HealthCardUtility.RemoveBodyPartSpecialLabel(pawn, current2); } else { text = localRecipe.LabelCap; } if (!current.hideBodyPartNames) { text = text + " (" + current2.def.label + ")"; } Action action = null; if (enumerable.Any <ThingDef>()) { text += " ("; bool flag = true; foreach (ThingDef current3 in enumerable) { if (!flag) { text += ", "; } flag = false; text += "MissingMedicalBillIngredient".Translate(new object[] { current3.label }); } text += ")"; } else { action = delegate { if (!Find.ListerPawns.FreeColonists.Any((Pawn col) => localRecipe.PawnSatisfiesSkillRequirements(col))) { Bill.CreateNoPawnsWithSkillDialog(localRecipe); } Pawn pawn2 = thingForMedBills as Pawn; if (pawn2 != null && !pawn.InBed() && pawn.RaceProps.Humanlike) { if (!Find.ListerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && (x as Building_Bed).Medical)) { Messages.Message("MessageNoMedicalBeds".Translate(), MessageSound.Negative); } } Bill_Medical bill_Medical = new Bill_Medical(localRecipe); pawn2.BillStack.AddBill(bill_Medical); bill_Medical.Part = localPart; if (pawn2.Faction != null && !pawn2.Faction.def.hidden && !pawn2.Faction.HostileTo(Faction.OfColony) && localRecipe.Worker.IsViolationOnPawn(pawn2, localPart, Faction.OfColony)) { Messages.Message("MessageMedicalOperationWillAngerFaction".Translate(new object[] { pawn2.Faction }), MessageSound.Negative); } }; } list.Add(new FloatMenuOption(text, action, MenuOptionPriority.Medium, null, null)); } } } } } return(list); }; Rect rect = new Rect(leftRect.x, curY, leftRect.width, leftRect.height - curY - 3f); this.DrawListing(pawn.BillStack, rect, recipeOptionsMaker, ref HealthCardUtility.billsScrollPosition, ref HealthCardUtility.billsScrollHeight); return(curY); }
private bool TryCreateBill(Dictionary <string, string> fields, out Bill_Medical bill) { bill = null; foreach (var field in fields) { string key = field.Key; string value = field.Value; switch (key) { case BREAK: return(true); case "recipeDefName": var def = DefDatabase <RecipeDef> .GetNamed(value); if (def == null) { Log.Warning("Unable to load bill with RecipeDef of [" + value + "]"); return(false); } bill = new Bill_Medical(def); break; case "suspended": bill.suspended = bool.Parse(value); break; case "part": string[] parts = value.Split(':'); if (bill.recipe.defName.StartsWith("Remove")) { bill.Part = null; string partToFind = parts[0]; foreach (BodyPartRecord part in Pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)) { if (part.Label.Equals(partToFind)) { bill.Part = part; break; } } if (bill.Part == null) { Log.Warning("Pawn [" + Pawn.Name.ToStringShort + "] does not have body part [" + partToFind + "] to have removed."); return(false); } } else if (bill.recipe.defName.StartsWith("Install")) { string partToFind = parts[1]; foreach (BodyPartRecord p in Pawn.RaceProps.body.AllParts) { if (p.def.defName.Equals(partToFind)) { bill.Part = p; break; } } if (bill.Part == null) { Log.Warning("Unknown body part [" + partToFind + "]."); return(false); } } break; } } return(false); }
public override void PostExposeData(object obj) { if (Scribe.mode == LoadSaveMode.PostLoadInit) { Map map = obj as Map; if (map != null) { if (map.retainedCaravanData == null) { map.retainedCaravanData = new RetainedCaravanData(map); } if (map.wildAnimalSpawner == null) { map.wildAnimalSpawner = new WildAnimalSpawner(map); } if (map.wildPlantSpawner == null) { map.wildPlantSpawner = new WildPlantSpawner(map); } } Thing thing = obj as Thing; if (thing != null && thing.def.useHitPoints && thing.MaxHitPoints != thing.HitPoints && Mathf.Abs((float)thing.HitPoints / (float)thing.MaxHitPoints - 0.617f) < 0.02f && thing.Stuff == ThingDefOf.WoodLog) { thing.HitPoints = thing.MaxHitPoints; } Pawn pawn = obj as Pawn; if (pawn != null && !pawn.Destroyed && !pawn.Dead && pawn.needs == null) { Log.Error(pawn.ToStringSafe() + " has null needs tracker even though he's not dead. Fixing..."); pawn.needs = new Pawn_NeedsTracker(pawn); pawn.needs.SetInitialLevels(); } History history = obj as History; if (history != null && history.archive == null) { history.archive = new Archive(); } WorldInfo worldInfo = obj as WorldInfo; if (worldInfo != null && worldInfo.persistentRandomValue == 0) { worldInfo.persistentRandomValue = Rand.Int; } Caravan caravan = obj as Caravan; if (caravan != null) { if (caravan.forage == null) { caravan.forage = new Caravan_ForageTracker(caravan); } if (caravan.needs == null) { caravan.needs = new Caravan_NeedsTracker(caravan); } if (caravan.carryTracker == null) { caravan.carryTracker = new Caravan_CarryTracker(caravan); } if (caravan.beds == null) { caravan.beds = new Caravan_BedsTracker(caravan); } } PlaySettings playSettings = obj as PlaySettings; if (playSettings != null) { playSettings.defaultCareForColonyHumanlike = MedicalCareCategory.Best; playSettings.defaultCareForColonyAnimal = MedicalCareCategory.HerbalOrWorse; playSettings.defaultCareForColonyPrisoner = MedicalCareCategory.HerbalOrWorse; playSettings.defaultCareForNeutralFaction = MedicalCareCategory.HerbalOrWorse; playSettings.defaultCareForNeutralAnimal = MedicalCareCategory.HerbalOrWorse; playSettings.defaultCareForHostileFaction = MedicalCareCategory.HerbalOrWorse; } } if (Scribe.mode == LoadSaveMode.LoadingVars) { Hediff hediff = obj as Hediff; if (hediff != null) { Scribe_Values.Look(ref hediff.temp_partIndexToSetLater, "partIndex", -1); } Bill_Medical bill_Medical = obj as Bill_Medical; if (bill_Medical != null) { Scribe_Values.Look(ref bill_Medical.temp_partIndexToSetLater, "partIndex", -1); } FactionRelation factionRelation = obj as FactionRelation; if (factionRelation != null) { bool value = false; Scribe_Values.Look(ref value, "hostile", defaultValue: false); if (value || factionRelation.goodwill <= -75) { factionRelation.kind = FactionRelationKind.Hostile; } else if (factionRelation.goodwill >= 75) { factionRelation.kind = FactionRelationKind.Ally; } } HediffComp_GetsPermanent hediffComp_GetsPermanent = obj as HediffComp_GetsPermanent; if (hediffComp_GetsPermanent != null) { bool value2 = false; Scribe_Values.Look(ref value2, "isOld", defaultValue: false); if (value2) { hediffComp_GetsPermanent.isPermanentInt = true; } } if (obj is World) { UniqueIDsManager target = null; Scribe_Deep.Look(ref target, "uniqueIDsManager"); if (target != null) { Current.Game.uniqueIDsManager = target; } } WorldFeature worldFeature = obj as WorldFeature; if (worldFeature != null && worldFeature.maxDrawSizeInTiles == 0f) { Vector2 value3 = Vector2.zero; Scribe_Values.Look(ref value3, "maxDrawSizeInTiles"); worldFeature.maxDrawSizeInTiles = value3.x; } } if (Scribe.mode != LoadSaveMode.ResolvingCrossRefs) { return; } Hediff hediff2 = obj as Hediff; if (hediff2 != null && hediff2.temp_partIndexToSetLater >= 0 && hediff2.pawn != null) { if (hediff2.temp_partIndexToSetLater == 0) { hediff2.Part = hediff2.pawn.RaceProps.body.GetPartAtIndex(hediff2.temp_partIndexToSetLater); } else { hediff2.pawn.health.hediffSet.hediffs.Remove(hediff2); } hediff2.temp_partIndexToSetLater = -1; } Bill_Medical bill_Medical2 = obj as Bill_Medical; if (bill_Medical2 != null) { if (bill_Medical2.temp_partIndexToSetLater == 0) { bill_Medical2.Part = bill_Medical2.GiverPawn.RaceProps.body.GetPartAtIndex(bill_Medical2.temp_partIndexToSetLater); } else { bill_Medical2.GiverPawn.BillStack.Bills.Remove(bill_Medical2); } bill_Medical2.temp_partIndexToSetLater = -1; } }
public static void IsSurgeryViolation_Postfix(Bill_Medical bill, ref bool __result) { __result = __result || (GetContractTracker(Find.World).IsHired(bill.GiverPawn) && bill.recipe.Worker.IsViolationOnPawn(bill.GiverPawn, bill.Part, Faction.OfPlayer)); }
private static bool Method_Prefix_2(ref FloatMenuOption __result, Pawn pawn, Thing thingForMedBills, RecipeDef recipe, IEnumerable <ThingDef> missingIngredients, BodyPartRecord part = null) { //Traverse ThingDef_Traverse = Traverse.Create<ThingDef>(); if (pawn.Dead) { //Log.Message("Own Generating SurgeryOptions"); string text = recipe.Worker.GetLabelWhenUsedOn(pawn, part); if (part != null && !recipe.hideBodyPartNames) { text = text + " (" + part.def.label + ")"; } FloatMenuOption floatMenuOption; if (missingIngredients.Any()) { text += " ("; bool flag = true; foreach (ThingDef missingIngredient in missingIngredients) { if (!flag) { text += ", "; } flag = false; text += "MissingMedicalBillIngredient".Translate(missingIngredient.label); } text += ")"; floatMenuOption = new FloatMenuOption(text, null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { Action action = delegate { //Log.Message("Delegate action"); Corpse pawn2 = thingForMedBills as Corpse; if (pawn2 != null) { Bill_Medical bill_Medical = new Bill_Medical(recipe); //Log.Message("adding bill_Medical to billstack " + bill_Medical.ToString()); pawn2.BillStack.AddBill(bill_Medical); bill_Medical.Part = part; if (recipe.conceptLearned != null) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(recipe.conceptLearned, KnowledgeAmount.Total); } Map map = thingForMedBills.Map; if (!map.mapPawns.FreeColonists.Any((Pawn col) => recipe.PawnSatisfiesSkillRequirements(col))) { Bill.CreateNoPawnsWithSkillDialog(recipe); } if (!pawn2.InnerPawn.InBed() && pawn2.InnerPawn.RaceProps.IsFlesh) { //if (pawn2.InnerPawn.RaceProps.Humanlike) //{ // if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(pawn, x.def) && ((Building_Bed)x).Medical)) // { // Messages.Message("MessageNoMedicalBeds".Translate(), pawn2, MessageTypeDefOf.CautionInput); // } //} //else if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(pawn, x.def))) //{ // Messages.Message("MessageNoAnimalBeds".Translate(), pawn2, MessageTypeDefOf.CautionInput); //} } if (pawn2.Faction != null && !pawn2.Faction.def.hidden && !pawn2.Faction.HostileTo(Faction.OfPlayer) && recipe.Worker.IsViolationOnPawn(pawn2.InnerPawn, part, Faction.OfPlayer)) { Messages.Message("MessageMedicalOperationWillAngerFaction".Translate(pawn2.Faction), pawn2, MessageTypeDefOf.CautionInput); } //Log.Message("Log10"); ThingDef minRequiredMedicine = (ThingDef)AccessTools.Method(typeof(HealthCardUtility), "GetMinRequiredMedicine", new Type[] { typeof(RecipeDef) }).Invoke(null, new object[] { recipe }); //(rect, pawn, thingForMedBills, curY); //Log.Message("Log11"); if (minRequiredMedicine != null && pawn2.InnerPawn.playerSettings != null && !pawn2.InnerPawn.playerSettings.medCare.AllowsMedicine(minRequiredMedicine)) { Messages.Message("MessageTooLowMedCare".Translate(minRequiredMedicine.label, pawn2.LabelShort, pawn2.InnerPawn.playerSettings.medCare.GetLabel()), pawn2, MessageTypeDefOf.CautionInput); } } }; floatMenuOption = new FloatMenuOption(text, action, MenuOptionPriority.Default, null, null, 0f, null, null); } floatMenuOption.extraPartWidth = 29f; floatMenuOption.extraPartOnGUI = ((Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, recipe)); __result = floatMenuOption; return(false); } else { //Log.Message("Generating SurgeryOptions forwarding"); return(true); } }
public static void RecipeOptionsMaker( Pawn pawn ) { if (pawn.RaceProps.Animal) { // TODO: See if we can auto-detect ADS, and/or auto-detect available bills on animals. Log.Warning( "Medical bills are currently not supported on animals. Stay tuned!"); return; } Thing thingForMedBills = pawn; var list = new List<FloatMenuOption>( ); foreach ( var current in thingForMedBills.def.AllRecipes ) { if (!current.AvailableNow) continue; IEnumerable<ThingDef> enumerable = current.PotentiallyMissingIngredients( null ); IEnumerable<ThingDef> thingDefs = enumerable as ThingDef[] ?? enumerable.ToArray( ); if (thingDefs.Any(x => x.isBodyPartOrImplant)) continue; { IEnumerable<BodyPartRecord> partsToApplyOn = current.Worker.GetPartsToApplyOn( pawn, current ); IEnumerable<BodyPartRecord> bodyPartRecords = partsToApplyOn as BodyPartRecord[] ?? partsToApplyOn.ToArray( ); if (!bodyPartRecords.Any()) continue; foreach ( var current2 in bodyPartRecords ) { var localRecipe = current; var localPart = current2; var text = localRecipe == RecipeDefOf.RemoveBodyPart ? HealthCardUtility.RemoveBodyPartSpecialLabel( pawn, current2 ) : localRecipe.LabelCap; if ( !current.hideBodyPartNames ) { text = text + " (" + current2.def.label + ")"; } Action action = null; if ( thingDefs.Any( ) ) { text += " ("; var flag = true; foreach ( var current3 in thingDefs ) { if ( !flag ) { text += ", "; } flag = false; text += "MissingMedicalBillIngredient".Translate( current3.label ); } text += ")"; } else { action = delegate { if ( !Find.MapPawns.FreeColonists.Any( col => localRecipe.PawnSatisfiesSkillRequirements( col ) ) ) { Bill.CreateNoPawnsWithSkillDialog( localRecipe ); } var pawn2 = thingForMedBills as Pawn; if ( pawn2 != null && !pawn.InBed( ) && pawn.RaceProps.Humanlike ) { if ( !Find.ListerBuildings.allBuildingsColonist.Any( x => x is Building_Bed && ( (Building_Bed) x ).Medical ) ) { Messages.Message( "MessageNoMedicalBeds".Translate( ), MessageSound.Negative ); } } var billMedical = new Bill_Medical( localRecipe ); if (pawn2 == null) return; pawn2.BillStack.AddBill( billMedical ); billMedical.Part = localPart; if ( pawn2.Faction != null && !pawn2.Faction.def.hidden && !pawn2.Faction.HostileTo( Faction.OfPlayer ) && localRecipe.Worker.IsViolationOnPawn( pawn2, localPart, Faction.OfPlayer ) ) { Messages.Message( "MessageMedicalOperationWillAngerFaction".Translate( pawn2.Faction ), MessageSound.Negative ); } }; } list.Add( new FloatMenuOption( text, action ) ); } } } Find.WindowStack.Add( new FloatMenu( list ) ); }
private static bool TryCreateBill(StreamReader sr, Pawn pawn, out Bill_Medical bill) { bill = null; string[] kv = null; try { while (!sr.EndOfStream) { if (ReadField(sr, out kv)) { switch (kv[0]) { case BREAK: return(true); case "recipeDefName": var def = DefDatabase <RecipeDef> .GetNamed(kv[1]); if (def == null) { Log.Warning("Unable to load bill with RecipeDef of [" + kv[1] + "]"); return(false); } bill = new Bill_Medical(def); break; case "part": var pv = kv[1].Split(':'); if (bill.recipe.defName.StartsWith("Remove")) { bill.Part = null; string partToFind = pv[0]; foreach (BodyPartRecord part in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)) { if (part.Label.Equals(partToFind)) { bill.Part = part; break; } } if (bill.Part == null) { Log.Warning("Pawn [" + pawn.Name.ToStringShort + "] does not have body part [" + partToFind + "] to have removed."); return(false); } } else if (bill.recipe.defName.StartsWith("Install")) { string partToFind = pv[1]; foreach (BodyPartRecord p in pawn.RaceProps.body.AllParts) { if (p.def.defName.Equals(partToFind)) { bill.Part = p; break; } } if (bill.Part == null) { Log.Warning("Unknown body part [" + partToFind + "]."); return(false); } } break; } } } } catch (Exception e) { string error = ""; if (bill != null && bill.recipe != null) { error = "Unable to load bill [" + bill.recipe.defName + "]."; } else { error = "Unable to load a bill."; } if (kv == null || kv.Length < 2) { error += " Current line: [" + kv[0] + ":" + kv[1] + "]"; } Log.Error(e.GetType().Name + " - " + e.Message); Log.Warning(error); bill = null; return(false); } return(true); }
public static void RecipeOptionsMaker( Pawn pawn ) { Thing thingForMedBills = pawn; List<FloatMenuOption> list = new List<FloatMenuOption>( ); foreach ( RecipeDef current in thingForMedBills.def.AllRecipes ) { if ( current.AvailableNow ) { IEnumerable<ThingDef> enumerable = current.PotentiallyMissingIngredients( null ); IEnumerable<ThingDef> thingDefs = enumerable as ThingDef[] ?? enumerable.ToArray( ); if ( !thingDefs.Any( x => x.isBodyPartOrImplant ) ) { IEnumerable<BodyPartRecord> partsToApplyOn = current.Worker.GetPartsToApplyOn( pawn, current ); IEnumerable<BodyPartRecord> bodyPartRecords = partsToApplyOn as BodyPartRecord[] ?? partsToApplyOn.ToArray( ); if ( bodyPartRecords.Any( ) ) { foreach ( BodyPartRecord current2 in bodyPartRecords ) { RecipeDef localRecipe = current; BodyPartRecord localPart = current2; string text = localRecipe == RecipeDefOf.RemoveBodyPart ? HealthCardUtility.RemoveBodyPartSpecialLabel( pawn, current2 ) : localRecipe.LabelCap; if ( !current.hideBodyPartNames ) { text = text + " (" + current2.def.label + ")"; } Action action = null; if ( thingDefs.Any( ) ) { text += " ("; bool flag = true; foreach ( ThingDef current3 in thingDefs ) { if ( !flag ) { text += ", "; } flag = false; text += "MissingMedicalBillIngredient".Translate( current3.label ); } text += ")"; } else { action = delegate { if ( !Find.ListerPawns.FreeColonists.Any( col => localRecipe.PawnSatisfiesSkillRequirements( col ) ) ) { Bill.CreateNoPawnsWithSkillDialog( localRecipe ); } Pawn pawn2 = thingForMedBills as Pawn; if ( pawn2 != null && !pawn.InBed( ) && pawn.RaceProps.Humanlike ) { if ( !Find.ListerBuildings.allBuildingsColonist.Any( x => x is Building_Bed && ( (Building_Bed) x ).Medical ) ) { Messages.Message( "MessageNoMedicalBeds".Translate( ), MessageSound.Negative ); } } Bill_Medical billMedical = new Bill_Medical( localRecipe ); if ( pawn2 != null ) { pawn2.BillStack.AddBill( billMedical ); billMedical.Part = localPart; if ( pawn2.Faction != null && !pawn2.Faction.def.hidden && !pawn2.Faction.HostileTo( Faction.OfColony ) && localRecipe.Worker.IsViolationOnPawn( pawn2, localPart, Faction.OfColony ) ) { Messages.Message( "MessageMedicalOperationWillAngerFaction".Translate( pawn2.Faction ), MessageSound.Negative ); } } }; } list.Add( new FloatMenuOption( text, action ) ); } } } } } Find.WindowStack.Add( new FloatMenu( list ) ); }
public static void RecipeOptionsMaker(Pawn pawn) { if (pawn.RaceProps.Animal) { // TODO: See if we can auto-detect ADS, and/or auto-detect available bills on animals. Log.Warning("Medical bills are currently not supported on animals. Stay tuned!"); return; } Thing thingForMedBills = pawn; var list = new List <FloatMenuOption>( ); foreach (var current in thingForMedBills.def.AllRecipes) { if (!current.AvailableNow) { continue; } IEnumerable <ThingDef> enumerable = current.PotentiallyMissingIngredients(null, thingForMedBills.MapHeld); IEnumerable <ThingDef> thingDefs = enumerable as ThingDef[] ?? enumerable.ToArray(); if (thingDefs.Any(x => x.isBodyPartOrImplant)) { continue; } { IEnumerable <BodyPartRecord> partsToApplyOn = current.Worker.GetPartsToApplyOn(pawn, current); IEnumerable <BodyPartRecord> bodyPartRecords = partsToApplyOn as BodyPartRecord[] ?? partsToApplyOn.ToArray(); if (!bodyPartRecords.Any()) { continue; } foreach (var current2 in bodyPartRecords) { var localRecipe = current; var localPart = current2; // Could not found RemoveBodyPartSpecialLabel() for A16. //var text = localRecipe == RecipeDefOf.RemoveBodyPart ? HealthCardUtility.RemoveBodyPartSpecialLabel( pawn, current2 ) : localRecipe.LabelCap; var text = localRecipe.LabelCap; if (!current.hideBodyPartNames) { text = text + " (" + current2.def.label + ")"; } Action action = null; if (thingDefs.Any( )) { text += " ("; var flag = true; foreach (var current3 in thingDefs) { if (!flag) { text += ", "; } flag = false; text += "MissingMedicalBillIngredient".Translate(current3.label); } text += ")"; } else { action = delegate { if ( !Find.VisibleMap.mapPawns.FreeColonists.Any(col => localRecipe.PawnSatisfiesSkillRequirements(col))) { Bill.CreateNoPawnsWithSkillDialog(localRecipe); } var pawn2 = thingForMedBills as Pawn; if (pawn2 != null && !pawn.InBed( ) && pawn.RaceProps.Humanlike) { if ( !Find.VisibleMap.listerBuildings.allBuildingsColonist.Any(x => x is Building_Bed && ((Building_Bed)x).Medical)) { Messages.Message("MessageNoMedicalBeds".Translate( ), MessageSound.Negative); } } var billMedical = new Bill_Medical(localRecipe); if (pawn2 == null) { return; } pawn2.BillStack.AddBill(billMedical); billMedical.Part = localPart; if (pawn2.Faction != null && !pawn2.Faction.def.hidden && !pawn2.Faction.HostileTo(Faction.OfPlayer) && localRecipe.Worker.IsViolationOnPawn(pawn2, localPart, Faction.OfPlayer)) { Messages.Message( "MessageMedicalOperationWillAngerFaction".Translate(pawn2.Faction), MessageSound.Negative); } }; } list.Add(new FloatMenuOption(text, action)); } } } Find.WindowStack.Add(new FloatMenu(list)); }