2023-06-21 00:59:14 +03:00
|
|
|
|
using Comfort.Common;
|
2022-09-02 02:28:40 +03:00
|
|
|
|
using EFT;
|
|
|
|
|
using EFT.Interactive;
|
2022-05-08 01:48:04 +03:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-06-21 00:59:14 +03:00
|
|
|
|
using Aki.Custom.Airdrops.Utils;
|
2022-05-08 01:48:04 +03:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace SamSWAT.HeliCrash
|
|
|
|
|
{
|
|
|
|
|
public class HeliCrash : MonoBehaviour
|
|
|
|
|
{
|
2023-06-21 00:59:14 +03:00
|
|
|
|
private AssetBundle _heliBundle;
|
2022-05-08 01:48:04 +03:00
|
|
|
|
|
|
|
|
|
public async void Init(string location)
|
|
|
|
|
{
|
2023-06-21 00:59:14 +03:00
|
|
|
|
var heliLocation = GetHeliCrashLocation(location);
|
|
|
|
|
var choppa = Instantiate(await LoadChoppaAsync(), heliLocation.Position, Quaternion.Euler(heliLocation.Rotation));
|
|
|
|
|
var container = choppa.GetComponentInChildren<LootableContainer>();
|
2022-05-08 01:48:04 +03:00
|
|
|
|
|
2023-06-21 00:59:14 +03:00
|
|
|
|
var itemCrate = Utils.CreateItem("goofyahcontainer", "6223349b3136504a544d1608");
|
|
|
|
|
LootItem.CreateLootContainer(container, itemCrate, "Heavy crate", Singleton<GameWorld>.Instance);
|
2022-05-08 01:48:04 +03:00
|
|
|
|
|
2023-06-21 00:59:14 +03:00
|
|
|
|
new ItemFactoryUtil().AddLoot(container);
|
2022-09-02 02:28:40 +03:00
|
|
|
|
}
|
2022-05-08 01:48:04 +03:00
|
|
|
|
|
2023-06-21 00:59:14 +03:00
|
|
|
|
private void OnDestroy()
|
2022-09-02 02:28:40 +03:00
|
|
|
|
{
|
2023-06-21 00:59:14 +03:00
|
|
|
|
_heliBundle.Unload(true);
|
2022-09-02 02:28:40 +03:00
|
|
|
|
}
|
2022-05-08 01:48:04 +03:00
|
|
|
|
|
2023-06-21 00:59:14 +03:00
|
|
|
|
private Location GetHeliCrashLocation(string location)
|
2022-09-02 02:28:40 +03:00
|
|
|
|
{
|
2023-06-21 00:59:14 +03:00
|
|
|
|
switch (location)
|
2022-05-08 01:48:04 +03:00
|
|
|
|
{
|
|
|
|
|
case "bigmap":
|
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
return Plugin.HeliCrashLocations.Customs.Shuffle().SelectRandom();
|
2022-05-08 01:48:04 +03:00
|
|
|
|
}
|
|
|
|
|
case "Interchange":
|
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
return Plugin.HeliCrashLocations.Interchange.Shuffle().SelectRandom();;
|
2022-05-08 01:48:04 +03:00
|
|
|
|
}
|
|
|
|
|
case "RezervBase":
|
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
return Plugin.HeliCrashLocations.Rezerv.Shuffle().SelectRandom();;
|
2022-05-08 01:48:04 +03:00
|
|
|
|
}
|
|
|
|
|
case "Shoreline":
|
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
return Plugin.HeliCrashLocations.Shoreline.Shuffle().SelectRandom();;
|
2022-05-08 01:48:04 +03:00
|
|
|
|
}
|
|
|
|
|
case "Woods":
|
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
return Plugin.HeliCrashLocations.Woods.Shuffle().SelectRandom();;
|
2022-05-08 01:48:04 +03:00
|
|
|
|
}
|
|
|
|
|
case "Lighthouse":
|
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
return Plugin.HeliCrashLocations.Lighthouse.Shuffle().SelectRandom();;
|
2022-05-08 01:48:04 +03:00
|
|
|
|
}
|
2023-06-21 00:59:14 +03:00
|
|
|
|
case "TarkovStreets":
|
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
return Plugin.HeliCrashLocations.StreetsOfTarkov.Shuffle().SelectRandom();;
|
2023-06-21 00:59:14 +03:00
|
|
|
|
}
|
2022-05-08 01:48:04 +03:00
|
|
|
|
case "develop":
|
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
return Plugin.HeliCrashLocations.Develop.Shuffle().SelectRandom();;
|
2022-05-08 01:48:04 +03:00
|
|
|
|
}
|
|
|
|
|
default: return new Location();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 02:28:40 +03:00
|
|
|
|
private async Task<GameObject> LoadChoppaAsync()
|
2022-05-08 01:48:04 +03:00
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
var path = $"{Plugin.Directory}/Assets/Content/Vehicles/sikorsky_uh60_blackhawk.bundle";
|
2022-09-02 02:28:40 +03:00
|
|
|
|
|
|
|
|
|
var bundleLoadRequest = AssetBundle.LoadFromFileAsync(path);
|
|
|
|
|
|
|
|
|
|
while (!bundleLoadRequest.isDone)
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
2023-06-21 00:59:14 +03:00
|
|
|
|
_heliBundle = bundleLoadRequest.assetBundle;
|
2022-09-02 02:28:40 +03:00
|
|
|
|
|
2023-06-21 00:59:14 +03:00
|
|
|
|
if (_heliBundle == null)
|
2022-09-02 02:28:40 +03:00
|
|
|
|
{
|
2023-06-29 19:30:53 +03:00
|
|
|
|
Plugin.LogSource.LogFatal("Can't load UH-60 Blackhawk bundle");
|
2022-09-02 02:28:40 +03:00
|
|
|
|
Debug.LogError("[SamSWAT.HeliCrash]: Can't load UH-60 Blackhawk bundle");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 00:59:14 +03:00
|
|
|
|
var assetLoadRequest = _heliBundle.LoadAllAssetsAsync<GameObject>();
|
2022-09-02 02:28:40 +03:00
|
|
|
|
|
|
|
|
|
while (!assetLoadRequest.isDone)
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
2023-06-29 19:30:53 +03:00
|
|
|
|
var requestedGo = assetLoadRequest.allAssets[0] as GameObject;
|
2022-09-02 02:28:40 +03:00
|
|
|
|
|
2023-06-29 19:30:53 +03:00
|
|
|
|
if (requestedGo != null) return requestedGo;
|
|
|
|
|
|
|
|
|
|
Plugin.LogSource.LogFatal("Failed to load heli asset");
|
|
|
|
|
Debug.LogError("[SamSWAT.HeliCrash]: failed to load heli asset");
|
|
|
|
|
return null;
|
2022-09-02 02:28:40 +03:00
|
|
|
|
|
|
|
|
|
}
|
2022-05-08 01:48:04 +03:00
|
|
|
|
}
|
|
|
|
|
}
|