public bool BuyItem(int price)
{
bool overFlowing;
long num1 = Utils.CoinsCount(out overFlowing, this.inventory, 58, 57, 56, 55, 54);
long num2 = Utils.CoinsCount(out overFlowing, this.bank.item);
long num3 = Utils.CoinsCount(out overFlowing, this.bank2.item);
if (Utils.CoinsCombineStacks(out overFlowing, num1, num2, num3) < (long)price)
return false;
List<Item[]> list1 = new List<Item[]>();
Dictionary<int, List<int>> dictionary1 = new Dictionary<int, List<int>>();
List<Point> list2 = new List<Point>();
List<Point> list3 = new List<Point>();
List<Point> list4 = new List<Point>();
List<Point> list5 = new List<Point>();
list1.Add(this.inventory);
list1.Add(this.bank.item);
list1.Add(this.bank2.item);
for (int index = 0; index < list1.Count; ++index)
dictionary1[index] = new List<int>();
dictionary1[0] = new List<int>()
{
58,
57,
56,
55,
54
};
for (int x = 0; x < list1.Count; ++x)
{
for (int y = 0; y < list1[x].Length; ++y)
{
if (!dictionary1[x].Contains(y) && list1[x][y].itemId >= 71 && list1[x][y].itemId <= 74)
list3.Add(new Point(x, y));
}
}
int x1 = 0;
for (int y = list1[x1].Length - 1; y >= 0; --y)
{
if (!dictionary1[x1].Contains(y) && (list1[x1][y].itemId == 0 || list1[x1][y].stack == 0))
list2.Add(new Point(x1, y));
}
int x2 = 1;
for (int y = list1[x2].Length - 1; y >= 0; --y)
{
if (!dictionary1[x2].Contains(y) && (list1[x2][y].itemId == 0 || list1[x2][y].stack == 0))
list4.Add(new Point(x2, y));
}
int x3 = 2;
for (int y = list1[x3].Length - 1; y >= 0; --y)
{
if (!dictionary1[x3].Contains(y) && (list1[x3][y].itemId == 0 || list1[x3][y].stack == 0))
list5.Add(new Point(x3, y));
}
long num4 = (long)price;
Dictionary<Point, Item> dictionary2 = new Dictionary<Point, Item>();
while (num4 > 0L)
{
long num5 = 1000000L;
for (int index1 = 0; index1 < 4; ++index1)
{
if (num4 >= num5)
{
foreach (Point index2 in list3)
{
if (list1[index2.X][index2.Y].itemId == 74 - index1)
{
long num6 = num4 / num5;
dictionary2[index2] = list1[index2.X][index2.Y].Clone();
if (num6 < (long)list1[index2.X][index2.Y].stack)
{
list1[index2.X][index2.Y].stack -= (int)num6;
}
else
{
list1[index2.X][index2.Y].SetDefaults(0, false);
list2.Add(index2);
}
num4 -= num5 * (long)(dictionary2[index2].stack - list1[index2.X][index2.Y].stack);
}
}
}
num5 /= 100L;
}
if (num4 > 0L)
{
if (list2.Count > 0)
{
list2.Sort(new Comparison<Point>(DelegateMethods.CompareYReverse));
Point point1 = new Point(-1, -1);
for (int index1 = 0; index1 < list1.Count; ++index1)
{
long num6 = 10000L;
for (int index2 = 0; index2 < 3; ++index2)
{
if (num4 >= num6)
{
foreach (Point point2 in list3)
{
if (point2.X == index1 && list1[point2.X][point2.Y].itemId == 74 - index2 && list1[point2.X][point2.Y].stack >= 1)
{
List<Point> list6 = list2;
if (index1 == 1 && list4.Count > 0)
list6 = list4;
if (index1 == 2 && list5.Count > 0)
list6 = list5;
if (--list1[point2.X][point2.Y].stack <= 0)
{
list1[point2.X][point2.Y].SetDefaults(0, false);
list6.Add(point2);
}
dictionary2[list6[0]] = list1[list6[0].X][list6[0].Y].Clone();
list1[list6[0].X][list6[0].Y].SetDefaults(73 - index2, false);
list1[list6[0].X][list6[0].Y].stack = 100;
point1 = list6[0];
list6.RemoveAt(0);
break;
}
}
}
if (point1.X == -1 && point1.Y == -1)
num6 /= 100L;
else
break;
}
for (int index2 = 0; index2 < 2; ++index2)
{
if (point1.X == -1 && point1.Y == -1)
{
foreach (Point point2 in list3)
{
if (point2.X == index1 && list1[point2.X][point2.Y].itemId == 73 + index2 && list1[point2.X][point2.Y].stack >= 1)
{
List<Point> list6 = list2;
if (index1 == 1 && list4.Count > 0)
list6 = list4;
if (index1 == 2 && list5.Count > 0)
list6 = list5;
if (--list1[point2.X][point2.Y].stack <= 0)
{
list1[point2.X][point2.Y].SetDefaults(0, false);
list6.Add(point2);
}
dictionary2[list6[0]] = list1[list6[0].X][list6[0].Y].Clone();
list1[list6[0].X][list6[0].Y].SetDefaults(72 + index2, false);
list1[list6[0].X][list6[0].Y].stack = 100;
point1 = list6[0];
list6.RemoveAt(0);
break;
}
}
}
}
if (point1.X != -1 && point1.Y != -1)
{
list3.Add(point1);
break;
}
}
list2.Sort(new Comparison<Point>(DelegateMethods.CompareYReverse));
list4.Sort(new Comparison<Point>(DelegateMethods.CompareYReverse));
list5.Sort(new Comparison<Point>(DelegateMethods.CompareYReverse));
}
else
{
foreach (KeyValuePair<Point, Item> keyValuePair in dictionary2)
list1[keyValuePair.Key.X][keyValuePair.Key.Y] = keyValuePair.Value.Clone();
return false;
}
}
}
return true;
}