111 lines
3.5 KiB
C#
Raw Normal View History

2023-06-21 00:59:14 +03:00
using Comfort.Common;
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-05-08 01:48:04 +03:00
2023-06-21 00:59:14 +03:00
private void OnDestroy()
{
2023-06-21 00:59:14 +03:00
_heliBundle.Unload(true);
}
2022-05-08 01:48:04 +03:00
2023-06-21 00:59:14 +03:00
private Location GetHeliCrashLocation(string location)
{
2023-06-21 00:59:14 +03:00
switch (location)
2022-05-08 01:48:04 +03:00
{
case "bigmap":
{
2022-06-26 18:50:55 +03:00
return PickRandom(Plugin.HeliCrashLocations.Customs);
2022-05-08 01:48:04 +03:00
}
case "Interchange":
{
2022-06-26 18:50:55 +03:00
return PickRandom(Plugin.HeliCrashLocations.Interchange);
2022-05-08 01:48:04 +03:00
}
case "RezervBase":
{
2022-06-26 18:50:55 +03:00
return PickRandom(Plugin.HeliCrashLocations.Rezerv);
2022-05-08 01:48:04 +03:00
}
case "Shoreline":
{
2022-06-26 18:50:55 +03:00
return PickRandom(Plugin.HeliCrashLocations.Shoreline);
2022-05-08 01:48:04 +03:00
}
case "Woods":
{
2022-06-26 18:50:55 +03:00
return PickRandom(Plugin.HeliCrashLocations.Woods);
2022-05-08 01:48:04 +03:00
}
case "Lighthouse":
{
2022-06-26 18:50:55 +03:00
return PickRandom(Plugin.HeliCrashLocations.Lighthouse);
2022-05-08 01:48:04 +03:00
}
2023-06-21 00:59:14 +03:00
case "TarkovStreets":
{
return PickRandom(Plugin.HeliCrashLocations.StreetsOfTarkov);
}
2022-05-08 01:48:04 +03:00
case "develop":
{
2022-06-26 18:50:55 +03:00
return PickRandom(Plugin.HeliCrashLocations.Develop);
2022-05-08 01:48:04 +03:00
}
default: return new Location();
}
}
private async Task<GameObject> LoadChoppaAsync()
2022-05-08 01:48:04 +03:00
{
string path = Plugin.Directory + "Assets/Content/Vehicles/sikorsky_uh60_blackhawk.bundle";
var bundleLoadRequest = AssetBundle.LoadFromFileAsync(path);
while (!bundleLoadRequest.isDone)
await Task.Yield();
2023-06-21 00:59:14 +03:00
_heliBundle = bundleLoadRequest.assetBundle;
2023-06-21 00:59:14 +03:00
if (_heliBundle == null)
{
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>();
while (!assetLoadRequest.isDone)
await Task.Yield();
var requestedGO = assetLoadRequest.allAssets[0] as GameObject;
if (requestedGO == null)
{
Debug.LogError("[SamSWAT.HeliCrash]: failed to load asset");
return null;
}
return requestedGO;
2022-05-08 01:48:04 +03:00
}
2022-05-08 01:53:35 +03:00
private T PickRandom<T>(List<T> list)
{
2023-06-21 00:59:14 +03:00
return list[Random.Range(0, list.Count)];
}
2022-05-08 01:48:04 +03:00
}
}