39 lines
1.1 KiB
C#
Raw Normal View History

2022-05-08 01:48:04 +03:00
using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
2022-05-08 01:48:04 +03:00
using Comfort.Common;
using EFT;
using EFT.Airdrop;
2022-05-08 01:48:04 +03:00
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace SamSWAT.HeliCrash
{
public class HeliCrashPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
2023-06-21 00:59:14 +03:00
return PatchConstants.LocalGameType.BaseType.GetMethod("method_10", BindingFlags.NonPublic | BindingFlags.Instance);
2022-05-08 01:48:04 +03:00
}
[PatchPostfix]
public static void PatchPostfix()
2022-05-08 01:48:04 +03:00
{
var gameWorld = Singleton<GameWorld>.Instance;
bool crashAvailable = LocationScene.GetAll<AirdropPoint>().Any();
2022-06-26 18:50:55 +03:00
string location = gameWorld.RegisteredPlayers[0].Location;
2022-05-08 01:48:04 +03:00
2022-06-26 18:50:55 +03:00
if (gameWorld != null && crashAvailable && WillHeliCrash())
2022-05-08 01:48:04 +03:00
{
2022-06-26 18:50:55 +03:00
var heliCrash = gameWorld.gameObject.AddComponent<HeliCrash>();
2022-05-08 01:48:04 +03:00
heliCrash.Init(location);
}
}
private static bool WillHeliCrash()
2022-05-08 01:48:04 +03:00
{
return Random.Range(0, 100) <= Plugin.HeliCrashChance.Value;
}
}
}