protected bool CheckSurgeryFailAndroid(Pawn surgeon, Pawn patient, List <Thing> ingredients, BodyPartRecord part, Bill bill)
        {
            float num = 1f;

            if (!patient.RaceProps.IsMechanoid)
            {
                num *= surgeon.GetStatValue(StatDefOf.AndroidSurgerySuccessChance, true);
            }
            if (patient.InBed())
            {
                num *= patient.CurrentBed().GetStatValue(StatDefOf.AndroidSurgerySuccessChance, true);
            }
            num *= this.recipe.surgerySuccessChanceFactor;
            if (surgeon.InspirationDef == InspirationDefOf.Inspired_Surgery && !patient.RaceProps.IsMechanoid)
            {
                if (num < 1f)
                {
                    num = 1f - (1f - num) * 0.1f;
                }
                surgeon.mindState.inspirationHandler.EndInspiration(InspirationDefOf.Inspired_Surgery);
            }
            if (!Rand.Chance(num))
            {
                if (Rand.Chance(this.recipe.deathOnFailedSurgeryChance))
                {
                    HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient, part);
                    if (!patient.Dead)
                    {
                        patient.Kill(null, null);
                    }
                    Messages.Message("MessageMedicalOperationFailureFatalAndroid".Translate(surgeon.LabelShort, patient.LabelShort, this.recipe.label), patient, MessageTypeDefOf.NegativeHealthEvent);
                }
                else if (Rand.Chance(0.5f))
                {
                    if (Rand.Chance(0.1f))
                    {
                        Messages.Message("MessageMedicalOperationFailureRidiculousAndroid".Translate(surgeon.LabelShort, patient.LabelShort), patient, MessageTypeDefOf.NegativeHealthEvent);
                        HealthUtility.GiveInjuriesOperationFailureRidiculous(patient);
                    }
                    else
                    {
                        Messages.Message("MessageMedicalOperationFailureCatastrophicAndroid".Translate(surgeon.LabelShort, patient.LabelShort), patient, MessageTypeDefOf.NegativeHealthEvent);
                        HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient, part);
                    }
                }
                else
                {
                    Messages.Message("MessageMedicalOperationFailureMinorAndroid".Translate(surgeon.LabelShort, patient.LabelShort), patient, MessageTypeDefOf.NegativeHealthEvent);
                    HealthUtility.GiveInjuriesOperationFailureMinor(patient, part);
                }
                if (!patient.Dead)
                {
                    this.TryGainBotchedSurgeryThought(patient, surgeon);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        protected bool CheckSurgeryFail(Pawn surgeon, Pawn patient, List <Thing> ingredients, BodyPartRecord part, Bill bill)
        {
            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")), patient, MessageTypeDefOf.NegativeHealthEvent);
                        HealthUtility.GiveInjuriesOperationFailureRidiculous(patient);
                    }
                    else
                    {
                        Messages.Message("MessageMedicalOperationFailureCatastrophic".Translate(surgeon.LabelShort, patient.LabelShort, surgeon.Named("SURGEON"), patient.Named("PATIENT")), patient, MessageTypeDefOf.NegativeHealthEvent);
                        HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient, part);
                    }
                }
                else
                {
                    Messages.Message("MessageMedicalOperationFailureMinor".Translate(surgeon.LabelShort, patient.LabelShort, surgeon.Named("SURGEON"), patient.Named("PATIENT")), patient, MessageTypeDefOf.NegativeHealthEvent);
                    HealthUtility.GiveInjuriesOperationFailureMinor(patient, part);
                }
                if (!patient.Dead)
                {
                    TryGainBotchedSurgeryThought(patient, surgeon);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        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);
        }
 protected override void HackingFailEvent(Pawn hacker, Pawn hackee, BodyPartRecord part, Random r)
 {
     base.HackingFailEvent(hacker, hackee, part, r);
     Messages.Message("MessageMedicalOperationFailureMinor".Translate(hacker.LabelShort, hackee.def.label, hacker.Named("SURGEON"), hackee.Named("PATIENT")), hackee, MessageTypeDefOf.NegativeHealthEvent, true);
     HealthUtility.GiveInjuriesOperationFailureMinor(hackee, part);
     foreach (IngredientCount ic in recipe.ingredients)
     {
         Thing t = ThingMaker.MakeThing(ic.filter.AnyAllowedDef, null);
         GenSpawn.Spawn(t, hackee.Position, hackee.Map);
     }
 }
 private static void Nothing(Pawn pawn, BodyPartRecord part)
 {
     //nothing
     Find.LetterStack.ReceiveLetter("WTH_Letter_Nothing_Label".Translate(), "WTH_Letter_Nothing_Description".Translate(), LetterDefOf.NeutralEvent, pawn);
     HealthUtility.GiveInjuriesOperationFailureMinor(pawn, part);
 }
Exemplo n.º 6
0
        internal static bool _CheckSurgeryFail(this Recipe_MedicalOperation m, Pawn surgeon, Pawn patient, List <Thing> ingredients)
        {
            if (surgeon == null)
            {
                Log.Error("surgeon is null");
                return(false);
            }
            if (patient == null)
            {
                Log.Error("patient is null");
                return(false);
            }
            float num1 = 1f;
            float f1   = surgeon.GetStatValue(StatDefOf.SurgerySuccessChance, true);

            if ((double)f1 < 1.0)
            {
                f1 = Mathf.Pow(f1, m.recipe.surgeonSurgerySuccessChanceExponent);
            }
            float num2 = num1 * f1;
            Room  room = surgeon.GetRoom();

            if (room != null)
            {
                float f2 = room.GetStat(RoomStatDefOf.SurgerySuccessChanceFactor);
                if ((double)f2 < 1.0)
                {
                    f2 = Mathf.Pow(f2, m.recipe.roomSurgerySuccessChanceFactorExponent);
                }
                num2 *= f2;
            }
            float potency = 0.0f;
            var   GetAverageMedicalPotency = typeof(Recipe_MedicalOperation).GetMethod("GetAverageMedicalPotency", BindingFlags.Instance | BindingFlags.NonPublic);

            if (GetAverageMedicalPotency != null)
            {
                potency = (float)GetAverageMedicalPotency.Invoke(m, new object[] { ingredients });
            }
            else
            {
                Log.ErrorOnce("Unable to reflect Recipe_MedicalOperation.GetAverageMedicalPotency!", 305432421);
            }
            if ((double)Rand.Value <= (double)(num2 * potency * m.recipe.surgerySuccessChanceFactor))
            {
                return(false);
            }
            if ((double)Rand.Value < (double)m.recipe.deathOnFailedSurgeryChance)
            {
                int num3 = 0;
                while (!patient.Dead)
                {
                    HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient);
                    ++num3;
                    if (num3 > 300)
                    {
                        Log.Error("Could not kill patient.");
                        break;
                    }
                }
            }
            else if ((double)Rand.Value < 0.5)
            {
                Messages.Message("MessageMedicalOperationFailureCatastrophic".Translate((object)surgeon.LabelShort, (object)patient.LabelShort), (TargetInfo)((Thing)patient), MessageSound.SeriousAlert);
                HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient);
            }
            else
            {
                Messages.Message("MessageMedicalOperationFailureMinor".Translate((object)surgeon.LabelShort, (object)patient.LabelShort), (TargetInfo)((Thing)patient), MessageSound.Negative);
                HealthUtility.GiveInjuriesOperationFailureMinor(patient);
            }
            if (!patient.Dead)
            {
                var TryGainBotchedSurgeryThought = typeof(Recipe_MedicalOperation).GetMethod("TryGainBotchedSurgeryThought", BindingFlags.Instance | BindingFlags.NonPublic);
                if (TryGainBotchedSurgeryThought != null)
                {
                    TryGainBotchedSurgeryThought.Invoke(m, new object[] { patient, surgeon });
                }
                else
                {
                    Log.ErrorOnce("Unable to reflect Recipe_MedicalOperation.TryGainBotchedSurgeryThought!", 305432421);
                }
            }
            else
            {
                surgeon.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.KilledPatientBleedingHeart, patient);
            }
            return(true);
        }
Exemplo n.º 7
0
 protected virtual void HackingFailEvent(Pawn hackee, BodyPartRecord part, System.Random r)
 {
     HealthUtility.GiveInjuriesOperationFailureMinor(hackee, part);
 }
Exemplo n.º 8
0
        internal static bool _CheckSurgeryFail(this Recipe_Surgery s, Pawn surgeon, Pawn patient, List <Thing> ingredients, BodyPartRecord part)
        {
            float num  = 1f;
            float num2 = surgeon.GetStatValue(StatDefOf.SurgerySuccessChance, true);

            if (num2 < 1f)
            {
                num2 = Mathf.Pow(num2, s.recipe.surgeonSurgerySuccessChanceExponent);
            }
            num *= num2;
            Room room = surgeon.GetRoom();

            if (room != null)
            {
                float num3 = room.GetStat(RoomStatDefOf.SurgerySuccessChanceFactor);
                if (num3 < 1f)
                {
                    num3 = Mathf.Pow(num3, s.recipe.roomSurgerySuccessChanceFactorExponent);
                }
                num *= num3;
            }
            var GetAverageMedicalPotency = typeof(Recipe_Surgery).GetMethod("GetAverageMedicalPotency", BindingFlags.Instance | BindingFlags.NonPublic);

            if (GetAverageMedicalPotency != null)
            {
                num *= (float)GetAverageMedicalPotency.Invoke(s, new object[] { ingredients });
            }
            num *= s.recipe.surgerySuccessChanceFactor;
            if (Rand.Value > num)
            {
                if (Rand.Value < s.recipe.deathOnFailedSurgeryChance)
                {
                    int num4 = 0;
                    while (!patient.Dead)
                    {
                        HealthUtility.GiveInjuriesOperationFailureRidiculous(patient);
                        num4++;
                        if (num4 > 300)
                        {
                            Log.Error("Could not kill patient.");
                            break;
                        }
                    }
                }
                else if (Rand.Value < 0.5f)
                {
                    if (Rand.Value < 0.1f)
                    {
                        Messages.Message("MessageMedicalOperationFailureRidiculous".Translate(new object[]
                        {
                            surgeon.LabelShort,
                            patient.LabelShort
                        }), patient, MessageSound.SeriousAlert);
                        HealthUtility.GiveInjuriesOperationFailureRidiculous(patient);
                    }
                    else
                    {
                        Messages.Message("MessageMedicalOperationFailureCatastrophic".Translate(new object[]
                        {
                            surgeon.LabelShort,
                            patient.LabelShort
                        }), patient, MessageSound.SeriousAlert);
                        HealthUtility.GiveInjuriesOperationFailureCatastrophic(patient, part);
                    }
                }
                else
                {
                    Messages.Message("MessageMedicalOperationFailureMinor".Translate(new object[]
                    {
                        surgeon.LabelShort,
                        patient.LabelShort
                    }), patient, MessageSound.Negative);
                    HealthUtility.GiveInjuriesOperationFailureMinor(patient, part);
                }
                if (!patient.Dead)
                {
                    var TryGainBotchedSurgeryThought = typeof(Recipe_Surgery).GetMethod("TryGainBotchedSurgeryThought", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (TryGainBotchedSurgeryThought != null)
                    {
                        TryGainBotchedSurgeryThought.Invoke(s, new object[] { patient, surgeon });
                    }
                    else
                    {
                        Log.ErrorOnce("Unable to reflect Recipe_MedicalOperation.TryGainBotchedSurgeryThought!", 305432421);
                    }
                }
                else
                {
                    surgeon.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.KilledPatientBleedingHeart, patient);
                }
                return(true);
            }
            return(false);
        }