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); }
public static float CalculateAverageTreatmentChance(this Patient patient, RoomDefinition roomDef) { if (roomDef == null) { return(0); } Level level = patient.Level; level.WorldState.GetRoomsOfType(roomDef._type, false, _roomsCache); int count = 0; float chanceOfSuccess = 0; foreach (Room room in _roomsCache) { if (room.WhoCanUse.IsMember(patient) && room.IsFunctional()) { try { var staff = room.AssignedStaff.FirstOrDefault(x => x.Definition._type == StaffDefinition.Type.Doctor); staff = staff ?? room.AssignedStaff.FirstOrDefault(x => x.Definition._type == StaffDefinition.Type.Nurse); if (staff == null || staff.Definition._type == StaffDefinition.Type.Nurse && !room.RequiredStaffAssigned()) { var leaveHistory = Room_StaffLeaveRoom_Patch.leaveHistory; for (int i = leaveHistory.Count - 1; i >= 0; i--) { if (leaveHistory.ElementAt(i).roomId == room.ID) { staff = patient.Level.CharacterManager.StaffMembers.Find(x => x.ID == leaveHistory.ElementAt(i).staffId); if (staff != null) { break; } } } } var breakdown = GameAlgorithms.CalculateEstimatedTreatmentOutcome(patient, staff, room); chanceOfSuccess += breakdown.ChanceOfSuccess; count++; } catch (Exception e) { Main.Logger.Error(e.ToString()); } } } _roomsCache.Clear(); return(count > 0 ? chanceOfSuccess / count : 0); }