static void Postfix(AdvisorTriggerDiagnosisRoomRequired __instance, Patient patient) { if (!Main.enabled || Main.settings.SendtoHomeTreatmentChance == 0) { return; } try { if (!patient.FullyDiagnosed()) { Level level = patient.Level; ResearchManager researchManager = level.ResearchManager; var roomDef = patient.Illness.GetTreatmentRoom(patient, researchManager); patient.SendToTreatmentRoom(roomDef, true); bool haveRoom = GameAlgorithms.DoesHospitalHaveRoom(patient.Level.WorldState, roomDef._type); var knownedIllness = patient.Level.GameplayStatsTracker.HasIllnessBeenDiagnosedBefore(patient.Illness); var treatmentChance = patient.CalculateAverageTreatmentChance(roomDef); if (knownedIllness && (treatmentChance < Main.settings.SendtoHomeTreatmentChance)) { patient.SendHome(); } } } catch (Exception e) { Main.Logger.Error(e.ToString()); } }
static bool Prefix(DiagnosisTreatmentComponent __instance, Patient patient, Staff ____doctor, Room ____room) { if (!Main.enabled) { return(true); } Level level = patient.Level; ResearchManager researchManager = level.ResearchManager; if (____doctor.ModifiersComponent != null) { ____doctor.ModifiersComponent.ApplyInteractWithOtherModifiers(patient); } float certainty = GameAlgorithms.GetDiagnosisCertainty(patient, ____room, ____doctor, researchManager).Certainty; patient.ReceiveDiagnosis(____room, ____doctor, certainty); ____room.OnUnitProcessed(); if (____room.Definition._type == RoomDefinition.Type.GPOffice) { if (patient.FullyDiagnosed()) { var roomDef = patient.Illness.GetTreatmentRoom(patient, researchManager); patient.SendToTreatmentRoom(roomDef, true); bool haveRoom = GameAlgorithms.DoesHospitalHaveRoom(patient.Level.WorldState, roomDef._type); var knownedIllness = patient.Level.GameplayStatsTracker.HasIllnessBeenDiagnosedBefore(patient.Illness); var treatmentChance = CalculateAverageTreatmentChance(patient, roomDef); if (knownedIllness && (haveRoom && treatmentChance < Main.settings.SendtoHomeTreatmentChance || !haveRoom && Main.settings.SendtoHomeIfRoomNotExists)) { SendHome(patient); //Main.Logger.Log($"send to home {patient.Name} room {roomDef._type} diagnosis {patient.DiagnosisCertainty} treatment {treatmentChance}"); } } else { patient.SendToDiagnosisRoom(Traverse.Create(__instance).Method("GetDiagnosisRoom", new Type[] { typeof(Patient), typeof(Staff) }).GetValue <Room>(patient, ____doctor)); } } else { Room bestRoomOfType = GameAlgorithms.GetBestRoomOfType(level.WorldState, RoomDefinition.Type.GPOffice, patient); if (bestRoomOfType != null) { patient.GotoRoom(bestRoomOfType, ReasonUseRoom.Diagnosis, false, -1); } else { patient.WaitForRoomToBeBuilt(RoomDefinition.Type.GPOffice, ReasonUseRoom.Diagnosis, GameAlgorithms.Config.PatientWaitLongTime); } } return(false); }