Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,15 @@ static void Postfix(CommsRadioController __instance, List<ICommsRadioMode> ___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;
}
}

}
25 changes: 20 additions & 5 deletions RadioJobControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -137,7 +139,7 @@ public void OnUse()
if (PointedCar != null) {
CommsRadioController.PlayAudioFromRadio(selectedCarSound, transform);
SetState(State.SelectCar);
Job jobOfCar = SingletonBehaviour<JobsManager>.Instance.GetJobOfCar(PointedCar);
Job jobOfCar = SingletonBehaviour<JobsManager>.Instance.GetJobOfCar(PointedCar.logicCar);
if (jobOfCar == null) {
selectedAction = PersistentJobsInstalled ? Act.reassign : Act.exit;
} else {
Expand All @@ -148,11 +150,11 @@ public void OnUse()
break;
case State.SelectCar:
if (PointedCar != null) {
Job jobOfCar = SingletonBehaviour<JobsManager>.Instance.GetJobOfCar(PointedCar);
Job jobOfCar = SingletonBehaviour<JobsManager>.Instance.GetJobOfCar(PointedCar.logicCar);

switch (selectedAction) {
case Act.accept:
if (jobOfCar != null && jobOfCar.State == JobState.Available) {
if (IsValidJob(jobOfCar)) {
CommsRadioController.PlayAudioFromRadio(confirmSound, transform);
//SingletonBehaviour<JobsManager>.Instance.TakeJob(jobOfCar, true);

Expand All @@ -162,6 +164,7 @@ public void OnUse()

List<JobOverview> spawnedJobOverviews = (List<JobOverview>)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);
Expand Down Expand Up @@ -229,7 +232,7 @@ private void UpdateDisplay()
string displayText = "manage jobs remotely";
if (PointedCar != null) {
displayText = "Car: " + PointedCar.ID.ToString();
Job jobOfCar = SingletonBehaviour<JobsManager>.Instance.GetJobOfCar(PointedCar);
Job jobOfCar = SingletonBehaviour<JobsManager>.Instance.GetJobOfCar(PointedCar.logicCar);
if (jobOfCar != null) {
displayText += "\nJob: " + jobOfCar.ID.ToString()
+ "\nState: " + jobOfCar.State.ToString();
Expand All @@ -251,7 +254,7 @@ private void UpdateDisplay()
}

private bool IsValidAction(Act action) {
bool hasJob = PointedCar != null && SingletonBehaviour<JobsManager>.Instance.GetJobOfCar(PointedCar) != null;
bool hasJob = PointedCar != null && SingletonBehaviour<JobsManager>.Instance.GetJobOfCar(PointedCar.logicCar) != null;
switch (action) {
case Act.reassign:
return !hasJob && PersistentJobsInstalled;
Expand All @@ -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<JobsManager>.Instance.currentJobs.Count >= SingletonBehaviour<LicenseManager>.Instance.GetNumberOfAllowedConcurrentJobs()) return false;
if (!SingletonBehaviour<LicenseManager>.Instance.IsLicensedForJob(JobLicenseType_v2.ToV2List(job.requiredLicenses))) return false;
if (!SingletonBehaviour<CareerManagerDebtController>.Instance.IsPlayerAllowedToTakeJob()) return false;
return true;
}
return false;
}

public bool ButtonACustomAction()
{
if (selectedAction != Act.complete) {
Expand Down
176 changes: 121 additions & 55 deletions dvRadioJobControl.csproj
Original file line number Diff line number Diff line change
@@ -1,56 +1,122 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<AssemblyName>dvRadioJobControlMod</AssemblyName>
<Description>Disable Steam or Diesel for more immersion!</Description>
<Version>0.2.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<RootNamespace>dvRadioJobControl</RootNamespace>
<ReferencePath>E:\Steam\steamapps\common\Derail Valley\DerailValley_Data\Managed</ReferencePath>
</PropertyGroup>

<PropertyGroup>
<AssemblySearchPaths>
$(AssemblySearchPaths);
$(ReferencePath);
</AssemblySearchPaths>
</PropertyGroup>

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp" />
<Reference Include="CommandTerminal" />
<Reference Include="DV.Simulation" />
<Reference Include="DV.ThingTypes" />
<Reference Include="DV.UI" />
<Reference Include="DV.Utils" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net481</TargetFramework>
<AssemblyName>dvRadioJobControlMod</AssemblyName>
<Version>0.2.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<RootNamespace>dvRadioJobControl</RootNamespace>
</PropertyGroup>

<PropertyGroup>
<AssemblySearchPaths>
$(AssemblySearchPaths);
$(ReferencePath);
$(DVInstallPath)
</AssemblySearchPaths>
</PropertyGroup>

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<None Remove="Directory.Build.Props" />
<None Remove="LICENSE" />
<None Remove="readme.md" />
<None Remove="repository.json" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.3.6" />
</ItemGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<Private>False</Private>
</Reference>
<Reference Include="DV.Common">
<Private>False</Private>
</Reference>
<Reference Include="DV.Interaction">
<Private>False</Private>
</Reference>
<Reference Include="DV.Inventory">
<Private>False</Private>
</Reference>
<Reference Include="DV.Scenarios.CRUD">
<Private>False</Private>
</Reference>
<Reference Include="DV.Simulation">
<Private>False</Private>
</Reference>
<Reference Include="DV.ThingTypes">
<Private>False</Private>
</Reference>
<Reference Include="DV.UI">
<Private>False</Private>
</Reference>
<Reference Include="DV.UIFramework">
<Private>False</Private>
</Reference>
<Reference Include="DV.UserManagement">
<Private>False</Private>
</Reference>
<Reference Include="DV.Utils">
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Unity.TextMeshPro">
<HintPath>E:\Steam\SteamApps\common\Derail Valley\DerailValley_Data\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI" />
<Reference Include="UnityEngine.IMGUIModule" />
<Reference Include="UnityEngine" />
<Reference Include="UnityEngine.CoreModule" />
<Reference Include="UnityEngine.AudioModule" />
<Reference Include="UnityEngine.PhysicsModule" />
<Reference Include="PersistentJobsMod">
<HintPath>$(ReferencePath)\..\..\Mods\PersistentJobs\PersistentJobsMod.dll</HintPath>
</Reference>

<PackageReference Include="UnityModManager" Version="0.27.2" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<!-- Copy to build folder -->
<Copy SourceFiles="$(TargetPath)" DestinationFolder="build/" />

<!-- Package after Release build -->
<Exec Condition="'$(ConfigurationName)' == 'Release' And '$(OS)' == 'Windows_NT'" Command="powershell -executionpolicy bypass -Command &quot;(./package.ps1)&quot;" />
<Exec Condition="'$(ConfigurationName)' == 'Release' And '$(OS)' != 'Windows_NT'" Command="pwsh -Command &quot;(./package.ps1)&quot;" />
</Target>
</Project>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.ImageConversionModule">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<Private>False</Private>
</Reference>
<Reference Include="UnityModManager">
<Private>False</Private>
</Reference>
<Reference Include="0Harmony">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.AudioModule">
<Private>False</Private>
</Reference>
<Reference Include="CommandTerminal">
<Private>False</Private>
</Reference>
<Reference Include="PersistentJobsMod">
<Private>False</Private>
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<!-- Copy to build folder -->
<Copy SourceFiles="$(TargetPath)" DestinationFolder="build/" />

<!-- Package after Release build -->
<Exec Condition="'$(ConfigurationName)' == 'Release' And '$(OS)' == 'Windows_NT'" Command="powershell -executionpolicy bypass -Command &quot;(./package.ps1)&quot;" />
<Exec Condition="'$(ConfigurationName)' == 'Release' And '$(OS)' != 'Windows_NT'" Command="pwsh -Command &quot;(./package.ps1)&quot;" />
</Target>
</Project>