start more botLootGen and fix types
This commit is contained in:
@@ -462,7 +462,7 @@ public class BotLootGenerator
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public void AddLootFromPool
|
||||
(
|
||||
Dictionary<string, int> pool,
|
||||
Dictionary<string, double> pool,
|
||||
List<EquipmentSlots> equipmentSlots,
|
||||
double totalItemCount,
|
||||
BotBaseInventory inventoryToAddItemsTo, // TODO: type for containersIdFull was Set<string>
|
||||
@@ -473,7 +473,137 @@ public class BotLootGenerator
|
||||
List<string> containersIdFull = null
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// Loot pool has items
|
||||
var poolSize = pool.Count;
|
||||
if (poolSize > 0)
|
||||
{
|
||||
double currentTotalRub = 0;
|
||||
|
||||
var fitItemIntoContainerAttempts = 0;
|
||||
for (var i = 0; i < totalItemCount; i++)
|
||||
{
|
||||
// Pool can become empty if item spawn limits keep removing items
|
||||
if (pool.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var weightedItemTpl = _weightedRandomHelper.GetWeightedValue<string>(pool);
|
||||
var itemResult = _itemHelper.GetItem(weightedItemTpl);
|
||||
var itemToAddTemplate = itemResult.Value;
|
||||
if (!itemResult.Key)
|
||||
{
|
||||
_logger.Warning($"Unable to process item tpl: {weightedItemTpl} for slots: {equipmentSlots} on bot: {botRole}");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (itemSpawnLimits is not null)
|
||||
{
|
||||
if (ItemHasReachedSpawnLimit(itemToAddTemplate, botRole, itemSpawnLimits))
|
||||
{
|
||||
// Remove item from pool to prevent it being picked again
|
||||
pool.Remove(weightedItemTpl);
|
||||
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var newRootItemId = _hashUtil.Generate();
|
||||
List<Item> itemWithChildrenToAdd =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = newRootItemId,
|
||||
Template = itemToAddTemplate.Id,
|
||||
Upd = _botGeneratorHelper.GenerateExtraPropertiesForItem(itemToAddTemplate, botRole)
|
||||
},
|
||||
];
|
||||
|
||||
// Is Simple-Wallet / WZ wallet
|
||||
if (_botConfig.WalletLoot.WalletTplPool.Contains(weightedItemTpl))
|
||||
{
|
||||
var addCurrencyToWallet = _randomUtil.GetChance100(_botConfig.WalletLoot.ChancePercent);
|
||||
if (addCurrencyToWallet)
|
||||
{
|
||||
// Create the currency items we want to add to wallet
|
||||
var itemsToAdd = CreateWalletLoot(newRootItemId);
|
||||
|
||||
// Get the container grid for the wallet
|
||||
var containerGrid = _inventoryHelper.GetContainerSlotMap(weightedItemTpl);
|
||||
|
||||
// Check if all the chosen currency items fit into wallet
|
||||
var canAddToContainer = _inventoryHelper.CanPlaceItemsInContainer(
|
||||
_cloner.Clone(containerGrid), // MUST clone grid before passing in as function modifies grid
|
||||
itemsToAdd
|
||||
);
|
||||
if (canAddToContainer)
|
||||
{
|
||||
// Add each currency to wallet
|
||||
foreach ( var itemToAdd in itemsToAdd) {
|
||||
_inventoryHelper.PlaceItemInContainer(
|
||||
containerGrid,
|
||||
itemToAdd,
|
||||
itemWithChildrenToAdd[0].Id,
|
||||
"main"
|
||||
);
|
||||
}
|
||||
|
||||
itemWithChildrenToAdd.AddRange(itemsToAdd.SelectMany(x => x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Some items (ammoBox/ammo) need extra changes
|
||||
AddRequiredChildItemsToParent(itemToAddTemplate, itemWithChildrenToAdd, isPmc, botRole);
|
||||
|
||||
// Attempt to add item to container(s)
|
||||
var itemAddedResult = _botGeneratorHelper.AddItemWithChildrenToEquipmentSlot(
|
||||
equipmentSlots,
|
||||
newRootItemId,
|
||||
itemToAddTemplate.Id,
|
||||
itemWithChildrenToAdd,
|
||||
inventoryToAddItemsTo,
|
||||
containersIdFull
|
||||
);
|
||||
|
||||
// Handle when item cannot be added
|
||||
if (itemAddedResult != ItemAddedResult.SUCCESS)
|
||||
{
|
||||
if (itemAddedResult == ItemAddedResult.NO_CONTAINERS)
|
||||
{
|
||||
// Bot has no container to put item in, exit
|
||||
_logger.Debug($"Unable to add: {totalItemCount} items to bot as it lacks a container to include them");
|
||||
break;
|
||||
}
|
||||
|
||||
fitItemIntoContainerAttempts++;
|
||||
if (fitItemIntoContainerAttempts >= 4)
|
||||
{
|
||||
_logger.Debug($"Failed placing item: { i } of: { totalItemCount } items into: { botRole } containers: { string.Join(",", equipmentSlots) }. Tried: { fitItemIntoContainerAttempts } times, reason: { itemAddedResult.ToString() }, skipping");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Try again, failed but still under attempt limit
|
||||
continue;
|
||||
}
|
||||
|
||||
// Item added okay, reset counter for next item
|
||||
fitItemIntoContainerAttempts = 0;
|
||||
|
||||
// Stop adding items to bots pool if rolling total is over total limit
|
||||
if (totalValueLimitRub > 0)
|
||||
{
|
||||
currentTotalRub += _handbookHelper.GetTemplatePrice(itemToAddTemplate.Id);
|
||||
if (currentTotalRub > totalValueLimitRub)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -482,7 +612,7 @@ public class BotLootGenerator
|
||||
/// <param name="walletId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public List<List<Item>> CrateWalletLoot(string walletId)
|
||||
public List<List<Item>> CreateWalletLoot(string walletId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -504,24 +504,24 @@ public class BotGeneratorHelper
|
||||
/// <param name="inventory">Inventory to add item+children into</param>
|
||||
/// <returns>ItemAddedResult result object</returns>
|
||||
public ItemAddedResult AddItemWithChildrenToEquipmentSlot(
|
||||
List<string> equipmentSlots,
|
||||
List<EquipmentSlots> equipmentSlots,
|
||||
string rootItemId,
|
||||
string rootItemTplId,
|
||||
List<Item> itemWithChildren,
|
||||
BotBaseInventory inventory,
|
||||
HashSet<string> containersIdFull = null)
|
||||
List<string> containersIdFull = null)
|
||||
{
|
||||
/** Track how many containers are unable to be found */
|
||||
var missingContainerCount = 0;
|
||||
foreach (var equipmentSlotId in equipmentSlots)
|
||||
{
|
||||
if (containersIdFull?.Contains(equipmentSlotId) ?? false)
|
||||
if (containersIdFull?.Contains(equipmentSlotId.ToString()) ?? false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get container to put item into
|
||||
var container = inventory.Items.FirstOrDefault((item) => item.SlotId == equipmentSlotId);
|
||||
var container = inventory.Items.FirstOrDefault((item) => item.SlotId == equipmentSlotId.ToString());
|
||||
if (container is null)
|
||||
{
|
||||
missingContainerCount++;
|
||||
@@ -642,7 +642,7 @@ public class BotGeneratorHelper
|
||||
// if the item was a one by one, we know it must be full. Or if the maps cant find a slot for a one by one
|
||||
if (itemSize[0] == 1 && itemSize[1] == 1)
|
||||
{
|
||||
containersIdFull.Add(equipmentSlotId);
|
||||
containersIdFull.Add(equipmentSlotId.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class InventoryHelper
|
||||
/// <param name="sessionId">Player id</param>
|
||||
/// <param name="itemsWithChildren">Array of items with children to try and fit</param>
|
||||
/// <returns>True all items fit</returns>
|
||||
public bool CanPlaceItemsInInventory(string sessionId, Item[][] itemsWithChildren)
|
||||
public bool CanPlaceItemsInInventory(string sessionId, List<List<Item>> itemsWithChildren)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class InventoryHelper
|
||||
/// <param name="containerFS2D">Container grid to fit items into</param>
|
||||
/// <param name="itemsWithChildren">Items to try and fit into grid</param>
|
||||
/// <returns>True all fit</returns>
|
||||
public bool CanPlaceItemsInContainer(int[][] containerFS2D, Item[][] itemsWithChildren)
|
||||
public bool CanPlaceItemsInContainer(List<List<double>> containerFS2D, List<List<Item>> itemsWithChildren)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class InventoryHelper
|
||||
/// <param name="containerFS2D">Container grid</param>
|
||||
/// <param name="itemWithChildren">Item to check fits</param>
|
||||
/// <returns>True it fits</returns>
|
||||
public bool CanPlaceItemInContainer(int[][] containerFS2D, Item[] itemWithChildren)
|
||||
public bool CanPlaceItemInContainer(List<List<int>> containerFS2D, List<Item> itemWithChildren)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -104,8 +104,8 @@ public class InventoryHelper
|
||||
/// <param name="containerId">Id of the container we're fitting item into</param>
|
||||
/// <param name="desiredSlotId">Slot id value to use, default is "hideout"</param>
|
||||
public void PlaceItemInContainer(
|
||||
int[][] containerFS2D,
|
||||
Item[] itemWithChildren,
|
||||
List<List<double>> containerFS2D,
|
||||
List<Item> itemWithChildren,
|
||||
string containerId,
|
||||
string desiredSlotId = "hideout")
|
||||
{
|
||||
@@ -122,9 +122,9 @@ public class InventoryHelper
|
||||
/// <param name="useSortingTable">Should sorting table to be used if main stash has no space</param>
|
||||
/// <param name="output">Output to send back to client</param>
|
||||
protected void PlaceItemInInventory(
|
||||
int[][] stashFS2D,
|
||||
int[][] sortingTableFS2D,
|
||||
Item[] itemWithChildren,
|
||||
List<List<double>> stashFS2D,
|
||||
List<List<double>> sortingTableFS2D,
|
||||
List<Item> itemWithChildren,
|
||||
BotBaseInventory playerInventory,
|
||||
bool useSortingTable,
|
||||
ItemEventRouterResponse output)
|
||||
@@ -262,7 +262,7 @@ public class InventoryHelper
|
||||
/// </summary>
|
||||
/// <param name="containerTpl">Container to get data for</param>
|
||||
/// <returns>blank two-dimensional array</returns>
|
||||
public int[,] GetContainerSlotMap(string containerTpl)
|
||||
public List<List<double>> GetContainerSlotMap(string containerTpl)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -272,7 +272,7 @@ public class InventoryHelper
|
||||
/// </summary>
|
||||
/// <param name="pmcData">Player profile</param>
|
||||
/// <returns>two-dimensional array</returns>
|
||||
protected int[,] GetSortingTableSlotMap(PmcData pmcData)
|
||||
protected List<List<double>> GetSortingTableSlotMap(PmcData pmcData)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public class InventoryHelper
|
||||
/// </summary>
|
||||
/// <param name="sessionID">Players id</param>
|
||||
/// <returns>Dictionary of 2 values, horizontal and vertical stash size</returns>
|
||||
protected Dictionary<int, int> GetPlayerStashSize(string sessionID)
|
||||
protected Dictionary<double, double> GetPlayerStashSize(string sessionID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class BotLootCacheService
|
||||
/// <param name="lootType">what type of loot is needed (backpack/pocket/stim/vest etc)</param>
|
||||
/// <param name="botJsonTemplate">Base json db file for the bot having its loot generated</param>
|
||||
/// <returns>Dictionary<string, int></returns>
|
||||
public Dictionary<string, int> GetLootFromCache(
|
||||
public Dictionary<string, double> GetLootFromCache(
|
||||
string botRole,
|
||||
bool isPmc,
|
||||
string lootType,
|
||||
|
||||
Reference in New Issue
Block a user