-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMisc.cs
More file actions
111 lines (94 loc) · 3.48 KB
/
Copy pathMisc.cs
File metadata and controls
111 lines (94 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Linq;
using System.Numerics;
using ExileCore2.PoEMemory.Components;
using ExileCore2.PoEMemory.MemoryObjects;
using ItemFilterLibrary;
namespace PickIt;
public partial class PickIt
{
private bool CanFitInventory(ItemData groundItem)
{
return FindSpotInventory(groundItem) != null;
}
private bool CanFitInventory(int itemHeight, int itemWidth)
{
return FindSpotInventory(itemHeight, itemWidth) != null;
}
const int width = 12;
const int height = 5;
/// <summary>
/// Finds a spot available in the inventory to place the item
/// </summary>
private Vector2? FindSpotInventory(ItemData item)
{
var inventoryItems = _inventoryItems.InventorySlotItems;
var itemToStackWith = inventoryItems.FirstOrDefault(x => CanItemBeStacked(item, x));
if (itemToStackWith != null)
{
return new Vector2(itemToStackWith.PosX, itemToStackWith.PosY);
}
var itemHeight = item.Height;
var itemWidth = item.Width;
return FindSpotInventory(itemHeight, itemWidth);
}
private Vector2? FindSpotInventory(int itemHeight, int itemWidth)
{
bool[,] inventorySlots = InventorySlots;
if (inventorySlots == null)
{
return null;
}
for (var yCol = 0; yCol < height - (itemHeight - 1); yCol++)
{
for (var xRow = 0; xRow < width - (itemWidth - 1); xRow++)
{
var obstructed = false;
for (var xWidth = 0; xWidth < itemWidth && !obstructed; xWidth++)
for (var yHeight = 0; yHeight < itemHeight && !obstructed; yHeight++)
{
obstructed |= inventorySlots[yCol + yHeight, xRow + xWidth];
}
if (!obstructed) return new Vector2(xRow, yCol);
}
}
return null;
}
private static bool CanItemBeStacked(ItemData item, ServerInventory.InventSlotItem inventoryItem)
{
if (item.Entity.Path != inventoryItem.Item.Path)
return false;
if (!item.Entity.HasComponent<Stack>() || !inventoryItem.Item.HasComponent<Stack>())
return false;
var itemStackComp = item.Entity.GetComponent<Stack>();
var inventoryItemStackComp = inventoryItem.Item.GetComponent<Stack>();
return inventoryItemStackComp.Size + itemStackComp.Size <= inventoryItemStackComp.Info.MaxStackSize;
}
private bool[,] GetContainer2DArray(ServerInventory containerItems)
{
var containerCells = new bool[containerItems.Rows, containerItems.Columns];
try
{
foreach (var item in containerItems.InventorySlotItems)
{
var itemSizeX = item.SizeX;
var itemSizeY = item.SizeY;
var inventPosX = item.PosX;
var inventPosY = item.PosY;
var startX = Math.Max(0, inventPosX);
var startY = Math.Max(0, inventPosY);
var endX = Math.Min(containerItems.Columns, inventPosX + itemSizeX);
var endY = Math.Min(containerItems.Rows, inventPosY + itemSizeY);
for (var y = startY; y < endY; y++)
for (var x = startX; x < endX; x++)
containerCells[y, x] = true;
}
}
catch (Exception e)
{
// ignored
LogMessage(e.ToString(), 5);
}
return containerCells;
}
}