private static bool TryFindBestBillIngredientsInSet(List <Thing> availableThings, Bill bill, List <ThingCount> chosen) { if (bill.recipe.allowMixingIngredients) { return(TryFindBestBillIngredientsInSet_AllowMix(availableThings, bill, chosen)); } return(TryFindBestBillIngredientsInSet_NoMix(availableThings, bill, chosen)); }
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); MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map); if (flag && flag2 && part.def.spawnThingOnRemoved != null) { ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn); } if (flag2) { ReportViolation(pawn, billDoer, pawn.FactionOrExtraHomeFaction, -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 && !CheckSurgeryFail(billDoer, pawn, ingredients, part, bill)) { TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map); } }
public void AddBill(Bill bill) { bill.billStack = this; this.bills.Add(bill); }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { 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(new object[] { billDoer.LabelShort, pawn.LabelShort, this.recipe.removesHediff.label }); } Messages.Message(text, pawn, MessageTypeDefOf.PositiveEvent); } } Hediff hediff = pawn.health.hediffSet.hediffs.Find((Hediff x) => x.def == this.recipe.removesHediff && x.Part == part && x.Visible); if (hediff != null) { pawn.health.RemoveHediff(hediff); } }
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 }); 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 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); } }
private static bool TryFindBestBillIngredientsInSet_NoMix(List <Thing> availableThings, Bill bill, List <ThingCount> chosen) { RecipeDef recipe = bill.recipe; chosen.Clear(); WorkGiver_DoBill.availableCounts.Clear(); WorkGiver_DoBill.availableCounts.GenerateFrom(availableThings); for (int i = 0; i < WorkGiver_DoBill.ingredientsOrdered.Count; i++) { IngredientCount ingredientCount = recipe.ingredients[i]; bool flag = false; for (int j = 0; j < WorkGiver_DoBill.availableCounts.Count; j++) { float num = (float)ingredientCount.CountRequiredOfFor(WorkGiver_DoBill.availableCounts.GetDef(j), bill.recipe); if (num <= WorkGiver_DoBill.availableCounts.GetCount(j)) { if (ingredientCount.filter.Allows(WorkGiver_DoBill.availableCounts.GetDef(j))) { if (ingredientCount.IsFixedIngredient || bill.ingredientFilter.Allows(WorkGiver_DoBill.availableCounts.GetDef(j))) { for (int k = 0; k < availableThings.Count; k++) { if (availableThings[k].def == WorkGiver_DoBill.availableCounts.GetDef(j)) { int num2 = availableThings[k].stackCount - ThingCountUtility.CountOf(chosen, availableThings[k]); if (num2 > 0) { int num3 = Mathf.Min(Mathf.FloorToInt(num), num2); ThingCountUtility.AddToList(chosen, availableThings[k], num3); num -= (float)num3; if (num < 0.001f) { flag = true; float num4 = WorkGiver_DoBill.availableCounts.GetCount(j); num4 -= (float)ingredientCount.CountRequiredOfFor(WorkGiver_DoBill.availableCounts.GetDef(j), bill.recipe); WorkGiver_DoBill.availableCounts.SetCount(j, num4); break; } } } } if (flag) { break; } } } } } if (!flag) { return(false); } } return(true); }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { if (billDoer != null) { TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); } Hediff_ImplantWithLevel hediff_ImplantWithLevel = (Hediff_ImplantWithLevel)pawn.health.hediffSet.hediffs.FirstOrDefault((Hediff h) => Operable(h, recipe) && h.Part == part); if (hediff_ImplantWithLevel != null) { if (IsViolationOnPawn(pawn, part, Faction.OfPlayer)) { ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_DowngradedImplant".Translate(hediff_ImplantWithLevel.Label)); } hediff_ImplantWithLevel.ChangeLevel(recipe.hediffLevelOffset); } }
private static void MakeIngredientsListInProcessingOrder(List <IngredientCount> ingredientsOrdered, Bill bill) { ingredientsOrdered.Clear(); if (bill.recipe.productHasIngredientStuff) { ingredientsOrdered.Add(bill.recipe.ingredients[0]); } for (int i = 0; i < bill.recipe.ingredients.Count; i++) { if (!bill.recipe.productHasIngredientStuff || i != 0) { IngredientCount ingredientCount = bill.recipe.ingredients[i]; if (ingredientCount.IsFixedIngredient) { ingredientsOrdered.Add(ingredientCount); } } } for (int j = 0; j < bill.recipe.ingredients.Count; j++) { IngredientCount item = bill.recipe.ingredients[j]; if (!ingredientsOrdered.Contains(item)) { ingredientsOrdered.Add(item); } } }
private static bool TryFindBestBillIngredientsInSet(List <Thing> availableThings, Bill bill, List <ThingCount> chosen) { bool result; if (bill.recipe.allowMixingIngredients) { result = WorkGiver_DoBill.TryFindBestBillIngredientsInSet_AllowMix(availableThings, bill, chosen); } else { result = WorkGiver_DoBill.TryFindBestBillIngredientsInSet_NoMix(availableThings, bill, chosen); } return(result); }
private static bool TryFindBestBillIngredients(Bill bill, Pawn pawn, Thing billGiver, List <ThingCount> chosen) { chosen.Clear(); WorkGiver_DoBill.newRelevantThings.Clear(); bool result; if (bill.recipe.ingredients.Count == 0) { result = true; } else { IntVec3 rootCell = WorkGiver_DoBill.GetBillGiverRootCell(billGiver, pawn); Region rootReg = rootCell.GetRegion(pawn.Map, RegionType.Set_Passable); if (rootReg == null) { result = false; } else { WorkGiver_DoBill.MakeIngredientsListInProcessingOrder(WorkGiver_DoBill.ingredientsOrdered, bill); WorkGiver_DoBill.relevantThings.Clear(); WorkGiver_DoBill.processedThings.Clear(); bool foundAll = false; Predicate <Thing> baseValidator = (Thing t) => t.Spawned && !t.IsForbidden(pawn) && (float)(t.Position - billGiver.Position).LengthHorizontalSquared < bill.ingredientSearchRadius * bill.ingredientSearchRadius && bill.IsFixedOrAllowedIngredient(t) && bill.recipe.ingredients.Any((IngredientCount ingNeed) => ingNeed.filter.Allows(t)) && pawn.CanReserve(t, 1, -1, null, false); bool billGiverIsPawn = billGiver is Pawn; if (billGiverIsPawn) { WorkGiver_DoBill.AddEveryMedicineToRelevantThings(pawn, billGiver, WorkGiver_DoBill.relevantThings, baseValidator, pawn.Map); if (WorkGiver_DoBill.TryFindBestBillIngredientsInSet(WorkGiver_DoBill.relevantThings, bill, chosen)) { WorkGiver_DoBill.relevantThings.Clear(); WorkGiver_DoBill.ingredientsOrdered.Clear(); return(true); } } TraverseParms traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false); RegionEntryPredicate entryCondition = (Region from, Region r) => r.Allows(traverseParams, false); int adjacentRegionsAvailable = rootReg.Neighbors.Count((Region region) => entryCondition(rootReg, region)); int regionsProcessed = 0; WorkGiver_DoBill.processedThings.AddRange(WorkGiver_DoBill.relevantThings); RegionProcessor regionProcessor = delegate(Region r) { List <Thing> list = r.ListerThings.ThingsMatching(ThingRequest.ForGroup(ThingRequestGroup.HaulableEver)); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (!WorkGiver_DoBill.processedThings.Contains(thing)) { if (ReachabilityWithinRegion.ThingFromRegionListerReachable(thing, r, PathEndMode.ClosestTouch, pawn)) { if (baseValidator(thing) && (!thing.def.IsMedicine || !billGiverIsPawn)) { WorkGiver_DoBill.newRelevantThings.Add(thing); WorkGiver_DoBill.processedThings.Add(thing); } } } } regionsProcessed++; if (WorkGiver_DoBill.newRelevantThings.Count > 0 && regionsProcessed > adjacentRegionsAvailable) { Comparison <Thing> comparison = delegate(Thing t1, Thing t2) { float num = (float)(t1.Position - rootCell).LengthHorizontalSquared; float value = (float)(t2.Position - rootCell).LengthHorizontalSquared; return(num.CompareTo(value)); }; WorkGiver_DoBill.newRelevantThings.Sort(comparison); WorkGiver_DoBill.relevantThings.AddRange(WorkGiver_DoBill.newRelevantThings); WorkGiver_DoBill.newRelevantThings.Clear(); if (WorkGiver_DoBill.TryFindBestBillIngredientsInSet(WorkGiver_DoBill.relevantThings, bill, chosen)) { foundAll = true; return(true); } } return(false); }; RegionTraverser.BreadthFirstTraverse(rootReg, entryCondition, regionProcessor, 99999, RegionType.Set_Passable); WorkGiver_DoBill.relevantThings.Clear(); WorkGiver_DoBill.newRelevantThings.Clear(); WorkGiver_DoBill.processedThings.Clear(); WorkGiver_DoBill.ingredientsOrdered.Clear(); result = foundAll; } } return(result); }
private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver) { for (int i = 0; i < giver.BillStack.Count; i++) { Bill bill = giver.BillStack[i]; if (bill.recipe.requiredGiverWorkType == null || bill.recipe.requiredGiverWorkType == this.def.workType) { if (Find.TickManager.TicksGame >= bill.lastIngredientSearchFailTicks + WorkGiver_DoBill.ReCheckFailedBillTicksRange.RandomInRange || FloatMenuMakerMap.makingFor == pawn) { bill.lastIngredientSearchFailTicks = 0; if (bill.ShouldDoNow()) { if (bill.PawnAllowedToStartAnew(pawn)) { SkillRequirement skillRequirement = bill.recipe.FirstSkillRequirementPawnDoesntSatisfy(pawn); if (skillRequirement == null) { Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft; if (bill_ProductionWithUft != null) { if (bill_ProductionWithUft.BoundUft != null) { if (bill_ProductionWithUft.BoundWorker != pawn || !pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly, 1, -1, null, false) || bill_ProductionWithUft.BoundUft.IsForbidden(pawn)) { goto IL_1F6; } return(WorkGiver_DoBill.FinishUftJob(pawn, bill_ProductionWithUft.BoundUft, bill_ProductionWithUft)); } else { UnfinishedThing unfinishedThing = WorkGiver_DoBill.ClosestUnfinishedThingForBill(pawn, bill_ProductionWithUft); if (unfinishedThing != null) { return(WorkGiver_DoBill.FinishUftJob(pawn, unfinishedThing, bill_ProductionWithUft)); } } } if (!WorkGiver_DoBill.TryFindBestBillIngredients(bill, pawn, (Thing)giver, this.chosenIngThings)) { if (FloatMenuMakerMap.makingFor != pawn) { bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame; } else { JobFailReason.Is(WorkGiver_DoBill.MissingMaterialsTranslated, bill.Label); } this.chosenIngThings.Clear(); goto IL_1F6; } Job result = this.TryStartNewDoBillJob(pawn, bill, giver); this.chosenIngThings.Clear(); return(result); } JobFailReason.Is("UnderRequiredSkill".Translate(new object[] { skillRequirement.minLevel }), bill.Label); } } } } IL_1F6 :; } this.chosenIngThings.Clear(); return(null); }
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, billDoer, pawn); MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, part, billDoer.Position, billDoer.Map); MedicalRecipesUtility.SpawnThingsFromHediffs(pawn, part, billDoer.Position, billDoer.Map); } DamageDef surgicalCut = DamageDefOf.SurgicalCut; int amount = 99999; pawn.TakeDamage(new DamageInfo(surgicalCut, amount, -1f, null, part, null, DamageInfo.SourceCategory.ThingOrUnknown)); if (flag) { if (pawn.Dead) { ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting); } else { ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn); } } if (flag2) { pawn.Faction.AffectGoodwillWith(billDoer.Faction, -20f); } }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { 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); } 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); }
private static bool TryFindBestBillIngredientsInSet_AllowMix(List <Thing> availableThings, Bill bill, List <ThingCount> chosen) { chosen.Clear(); for (int i = 0; i < bill.recipe.ingredients.Count; i++) { IngredientCount ingredientCount = bill.recipe.ingredients[i]; float num = ingredientCount.GetBaseCount(); for (int j = 0; j < availableThings.Count; j++) { Thing thing = availableThings[j]; if (ingredientCount.filter.Allows(thing)) { if (ingredientCount.IsFixedIngredient || bill.ingredientFilter.Allows(thing)) { float num2 = bill.recipe.IngredientValueGetter.ValuePerUnitOf(thing.def); int num3 = Mathf.Min(Mathf.CeilToInt(num / num2), thing.stackCount); ThingCountUtility.AddToList(chosen, thing, num3); num -= (float)num3 * num2; if (num <= 0.0001f) { break; } } } } if (num > 0.0001f) { return(false); } } return(true); }
protected bool CheckSurgeryFail(Pawn surgeon, Pawn patient, List <Thing> ingredients, BodyPartRecord part, Bill bill) { if (bill.recipe.surgerySuccessChanceFactor >= 99999f) { return(false); } float num = 1f; if (!patient.RaceProps.IsMechanoid) { num *= surgeon.GetStatValue(StatDefOf.MedicalSurgerySuccessChance); } if (patient.InBed()) { num *= patient.CurrentBed().GetStatValue(StatDefOf.SurgerySuccessChanceFactor); } num *= MedicineMedicalPotencyToSurgeryChanceFactor.Evaluate(GetAverageMedicalPotency(ingredients, bill)); num *= recipe.surgerySuccessChanceFactor; if (surgeon.InspirationDef == InspirationDefOf.Inspired_Surgery && !patient.RaceProps.IsMechanoid) { num *= 2f; surgeon.mindState.inspirationHandler.EndInspiration(InspirationDefOf.Inspired_Surgery); } num = Mathf.Min(num, 0.98f); if (!Rand.Chance(num)) { if (Rand.Chance(recipe.deathOnFailedSurgeryChance)) { HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient, part); if (!patient.Dead) { patient.Kill(null, null); } Messages.Message("MessageMedicalOperationFailureFatal".Translate(surgeon.LabelShort, patient.LabelShort, recipe.LabelCap, surgeon.Named("SURGEON"), patient.Named("PATIENT")), patient, MessageTypeDefOf.NegativeHealthEvent); } else if (Rand.Chance(0.5f)) { if (Rand.Chance(0.1f)) { Messages.Message("MessageMedicalOperationFailureRidiculous".Translate(surgeon.LabelShort, patient.LabelShort, surgeon.Named("SURGEON"), patient.Named("PATIENT"), recipe.Named("RECIPE")), patient, MessageTypeDefOf.NegativeHealthEvent); HealthUtility.GiveInjuriesOperationFailureRidiculous(patient); } else { Messages.Message("MessageMedicalOperationFailureCatastrophic".Translate(surgeon.LabelShort, patient.LabelShort, surgeon.Named("SURGEON"), patient.Named("PATIENT"), recipe.Named("RECIPE")), patient, MessageTypeDefOf.NegativeHealthEvent); HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient, part); } } else { Messages.Message("MessageMedicalOperationFailureMinor".Translate(surgeon.LabelShort, patient.LabelShort, surgeon.Named("SURGEON"), patient.Named("PATIENT"), recipe.Named("RECIPE")), patient, MessageTypeDefOf.NegativeHealthEvent); HealthUtility.GiveInjuriesOperationFailureMinor(patient, part); } if (!patient.Dead) { TryGainBotchedSurgeryThought(patient, surgeon); } return(true); } return(false); }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { ingredients[0].TryGetComp <CompUsable>().UsedBy(pawn); }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { ExecutionUtility.DoExecutionByCut(billDoer, pawn); ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.GenericHumane); }
protected override void FillTab() { PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.BillsTab, KnowledgeAmount.FrameDisplayed); Rect rect2 = new Rect(WinSize.x - PasteX, PasteY, PasteSize, PasteSize); if (BillUtility.Clipboard == null) { GUI.color = Color.gray; Widgets.DrawTextureFitted(rect2, TexButton.Paste, 1f); GUI.color = Color.white; TooltipHandler.TipRegionByKey(rect2, "PasteBillTip"); } else if (!SelTable.def.AllRecipes.Contains(BillUtility.Clipboard.recipe) || !BillUtility.Clipboard.recipe.AvailableNow || !BillUtility.Clipboard.recipe.AvailableOnNow(SelTable)) { GUI.color = Color.gray; Widgets.DrawTextureFitted(rect2, TexButton.Paste, 1f); GUI.color = Color.white; TooltipHandler.TipRegionByKey(rect2, "ClipboardBillNotAvailableHere"); } else if (SelTable.billStack.Count >= 15) { GUI.color = Color.gray; Widgets.DrawTextureFitted(rect2, TexButton.Paste, 1f); GUI.color = Color.white; if (Mouse.IsOver(rect2)) { TooltipHandler.TipRegion(rect2, "PasteBillTip".Translate() + " (" + "PasteBillTip_LimitReached".Translate() + ")"); } } else { if (Widgets.ButtonImageFitted(rect2, TexButton.Paste, Color.white)) { Bill bill = BillUtility.Clipboard.Clone(); bill.InitializeAfterClone(); SelTable.billStack.AddBill(bill); SoundDefOf.Tick_Low.PlayOneShotOnCamera(); } TooltipHandler.TipRegionByKey(rect2, "PasteBillTip"); } Rect rect3 = new Rect(0f, 0f, WinSize.x, WinSize.y).ContractedBy(10f); Func <List <FloatMenuOption> > recipeOptionsMaker = delegate { List <FloatMenuOption> list = new List <FloatMenuOption>(); RecipeDef recipe = default(RecipeDef); for (int i = 0; i < SelTable.def.AllRecipes.Count; i++) { if (SelTable.def.AllRecipes[i].AvailableNow && SelTable.def.AllRecipes[i].AvailableOnNow(SelTable)) { recipe = SelTable.def.AllRecipes[i]; list.Add(new FloatMenuOption(recipe.LabelCap, delegate { if (!SelTable.Map.mapPawns.FreeColonists.Any((Pawn col) => recipe.PawnSatisfiesSkillRequirements(col))) { Bill.CreateNoPawnsWithSkillDialog(recipe); } Bill bill2 = recipe.MakeNewBill(); SelTable.billStack.AddBill(bill2); if (recipe.conceptLearned != null) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(recipe.conceptLearned, KnowledgeAmount.Total); } if (TutorSystem.TutorialMode) { TutorSystem.Notify_Event("AddBill-" + recipe.LabelCap.Resolve()); } }, recipe.UIIconThing, MenuOptionPriority.Default, null, null, 29f, (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, recipe))); } } if (!list.Any()) { list.Add(new FloatMenuOption("NoneBrackets".Translate(), null)); } return(list); }; mouseoverBill = SelTable.billStack.DoListing(rect3, recipeOptionsMaker, ref scrollPosition, ref viewHeight); }
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) && 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); } 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); if (flag && flag2 && part.def.spawnThingOnRemoved != null) { ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn); } if (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null) { Faction arg_151_0 = pawn.Faction; Faction faction = billDoer.Faction; int goodwillChange = -15; string reason = "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(new object[] { this.recipe.addsHediff.label }); GlobalTargetInfo?lookTarget = new GlobalTargetInfo?(pawn); arg_151_0.TryAffectGoodwillWith(faction, goodwillChange, true, true, reason, lookTarget); } }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { if (billDoer != null) { if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill)) { return; } TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); if (PawnUtility.ShouldSendNotificationAbout(pawn) || PawnUtility.ShouldSendNotificationAbout(billDoer)) { string text = (recipe.successfullyRemovedHediffMessage.NullOrEmpty() ? ((string)"MessageSuccessfullyRemovedHediff".Translate(billDoer.LabelShort, pawn.LabelShort, recipe.removesHediff.label.Named("HEDIFF"), billDoer.Named("SURGEON"), pawn.Named("PATIENT"))) : ((string)recipe.successfullyRemovedHediffMessage.Formatted(billDoer.LabelShort, pawn.LabelShort))); Messages.Message(text, pawn, MessageTypeDefOf.PositiveEvent); } } Hediff hediff = pawn.health.hediffSet.hediffs.Find((Hediff x) => x.def == recipe.removesHediff && x.Part == part && x.Visible); if (hediff != null) { pawn.health.RemoveHediff(hediff); } }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { if (billDoer != null) { if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill)) { return; } TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[] { billDoer, pawn }); } pawn.health.AddHediff(this.recipe.addsHediff, part, null); }
private static FloatMenuOption GenerateSurgeryOption(Pawn pawn, Thing thingForMedBills, RecipeDef recipe, IEnumerable <ThingDef> missingIngredients, BodyPartRecord part = null) { string text = recipe.Worker.GetLabelWhenUsedOn(pawn, part).CapitalizeFirst(); if (part != null && !recipe.hideBodyPartNames) { text = text + " (" + part.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); } else { Action action = delegate { Pawn pawn2 = thingForMedBills as Pawn; if (pawn2 != null) { Bill_Medical bill_Medical = new Bill_Medical(recipe); 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.InBed() && pawn2.RaceProps.IsFlesh) { if (pawn2.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, historical: false); } } else if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(pawn, x.def))) { Messages.Message("MessageNoAnimalBeds".Translate(), pawn2, MessageTypeDefOf.CautionInput, historical: false); } } if (pawn2.Faction != null && !pawn2.Faction.def.hidden && !pawn2.Faction.HostileTo(Faction.OfPlayer) && recipe.Worker.IsViolationOnPawn(pawn2, part, Faction.OfPlayer)) { Messages.Message("MessageMedicalOperationWillAngerFaction".Translate(pawn2.Faction), pawn2, MessageTypeDefOf.CautionInput, historical: false); } ThingDef minRequiredMedicine = GetMinRequiredMedicine(recipe); if (minRequiredMedicine != null && pawn2.playerSettings != null && !pawn2.playerSettings.medCare.AllowsMedicine(minRequiredMedicine)) { Messages.Message("MessageTooLowMedCare".Translate(minRequiredMedicine.label, pawn2.LabelShort, pawn2.playerSettings.medCare.GetLabel(), pawn2.Named("PAWN")), pawn2, MessageTypeDefOf.CautionInput, historical: false); } } }; floatMenuOption = new FloatMenuOption(text, action); } floatMenuOption.extraPartWidth = 29f; floatMenuOption.extraPartOnGUI = ((Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, recipe)); return(floatMenuOption); }
public int IndexOf(Bill bill) { return(this.bills.IndexOf(bill)); }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { bool flag = MedicalRecipesUtility.IsClean(pawn, part); bool flag2 = IsViolationOnPawn(pawn, part, Faction.OfPlayer); if (billDoer != null) { if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill)) { return; } TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn); MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, part, billDoer.Position, billDoer.Map); MedicalRecipesUtility.SpawnThingsFromHediffs(pawn, part, billDoer.Position, billDoer.Map); } pawn.TakeDamage(new DamageInfo(DamageDefOf.SurgicalCut, 99999f, 999f, -1f, null, part)); if (flag) { if (pawn.Dead) { ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting); } ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn); } if (flag2) { ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort)); } }
public void Delete(Bill bill) { bill.deleted = true; this.bills.Remove(bill); }
protected bool CheckSurgeryFail(Pawn surgeon, Pawn patient, List <Thing> ingredients, BodyPartRecord part, Bill bill) { float num = 1f; num *= surgeon.GetStatValue((!patient.RaceProps.IsMechanoid) ? StatDefOf.MedicalSurgerySuccessChance : StatDefOf.MechanoidOperationSuccessChance, true); if (patient.InBed()) { num *= patient.CurrentBed().GetStatValue(StatDefOf.SurgerySuccessChanceFactor, true); } num *= Recipe_Surgery.MedicineMedicalPotencyToSurgeryChanceFactor.Evaluate(this.GetAverageMedicalPotency(ingredients, bill)); num *= base.recipe.surgerySuccessChanceFactor; if (surgeon.InspirationDef == InspirationDefOf.InspiredSurgery && !patient.RaceProps.IsMechanoid) { if (num < 1.0) { num = (float)(1.0 - (1.0 - num) * 0.10000000149011612); } surgeon.mindState.inspirationHandler.EndInspiration(InspirationDefOf.InspiredSurgery); } if (!Rand.Chance(num)) { if (Rand.Chance(base.recipe.deathOnFailedSurgeryChance)) { HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient, part); if (!patient.Dead) { patient.Kill(null, null); } Messages.Message("MessageMedicalOperationFailureFatal".Translate(surgeon.LabelShort, patient.LabelShort, base.recipe.label), patient, MessageTypeDefOf.NegativeHealthEvent); } else if (Rand.Chance(0.5f)) { if (Rand.Chance(0.1f)) { Messages.Message("MessageMedicalOperationFailureRidiculous".Translate(surgeon.LabelShort, patient.LabelShort), patient, MessageTypeDefOf.NegativeHealthEvent); HealthUtility.GiveInjuriesOperationFailureRidiculous(patient); } else { Messages.Message("MessageMedicalOperationFailureCatastrophic".Translate(surgeon.LabelShort, patient.LabelShort), patient, MessageTypeDefOf.NegativeHealthEvent); HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient, part); } } else { Messages.Message("MessageMedicalOperationFailureMinor".Translate(surgeon.LabelShort, patient.LabelShort), patient, MessageTypeDefOf.NegativeHealthEvent); HealthUtility.GiveInjuriesOperationFailureMinor(patient, part); } if (!patient.Dead) { this.TryGainBotchedSurgeryThought(patient, surgeon); } return(true); } return(false); }