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

Implement BTR taxi service (!64)

- Move creation/init of the BTRManager to before the `ExtractionTimerPanel.SetTime` method, to fix BTR timer panel not functioning
- Add subserviceId to the `OnTraderServicePurchased` event
- Add BTR taxi service handling

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: SPT-AKI/Modules#64
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-01-20 21:43:02 +00:00 committed by chomp
parent 7c744a4dc0
commit 136b051623
3 changed files with 37 additions and 18 deletions

View File

@ -50,13 +50,7 @@ namespace Aki.Debugging.BTR
_updateTaxiPriceMethod = AccessTools.GetDeclaredMethods(btrControllerType).Single(IsUpdateTaxiPriceMethod); _updateTaxiPriceMethod = AccessTools.GetDeclaredMethods(btrControllerType).Single(IsUpdateTaxiPriceMethod);
} }
// Find `BTRControllerClass.method_9(PathDestination currentDestinationPoint, bool lastRoutePoint)` public void Init()
private bool IsUpdateTaxiPriceMethod(MethodInfo method)
{
return (method.GetParameters().Length == 2 && method.GetParameters()[0].ParameterType == typeof(PathDestination));
}
private void Start()
{ {
try try
{ {
@ -88,6 +82,12 @@ namespace Aki.Debugging.BTR
} }
} }
// Find `BTRControllerClass.method_9(PathDestination currentDestinationPoint, bool lastRoutePoint)`
private bool IsUpdateTaxiPriceMethod(MethodInfo method)
{
return (method.GetParameters().Length == 2 && method.GetParameters()[0].ParameterType == typeof(PathDestination));
}
private void Update() private void Update()
{ {
btrController.SyncBTRVehicleFromServer(UpdateDataPacket()); btrController.SyncBTRVehicleFromServer(UpdateDataPacket());
@ -189,12 +189,18 @@ namespace Aki.Debugging.BTR
} }
/** /**
* BTR has arrived at a destination, re-calculate taxi prices * BTR has arrived at a destination, re-calculate taxi prices and remove purchased taxi service
*/ */
private void ToDestinationEvent(PathDestination destinationPoint, bool isFirst, bool isFinal, bool isLastRoutePoint) private void ToDestinationEvent(PathDestination destinationPoint, bool isFirst, bool isFinal, bool isLastRoutePoint)
{ {
// Remove purchased taxi service
TraderServicesManager.Instance.RemovePurchasedService(ETraderServiceType.PlayerTaxi, BTRUtil.BTRTraderId);
// Update the prices for the taxi service // Update the prices for the taxi service
_updateTaxiPriceMethod.Invoke(btrController, new object[] { destinationPoint, isFinal }); _updateTaxiPriceMethod.Invoke(btrController, new object[] { destinationPoint, isFinal });
// Update the UI
TraderServicesManager.Instance.GetTraderServicesDataFromServer(BTRUtil.BTRTraderId);
} }
private bool IsBtrService(ETraderServiceType serviceType) private bool IsBtrService(ETraderServiceType serviceType)
@ -209,7 +215,7 @@ namespace Aki.Debugging.BTR
return false; return false;
} }
private void BTRTraderServicePurchased(ETraderServiceType serviceType) private void BTRTraderServicePurchased(ETraderServiceType serviceType, string subserviceId)
{ {
if (!IsBtrService(serviceType)) if (!IsBtrService(serviceType))
{ {
@ -227,6 +233,8 @@ namespace Aki.Debugging.BTR
StartCoverFireTimer(90f); StartCoverFireTimer(90f);
break; break;
case ETraderServiceType.PlayerTaxi: case ETraderServiceType.PlayerTaxi:
btrController.BtrVehicle.IsPaid = true;
btrController.BtrVehicle.MoveToDestination(subserviceId);
break; break;
} }
} }

View File

@ -14,11 +14,13 @@ namespace Aki.Debugging.BTR.Patches
{ {
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
return AccessTools.Method(typeof(GameWorld), nameof(GameWorld.OnGameStarted)); // Note: This may seem like a weird place to hook, but `SetTime` requires that the BtrController
// exist and be setup, so we'll use this as the entry point
return AccessTools.Method(typeof(ExtractionTimersPanel), nameof(ExtractionTimersPanel.SetTime));
} }
[PatchPostfix] [PatchPrefix]
private static void PatchPostfix() private static void PatchPrefix()
{ {
try try
{ {
@ -35,7 +37,8 @@ namespace Aki.Debugging.BTR.Patches
gameWorld.LocationId = gameWorld.MainPlayer.Location; gameWorld.LocationId = gameWorld.MainPlayer.Location;
} }
gameWorld.gameObject.AddComponent<BTRManager>(); var btrManager = gameWorld.gameObject.AddComponent<BTRManager>();
btrManager.Init();
} }
catch (System.Exception) catch (System.Exception)
{ {

View File

@ -15,7 +15,7 @@ namespace Aki.SinglePlayer.Utils.TraderServices
/// <summary> /// <summary>
/// Subscribe to this event to trigger trader service logic. /// Subscribe to this event to trigger trader service logic.
/// </summary> /// </summary>
public event Action<ETraderServiceType> OnTraderServicePurchased; public event Action<ETraderServiceType, string> OnTraderServicePurchased;
private static TraderServicesManager _instance; private static TraderServicesManager _instance;
@ -136,10 +136,10 @@ namespace Aki.SinglePlayer.Utils.TraderServices
return; return;
} }
SetServicePurchased(serviceType, serviceData.TraderId); SetServicePurchased(serviceType, subServiceId, serviceData.TraderId);
} }
public void SetServicePurchased(ETraderServiceType serviceType, string traderId) public void SetServicePurchased(ETraderServiceType serviceType, string subserviceId, string traderId)
{ {
if (_servicePurchased.TryGetValue(serviceType, out var traderDict)) if (_servicePurchased.TryGetValue(serviceType, out var traderDict))
{ {
@ -150,7 +150,15 @@ namespace Aki.SinglePlayer.Utils.TraderServices
_servicePurchased[serviceType] = new Dictionary<string, bool>(); _servicePurchased[serviceType] = new Dictionary<string, bool>();
_servicePurchased[serviceType][traderId] = true; _servicePurchased[serviceType][traderId] = true;
} }
OnTraderServicePurchased.Invoke(serviceType); OnTraderServicePurchased.Invoke(serviceType, subserviceId);
}
public void RemovePurchasedService(ETraderServiceType serviceType, string traderId)
{
if (_servicePurchased.TryGetValue(serviceType, out var traderDict))
{
traderDict[traderId] = false;
}
} }
public bool IsServicePurchased(ETraderServiceType serviceType, string traderId) public bool IsServicePurchased(ETraderServiceType serviceType, string traderId)