add loot generation code partially stolen from CWX and update for aki 3.2.2
This commit is contained in:
parent
6f42748d06
commit
1aae2f194c
22
project/SamSWAT.HeliCrash/GeneratedContainer.cs
Normal file
22
project/SamSWAT.HeliCrash/GeneratedContainer.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SamSWAT.HeliCrash.Json
|
||||
{
|
||||
public class GeneratedContainer
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Root { get; set; }
|
||||
public List<ItemInfo> Items { get; set; }
|
||||
}
|
||||
|
||||
public class ItemInfo
|
||||
{
|
||||
public string _id { get; set; }
|
||||
public string _tpl { get; set; }
|
||||
public string parentId { get; set; }
|
||||
public string slotId { get; set; }
|
||||
public LocationInGrid location { get; set; }
|
||||
public JObject upd { get; set; }
|
||||
}
|
||||
}
|
@ -1,7 +1,13 @@
|
||||
using EFT.Interactive;
|
||||
using Aki.Common.Http;
|
||||
using Comfort.Common;
|
||||
using EFT;
|
||||
using EFT.Interactive;
|
||||
using EFT.InventoryLogic;
|
||||
using Newtonsoft.Json;
|
||||
using SamSWAT.HeliCrash.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
@ -9,67 +15,68 @@ namespace SamSWAT.HeliCrash
|
||||
{
|
||||
public class HeliCrash : MonoBehaviour
|
||||
{
|
||||
private AssetBundle UH60Bundle;
|
||||
private GameObject Choppa;
|
||||
private Location HeliLocation;
|
||||
private LootableContainer ChoppaContainer;
|
||||
private string playerlocation;
|
||||
//public GameObject fpscamera;
|
||||
//private int counter = 0;
|
||||
private AssetBundle _uh60Bundle;
|
||||
private LootableContainer _choppaContainer;
|
||||
private List<ResourceKey> _resources;
|
||||
private string _playerLocation;
|
||||
|
||||
public async void Init(string location)
|
||||
{
|
||||
playerlocation = location;
|
||||
string path = Plugin.Directory + "Assets/Content/Vehicles/sikorsky_uh60_blackhawk.bundle";
|
||||
_playerLocation = location;
|
||||
|
||||
var bundleLoadRequest = AssetBundle.LoadFromFileAsync(path);
|
||||
Location heliLocation = GetHeliCrashLocation();
|
||||
var _choppa = Instantiate(await LoadChoppaAsync(), heliLocation.Position, Quaternion.Euler(heliLocation.Rotation));
|
||||
_choppaContainer = _choppa.GetComponentInChildren<LootableContainer>();
|
||||
|
||||
while (!bundleLoadRequest.isDone)
|
||||
await Task.Yield();
|
||||
Item itemCrate = Singleton<GClass1307>.Instance.CreateItem("goofyahcontainer", "61a89e5445a2672acf66c877", null);
|
||||
LootItem.CreateLootContainer(_choppaContainer, itemCrate, "Heavy crate", Singleton<GameWorld>.Instance);
|
||||
|
||||
UH60Bundle = bundleLoadRequest.assetBundle;
|
||||
|
||||
if (UH60Bundle == null)
|
||||
{
|
||||
Debug.LogError("[SamSWAT.HeliCrash]: Can't load UH-60 Blackhawk bundle");
|
||||
return;
|
||||
}
|
||||
|
||||
var assetLoadRequest = UH60Bundle.LoadAllAssetsAsync<GameObject>();
|
||||
|
||||
while (!assetLoadRequest.isDone)
|
||||
await Task.Yield();
|
||||
|
||||
Choppa = assetLoadRequest.allAssets[0] as GameObject;
|
||||
|
||||
if (Choppa == null)
|
||||
{
|
||||
Debug.LogError("[SamSWAT.HeliCrash]: failed to load asset");
|
||||
return;
|
||||
}
|
||||
|
||||
HeliLocation = HeliCrashLocation();
|
||||
Choppa = Instantiate(Choppa, HeliLocation.Position, Quaternion.Euler(HeliLocation.Rotation));
|
||||
UH60Bundle.Unload(false);
|
||||
|
||||
ChoppaContainer = Choppa.GetComponentInChildren<LootableContainer>();
|
||||
var airdropsyncobjects = LocationScene.GetAll<SynchronizableObject>().Where(x => x.GetComponent<AirdropSynchronizableObject>());
|
||||
var airdropcrates = new List<LootableContainer>();
|
||||
|
||||
foreach(var crate in airdropsyncobjects)
|
||||
{
|
||||
airdropcrates.Add(crate.GetComponentInChildren<LootableContainer>());
|
||||
}
|
||||
|
||||
FieldInfo itemOwner = typeof(LootableContainer).GetField("ItemOwner");
|
||||
object items = itemOwner.GetValue(PickRandom(airdropcrates));
|
||||
itemOwner.SetValue(ChoppaContainer, items);
|
||||
//fpscamera = GameObject.Find("FPS Camera");
|
||||
await Task.Run(() => GenerateLoot());
|
||||
await Singleton<PoolManager>.Instance.LoadBundlesAndCreatePools(PoolManager.PoolsCategory.Raid, PoolManager.AssemblyType.Local, _resources.ToArray(), JobPriority.Low, null, default);
|
||||
}
|
||||
|
||||
private Location HeliCrashLocation()
|
||||
void OnDestroy()
|
||||
{
|
||||
switch (playerlocation)
|
||||
_uh60Bundle.Unload(true);
|
||||
}
|
||||
|
||||
private void GenerateLoot()
|
||||
{
|
||||
var itemFactory = Singleton<GClass1307>.Instance;
|
||||
var json = RequestHandler.GetJson("/client/helicrash/getLoot");
|
||||
var akiContainer = JsonConvert.DeserializeObject<GeneratedContainer>(json);
|
||||
_resources = new List<ResourceKey>();
|
||||
|
||||
for (int i = 1; i < akiContainer.Items.Count; i++)
|
||||
{
|
||||
var item = akiContainer.Items[i];
|
||||
|
||||
if (item.slotId != "main")
|
||||
continue;
|
||||
|
||||
Item actualItem;
|
||||
|
||||
if (Array.Exists(itemFactory.SavedPresets, x => x.Encyclopedia == item._tpl))
|
||||
{
|
||||
actualItem = itemFactory.GetPresetItem(item._tpl);
|
||||
_resources.AddRange(actualItem.GetAllItems().Select(x => x.Template).SelectMany(x => x.AllResources));
|
||||
}
|
||||
else
|
||||
{
|
||||
actualItem = itemFactory.CreateItem(item._id, item._tpl, null);
|
||||
_resources.AddRange(actualItem.Template.AllResources);
|
||||
}
|
||||
|
||||
if (item.upd != null)
|
||||
actualItem.StackObjectsCount = item.upd.Value<int>("StackObjectsCount");
|
||||
|
||||
_choppaContainer.ItemOwner.MainStorage[0].Add(actualItem, item.location, false);
|
||||
}
|
||||
}
|
||||
|
||||
private Location GetHeliCrashLocation()
|
||||
{
|
||||
switch (_playerLocation)
|
||||
{
|
||||
case "bigmap":
|
||||
{
|
||||
@ -103,206 +110,42 @@ namespace SamSWAT.HeliCrash
|
||||
}
|
||||
}
|
||||
|
||||
private T PickRandom<T>(List<T> list)
|
||||
private async Task<GameObject> LoadChoppaAsync()
|
||||
{
|
||||
return list[Random.Range(0, list.Count)];
|
||||
string path = Plugin.Directory + "Assets/Content/Vehicles/sikorsky_uh60_blackhawk.bundle";
|
||||
|
||||
var bundleLoadRequest = AssetBundle.LoadFromFileAsync(path);
|
||||
|
||||
while (!bundleLoadRequest.isDone)
|
||||
await Task.Yield();
|
||||
|
||||
_uh60Bundle = bundleLoadRequest.assetBundle;
|
||||
|
||||
if (_uh60Bundle == null)
|
||||
{
|
||||
Debug.LogError("[SamSWAT.HeliCrash]: Can't load UH-60 Blackhawk bundle");
|
||||
return null;
|
||||
}
|
||||
|
||||
var assetLoadRequest = _uh60Bundle.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;
|
||||
}
|
||||
|
||||
/* private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Keypad5))
|
||||
{
|
||||
var cumpos = fpscamera.transform.position;
|
||||
var cumrot = fpscamera.transform.eulerAngles;
|
||||
Physics.Raycast(cumpos, Vector3.down, out var raycastHit, 50f);
|
||||
Choppa.transform.position = new Vector3(cumpos.x, raycastHit.point.y - 0.12f, cumpos.z);
|
||||
Choppa.transform.eulerAngles = new Vector3(0, cumrot.y, 0);
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Keypad6))
|
||||
{
|
||||
switch (playerlocation)
|
||||
{
|
||||
case "bigmap":
|
||||
{
|
||||
Plugin.heliCrashSites.Customs.Add(new Location { Position = Choppa.transform.position, Rotation = Choppa.transform.rotation.eulerAngles });
|
||||
break;
|
||||
}
|
||||
case "Interchange":
|
||||
{
|
||||
Plugin.heliCrashSites.Interchange.Add(new Location { Position = Choppa.transform.position, Rotation = Choppa.transform.rotation.eulerAngles });
|
||||
break;
|
||||
}
|
||||
case "RezervBase":
|
||||
{
|
||||
Plugin.heliCrashSites.Rezerv.Add(new Location { Position = Choppa.transform.position, Rotation = Choppa.transform.rotation.eulerAngles });
|
||||
break;
|
||||
}
|
||||
case "Shoreline":
|
||||
{
|
||||
Plugin.heliCrashSites.Shoreline.Add(new Location { Position = Choppa.transform.position, Rotation = Choppa.transform.rotation.eulerAngles });
|
||||
break;
|
||||
}
|
||||
case "Woods":
|
||||
{
|
||||
Plugin.heliCrashSites.Woods.Add(new Location { Position = Choppa.transform.position, Rotation = Choppa.transform.rotation.eulerAngles });
|
||||
break;
|
||||
}
|
||||
case "Lighthouse":
|
||||
{
|
||||
Plugin.heliCrashSites.Lighthouse.Add(new Location { Position = Choppa.transform.position, Rotation = Choppa.transform.rotation.eulerAngles });
|
||||
break;
|
||||
}
|
||||
case "develop":
|
||||
{
|
||||
Plugin.heliCrashSites.Develop.Add(new Location { Position = Choppa.transform.position, Rotation = Choppa.transform.rotation.eulerAngles });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Keypad0))
|
||||
{
|
||||
File.WriteAllText(Plugin.Directory + "HeliCrashLocations.json", JsonConvert.SerializeObject(Plugin.heliCrashSites));
|
||||
Debug.LogError("Data has been saved to file");
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Keypad8))
|
||||
{
|
||||
switch (playerlocation)
|
||||
{
|
||||
case "bigmap":
|
||||
{
|
||||
if (counter < Plugin.heliCrashSites.Customs.Count)
|
||||
{
|
||||
var loca = Plugin.heliCrashSites.Customs[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter = 0;
|
||||
var loca = Plugin.heliCrashSites.Customs[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Interchange":
|
||||
{
|
||||
if (counter < Plugin.heliCrashSites.Interchange.Count)
|
||||
{
|
||||
var loca = Plugin.heliCrashSites.Interchange[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter = 0;
|
||||
var loca = Plugin.heliCrashSites.Interchange[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "RezervBase":
|
||||
{
|
||||
if (counter < Plugin.heliCrashSites.Rezerv.Count)
|
||||
{
|
||||
var loca = Plugin.heliCrashSites.Rezerv[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter = 0;
|
||||
var loca = Plugin.heliCrashSites.Rezerv[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Shoreline":
|
||||
{
|
||||
if (counter < Plugin.heliCrashSites.Shoreline.Count)
|
||||
{
|
||||
var loca = Plugin.heliCrashSites.Shoreline[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter = 0;
|
||||
var loca = Plugin.heliCrashSites.Shoreline[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Woods":
|
||||
{
|
||||
if (counter < Plugin.heliCrashSites.Woods.Count)
|
||||
{
|
||||
var loca = Plugin.heliCrashSites.Woods[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter = 0;
|
||||
var loca = Plugin.heliCrashSites.Woods[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Lighthouse":
|
||||
{
|
||||
if (counter < Plugin.heliCrashSites.Lighthouse.Count)
|
||||
{
|
||||
var loca = Plugin.heliCrashSites.Lighthouse[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter = 0;
|
||||
var loca = Plugin.heliCrashSites.Lighthouse[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "develop":
|
||||
{
|
||||
if (counter < Plugin.heliCrashSites.Develop.Count)
|
||||
{
|
||||
var loca = Plugin.heliCrashSites.Develop[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter = 0;
|
||||
var loca = Plugin.heliCrashSites.Develop[counter];
|
||||
Choppa.transform.position = loca.Position;
|
||||
Choppa.transform.eulerAngles = loca.Rotation;
|
||||
counter++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
private T PickRandom<T>(List<T> list)
|
||||
{
|
||||
return list[UnityEngine.Random.Range(0, list.Count)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
using Aki.Reflection.Patching;
|
||||
using Aki.Reflection.Utils;
|
||||
using Comfort.Common;
|
||||
using EFT;
|
||||
using EFT.Airdrop;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
@ -11,14 +13,14 @@ namespace SamSWAT.HeliCrash
|
||||
{
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
return typeof(GameWorld).GetMethod("OnGameStarted", BindingFlags.Public | BindingFlags.Instance);
|
||||
return PatchConstants.LocalGameType.BaseType.GetMethod("method_11", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
}
|
||||
|
||||
[PatchPostfix]
|
||||
public static void PatchPostFix()
|
||||
public static void PatchPostfix()
|
||||
{
|
||||
var gameWorld = Singleton<GameWorld>.Instance;
|
||||
var crashAvailable = LocationScene.GetAll<AirdropPoint>().Any();
|
||||
bool crashAvailable = LocationScene.GetAll<AirdropPoint>().Any();
|
||||
string location = gameWorld.RegisteredPlayers[0].Location;
|
||||
|
||||
if (gameWorld != null && crashAvailable && WillHeliCrash())
|
||||
@ -28,7 +30,7 @@ namespace SamSWAT.HeliCrash
|
||||
}
|
||||
}
|
||||
|
||||
public static bool WillHeliCrash()
|
||||
private static bool WillHeliCrash()
|
||||
{
|
||||
return Random.Range(0, 100) <= Plugin.HeliCrashChance.Value;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ using System.IO;
|
||||
|
||||
namespace SamSWAT.HeliCrash
|
||||
{
|
||||
[BepInPlugin("com.SamSWAT.HeliCrash", "SamSWAT.HeliCrash", "1.1.0")]
|
||||
[BepInPlugin("com.SamSWAT.HeliCrash", "SamSWAT.HeliCrash", "1.2.0")]
|
||||
public class Plugin : BaseUnityPlugin
|
||||
{
|
||||
public static HeliCrashLocations HeliCrashLocations;
|
||||
|
BIN
project/SamSWAT.HeliCrash/References/Aki.Common.dll
Normal file
BIN
project/SamSWAT.HeliCrash/References/Aki.Common.dll
Normal file
Binary file not shown.
Binary file not shown.
@ -31,10 +31,15 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Aki.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>References\Aki.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Aki.Reflection">
|
||||
<HintPath>References\Aki.Reflection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>References\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="BepInEx">
|
||||
@ -58,6 +63,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GeneratedContainer.cs" />
|
||||
<Compile Include="HeliCrash.cs" />
|
||||
<Compile Include="HeliCrashLocations.cs" />
|
||||
<Compile Include="HeliCrashPatch.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user