Exemplo n.º 1
0
        public static MedicalCareCategory TendAdvice(Pawn patient, InjurySeverity severity)
        {
            Population population = patient.GetPopulation();

            Log.Message(PharmacistSettings.medicalCare?.ToString() ?? "settings NULL");
            Log.Message(PharmacistSettings.medicalCare?[population]?.ToString() ?? "population NULL");
            Log.Message(PharmacistSettings.medicalCare?[population]?[severity].ToString() ?? "something NULL");

            var pharmacist    = PharmacistSettings.medicalCare[population][severity];
            var playerSetting = patient?.playerSettings?.medCare ?? MedicalCareCategory.Best;

            #if DEBUG
            Log.Message(
                "Pharmacist :: Advice" +
                $"\n\tpatient: {patient?.LabelShort}" +
                $"\n\tpopulation: {population}" +
                $"\n\tseverity: {severity}" +
                $"\n\tplayerSettings: {playerSetting}" +
                $"\n\tpharmacist: {pharmacist}");
            #endif

            // return lowest
            if (pharmacist < playerSetting)
            {
                return(pharmacist);
            }
            return(playerSetting);
        }
 public InjuryAccidentDetailsDto(InjurySeverity severity, List<string> injuries, List<string> bodyPartsInjured, string customInjury, string customBodyPart, InjuredToHospital takenToHospital, InjuredAbleToWork wasPersonAbleToWork, UnableToWork lengthOfTimeNotWorking)
 {
     Severity = severity;
     Injuries = injuries;
     BodyPartsInjured = bodyPartsInjured;
     CustomInjury = customInjury;
     CustomBodyPart = customBodyPart;
     TakenToHospital = takenToHospital;
     WasPersonAbleToWork = wasPersonAbleToWork;
     LengthOfTimeNotWorking = lengthOfTimeNotWorking;
 }
        protected void AddInjuryToPawn(CustomPawn pawn, InjuryOption option, InjurySeverity severity, BodyPartRecord bodyPart)
        {
            Injury injury = new Injury();

            injury.BodyPartRecord = bodyPart;
            injury.Option         = option;
            if (severity != null)
            {
                injury.Severity = severity.Value;
            }
            else
            {
                injury.Severity = option.HediffDef.initialSeverity;
            }
            pawn.AddInjury(injury);
        }
Exemplo n.º 4
0
        public static MedicalCareCategory TendAdvice(Pawn patient)
        {
            InjurySeverity severity = patient.GetTendSeverity();

            return(TendAdvice(patient, severity));
        }
        protected void ResetSeverityOptions(InjuryOption injuryOption)
        {
            severityOptions.Clear();

            // Don't add stages for addictions since they are handled sort of differently.
            if (injuryOption.HediffDef.hediffClass != null && typeof(Hediff_Addiction).IsAssignableFrom(injuryOption.HediffDef.hediffClass))
            {
                return;
            }

            // If the injury has no stages, add the old injury severity options.
            // TODO: Is this right?
            if (injuryOption.HediffDef.stages == null || injuryOption.HediffDef.stages.Count == 0)
            {
                severityOptions.AddRange(oldInjurySeverities);
                return;
            }

            int            variant  = 1;
            InjurySeverity previous = null;

            foreach (var stage in injuryOption.HediffDef.stages)
            {
                // Filter out a stage if it will definitely kill the pawn.
                if (PrepareCarefully.Instance.HealthManager.InjuryManager.DoesStageKillPawn(injuryOption.HediffDef, stage))
                {
                    continue;
                }

                if (!stage.everVisible)
                {
                    continue;
                }

                InjurySeverity value = null;
                if (stage.minSeverity == 0)
                {
                    float severity = injuryOption.HediffDef.initialSeverity > 0 ? injuryOption.HediffDef.initialSeverity : 0.001f;
                    value = new InjurySeverity(severity, stage);
                }
                else
                {
                    value = new InjurySeverity(stage.minSeverity, stage);
                }
                if (previous == null)
                {
                    previous = value;
                    variant  = 1;
                }
                else
                {
                    if (previous.Stage.label == stage.label)
                    {
                        previous.Variant = variant;
                        variant++;
                        value.Variant = variant;
                    }
                    else
                    {
                        previous = value;
                        variant  = 1;
                    }
                }
                severityOptions.Add(value);
            }
        }
        public void DrawHeader()
        {
            GUI.BeginGroup(RectHeader);
            GUI.color = Color.white;

            // Injury button.
            if (Widgets.ButtonText(new Rect(0, 0, 120, 28), "EdB.PrepareCarefully.AddInjury".Translate(), true, true, true))
            {
                CustomPawn     customPawn                = PrepareCarefully.Instance.State.CurrentPawn;
                InjuryOption   selectedInjury            = null;
                BodyPartRecord selectedBodyPart          = null;
                bool           bodyPartSelectionRequired = true;
                InjurySeverity selectedSeverity          = null;

                Dialog_Options <InjurySeverity> severityDialog;
                Dialog_Options <BodyPartRecord> bodyPartDialog;

                ResetInjuryOptionEnabledState(customPawn);

                Action addInjuryAction = () => {
                    if (bodyPartSelectionRequired)
                    {
                        AddInjuryToPawn(customPawn, selectedInjury, selectedSeverity, selectedBodyPart);
                    }
                    else
                    {
                        if (selectedInjury.ValidParts.Count > 0)
                        {
                            foreach (var p in selectedInjury.ValidParts)
                            {
                                BodyPartRecord record = PrepareCarefully.Instance.HealthManager.FirstBodyPartRecord(customPawn, p);
                                if (record != null)
                                {
                                    AddInjuryToPawn(customPawn, selectedInjury, selectedSeverity, record);
                                }
                                else
                                {
                                    Log.Warning("Could not find body part record for definition: " + p.defName);
                                }
                            }
                        }
                        else
                        {
                            AddInjuryToPawn(customPawn, selectedInjury, selectedSeverity, null);
                        }
                    }
                };

                severityDialog = new Dialog_Options <InjurySeverity>(severityOptions)
                {
                    ConfirmButtonLabel = "EdB.PrepareCarefully.Add",
                    CancelButtonLabel  = "EdB.PrepareCarefully.Cancel",
                    HeaderLabel        = "EdB.PrepareCarefully.SelectSeverity",
                    NameFunc           = (InjurySeverity option) => {
                        if (!string.IsNullOrEmpty(option.Label))
                        {
                            return(option.Label);
                        }
                        else
                        {
                            return(selectedInjury.HediffDef.LabelCap);
                        }
                    },
                    SelectedFunc = (InjurySeverity option) => {
                        return(option == selectedSeverity);
                    },
                    SelectAction = (InjurySeverity option) => {
                        selectedSeverity = option;
                    },
                    ConfirmValidation = () => {
                        if (selectedSeverity == null)
                        {
                            return("EdB.PrepareCarefully.ErrorMustSelectSeverity");
                        }
                        else
                        {
                            return(null);
                        }
                    },
                    CloseAction = () => {
                        addInjuryAction();
                    }
                };

                bodyPartDialog = new Dialog_Options <BodyPartRecord>(null)
                {
                    ConfirmButtonLabel = "EdB.PrepareCarefully.Add",
                    CancelButtonLabel  = "EdB.PrepareCarefully.Cancel",
                    HeaderLabel        = "EdB.PrepareCarefully.SelectBodyPart",
                    NameFunc           = (BodyPartRecord option) => {
                        return(option.def.LabelCap);
                    },
                    SelectedFunc = (BodyPartRecord option) => {
                        return(option == selectedBodyPart);
                    },
                    SelectAction = (BodyPartRecord option) => {
                        selectedBodyPart = option;
                    },
                    EnabledFunc = (BodyPartRecord option) => {
                        return(!disabledBodyParts.Contains(option));
                    },
                    ConfirmValidation = () => {
                        if (selectedBodyPart == null)
                        {
                            return("EdB.PrepareCarefully.ErrorMustSelectBodyPart");
                        }
                        else
                        {
                            return(null);
                        }
                    },
                    CloseAction = () => {
                        if (this.severityOptions.Count > 1)
                        {
                            Find.WindowStack.Add(severityDialog);
                        }
                        else
                        {
                            if (severityOptions.Count > 0)
                            {
                                selectedSeverity = this.severityOptions[0];
                            }
                            addInjuryAction();
                        }
                    }
                };


                Dialog_Options <InjuryOption> injuryOptionDialog
                    = new Dialog_Options <InjuryOption>(PrepareCarefully.Instance.HealthManager.InjuryManager.Options)
                    {
                    ConfirmButtonLabel = "EdB.PrepareCarefully.Next",
                    CancelButtonLabel  = "EdB.PrepareCarefully.Cancel",
                    HeaderLabel        = "EdB.PrepareCarefully.SelectInjury",
                    NameFunc           = (InjuryOption option) => {
                        return(option.Label);
                    },
                    SelectedFunc = (InjuryOption option) => {
                        return(selectedInjury == option);
                    },
                    SelectAction = (InjuryOption option) => {
                        selectedInjury = option;
                        if (option.ValidParts == null)
                        {
                            bodyPartSelectionRequired = true;
                        }
                        else
                        {
                            bodyPartSelectionRequired = false;
                        }
                    },
                    EnabledFunc = (InjuryOption option) => {
                        return(!disabledInjuryOptions.Contains(option));
                    },
                    ConfirmValidation = () => {
                        if (selectedInjury == null)
                        {
                            return("EdB.PrepareCarefully.ErrorMustSelectInjury");
                        }
                        else
                        {
                            return(null);
                        }
                    },
                    CloseAction = () => {
                        ResetSeverityOptions(selectedInjury);
                        if (bodyPartSelectionRequired)
                        {
                            bodyPartDialog.Options = PrepareCarefully.Instance.HealthManager.AllSkinCoveredBodyParts(customPawn);
                            ResetBodyPartEnabledState(bodyPartDialog.Options, customPawn);
                            Find.WindowStack.Add(bodyPartDialog);
                        }
                        else if (severityOptions.Count > 1)
                        {
                            Find.WindowStack.Add(severityDialog);
                        }
                        else
                        {
                            if (severityOptions.Count > 0)
                            {
                                selectedSeverity = this.severityOptions[0];
                            }
                            addInjuryAction();
                        }
                    }
                    };
                Find.WindowStack.Add(injuryOptionDialog);
            }

            // Implant button.
            if (Widgets.ButtonText(new Rect(RectHeader.width - 120, 0, 120, 28),
                                   "EdB.PrepareCarefully.AddImplant".Translate(), true, true, true))
            {
                CustomPawn     customPawn                = PrepareCarefully.Instance.State.CurrentPawn;
                RecipeDef      selectedRecipe            = null;
                BodyPartRecord selectedBodyPart          = null;
                bool           bodyPartSelectionRequired = true;

                Dialog_Options <BodyPartRecord> bodyPartDialog =
                    new Dialog_Options <BodyPartRecord>(null)
                {
                    ConfirmButtonLabel = "EdB.PrepareCarefully.Add",
                    CancelButtonLabel  = "EdB.PrepareCarefully.Cancel",
                    HeaderLabel        = "EdB.PrepareCarefully.SelectBodyPart",
                    NameFunc           = (BodyPartRecord record) => {
                        return(record.def.LabelCap);
                    },
                    SelectedFunc = (BodyPartRecord record) => {
                        return(record == selectedBodyPart);
                    },
                    SelectAction = (BodyPartRecord record) => {
                        selectedBodyPart = record;
                    },
                    EnabledFunc = (BodyPartRecord record) => {
                        return(!disabledBodyParts.Contains(record));
                    },
                    ConfirmValidation = () => {
                        if (selectedBodyPart == null)
                        {
                            return("EdB.PrepareCarefully.ErrorMustSelectBodyPart");
                        }
                        else
                        {
                            return(null);
                        }
                    },
                    CloseAction = () => {
                        customPawn.AddImplant(new Implant(selectedBodyPart, selectedRecipe));
                    }
                };


                Dialog_Options <RecipeDef> implantRecipeDialog = new Dialog_Options <RecipeDef>(PrepareCarefully.Instance.HealthManager.ImplantManager.RecipesForPawn(customPawn))
                {
                    ConfirmButtonLabel = "EdB.PrepareCarefully.Next",
                    CancelButtonLabel  = "EdB.PrepareCarefully.Cancel",
                    HeaderLabel        = "EdB.PrepareCarefully.SelectImplant",
                    NameFunc           = (RecipeDef recipe) => {
                        return(recipe.LabelCap);
                    },
                    SelectedFunc = (RecipeDef recipe) => {
                        return(selectedRecipe == recipe);
                    },
                    SelectAction = (RecipeDef recipe) => {
                        selectedRecipe = recipe;
                        IEnumerable <BodyPartRecord> bodyParts = PrepareCarefully.Instance.HealthManager.ImplantManager.PartsForRecipe(customPawn.Pawn, recipe);
                        int bodyPartCount = bodyParts.Count();
                        if (bodyParts != null && bodyPartCount > 0)
                        {
                            if (bodyPartCount > 1)
                            {
                                selectedBodyPart          = null;
                                bodyPartDialog.Options    = bodyParts;
                                bodyPartSelectionRequired = true;
                                ResetBodyPartEnabledState(bodyParts, customPawn);
                            }
                            else
                            {
                                selectedBodyPart          = bodyParts.First();
                                bodyPartSelectionRequired = false;
                            }
                        }
                        else
                        {
                            selectedBodyPart          = null;
                            bodyPartSelectionRequired = false;
                        }
                    },
                    ConfirmValidation = () => {
                        if (selectedRecipe == null)
                        {
                            return("EdB.PrepareCarefully.ErrorMustSelectImplant");
                        }
                        else
                        {
                            return(null);
                        }
                    },
                    CloseAction = () => {
                        if (bodyPartSelectionRequired)
                        {
                            Find.WindowStack.Add(bodyPartDialog);
                        }
                        else
                        {
                            customPawn.AddImplant(new Implant(selectedBodyPart, selectedRecipe));
                        }
                    }
                };
                Find.WindowStack.Add(implantRecipeDialog);
            }

            GUI.EndGroup();
        }
Exemplo n.º 7
0
            public static void _Postfix(ref MedicalCareCategory __result, Pawn patient, InjurySeverity severity)
            {
                //left original function running for logs

                Population population    = patient.GetPopulation();
                var        pharmacist    = PharmacistSettings.medicalCare[population][severity];
                var        playerSetting = patient?.playerSettings?.medCare ?? MedicalCareCategory.Best;

                //get values which indicate relative medical potency
                int ph = localMedsList.IndexOf((int)pharmacist - 2);
                int ps = localMedsList.IndexOf((int)playerSetting - 2);

                MedicalCareCategory r = playerSetting;

                if (ph < ps)
                {
                    r = pharmacist;
                }

                __result = r;
            }
Exemplo n.º 8
0
        public void DrawAddButton()
        {
            if (RectButtonAdd.Contains(Event.current.mousePosition))
            {
                GUI.color = Style.ColorButtonHighlight;
            }
            else
            {
                GUI.color = Style.ColorButton;
            }
            GUI.DrawTexture(RectButtonAdd, Textures.TextureButtonAdd);

            // Add button.
            if (Widgets.ButtonInvisible(RectButtonAdd, false))
            {
                CustomPawn customPawn = PrepareCarefully.Instance.State.CurrentPawn;

                Action addEntryAction = () => { };

                OptionsHealth  healthOptions             = PrepareCarefully.Instance.Providers.Health.GetOptions(customPawn);
                string         selectedHediffType        = this.selectedHediffType;
                RecipeDef      selectedRecipe            = null;
                InjuryOption   selectedInjury            = null;
                BodyPartRecord selectedBodyPart          = null;
                bool           bodyPartSelectionRequired = true;
                InjurySeverity selectedSeverity          = null;

                Dialog_Options <InjurySeverity> severityDialog;
                Dialog_Options <BodyPartRecord> bodyPartDialog;
                Dialog_Options <InjuryOption>   injuryOptionDialog;
                //Dialog_Options<RecipeDef> implantRecipeDialog;
                DialogManageImplants    manageImplantsDialog;
                Dialog_Options <string> hediffTypeDialog;

                ResetDisabledInjuryOptions(customPawn);

                Action addInjuryAction = () => {
                    if (bodyPartSelectionRequired)
                    {
                        AddInjuryToPawn(selectedInjury, selectedSeverity, selectedBodyPart);
                    }
                    else
                    {
                        if (selectedInjury.ValidParts != null && selectedInjury.ValidParts.Count > 0)
                        {
                            foreach (var p in selectedInjury.ValidParts)
                            {
                                var part = healthOptions.FindBodyPartsForDef(p).FirstOrDefault();
                                if (part != null)
                                {
                                    AddInjuryToPawn(selectedInjury, selectedSeverity, part.Record);
                                }
                                else
                                {
                                    Log.Warning("Could not find body part record for definition: " + p.defName);
                                }
                            }
                        }
                        else
                        {
                            AddInjuryToPawn(selectedInjury, selectedSeverity, null);
                        }
                    }
                };

                severityDialog = new Dialog_Options <InjurySeverity>(severityOptions)
                {
                    ConfirmButtonLabel = "EdB.PC.Common.Add".Translate(),
                    CancelButtonLabel  = "EdB.PC.Common.Cancel".Translate(),
                    HeaderLabel        = "EdB.PC.Panel.Health.SelectSeverity".Translate(),
                    NameFunc           = (InjurySeverity option) => {
                        if (!string.IsNullOrEmpty(option.Label))
                        {
                            return(option.Label);
                        }
                        else
                        {
                            return(selectedInjury.HediffDef.LabelCap);
                        }
                    },
                    SelectedFunc = (InjurySeverity option) => {
                        return(option == selectedSeverity);
                    },
                    SelectAction = (InjurySeverity option) => {
                        selectedSeverity = option;
                    },
                    ConfirmValidation = () => {
                        if (selectedSeverity == null)
                        {
                            return("EdB.PC.Panel.Health.Error.MustSelectSeverity");
                        }
                        else
                        {
                            return(null);
                        }
                    },
                    CloseAction = () => {
                        addInjuryAction();
                    }
                };

                bodyPartDialog = new Dialog_Options <BodyPartRecord>(null)
                {
                    ConfirmButtonLabel = "EdB.PC.Common.Add".Translate(),
                    CancelButtonLabel  = "EdB.PC.Common.Cancel".Translate(),
                    HeaderLabel        = "EdB.PC.Dialog.BodyPart.Header".Translate(),
                    NameFunc           = (BodyPartRecord option) => {
                        return(option.LabelCap);
                    },
                    SelectedFunc = (BodyPartRecord option) => {
                        return(option == selectedBodyPart);
                    },
                    SelectAction = (BodyPartRecord option) => {
                        selectedBodyPart = option;
                    },
                    EnabledFunc = (BodyPartRecord option) => {
                        return(!disabledBodyParts.Contains(option));
                    },
                    ConfirmValidation = () => {
                        if (selectedBodyPart == null)
                        {
                            return("EdB.PC.Dialog.BodyPart.Error.Required");
                        }
                        else
                        {
                            return(null);
                        }
                    },
                    CloseAction = () => {
                        if (selectedHediffType == HediffTypeInjury)
                        {
                            if (this.severityOptions.Count > 1)
                            {
                                Find.WindowStack.Add(severityDialog);
                            }
                            else
                            {
                                if (severityOptions.Count > 0)
                                {
                                    selectedSeverity = this.severityOptions[0];
                                }
                                addInjuryAction();
                            }
                        }
                        else if (selectedHediffType == HediffTypeImplant)
                        {
                            ImplantAdded(new Implant(selectedBodyPart, selectedRecipe));
                        }
                    }
                };

                injuryOptionDialog = new Dialog_Options <InjuryOption>(healthOptions.InjuryOptions)
                {
                    ConfirmButtonLabel = "EdB.PC.Common.Next".Translate(),
                    CancelButtonLabel  = "EdB.PC.Common.Cancel".Translate(),
                    HeaderLabel        = "EdB.PC.Dialog.Injury.Header".Translate(),
                    NameFunc           = (InjuryOption option) => {
                        return(option.Label);
                    },
                    SelectedFunc = (InjuryOption option) => {
                        return(selectedInjury == option);
                    },
                    SelectAction = (InjuryOption option) => {
                        selectedInjury = option;
                        if (option.ValidParts == null && !option.WholeBody)
                        {
                            bodyPartSelectionRequired = true;
                        }
                        else if (option.ValidParts != null && option.ValidParts.Count > 0)
                        {
                            bodyPartSelectionRequired = true;
                        }
                        else
                        {
                            bodyPartSelectionRequired = false;
                        }
                    },
                    EnabledFunc = (InjuryOption option) => {
                        return(!disabledInjuryOptions.Contains(option));
                    },
                    ConfirmValidation = () => {
                        if (selectedInjury == null)
                        {
                            return("EdB.PC.Dialog.Injury.Error.Required");
                        }
                        else
                        {
                            return(null);
                        }
                    },
                    CloseAction = () => {
                        ResetSeverityOptions(selectedInjury);
                        if (bodyPartSelectionRequired)
                        {
                            bodyPartDialog.Options = healthOptions.BodyPartsForInjury(selectedInjury);
                            int count = bodyPartDialog.Options.Count();
                            if (count > 1)
                            {
                                ResetDisabledBodyParts(bodyPartDialog.Options, customPawn);
                                Find.WindowStack.Add(bodyPartDialog);
                                return;
                            }
                            else if (count == 1)
                            {
                                selectedBodyPart = bodyPartDialog.Options.First();
                            }
                        }

                        if (severityOptions.Count > 1)
                        {
                            Find.WindowStack.Add(severityDialog);
                        }
                        else
                        {
                            if (severityOptions.Count > 0)
                            {
                                selectedSeverity = this.severityOptions[0];
                            }
                            addInjuryAction();
                        }
                    }
                };

                hediffTypeDialog = new Dialog_Options <string>(new string[] { HediffTypeInjury, HediffTypeImplant })
                {
                    ConfirmButtonLabel = "EdB.PC.Common.Next".Translate(),
                    CancelButtonLabel  = "EdB.PC.Common.Cancel".Translate(),
                    NameFunc           = (string type) => {
                        return(("EdB.PC.Panel.Health." + type).Translate());
                    },
                    SelectedFunc = (string type) => {
                        return(selectedHediffType == type);
                    },
                    SelectAction = (string type) => {
                        selectedHediffType = type;
                    },
                    ConfirmValidation = () => {
                        if (selectedHediffType == null)
                        {
                            return("EdB.PC.Panel.Health.Error.MustSelectOption");
                        }
                        else
                        {
                            return(null);
                        }
                    },
                    CloseAction = () => {
                        this.selectedHediffType = selectedHediffType;
                        if (selectedHediffType == HediffTypeInjury)
                        {
                            Find.WindowStack.Add(injuryOptionDialog);
                        }
                        else
                        {
                            ResetDisabledImplantRecipes(customPawn);
                            manageImplantsDialog = new DialogManageImplants(customPawn)
                            {
                                HeaderLabel = "EdB.PC.Dialog.Implant.Header".Translate(),
                                CloseAction = (List <Implant> implants) => {
                                    ApplyImplantsToPawn(customPawn, implants);
                                }
                            };
                            Find.WindowStack.Add(manageImplantsDialog);
                        }
                    }
                };
                Find.WindowStack.Add(hediffTypeDialog);
            }
        }
Exemplo n.º 9
0
 public MedicalCareCategory this[InjurySeverity index]
 {
     get => _populationCare[index];