0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 02:50: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 BTRDataPacket btrDataPacket = default;
private bool btrBotShooterInitialized = false;
private float coverFireTime = 90f;
private EPlayerBtrState previousPlayerBtrState;
private BTRSide lastInteractedBtrSide;
@ -149,6 +150,9 @@ namespace Aki.Debugging.BTR
private void InitBTR()
{
// Fetch config from the server
var serverConfig = BTRUtil.GetConfigFromServer();
// Initial setup
botEventHandler = Singleton<BotEventHandler>.Instance;
var botsController = Singleton<IBotGame>.Instance.BotsController;
@ -159,7 +163,14 @@ namespace Aki.Debugging.BTR
// Initial BTR configuration
btrServerSide = btrController.BtrVehicle;
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;
btrServerSide.CurrentPathConfig = btrMapConfig.PathsConfiguration.pathsConfigurations.RandomElement();
btrServerSide.Initialization(btrMapConfig);
@ -230,7 +241,7 @@ namespace Aki.Debugging.BTR
{
case ETraderServiceType.BtrBotCover:
botEventHandler.ApplyTraderServiceBtrSupport(passengers);
StartCoverFireTimer(90f);
StartCoverFireTimer(coverFireTime);
break;
case ETraderServiceType.PlayerTaxi:
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 Aki.Reflection.Patching;
using Comfort.Common;
@ -24,17 +25,14 @@ namespace Aki.Debugging.BTR.Patches
{
try
{
var btrSettings = Singleton<BackendConfigSettingsClass>.Instance.BTRSettings;
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
gameWorld.LocationId = gameWorld.MainPlayer.Location;
return;
}
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.InventoryLogic;
using Newtonsoft.Json;
using System;
namespace Aki.Debugging.BTR.Utils
@ -19,5 +22,11 @@ namespace Aki.Debugging.BTR.Utils
var id = Guid.NewGuid().ToString("N").Substring(0, 24);
return Singleton<ItemFactory>.Instance.CreateItem(id, tplId, null);
}
public static BtrConfigModel GetConfigFromServer()
{
string json = RequestHandler.GetJson("/singleplayer/btr/config");
return JsonConvert.DeserializeObject<BtrConfigModel>(json);
}
}
}