0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 06:30:43 -05:00

Fix LightKeeper tasks not progressing correctly (!91)

To handle in-raid LK task unlocking, when a task is switched from AvailableAfter to Locked, instead switch it to AvailableForStart

This handles the lack of `status` values for tasks, where the target state would normally be read from, without risking breaking non-LK tasks by adding that data.

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: SPT-AKI/Modules#91
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-03-09 22:44:56 +00:00 committed by chomp
parent b87b569ece
commit f1a7a0cb99
2 changed files with 59 additions and 0 deletions

View File

@ -42,6 +42,7 @@ namespace Aki.SinglePlayer
new SpawnPmcPatch().Enable();
new PostRaidHealingPricePatch().Enable();
new EndByTimerPatch().Enable();
new InRaidQuestAvailablePatch().Enable();
new PostRaidHealScreenPatch().Enable();
new VoIPTogglerPatch().Enable();
new MidRaidQuestChangePatch().Enable();

View File

@ -0,0 +1,58 @@
using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
using EFT.Quests;
using HarmonyLib;
using System;
using System.Linq;
using System.Reflection;
namespace Aki.SinglePlayer.Patches.Quests
{
/**
* Lightkeeper quests change their state in-raid, and will change to the `AppearStatus` of the quest once
* the AvailableAfter time has been hit. This defaults to `Locked`, but should actually be `AvailableForStart`
*
* So if we get a quest state change from `AvailableAfter` to `Locked`, we should actually change to `AvailableForStart`
*/
public class InRaidQuestAvailablePatch : ModulePatch
{
private static PropertyInfo _questStatusProperty;
protected override MethodBase GetTargetMethod()
{
var targetType = PatchConstants.EftTypes.FirstOrDefault(IsTargetType);
var targetMethod = AccessTools.Method(targetType, "SetStatus");
_questStatusProperty = AccessTools.Property(targetType, "QuestStatus");
Logger.LogDebug($"{this.GetType().Name} Type: {targetType?.Name}");
Logger.LogDebug($"{this.GetType().Name} Method: {targetMethod?.Name}");
Logger.LogDebug($"{this.GetType().Name} QuestStatus: {_questStatusProperty?.Name}");
return targetMethod;
}
private bool IsTargetType(Type type)
{
if (type.GetProperty("StatusTransition") != null &&
type.GetProperty("IsChangeAllowed") != null &&
type.GetProperty("NeedCountdown") == null)
{
return true;
}
return false;
}
[PatchPrefix]
private static void PatchPrefix(object __instance, ref EQuestStatus status)
{
var currentStatus = (EQuestStatus)_questStatusProperty.GetValue(__instance);
if (currentStatus == EQuestStatus.AvailableAfter && status == EQuestStatus.Locked)
{
status = EQuestStatus.AvailableForStart;
}
}
}
}