Coh3n
2010-07-21 13:48:01
I switched back to the "Slots" system. I also added MSI_FindAllToolSlots, and MSI_DropAll. The banking and dropping will now drop/bank everything except the script's required tools. :) Banking will also use the Deposit All buttons if there are no tools in the inventory.
There are also small changes to MSI_Deposit plus a few functions here and there to compensate for the ItemInfo changes.
Cheers,
Coh3n
{******************************************************************************}
{ function MSI_FindItemSlots(Item: Integer): TIntegerArray; }
{ By: Coh3n }
{ Date: 21 July 2010 }
{ Description: Returns an array of the inventory/bank deposit slots where }
{ 'Item' is found }
{******************************************************************************}
function MSI_FindItemSlots(Item: Integer): TIntegerArray;
var
i, j, l, x, y: Integer;
itemPoints: TPointArray;
b: TBox;
bankType: TBank;
searchArea: string;
begin
SetLength(result, 0);
GameTab(TAB_INV);
bankType := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]].BankType;
case bankType of
Bank, NoBank: searchArea := 'inv';
DBox: searchArea := 'deposit box';
end;
itemPoints := ItemCoordinates(searchArea, 'dtm', MSI_Items[Item].DTM, []);
for i := 0 to High(itemPoints) do
for j := 1 to 28 do
begin
case bankType of
Bank, NoBank: b := InvBox(j);
DBox: b := DepositItemBox(j);
end;
if (PointInBox(itemPoints[i], b)) then
begin
l := Length(result);
SetLength(result, l + 1);
result[l] := j;
end;
end;
MSI_Debug('MSI_FindItemSlots', 'Found '+IntToStr(Length(result))+' '+MSI_Items[Item].Name+' in inventory', DEBUG_FUNCTIONS);
end;
{******************************************************************************}
{ function MSI_ClickItemSlot(Slot: Integer; Options: TStringArray): Boolean; }
{ By: Coh3n }
{ Date: 21 July 2010 }
{ Description: Clicks the inventory/deposit box 'Slot' and chooses the correct }
{ option }
{******************************************************************************}
function MSI_ClickItemSlot(Slot: Integer; Options: TStringArray): Boolean;
var
x, y: Integer;
bankType: TBank;
b: TBox;
begin
bankType := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]].BankType;
case bankType of
Bank, NoBank: b := InvBox(Slot);
DBox: b := DepositItemBox(Slot);
end;
MMouse((b.x1+b.x2)/2, (b.y1+b.y2)/2, 10, 10);
GetMousePos(x, y);
if (WaitUpTextMulti(Options, 100+Random(20))) then
begin
Mouse(x, y, 0, 0, True);
Result := True;
end else begin
Mouse(x, y, 0, 0, False);
Result := WaitOptionMulti(Options, 250+Random(50));
end;
if (not Result) then
MSI_Debug('MSI_ClickItemSlot', 'Failed to click item slot', DEBUG_FUNCTIONS);
end;
{******************************************************************************}
{ function MSI_ClickItem(Item: Integer; Options: TStringArray): Boolean; }
{ By: Coh3n }
{ Date: 11 July 2010 }
{ Description: Will right/left click and choose option 'Options' depending on }
{ on the 'Item' parameter. Clicks the first occurance of the }
{ item found }
{******************************************************************************}
function MSI_ClickItem(Item: Integer; Options: TStringArray): Boolean;
var
slots: TIntegerArray;
begin
slots := MSI_FindItemSlots(Item);
if (Length(slots) > 0) then
Result := MSI_ClickItemSlot(slots[0], Options);
if (not Result) then
MSI_Debug('MSI_ClickItem', 'Failed to click item: '+MSI_Items[Item].Name, DEBUG_FUNCTIONS);
end;
{******************************************************************************}
{ procedure MSI_ClickItems(Items: TIntegerArray; Options: TStringArray); }
{ By: Coh3n }
{ Date: 11 July 2010 }
{ Description: Clicks all items in the 'Items' array. Will right/left click }
{ and choose option depending on the 'Options' array }
{******************************************************************************}
procedure MSI_ClickItems(Items: TIntegerArray; Options: TStringArray);
var
i, j: Integer;
slots: TIntegerArray;
begin
for i := 0 to High(Items) do
begin
slots := MSI_FindItemSlots(Items[i]);
for j := 0 to High(slots) do
MSI_ClickItemSlot(slots[j], Options);
end;
end;
{******************************************************************************}
{ function MSI_FindAllToolSlots: TIntegerArray; }
{ By: Coh3n }
{ Date: 21 July 2010 }
{ Description: Returns the slots where the required script tools are found. }
{ Used for dropping and banking }
{******************************************************************************}
function MSI_FindAllToolSlots: TIntegerArray;
var
i, j, l, x, y: Integer;
info: TIntegerArray;
script: TScript;
begin
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
for i := 0 to High(script.ScriptTools) do
case script.ScriptTools[i] of
TOOL_HATCHET, TOOL_PICKAXE:
begin
if (script.ScriptTools[i] = TOOL_HATCHET) then
info := [HATCHET_BRONZE, HATCHET_RUNE]
else
info := [PICKAXE_BRONZE, PICKAXE_RUNE];
for j := info[0] to info[1] do
Result := CombineIntArray(Result, MSI_FindItemSlots(j));
end;
else
MSI_Debug('MSI_DropAll', 'Invalid tool!', DEBUG_FORCE);
end;
ClearSameIntegers(Result);
end;
{******************************************************************************}
{ procedure MSI_DropAll; }
{ By: Coh3n }
{ Date: 21 July 2010 }
{ Description: Drops the entire inventory except the required tools }
{******************************************************************************}
procedure MSI_DropAll;
var
exceptions: TIntegerArray;
begin
exceptions := MSI_FindAllToolSlots;
if (Length(exceptions) <= 0) then
DropAll
else
DropAllExcept(exceptions);
end;
There are also small changes to MSI_Deposit plus a few functions here and there to compensate for the ItemInfo changes.
Cheers,
Coh3n