mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 09:50:43 -05:00
Work towards implementing LK services (!79)
- Move clearing trader service data to raid end instead of as part of BTR Manager - Fix data type for TraderServices ItemsToPay property - Add ItemsToReceive property to TraderServices (Used for LK amulet) - Don't throw NRE when nothing is bound to OnTraderServicePurchased Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: SPT-AKI/Modules#79 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:
parent
5622e05b13
commit
d08754fb61
@ -67,6 +67,8 @@ namespace Aki.Custom
|
|||||||
new BTRDestroyAtRaidEndPatch().Enable();
|
new BTRDestroyAtRaidEndPatch().Enable();
|
||||||
new BTRVehicleMovementSpeedPatch().Enable();
|
new BTRVehicleMovementSpeedPatch().Enable();
|
||||||
new ScavItemCheckmarkPatch().Enable();
|
new ScavItemCheckmarkPatch().Enable();
|
||||||
|
new ResetTraderServicesPatch().Enable();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -491,7 +491,6 @@ namespace Aki.Custom.BTR
|
|||||||
if (TraderServicesManager.Instance != null)
|
if (TraderServicesManager.Instance != null)
|
||||||
{
|
{
|
||||||
TraderServicesManager.Instance.OnTraderServicePurchased -= BtrTraderServicePurchased;
|
TraderServicesManager.Instance.OnTraderServicePurchased -= BtrTraderServicePurchased;
|
||||||
TraderServicesManager.Instance.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameWorld.MainPlayer != null)
|
if (gameWorld.MainPlayer != null)
|
||||||
|
22
project/Aki.Custom/Patches/ResetTraderServicesPatch.cs
Normal file
22
project/Aki.Custom/Patches/ResetTraderServicesPatch.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using Aki.Reflection.Patching;
|
||||||
|
using Aki.SinglePlayer.Utils.TraderServices;
|
||||||
|
using EFT;
|
||||||
|
using HarmonyLib;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Aki.Custom.Patches
|
||||||
|
{
|
||||||
|
public class ResetTraderServicesPatch : ModulePatch
|
||||||
|
{
|
||||||
|
protected override MethodBase GetTargetMethod()
|
||||||
|
{
|
||||||
|
return AccessTools.Method(typeof(BaseLocalGame<GamePlayerOwner>), nameof(BaseLocalGame<GamePlayerOwner>.Stop));
|
||||||
|
}
|
||||||
|
|
||||||
|
[PatchPrefix]
|
||||||
|
private static void PatchPrefix()
|
||||||
|
{
|
||||||
|
TraderServicesManager.Instance.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -63,6 +63,7 @@ namespace Aki.SinglePlayer
|
|||||||
new ScavSellAllPriceStorePatch().Enable();
|
new ScavSellAllPriceStorePatch().Enable();
|
||||||
new ScavSellAllRequestPatch().Enable();
|
new ScavSellAllRequestPatch().Enable();
|
||||||
new HideoutQuestIgnorePatch().Enable();
|
new HideoutQuestIgnorePatch().Enable();
|
||||||
|
new LightKeeperServicesPatch().Enable();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
using Aki.Reflection.Patching;
|
||||||
|
using Aki.SinglePlayer.Utils.TraderServices;
|
||||||
|
using Comfort.Common;
|
||||||
|
using EFT;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Aki.SinglePlayer.Patches.TraderServices
|
||||||
|
{
|
||||||
|
public class LightKeeperServicesPatch : ModulePatch
|
||||||
|
{
|
||||||
|
protected override MethodBase GetTargetMethod()
|
||||||
|
{
|
||||||
|
return typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted));
|
||||||
|
}
|
||||||
|
|
||||||
|
[PatchPostfix]
|
||||||
|
public static void PatchPostFix()
|
||||||
|
{
|
||||||
|
var gameWorld = Singleton<GameWorld>.Instance;
|
||||||
|
|
||||||
|
if (gameWorld != null)
|
||||||
|
{
|
||||||
|
gameWorld.gameObject.AddComponent<LightKeeperServicesManager>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
using BepInEx.Logging;
|
||||||
|
using Comfort.Common;
|
||||||
|
using EFT;
|
||||||
|
using HarmonyLib.Tools;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Aki.SinglePlayer.Utils.TraderServices
|
||||||
|
{
|
||||||
|
internal class LightKeeperServicesManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
private static ManualLogSource logger;
|
||||||
|
GameWorld gameWorld;
|
||||||
|
BotsController botsController;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
logger = BepInEx.Logging.Logger.CreateLogSource(nameof(LightKeeperServicesManager));
|
||||||
|
|
||||||
|
gameWorld = Singleton<GameWorld>.Instance;
|
||||||
|
if (gameWorld == null || TraderServicesManager.Instance == null)
|
||||||
|
{
|
||||||
|
logger.LogError("[AKI-LKS] GameWorld or TraderServices null");
|
||||||
|
Destroy(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
botsController = Singleton<IBotGame>.Instance.BotsController;
|
||||||
|
if (botsController == null)
|
||||||
|
{
|
||||||
|
logger.LogError("[AKI-LKS] BotsController null");
|
||||||
|
Destroy(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TraderServicesManager.Instance.OnTraderServicePurchased += OnTraderServicePurchased;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTraderServicePurchased(ETraderServiceType serviceType, string subserviceId)
|
||||||
|
{
|
||||||
|
switch (serviceType)
|
||||||
|
{
|
||||||
|
case ETraderServiceType.ExUsecLoyalty:
|
||||||
|
botsController.BotTradersServices.LighthouseKeeperServices.OnFriendlyExUsecPurchased(gameWorld.MainPlayer);
|
||||||
|
break;
|
||||||
|
case ETraderServiceType.ZryachiyAid:
|
||||||
|
botsController.BotTradersServices.LighthouseKeeperServices.OnFriendlyZryachiyPurchased(gameWorld.MainPlayer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
if (gameWorld == null || botsController == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TraderServicesManager.Instance != null)
|
||||||
|
{
|
||||||
|
TraderServicesManager.Instance.OnTraderServicePurchased -= OnTraderServicePurchased;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,9 +10,12 @@ namespace Aki.SinglePlayer.Utils.TraderServices
|
|||||||
public ETraderServiceType ServiceType { get; set; }
|
public ETraderServiceType ServiceType { get; set; }
|
||||||
|
|
||||||
[JsonProperty("itemsToPay")]
|
[JsonProperty("itemsToPay")]
|
||||||
public Dictionary<string, int> ItemsToPay { get; set; }
|
public Dictionary<MongoID, int> ItemsToPay { get; set; }
|
||||||
|
|
||||||
[JsonProperty("subServices")]
|
[JsonProperty("subServices")]
|
||||||
public Dictionary<string, int> SubServices { get; set; }
|
public Dictionary<string, int> SubServices { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("itemsToReceive")]
|
||||||
|
public MongoID[] ItemsToReceive { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -78,24 +78,17 @@ namespace Aki.SinglePlayer.Utils.TraderServices
|
|||||||
// Only populate trader services that don't exist yet
|
// Only populate trader services that don't exist yet
|
||||||
if (!servicesData.ContainsKey(traderServiceModel.ServiceType))
|
if (!servicesData.ContainsKey(traderServiceModel.ServiceType))
|
||||||
{
|
{
|
||||||
TraderServiceClass traderService = new TraderServiceClass();
|
TraderServiceClass traderService = new TraderServiceClass
|
||||||
traderService.TraderId = traderId;
|
|
||||||
traderService.ServiceType = serviceType;
|
|
||||||
traderService.ItemsToPay = new Dictionary<MongoID, int>();
|
|
||||||
if (traderServiceModel.ItemsToPay != null)
|
|
||||||
{
|
{
|
||||||
foreach (var item in traderServiceModel.ItemsToPay)
|
TraderId = traderId,
|
||||||
{
|
ServiceType = serviceType,
|
||||||
traderService.ItemsToPay[item.Key] = item.Value;
|
UniqueItems = traderServiceModel.ItemsToReceive ?? new MongoID[0],
|
||||||
}
|
ItemsToPay = traderServiceModel.ItemsToPay ?? new Dictionary<MongoID, int>(),
|
||||||
}
|
|
||||||
|
|
||||||
// SubServices seem to be populated dynamically in the client (For BTR taxi atleast), so we can just ignore it
|
// SubServices seem to be populated dynamically in the client (For BTR taxi atleast), so we can just ignore it
|
||||||
// NOTE: For future reference, this is a dict of `point id` to `price` for the BTR taxi
|
// NOTE: For future reference, this is a dict of `point id` to `price` for the BTR taxi
|
||||||
traderService.SubServices = new Dictionary<string, int>();
|
SubServices = new Dictionary<string, int>()
|
||||||
|
};
|
||||||
// TODO: What is this used for? Maybe lightkeeper?
|
|
||||||
traderService.UniqueItems = new MongoID[] { };
|
|
||||||
|
|
||||||
// Convert our format to the backend settings format and store it
|
// Convert our format to the backend settings format and store it
|
||||||
serviceData = new ServiceData(traderService);
|
serviceData = new ServiceData(traderService);
|
||||||
@ -156,8 +149,12 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OnTraderServicePurchased != null)
|
||||||
|
{
|
||||||
OnTraderServicePurchased.Invoke(serviceType, subserviceId);
|
OnTraderServicePurchased.Invoke(serviceType, subserviceId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void RemovePurchasedService(ETraderServiceType serviceType, string traderId)
|
public void RemovePurchasedService(ETraderServiceType serviceType, string traderId)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user