D2R-BMBot/Strucs/InventoryStruc.cs

377 lines
15 KiB
C#
Raw Normal View History

2023-04-20 21:39:08 -07:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace app
{
public class InventoryStruc
{
Form1 Form1_0;
public int[] InventoryHasItem = new int[40];
public int[] InventoryHasUnidItem = new int[40];
public int[] InventoryHasStashItem = new int[40];
2024-04-22 17:48:19 -07:00
public int[] InventoryHasItemToID = new int[40];
2023-04-20 21:39:08 -07:00
public long[] InventoryItemPointers = new long[40];
public string[] InventoryItemNames = new string[40];
2024-04-05 21:50:39 -07:00
public int[] InventoryItemQuality = new int[40];
2023-04-20 21:39:08 -07:00
public int HUDItems_idscrolls = 0;
public int HUDItems_tpscrolls = 0;
public int HUDItems_keys = 0;
public int HUDItems_tpscrolls_locx = 0;
public int HUDItems_tpscrolls_locy = 0;
public int HUDItems_idscrolls_locx = 0;
public int HUDItems_idscrolls_locy = 0;
2024-04-18 18:51:45 -07:00
public bool HasIDTome = false;
2023-04-20 21:39:08 -07:00
public void SetForm1(Form1 form1_1)
{
Form1_0 = form1_1;
}
public void UseTP()
{
Dictionary<string, int> itemScreenPos = ConvertInventoryLocToScreenPos(HUDItems_tpscrolls_locx, HUDItems_tpscrolls_locy);
Form1_0.KeyMouse_0.MouseCliccRight(itemScreenPos["x"], itemScreenPos["y"]);
}
public Dictionary<string, int> ConvertInventoryLocToScreenPos(int ThisX, int ThisY)
{
//starting at 1295,580 on screen for first item in inv, increment for 48px
2024-04-18 18:51:45 -07:00
int xS = 1300 + (ThisX * 48);
2023-04-20 21:39:08 -07:00
int yS = 580 + (ThisY * 48);
Dictionary<string, int> NewDict = new Dictionary<string, int>();
NewDict["x"] = xS;
NewDict["y"] = yS;
return NewDict;
}
public int ConvertXYToIndex(int ThisX, int ThisY)
{
return ThisX + (ThisY * 10);
}
public Dictionary<string, int> ConvertIndexToXY(int Thisndex)
{
int yS = (int) Math.Floor((double) Thisndex / 10);
int xS = Thisndex - (yS * 10);
Dictionary<string, int> NewDict = new Dictionary<string, int>();
NewDict["x"] = xS;
NewDict["y"] = yS;
return NewDict;
}
public bool ContainStashItemInInventory()
{
bool ContainStashItem = false;
Form1_0.ItemsStruc_0.GetItems(false);
for (int i = 0; i < 40; i++)
{
if (CharConfig.InventoryDontCheckItem[i] == 0 && InventoryHasItem[i] >= 1 && InventoryHasStashItem[i] >= 1)
{
ContainStashItem = true;
}
/*if (InventoryDontCheckItem[i] == 0 && InventoryHasItem[i] >= 1)
{
Form1_0.ItemsStruc_0.GetItemAtPointer(InventoryItemPointers[i]);
if (Form1_0.ItemsAlert_0.ShouldKeepItem())
{
ContainStashItem = true;
}
}*/
}
return ContainStashItem;
}
2024-03-29 00:19:36 -07:00
public void VerifyKeysInventory()
{
int thisindex = CharConfig.KeysLocationInInventory.Item1 + (CharConfig.KeysLocationInInventory.Item2 * 10);
//if its not a key at the key location, relocate the item
if (InventoryItemNames[thisindex] != "Key")
{
int ThisNewIndex = GetNextFreeSpaceInInventory();
2024-04-14 18:51:35 -07:00
if (ThisNewIndex > -1)
2024-03-29 00:19:36 -07:00
{
//remove item from this slot
Dictionary<string, int> itemScreenPos = Form1_0.InventoryStruc_0.ConvertIndexToXY(thisindex);
itemScreenPos = Form1_0.InventoryStruc_0.ConvertInventoryLocToScreenPos(itemScreenPos["x"], itemScreenPos["y"]);
//Form1_0.KeyMouse_0.MouseClicc(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.Stash_0.PickItem(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.WaitDelay(5);
//place to next free space
itemScreenPos = Form1_0.InventoryStruc_0.ConvertIndexToXY(ThisNewIndex);
itemScreenPos = Form1_0.InventoryStruc_0.ConvertInventoryLocToScreenPos(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.Stash_0.PlaceItem(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.Stash_0.PlaceItem(itemScreenPos["x"], itemScreenPos["y"]);
}
}
//place all keys together
for (int i = 0; i < 40; i++)
{
if (CharConfig.InventoryDontCheckItem[i] == 0 && InventoryHasItem[i] >= 1 && InventoryItemNames[i] == "Key")
{
//pick key item from this slot
Dictionary<string, int> itemScreenPos = Form1_0.InventoryStruc_0.ConvertIndexToXY(i);
itemScreenPos = Form1_0.InventoryStruc_0.ConvertInventoryLocToScreenPos(itemScreenPos["x"], itemScreenPos["y"]);
//Form1_0.KeyMouse_0.MouseClicc(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.Stash_0.PickItem(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.WaitDelay(5);
//place with other key
itemScreenPos = Form1_0.InventoryStruc_0.ConvertIndexToXY(thisindex);
itemScreenPos = Form1_0.InventoryStruc_0.ConvertInventoryLocToScreenPos(itemScreenPos["x"], itemScreenPos["y"]);
if (!Form1_0.Stash_0.PlaceItem(itemScreenPos["x"], itemScreenPos["y"]))
{
itemScreenPos = Form1_0.InventoryStruc_0.ConvertIndexToXY(i);
itemScreenPos = Form1_0.InventoryStruc_0.ConvertInventoryLocToScreenPos(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.Stash_0.PlaceItem(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.Stash_0.PlaceItem(itemScreenPos["x"], itemScreenPos["y"]);
}
}
}
}
2023-04-20 21:39:08 -07:00
public void SetHUDItem()
{
if (Form1_0.ItemsStruc_0.statCount > 0)
{
//; get quantity
int quantity = 1;
//Form1_0.Mem_0.ReadRawMemory(Form1_0.ItemsStruc_0.statPtr, ref Form1_0.ItemsStruc_0.statBuffer, (int)(Form1_0.ItemsStruc_0.statCount * 10));
for (int i = 0; i < Form1_0.ItemsStruc_0.statCount; i++)
{
int offset = i * 8;
ushort statEnum = BitConverter.ToUInt16(Form1_0.ItemsStruc_0.statBuffer, offset);
int statValue = BitConverter.ToInt32(Form1_0.ItemsStruc_0.statBuffer, offset + 0x2);
//bad verif
if (statEnum == 70)
{
quantity = statValue;
}
//good verif
if ((statEnum == 0 && Form1_0.ItemsStruc_0.statCount == 1))
{
quantity = ((statValue >> 8) / 256);
}
}
//; 543 is key
//; 529 is TP scroll
//; 530 is ID scroll
//; 518 is tome of TP
//; 519 is tome of ID
if (Form1_0.ItemsStruc_0.txtFileNo == 543)
{
HUDItems_keys = HUDItems_keys + quantity;
}
else if (Form1_0.ItemsStruc_0.txtFileNo == 529)
{
HUDItems_tpscrolls = HUDItems_tpscrolls + quantity;
HUDItems_tpscrolls_locx = Form1_0.ItemsStruc_0.itemx;
HUDItems_tpscrolls_locy = Form1_0.ItemsStruc_0.itemy;
}
else if (Form1_0.ItemsStruc_0.txtFileNo == 530)
{
HUDItems_idscrolls = HUDItems_idscrolls + quantity;
HUDItems_idscrolls_locx = Form1_0.ItemsStruc_0.itemx;
HUDItems_idscrolls_locy = Form1_0.ItemsStruc_0.itemy;
}
else if (Form1_0.ItemsStruc_0.txtFileNo == 518)
{
HUDItems_tpscrolls = HUDItems_tpscrolls + quantity;
HUDItems_tpscrolls_locx = Form1_0.ItemsStruc_0.itemx;
HUDItems_tpscrolls_locy = Form1_0.ItemsStruc_0.itemy;
}
else if (Form1_0.ItemsStruc_0.txtFileNo == 519)
{
2024-04-18 18:51:45 -07:00
HasIDTome = true;
2023-04-20 21:39:08 -07:00
HUDItems_idscrolls = HUDItems_idscrolls + quantity;
HUDItems_idscrolls_locx = Form1_0.ItemsStruc_0.itemx;
HUDItems_idscrolls_locy = Form1_0.ItemsStruc_0.itemy;
}
}
}
2024-04-14 18:51:35 -07:00
public void DumpBadItemsOnGround()
{
Form1_0.UIScan_0.OpenUIMenu("invMenu");
2024-04-18 18:51:45 -07:00
Form1_0.ItemsStruc_0.GetBadItemsOnCursor();
//Form1_0.ItemsStruc_0.GetItems(false);
2024-04-14 18:51:35 -07:00
//place all bad items on ground
for (int i = 0; i < 40; i++)
{
Form1_0.UIScan_0.OpenUIMenu("invMenu");
2024-04-24 16:47:22 -07:00
if (CharConfig.InventoryDontCheckItem[i] == 0 && InventoryHasItem[i] >= 1 && InventoryHasItemToID[i] == 0 && InventoryHasStashItem[i] == 0)
2024-04-14 18:51:35 -07:00
{
//pick key item from this slot
Dictionary<string, int> itemScreenPos = Form1_0.InventoryStruc_0.ConvertIndexToXY(i);
itemScreenPos = Form1_0.InventoryStruc_0.ConvertInventoryLocToScreenPos(itemScreenPos["x"], itemScreenPos["y"]);
2024-04-18 18:51:45 -07:00
if (InventoryItemNames[i].Contains("Healing") || InventoryItemNames[i].Contains("Mana") || InventoryItemNames[i].Contains("Rejuvenation"))
2024-04-14 18:51:35 -07:00
{
2024-04-18 18:51:45 -07:00
Form1_0.KeyMouse_0.MouseCliccRight(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.WaitDelay(10);
}
else
{
/*Form1_0.Stash_0.PickItem(itemScreenPos["x"], itemScreenPos["y"]);
if (!Form1_0.Stash_0.PlaceItem(Form1_0.CenterX, Form1_0.CenterY))
{
Form1_0.Stash_0.PlaceItem(itemScreenPos["x"], itemScreenPos["y"]);
}*/
Form1_0.KeyMouse_0.MouseClicc(itemScreenPos["x"], itemScreenPos["y"]);
Form1_0.WaitDelay(12);
2024-04-24 16:47:22 -07:00
//Form1_0.KeyMouse_0.MouseClicc_RealPos(Form1_0.CenterX, Form1_0.CenterY);
Form1_0.Stash_0.PlaceItem(Form1_0.CenterX, Form1_0.CenterY);
2024-04-18 18:51:45 -07:00
Form1_0.WaitDelay(10);
}
2024-04-14 18:51:35 -07:00
}
}
Form1_0.UIScan_0.CloseUIMenu("invMenu");
}
2023-04-20 21:39:08 -07:00
public void ResetInventory()
{
InventoryHasItem = new int[40];
2024-04-22 17:48:19 -07:00
InventoryHasItemToID = new int[40];
2023-04-20 21:39:08 -07:00
InventoryHasUnidItem = new int[40];
InventoryItemPointers = new long[40];
InventoryItemNames = new string[40];
2024-04-05 21:50:39 -07:00
InventoryItemQuality = new int[40];
2023-04-20 21:39:08 -07:00
InventoryHasStashItem = new int[40];
HUDItems_idscrolls = 0;
HUDItems_tpscrolls = 0;
HUDItems_keys = 0;
}
public void SetInventoryItem()
{
2024-03-29 00:19:36 -07:00
try
2023-04-20 21:39:08 -07:00
{
2024-03-29 00:19:36 -07:00
int FullIndex = ConvertXYToIndex(Form1_0.ItemsStruc_0.itemx, Form1_0.ItemsStruc_0.itemy);
InventoryHasItem[FullIndex] = 1;
InventoryItemPointers[FullIndex] = Form1_0.ItemsStruc_0.ItemPointerLocation;
InventoryItemNames[FullIndex] = Form1_0.ItemsStruc_0.ItemNAAME;
2024-04-05 21:50:39 -07:00
InventoryItemQuality[FullIndex] = (int) Form1_0.ItemsStruc_0.itemQuality;
2024-03-29 00:19:36 -07:00
if (Form1_0.ItemsAlert_0.ShouldKeepItem())
{
InventoryHasStashItem[FullIndex] = 1;
}
2024-04-22 17:48:19 -07:00
if (Form1_0.ItemsAlert_0.ShouldPickItem(false))
{
InventoryHasItemToID[FullIndex] = 1;
}
2023-04-20 21:39:08 -07:00
2024-03-29 00:19:36 -07:00
if (!Form1_0.ItemsStruc_0.identified)
{
InventoryHasUnidItem[FullIndex] = 1;
}
2023-04-20 21:39:08 -07:00
}
2024-03-29 00:19:36 -07:00
catch { }
2023-04-20 21:39:08 -07:00
}
public bool HasUnidItemInInventory()
{
for (int i = 0; i < 40; i++)
{
if (CharConfig.InventoryDontCheckItem[i] == 0 && InventoryHasUnidItem[i] >= 1)
{
return true;
}
}
return false;
}
2024-03-29 00:19:36 -07:00
public int GetNextFreeSpaceInInventory()
{
for (int i = 0; i < 40; i++)
{
if (CharConfig.InventoryDontCheckItem[i] == 0 && InventoryHasItem[i] == 0)
{
return i;
}
}
return -1;
}
2023-04-20 21:39:08 -07:00
public bool HasInventoryItems()
{
for (int i = 0; i < 40; i++)
{
if (CharConfig.InventoryDontCheckItem[i] == 0 && InventoryHasItem[i] >= 1)
{
return true;
}
}
return false;
}
public bool HasInventoryItemName(string ItemmN)
{
for (int i = 0; i < 40; i++)
{
if (CharConfig.InventoryDontCheckItem[i] == 0 && InventoryHasItem[i] >= 1)
{
if (InventoryItemNames[i] == ItemmN)
{
return true;
}
}
}
return false;
}
2024-04-18 18:51:45 -07:00
public bool HasInventoryItemsForShop()
{
for (int i = 0; i < 40; i++)
{
if (CharConfig.RunCowsScript && !Form1_0.Cows_0.ScriptDone && Form1_0.InventoryStruc_0.InventoryItemNames[i] == "Wirt's Leg") continue;
if (CharConfig.RunCowsScript && !Form1_0.Cows_0.ScriptDone && Form1_0.InventoryStruc_0.InventoryItemNames[i] == "Tome of Town Portal") continue;
if (CharConfig.InventoryDontCheckItem[i] == 0 && InventoryHasItem[i] >= 1 && InventoryHasStashItem[i] == 0)
{
return true;
}
}
return false;
}
2023-04-20 21:39:08 -07:00
/*public bool HasInventoryItemAt(int AtIndex)
{
if (InventoryHasItem[AtIndex] >= 1)
{
return true;
}
return false;
}*/
}
}