0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.Custom/BTR/Patches/BTRInteractionPatch.cs
Arys 89f0db250d BTR code refactors and turret aim improvements (!67)
Todo:

* Make BTR spawn at random time during raid instead of at the start
* Find out why some players receive error relating to `BTRBotAttachPatch` resulting BTR failing to initialise

Co-authored-by: Nympfonic <arys.steam@gmail.com>
Reviewed-on: SPT-AKI/Modules#67
Co-authored-by: Arys <arys@noreply.dev.sp-tarkov.com>
Co-committed-by: Arys <arys@noreply.dev.sp-tarkov.com>
2024-01-25 08:52:33 +00:00

60 lines
2.0 KiB
C#

using Aki.Reflection.Patching;
using Comfort.Common;
using EFT;
using EFT.GlobalEvents;
using EFT.Vehicle;
using HarmonyLib;
using System.Reflection;
using GlobalEventHandler = GClass2911;
namespace Aki.Custom.BTR.Patches
{
public class BTRInteractionPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.FirstMethod(typeof(Player), IsTargetMethod);
}
/**
* Find the "BtrInteraction" method that takes parameters
*/
private bool IsTargetMethod(MethodBase method)
{
return method.Name == nameof(Player.BtrInteraction) && method.GetParameters().Length > 0;
}
[PatchPostfix]
private static void PatchPostfix(Player __instance, BTRSide btr, byte placeId, EInteractionType interaction)
{
var gameWorld = Singleton<GameWorld>.Instance;
var btrManager = gameWorld.GetComponent<BTRManager>();
var interactionBtrPacket = btr.GetInteractWithBtrPacket(placeId, interaction);
__instance.UpdateInteractionCast();
// Prevent player from entering BTR when blacklisted
var btrBot = gameWorld.BtrController.BotShooterBtr;
if (btrBot.BotsGroup.Enemies.ContainsKey(__instance))
{
// Notify player they are blacklisted from entering BTR
GlobalEventHandler.CreateEvent<BtrNotificationInteractionMessageEvent>().Invoke(__instance.Id, EBtrInteractionStatus.Blacklisted);
return;
}
if (interactionBtrPacket.HasInteraction)
{
BTRView btrView = gameWorld.BtrController.BtrView;
if (btrView == null)
{
Logger.LogError("[AKI-BTR] BTRInteractionPatch - btrView is null");
return;
}
btrView.Interaction(__instance, interactionBtrPacket);
btrManager.OnPlayerInteractDoor(interactionBtrPacket);
}
}
}
}