diff --git a/Patch.cs b/Patch.cs index 4ebc275..79966f1 100644 --- a/Patch.cs +++ b/Patch.cs @@ -75,4 +75,15 @@ static void Postfix(CommsRadioController __instance, List ___al ___allModes.Add(jobControl); } } + + //set booklet distance slightly smaller than job distance to ensure the booklets exist no matter where in the station the player is, so the mod can accept a job + [HarmonyPatch(typeof(StationJobGenerationRange), "Awake")] + public static class StationJobGenerationRange_Awake_Patch + { + static void Postfix(StationJobGenerationRange __instance) + { + __instance.jobOverviewBookletGenerationSqrDistance = 249000f; + } + } + } diff --git a/RadioJobControl.cs b/RadioJobControl.cs index b949d6d..d8dea9e 100644 --- a/RadioJobControl.cs +++ b/RadioJobControl.cs @@ -2,11 +2,13 @@ using DV; using DV.Booklets; using DV.Logic.Job; +using DV.ServicePenalty; using DV.ThingTypes; using DV.Utils; using System.Collections.Generic; using System.Linq; using System.Reflection; +using Unity.Jobs; using UnityEngine; using UnityModManagerNet; @@ -137,7 +139,7 @@ public void OnUse() if (PointedCar != null) { CommsRadioController.PlayAudioFromRadio(selectedCarSound, transform); SetState(State.SelectCar); - Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar); + Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar.logicCar); if (jobOfCar == null) { selectedAction = PersistentJobsInstalled ? Act.reassign : Act.exit; } else { @@ -148,11 +150,11 @@ public void OnUse() break; case State.SelectCar: if (PointedCar != null) { - Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar); + Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar.logicCar); switch (selectedAction) { case Act.accept: - if (jobOfCar != null && jobOfCar.State == JobState.Available) { + if (IsValidJob(jobOfCar)) { CommsRadioController.PlayAudioFromRadio(confirmSound, transform); //SingletonBehaviour.Instance.TakeJob(jobOfCar, true); @@ -162,6 +164,7 @@ public void OnUse() List spawnedJobOverviews = (List)typeof(StationController).GetField("spawnedJobOverviews", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(startingStation); JobOverview jobOverview = spawnedJobOverviews.Find(jo => jo.job == jobOfCar); + if (PersistentJobsInstalled) PersistentJobsMod.HarmonyPatches.JobValidators.JobValidator_ProcessJobOverview_Patch.ReserveSpacePJ(jobOfCar, out bool shuntingJobOnWarehouseTrack); startingStation.TakeJobFromStation(jobOverview); BookletCreator.CreateJobBooklet(jobOfCar, valueTuple.Item1, valueTuple.Item2, (Transform)null); @@ -229,7 +232,7 @@ private void UpdateDisplay() string displayText = "manage jobs remotely"; if (PointedCar != null) { displayText = "Car: " + PointedCar.ID.ToString(); - Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar); + Job jobOfCar = SingletonBehaviour.Instance.GetJobOfCar(PointedCar.logicCar); if (jobOfCar != null) { displayText += "\nJob: " + jobOfCar.ID.ToString() + "\nState: " + jobOfCar.State.ToString(); @@ -251,7 +254,7 @@ private void UpdateDisplay() } private bool IsValidAction(Act action) { - bool hasJob = PointedCar != null && SingletonBehaviour.Instance.GetJobOfCar(PointedCar) != null; + bool hasJob = PointedCar != null && SingletonBehaviour.Instance.GetJobOfCar(PointedCar.logicCar) != null; switch (action) { case Act.reassign: return !hasJob && PersistentJobsInstalled; @@ -264,6 +267,18 @@ private bool IsValidAction(Act action) { return true; } + private bool IsValidJob(Job job) + { + if (job != null && job.State == JobState.Available) + { + if (SingletonBehaviour.Instance.currentJobs.Count >= SingletonBehaviour.Instance.GetNumberOfAllowedConcurrentJobs()) return false; + if (!SingletonBehaviour.Instance.IsLicensedForJob(JobLicenseType_v2.ToV2List(job.requiredLicenses))) return false; + if (!SingletonBehaviour.Instance.IsPlayerAllowedToTakeJob()) return false; + return true; + } + return false; + } + public bool ButtonACustomAction() { if (selectedAction != Act.complete) { diff --git a/dvRadioJobControl.csproj b/dvRadioJobControl.csproj index 48d42a8..8380ad8 100644 --- a/dvRadioJobControl.csproj +++ b/dvRadioJobControl.csproj @@ -1,56 +1,122 @@ - - - - net48 - dvRadioJobControlMod - Disable Steam or Diesel for more immersion! - 0.2.0 - true - latest - dvRadioJobControl - E:\Steam\steamapps\common\Derail Valley\DerailValley_Data\Managed - - - - - $(AssemblySearchPaths); - $(ReferencePath); - - - - - enable - - - - - - - - - + + + + net481 + dvRadioJobControlMod + 0.2.0 + true + latest + dvRadioJobControl + + + + + $(AssemblySearchPaths); + $(ReferencePath); + $(DVInstallPath) + + + + + enable + + + + + + + + + + + + + + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + + + + + + - E:\Steam\SteamApps\common\Derail Valley\DerailValley_Data\Managed\Unity.TextMeshPro.dll - - - - - - - - - $(ReferencePath)\..\..\Mods\PersistentJobs\PersistentJobsMod.dll - - - - - - - - - - - - - - + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + + + + + + + + + +