Skip to content

Commit

Permalink
Update BTR to latest from SPT
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jun 19, 2024
1 parent 9cb3937 commit 019a6f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
25 changes: 15 additions & 10 deletions Fika.Core/Coop/BTR/FikaBTRManager_Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void InitBtr()
{
// Initial setup
botEventHandler = Singleton<BotEventHandler>.Instance;
var botsController = Singleton<IBotGame>.Instance.BotsController;
BotsController botsController = Singleton<IBotGame>.Instance.BotsController;
btrBotService = botsController.BotTradersServices.BTRServices;
btrController.method_3(); // spawns server-side BTR game object
//botsController.BotSpawner.SpawnBotBTR(); // spawns the scav bot which controls the BTR's turret
Expand Down Expand Up @@ -272,7 +272,7 @@ private void InitBtr()

// Initialise turret variables
btrTurretServer = btrServerSide.BTRTurret;
var btrTurretDefaultTargetTransform = (Transform)AccessTools.Field(btrTurretServer.GetType(), "defaultTargetTransform").GetValue(btrTurretServer);
Transform btrTurretDefaultTargetTransform = (Transform)AccessTools.Field(btrTurretServer.GetType(), "defaultTargetTransform").GetValue(btrTurretServer);
isTurretInDefaultRotation = btrTurretServer.targetTransform == btrTurretDefaultTargetTransform
&& btrTurretServer.targetPosition == btrTurretServer.defaultAimingPosition;
btrMachineGunAmmo = (BulletClass)BTRUtil.CreateItem(BTRUtil.BTRMachineGunAmmoTplId);
Expand All @@ -284,7 +284,7 @@ private void InitBtr()

private void ConfigureSettingsFromServer()
{
var serverConfig = BTRUtil.GetConfigFromServer();
SPT.Custom.BTR.Models.BTRConfigModel serverConfig = BTRUtil.GetConfigFromServer();

btrServerSide.moveSpeed = serverConfig.MoveSpeed;
btrServerSide.pauseDurationRange.x = serverConfig.PointWaitTime.Min;
Expand Down Expand Up @@ -396,13 +396,18 @@ private void DisableServerSideObjects()

btrServerSide.turnCheckerObject.GetComponent<Renderer>().enabled = false; // Disables the red debug sphere

// Something is colliding with each other. We disabled the Main exterior collider on server objects
// and changed the layer of the Client exterior collider to be highPolyCollider to stop it twerking. Needs Proper fix
MeshCollider[] servercolliders = btrServerSide.transform.GetComponentsInChildren<MeshCollider>();
MeshCollider[] clientcolliders = btrClientSide.transform.GetComponentsInChildren<MeshCollider>();

clientcolliders.FirstOrDefault(x => x.gameObject.name == "BTR_82_exterior_COLLIDER").gameObject.layer = LayerMask.NameToLayer("HighPolyCollider");
servercolliders.FirstOrDefault(x => x.gameObject.name == "BTR_82_exterior_COLLIDER").enabled = false;
// For some reason the client BTR collider is disabled but the server collider is enabled.
// Initially we assumed there was a reason for this so it was left as is.
// Turns out disabling the server collider in favour of the client collider fixes the "BTR doing a wheelie" bug,
// while preventing the player from walking through the BTR.
const string exteriorColliderName = "BTR_82_exterior_COLLIDER";
Collider serverExteriorCollider = btrServerSide.GetComponentsInChildren<Collider>(true)
.First(x => x.gameObject.name == exteriorColliderName);
Collider clientExteriorCollider = btrClientSide.GetComponentsInChildren<Collider>(true)
.First(x => x.gameObject.name == exteriorColliderName);

serverExteriorCollider.gameObject.SetActive(false);
clientExteriorCollider.gameObject.SetActive(true);
}

public void ClientInteraction(Player player, PlayerInteractPacket packet)
Expand Down
25 changes: 15 additions & 10 deletions Fika.Core/Coop/BTR/FikaBTRManager_Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,18 @@ private void DisableServerSideObjects()

btrServerSide.turnCheckerObject.GetComponent<Renderer>().enabled = false; // Disables the red debug sphere

// Something is colliding with each other. We disabled the Main exterior collider on server objects
// and changed the layer of the Client exterior collider to be highPolyCollider to stop it twerking. Needs Proper fix
MeshCollider[] servercolliders = btrServerSide.transform.GetComponentsInChildren<MeshCollider>();
MeshCollider[] clientcolliders = btrClientSide.transform.GetComponentsInChildren<MeshCollider>();

clientcolliders.FirstOrDefault(x => x.gameObject.name == "BTR_82_exterior_COLLIDER").gameObject.layer = LayerMask.NameToLayer("HighPolyCollider");
servercolliders.FirstOrDefault(x => x.gameObject.name == "BTR_82_exterior_COLLIDER").enabled = false;
// For some reason the client BTR collider is disabled but the server collider is enabled.
// Initially we assumed there was a reason for this so it was left as is.
// Turns out disabling the server collider in favour of the client collider fixes the "BTR doing a wheelie" bug,
// while preventing the player from walking through the BTR.
const string exteriorColliderName = "BTR_82_exterior_COLLIDER";
Collider serverExteriorCollider = btrServerSide.GetComponentsInChildren<Collider>(true)
.First(x => x.gameObject.name == exteriorColliderName);
Collider clientExteriorCollider = btrClientSide.GetComponentsInChildren<Collider>(true)
.First(x => x.gameObject.name == exteriorColliderName);

serverExteriorCollider.gameObject.SetActive(false);
clientExteriorCollider.gameObject.SetActive(true);
}

private void UpdateTarget()
Expand Down Expand Up @@ -607,7 +612,7 @@ private IEnumerator ShootMachineGun()
{
isShooting = true;

yield return new WaitForSecondsRealtime(machineGunAimDelay);
yield return new WaitForSeconds(machineGunAimDelay);
if (currentTarget?.Person == null || currentTarget?.IsVisible == false || !btrBotShooter.BotBtrData.CanShoot())
{
isShooting = false;
Expand All @@ -633,11 +638,11 @@ private IEnumerator ShootMachineGun()
firearmController.method_54(weaponSoundPlayer, btrMachineGunAmmo, machineGunMuzzle.position, aimDirection, false);
burstCount--;
shotQueue.Enqueue(new(machineGunMuzzle.position, aimDirection));
yield return new WaitForSecondsRealtime(0.092308f); // 650 RPM
yield return new WaitForSeconds(0.092308f); // 650 RPM
}

float waitTime = Random.Range(machineGunRecoveryTime.x, machineGunRecoveryTime.y);
yield return new WaitForSecondsRealtime(waitTime);
yield return new WaitForSeconds(waitTime);

isShooting = false;
}
Expand Down

0 comments on commit 019a6f5

Please sign in to comment.