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

Add BTR config, and use LocationsWithBTR setting (!65)

Depends on server change: SPT-AKI/Server#203

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: SPT-AKI/Modules#65
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-21 08:46:27 +00:00 committed by chomp
parent 136b051623
commit dee1e4a76c
4 changed files with 58 additions and 11 deletions

View File

@ -28,6 +28,7 @@ namespace Aki.Debugging.BTR
private BotOwner btrBotShooter; private BotOwner btrBotShooter;
private BTRDataPacket btrDataPacket = default; private BTRDataPacket btrDataPacket = default;
private bool btrBotShooterInitialized = false; private bool btrBotShooterInitialized = false;
private float coverFireTime = 90f;
private EPlayerBtrState previousPlayerBtrState; private EPlayerBtrState previousPlayerBtrState;
private BTRSide lastInteractedBtrSide; private BTRSide lastInteractedBtrSide;
@ -149,6 +150,9 @@ namespace Aki.Debugging.BTR
private void InitBTR() private void InitBTR()
{ {
// Fetch config from the server
var serverConfig = BTRUtil.GetConfigFromServer();
// Initial setup // Initial setup
botEventHandler = Singleton<BotEventHandler>.Instance; botEventHandler = Singleton<BotEventHandler>.Instance;
var botsController = Singleton<IBotGame>.Instance.BotsController; var botsController = Singleton<IBotGame>.Instance.BotsController;
@ -159,7 +163,14 @@ namespace Aki.Debugging.BTR
// Initial BTR configuration // Initial BTR configuration
btrServerSide = btrController.BtrVehicle; btrServerSide = btrController.BtrVehicle;
btrServerSide.transform.Find("KillBox").gameObject.AddComponent<BTRRoadKillTrigger>(); btrServerSide.transform.Find("KillBox").gameObject.AddComponent<BTRRoadKillTrigger>();
btrServerSide.moveSpeed = 20f;
// Update values from server side config
btrServerSide.moveSpeed = serverConfig.MoveSpeed;
btrServerSide.pauseDurationRange.x = serverConfig.PointWaitTime.Min;
btrServerSide.pauseDurationRange.y = serverConfig.PointWaitTime.Max;
btrServerSide.readyToDeparture = serverConfig.TaxiWaitTime;
coverFireTime = serverConfig.CoverFireTime;
var btrMapConfig = btrController.MapPathsConfiguration; var btrMapConfig = btrController.MapPathsConfiguration;
btrServerSide.CurrentPathConfig = btrMapConfig.PathsConfiguration.pathsConfigurations.RandomElement(); btrServerSide.CurrentPathConfig = btrMapConfig.PathsConfiguration.pathsConfigurations.RandomElement();
btrServerSide.Initialization(btrMapConfig); btrServerSide.Initialization(btrMapConfig);
@ -230,7 +241,7 @@ namespace Aki.Debugging.BTR
{ {
case ETraderServiceType.BtrBotCover: case ETraderServiceType.BtrBotCover:
botEventHandler.ApplyTraderServiceBtrSupport(passengers); botEventHandler.ApplyTraderServiceBtrSupport(passengers);
StartCoverFireTimer(90f); StartCoverFireTimer(coverFireTime);
break; break;
case ETraderServiceType.PlayerTaxi: case ETraderServiceType.PlayerTaxi:
btrController.BtrVehicle.IsPaid = true; btrController.BtrVehicle.IsPaid = true;

View File

@ -0,0 +1,29 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Aki.Debugging.BTR.Models
{
public class BtrConfigModel
{
[JsonProperty("moveSpeed")]
public float MoveSpeed { get; set; }
[JsonProperty("coverFireTime")]
public float CoverFireTime { get; set; }
[JsonProperty("pointWaitTime")]
public BtrMinMaxValue PointWaitTime { get; set; }
[JsonProperty("taxiWaitTime")]
public float TaxiWaitTime { get; set; }
}
public class BtrMinMaxValue
{
[JsonProperty("min")]
public float Min { get; set; }
[JsonProperty("max")]
public float Max { get; set; }
}
}

View File

@ -1,3 +1,4 @@
using System.Linq;
using System.Reflection; using System.Reflection;
using Aki.Reflection.Patching; using Aki.Reflection.Patching;
using Comfort.Common; using Comfort.Common;
@ -24,17 +25,14 @@ namespace Aki.Debugging.BTR.Patches
{ {
try try
{ {
var btrSettings = Singleton<BackendConfigSettingsClass>.Instance.BTRSettings;
var gameWorld = Singleton<GameWorld>.Instance; var gameWorld = Singleton<GameWorld>.Instance;
if (gameWorld.MainPlayer.Location.ToLower() != "tarkovstreets")
{
// only run patch on streets
return;
}
if (gameWorld.LocationId.IsNullOrEmpty()) // Only run on maps that have the BTR enabled
string location = gameWorld.MainPlayer.Location;
if (!btrSettings.LocationsWithBTR.Contains(location))
{ {
// GameWorld's LocationId needs to be set otherwise BTR doesn't get spawned in automatically return;
gameWorld.LocationId = gameWorld.MainPlayer.Location;
} }
var btrManager = gameWorld.gameObject.AddComponent<BTRManager>(); var btrManager = gameWorld.gameObject.AddComponent<BTRManager>();

View File

@ -1,6 +1,9 @@
using Comfort.Common; using Aki.Common.Http;
using Aki.Debugging.BTR.Models;
using Comfort.Common;
using EFT; using EFT;
using EFT.InventoryLogic; using EFT.InventoryLogic;
using Newtonsoft.Json;
using System; using System;
namespace Aki.Debugging.BTR.Utils namespace Aki.Debugging.BTR.Utils
@ -19,5 +22,11 @@ namespace Aki.Debugging.BTR.Utils
var id = Guid.NewGuid().ToString("N").Substring(0, 24); var id = Guid.NewGuid().ToString("N").Substring(0, 24);
return Singleton<ItemFactory>.Instance.CreateItem(id, tplId, null); return Singleton<ItemFactory>.Instance.CreateItem(id, tplId, null);
} }
public static BtrConfigModel GetConfigFromServer()
{
string json = RequestHandler.GetJson("/singleplayer/btr/config");
return JsonConvert.DeserializeObject<BtrConfigModel>(json);
}
} }
} }