private float GetAverageMedicalPotency(List <Thing> ingredients, Bill bill)
        {
            ThingDef thingDef = (bill as Bill_Medical)?.consumedInitialMedicineDef;
            int      num      = 0;
            float    num2     = 0f;

            if (thingDef != null)
            {
                num++;
                num2 += thingDef.GetStatValueAbstract(StatDefOf.MedicalPotency);
            }
            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) * (float)medicine.stackCount;
                }
            }
            if (num == 0)
            {
                return(1f);
            }
            return(num2 / (float)num);
        }
        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;
                }
            }
            float result;

            if (num == 0)
            {
                result = 1f;
            }
            else
            {
                result = num2 / (float)num;
            }
            return(result);
        }
Esempio n. 3
0
        public static void DoTend(Pawn doctor, Pawn patient, Medicine medicine)
        {
            if (!patient.health.HasHediffsNeedingTend(false))
            {
                return;
            }
            if (medicine != null && medicine.Destroyed)
            {
                Log.Warning("Tried to use destroyed medicine.", false);
                medicine = null;
            }
            float quality = TendUtility.CalculateBaseTendQuality(doctor, patient, (medicine == null) ? null : medicine.def);

            TendUtility.GetOptimalHediffsToTendWithSingleTreatment(patient, medicine != null, TendUtility.tmpHediffsToTend, null);
            for (int i = 0; i < TendUtility.tmpHediffsToTend.Count; i++)
            {
                TendUtility.tmpHediffsToTend[i].Tended(quality, i);
            }
            if (doctor != null && doctor.Faction == Faction.OfPlayer && patient.Faction != doctor.Faction && !patient.IsPrisoner && patient.Faction != null)
            {
                patient.mindState.timesGuestTendedToByPlayer++;
            }
            if (doctor != null && doctor.IsColonistPlayerControlled)
            {
                patient.records.AccumulateStoryEvent(StoryEventDefOf.TendedByPlayer);
            }
            if (doctor != null && doctor.RaceProps.Humanlike && patient.RaceProps.Animal && RelationsUtility.TryDevelopBondRelation(doctor, patient, 0.004f) && doctor.Faction != null && doctor.Faction != patient.Faction)
            {
                InteractionWorker_RecruitAttempt.DoRecruit(doctor, patient, 1f, false);
            }
            patient.records.Increment(RecordDefOf.TimesTendedTo);
            if (doctor != null)
            {
                doctor.records.Increment(RecordDefOf.TimesTendedOther);
            }
            if (doctor == patient && !doctor.Dead)
            {
                doctor.mindState.Notify_SelfTended();
            }
            if (medicine != null)
            {
                if ((patient.Spawned || (doctor != null && doctor.Spawned)) && medicine != null && medicine.GetStatValue(StatDefOf.MedicalPotency, true) > ThingDefOf.MedicineIndustrial.GetStatValueAbstract(StatDefOf.MedicalPotency, null))
                {
                    SoundDefOf.TechMedicineUsed.PlayOneShot(new TargetInfo(patient.Position, patient.Map, false));
                }
                if (medicine.stackCount > 1)
                {
                    medicine.stackCount--;
                }
                else if (!medicine.Destroyed)
                {
                    medicine.Destroy(DestroyMode.Vanish);
                }
            }
        }