From d2d1581859346693a736bbdce3d9d88697c0db5f Mon Sep 17 00:00:00 2001 From: Dev Date: Sun, 9 Jul 2023 14:49:12 +0100 Subject: [PATCH] use new containerIds dictionary when choosing container to spawn --- .../Aki.Custom/Airdrops/AirdropsManager.cs | 12 +++++---- .../Airdrops/Models/AirdropConfigModel.cs | 4 +++ .../Airdrops/Models/AirdropLootModel.cs | 11 ++++++++ .../Airdrops/Utils/ItemFactoryUtil.cs | 26 ++++++++----------- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/project/Aki.Custom/Airdrops/AirdropsManager.cs b/project/Aki.Custom/Airdrops/AirdropsManager.cs index 9c72961..60ad401 100644 --- a/project/Aki.Custom/Airdrops/AirdropsManager.cs +++ b/project/Aki.Custom/Airdrops/AirdropsManager.cs @@ -1,4 +1,5 @@ -using Aki.Custom.Airdrops.Models; +using Aki.Common.Http; +using Aki.Custom.Airdrops.Models; using Aki.Custom.Airdrops.Utils; using Comfort.Common; using EFT; @@ -69,7 +70,7 @@ namespace Aki.Custom.Airdrops if (airdropParameters.DistanceTraveled >= airdropParameters.DistanceToDrop && !airdropParameters.BoxSpawned) { StartBox(); - BuildLootContainer(); + BuildLootContainer(airdropParameters.Config); } if (airdropParameters.DistanceTraveled < airdropParameters.DistanceToTravel) @@ -100,10 +101,11 @@ namespace Aki.Custom.Airdrops airdropBox.StartCoroutine(airdropBox.DropCrate(dropPos)); } - private void BuildLootContainer() + private void BuildLootContainer(AirdropConfigModel config) { - factory.BuildContainer(airdropBox.container); - factory.AddLoot(airdropBox.container); + var lootData = factory.GetLoot(); + factory.BuildContainer(airdropBox.container, config, lootData.DropType); + factory.AddLoot(airdropBox.container, lootData); } private void SetDistanceToDrop() diff --git a/project/Aki.Custom/Airdrops/Models/AirdropConfigModel.cs b/project/Aki.Custom/Airdrops/Models/AirdropConfigModel.cs index b035f1e..6601bd3 100644 --- a/project/Aki.Custom/Airdrops/Models/AirdropConfigModel.cs +++ b/project/Aki.Custom/Airdrops/Models/AirdropConfigModel.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using System.Collections.Generic; namespace Aki.Custom.Airdrops.Models { @@ -27,6 +28,9 @@ namespace Aki.Custom.Airdrops.Models [JsonProperty("crateFallSpeed")] public float CrateFallSpeed { get; set; } + + [JsonProperty("containerIds")] + public Dictionary ContainerIds { get; set; } } public class AirdropChancePercent diff --git a/project/Aki.Custom/Airdrops/Models/AirdropLootModel.cs b/project/Aki.Custom/Airdrops/Models/AirdropLootModel.cs index b7ed34d..e03d24e 100644 --- a/project/Aki.Custom/Airdrops/Models/AirdropLootModel.cs +++ b/project/Aki.Custom/Airdrops/Models/AirdropLootModel.cs @@ -1,7 +1,18 @@ using Newtonsoft.Json; +using System.Collections.Generic; namespace Aki.Custom.Airdrops.Models { + public class AirdropLootResultModel + { + [JsonProperty("dropType")] + public string DropType { get; set; } + + [JsonProperty("loot")] + public IEnumerable Loot { get;set;} + } + + public class AirdropLootModel { [JsonProperty("tpl")] diff --git a/project/Aki.Custom/Airdrops/Utils/ItemFactoryUtil.cs b/project/Aki.Custom/Airdrops/Utils/ItemFactoryUtil.cs index 1601127..2ea4e9f 100644 --- a/project/Aki.Custom/Airdrops/Utils/ItemFactoryUtil.cs +++ b/project/Aki.Custom/Airdrops/Utils/ItemFactoryUtil.cs @@ -8,40 +8,36 @@ using Newtonsoft.Json; using System.Collections.Generic; using Aki.Custom.Airdrops.Models; using System.Linq; -using System.Threading.Tasks; namespace Aki.Custom.Airdrops.Utils { public class ItemFactoryUtil { - private ItemFactory itemFactory; - private static readonly string DropContainer = "6223349b3136504a544d1608"; + private readonly ItemFactory itemFactory; public ItemFactoryUtil() { itemFactory = Singleton.Instance; } - public void BuildContainer(LootableContainer container) + public void BuildContainer(LootableContainer container, AirdropConfigModel config, string dropType) { - if (itemFactory.ItemTemplates.TryGetValue(DropContainer, out var template)) + var containerId = config.ContainerIds[dropType]; + if (itemFactory.ItemTemplates.TryGetValue(containerId, out var template)) { - Item item = itemFactory.CreateItem(DropContainer, template._id, null); + Item item = itemFactory.CreateItem(containerId, template._id, null); LootItem.CreateLootContainer(container, item, "CRATE", Singleton.Instance); } else { - Debug.LogError($"[AKI-AIRDROPS]: unable to find template: {DropContainer}"); + Debug.LogError($"[AKI-AIRDROPS]: unable to find template: {containerId}"); } } - public async void AddLoot(LootableContainer container) + public async void AddLoot(LootableContainer container, AirdropLootResultModel lootToAdd) { - List loot = GetLoot(); - Item actualItem; - - foreach (var item in loot) + foreach (var item in lootToAdd.Loot) { ResourceKey[] resources; if (item.IsPreset) @@ -62,12 +58,12 @@ namespace Aki.Custom.Airdrops.Utils } } - private List GetLoot() + public AirdropLootResultModel GetLoot() { var json = RequestHandler.GetJson("/client/location/getAirdropLoot"); - var loot = JsonConvert.DeserializeObject>(json); + var result = JsonConvert.DeserializeObject (json); - return loot; + return result; } } } \ No newline at end of file