Update var naming to be easier to read
This commit is contained in:
@@ -10,15 +10,15 @@ public class ContainerHelper
|
||||
/// Finds a slot for an item in a given 2D container map
|
||||
/// </summary>
|
||||
/// <param name="container2D">List of container with positions filled/free</param>
|
||||
/// <param name="itemWidth">Width of item</param>
|
||||
/// <param name="itemHeight">Height of item</param>
|
||||
/// <param name="itemX">Width of item</param>
|
||||
/// <param name="itemY">Height of item</param>
|
||||
/// <returns>Location to place item in container</returns>
|
||||
public FindSlotResult FindSlotForItem(int[][] container2D, int itemWidth, int itemHeight)
|
||||
public FindSlotResult FindSlotForItem(int[][] container2D, int? itemX, int? itemY)
|
||||
{
|
||||
// Assume not rotated
|
||||
var rotation = false;
|
||||
|
||||
var minVolume = (itemWidth < itemHeight ? itemWidth : itemHeight) - 1;
|
||||
var minVolume = (itemX < itemY ? itemX : itemY) - 1;
|
||||
var containerY = container2D.Length;
|
||||
var containerX = container2D[0].Length;
|
||||
var limitY = containerY - minVolume;
|
||||
@@ -42,20 +42,20 @@ public class ContainerHelper
|
||||
// Go left to right across x-axis looking for free position
|
||||
for (var x = 0; x < limitX; x++)
|
||||
{
|
||||
if (CanItemBePlacedInContainerAtPosition(container2D, containerX, containerY, x, y, itemWidth, itemHeight))
|
||||
if (CanItemBePlacedInContainerAtPosition(container2D, containerX, containerY, x, y, itemX!.Value, itemY!.Value))
|
||||
{
|
||||
// Success, return result
|
||||
return new FindSlotResult(true, x, y, rotation);
|
||||
}
|
||||
|
||||
if (ItemBiggerThan1X1(itemWidth, itemHeight))
|
||||
if (ItemBiggerThan1X1(itemX!.Value, itemY!.Value))
|
||||
{
|
||||
// Pointless rotating a 1x1, try next position across
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bigger than 1x1, try rotating by swapping x and y values
|
||||
if (!CanItemBePlacedInContainerAtPosition(container2D, containerX, containerY, x, y, itemHeight, itemWidth))
|
||||
if (!CanItemBePlacedInContainerAtPosition(container2D, containerX, containerY, x, y, itemY!.Value, itemX!.Value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -132,8 +132,8 @@ public class ContainerHelper
|
||||
int[][] container2D,
|
||||
int x,
|
||||
int y,
|
||||
int itemW,
|
||||
int itemH,
|
||||
int? itemW,
|
||||
int? itemH,
|
||||
bool rotate)
|
||||
{
|
||||
// Swap height/width if we want to fit it in rotated
|
||||
|
||||
@@ -803,10 +803,10 @@ public class InventoryHelper(
|
||||
/// <param name="itemList">Players inventory items</param>
|
||||
/// <param name="containerId">Id of the container</param>
|
||||
/// <returns>Two-dimensional representation of container</returns>
|
||||
public int[][] GetContainerMap(int containerH, int containerV, List<Item> itemList, string containerId)
|
||||
public int[][] GetContainerMap(int sizeX, int sizeY, List<Item> itemList, string containerId)
|
||||
{
|
||||
// Create blank 2d map of container
|
||||
var container2D = _itemHelper.GetBlankContainerMap(containerH, containerV);
|
||||
var containerYX = _itemHelper.GetBlankContainerMap(sizeY, sizeX);
|
||||
|
||||
// Get all items in players inventory keyed by their parentId and by ItemId
|
||||
var inventoryItemHash = GetInventoryItemHash(itemList);
|
||||
@@ -815,7 +815,7 @@ public class InventoryHelper(
|
||||
if (!inventoryItemHash.ByParentId.TryGetValue(containerId, out var containerItemHash))
|
||||
// No items in container, exit early
|
||||
{
|
||||
return container2D;
|
||||
return containerYX;
|
||||
}
|
||||
|
||||
// Check each item in container
|
||||
@@ -854,14 +854,14 @@ public class InventoryHelper(
|
||||
try
|
||||
{
|
||||
var rowIndex = itemLocation.Y + y;
|
||||
var containerRow = container2D[rowIndex.Value];
|
||||
if (containerRow is null)
|
||||
var containerX = containerYX[rowIndex.Value];
|
||||
if (containerX is null)
|
||||
{
|
||||
_logger.Error($"Unable to find container: {containerId} row line: {itemLocation.Y + y}");
|
||||
}
|
||||
|
||||
// Fill the corresponding cells in the container map to show the slot is taken
|
||||
Array.Fill(containerRow, 1, itemLocation.X.Value, fW);
|
||||
Array.Fill(containerX, 1, itemLocation.X.Value, fW);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -879,7 +879,7 @@ public class InventoryHelper(
|
||||
}
|
||||
}
|
||||
|
||||
return container2D;
|
||||
return containerYX;
|
||||
}
|
||||
|
||||
protected bool IsVertical(ItemLocation itemLocation)
|
||||
|
||||
@@ -2206,7 +2206,7 @@ public class ItemHelper(
|
||||
/// <param name="containerH">Horizontal size of container</param>
|
||||
/// <param name="containerY">Vertical size of container</param>
|
||||
/// <returns>Two-dimensional representation of container</returns>
|
||||
public int[][] GetBlankContainerMap(int containerH, int containerY)
|
||||
public int[][] GetBlankContainerMap(int containerY, int containerX)
|
||||
{
|
||||
//var x = new int[containerY][];
|
||||
//for (int i = 0; i < containerY; i++)
|
||||
@@ -2217,7 +2217,7 @@ public class ItemHelper(
|
||||
//return x;
|
||||
|
||||
return Enumerable.Range(0, containerY)
|
||||
.Select(i => new int[containerH])
|
||||
.Select(i => new int[containerX])
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user