Okay I've got all of the functions done and I've commited them as comments as I don't have the time right now to make the necessary core changes and test everything. I will within the next couple days though.
Few things to note:
- The bug where player setup would click the stats tab multiple times will be fixed.
- I've implemented the InvSlot attribute from TItem, so there will be no mistakes between items and tools when the time comes to drop and bank the materials (I still need to edit MSI_DropAll and MSI_Deposit so this will work).
- MSI_SetupFishing is completely rewritten and is much, much better. It will now search for the tools for each object in the player array. If a tool isn't found, it's stored in a separate array so after looking for every tool for EACH object the script can withdraw all the tools at the same time.
Then, if all tools are found for their respective object, that object will be added to a temporary object array. The same is done for all objects. MSI_Players[CurrentPlayer].Objects[CurrentScript] is then reset with only the objects that have had their tools found.
Probably sounds confusing, but it is A LOT better then what we currently have.
- TScript.Tools will be gone, and TScript.PlayerSetup will be added.
I'm not sure if there's anything else. I'll update the post if there is. Here's the code. It hasn't been tested so of course there will be flaws; some may not even compile.
// Skills.simba
{******************************************************************************}
{ procedure MSI_SetSkillLevels(); }
{ By: Coh3n }
{ Date: 04 October 2010 }
{ Description: Gets the player's skill levels for each script }
{******************************************************************************}
procedure MSI_SetSkillLevels();
var
i, curLev: Integer;
begin
if (not LoggedIn) then
Exit;
MSI_AddHeader('MSI_GetSkillLevels');
with MSI_Players[CurrentPlayer] do
for i := 0 to High(Scripts) do
begin
curLev := GetSkillLevel(MSI_Scripts[i].Skill);
// Only sets if the level has increased
if (curLev <= MSI_Scripts[Scripts[i]].PlayerSkillLevel) then
Continue;
// Set the TScript & ProgressReportArray attribute
MSI_Scripts[Scripts[i]].PlayerSkillLevel := curLev;
ProgressReportArray[CurrentPlayer].ScriptInfo[i].PlayerSkillLevel := curLev;
with MSI_Scripts[Scripts[i]] do
MSI_Debug(Skill + ' Level: ' + IntToStr(PlayerSkillLevel));
end;
MSI_CloseHeader('MSI_GetSkillLevels: Exit');
end;
{******************************************************************************}
{ function MSI_BestTool: Integer; }
{ By: Coh3n }
{ Date: 05 October 2010 }
{ Description: Determines the best tool for the chosen skill. Keep in mind }
{ this may not be used for every skill }
{******************************************************************************}
function MSI_BestTool: Integer;
begin
if (not LoggedIn) then
Exit;
with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do
begin
case (SkillConstant) of
SKILL_WOODCUTTING:
case (PlayerSkillLevel) of
REQ_DRAGON..REQ_MAX_LEVEL: Result := HATCHET_DRAGON;
REQ_RUNE..REQ_DRAGON : Result := HATCHET_RUNE;
REQ_ADAMANT..REQ_RUNE : Result := HATCHET_ADAMANT;
REQ_MITHRIL..REQ_ADAMANT : Result := HATCHET_MITHRIL;
REQ_STEEL..REQ_MITHRIL : Result := HATCHET_STEEL;
else
Result := HATCHET_IRON;
end;
SKILL_MINING:
case (PlayerSkillLevel) of
REQ_DRAGON..REQ_MAX_LEVEL: Result := PICKAXE_DRAGON;
REQ_RUNE..REQ_DRAGON : Result := PICKAXE_RUNE;
REQ_ADAMANT..REQ_RUNE : Result := PICKAXE_ADAMANT;
REQ_MITHRIL..REQ_ADAMANT : Result := PICKAXE_MITHRIL;
REQ_STEEL..REQ_MITHRIL : Result := PICKAXE_STEEL;
else
Result := PICKAXE_IRON;
end;
else
MSI_SubDebug('MSI_BestTool: Invalid skill!');
end;
MSI_Debug('Best tool for ' + Skill + ' is '+ MSI_Items[Result].Name);
end;
end;
{******************************************************************************}
{ function MSI_WorstTool: Integer; }
{ By: Coh3n }
{ Date: 05 October 2010 }
{ Description: Determines the worst tool for the job at hand. }
{******************************************************************************}
function MSI_WorstTool: Integer;
begin
if (not LoggedIn) then
Exit;
with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do
case skill of
SKILL_WOODCUTTING:
Result := HATCHET_BRONZE;
SKILL_MINING:
Result := PICKAXE_BRONZE;
else
MSI_SubDebug('MSI_WorstTool: Invalid skill!');
end;
end;
// Debug.simba
{******************************************************************************}
{ procedure MSI_GetReportInfo; }
{ By: Coh3n & Shuttleu }
{ Date: 04 October 2010 }
{ Description: Gets the necessary proggy info that isn't automatically reset }
{ during runtime }
{******************************************************************************}
procedure MSI_GetReportInfo;
var
curLev, i: Integer;
script: TScript;
begin
for i := 0 to High(MSI_Players) do
with ProgressReportArray[i] do
begin
if (i = CurrentPlayer) then
MSI_SetSkillLevels();
MSI_Players[i].Active := Players[i].Active;
PlayerLoc := MSI_Players[i].Location;
PlayerStatus := MSI_Players[i].Active;
end;
end;
// Mainloop.simba
{******************************************************************************}
{ function MSI_SetupPlayer: Boolean; }
{ By: Coh3n }
{ Date: 05 October 2010 }
{ Description: Sets up the player for autoing }
{******************************************************************************}
function MSI_SetupPlayer: Boolean;
begin
MSI_AddHeader('MSI_SetupPlayer');
if (not LoggedIn) then
begin
MSI_Debug('Player is not logged in');
if (not (WaitFunc(@LoginPlayer, 100, 5000))) then
begin
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;
end;
// Add logins to stats
Inc(Stats_CustomVars[STATS_LOGINS]);
MSI_SendStats;
// Standard setup procedures
MSI_FindRandoms;
SetAngle(True);
RunEnergy(20);
// Setup the player
MSI_SetSkillLevels();
with MSI_Players[CurrentPlayer] do
Result := MSI_Scripts[Scripts[CurrentScript]].SetupPlayer();
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
end;
// Fishing.simba
{******************************************************************************}
{ function MSI_SetupFishing(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Sets up the player for fishing }
{******************************************************************************}
function MSI_SetupFishing(): Boolean;
var
i, j, t, x, y: Integer;
tools, newObjs: TIntegerArray;
toWithdraw: array of TIntegerArray;
objReady: TBooleanArray;
curScript: TScript;
begin
MSI_AddHeader('MSI_SetupFishing');
with MSI_Players[CurrentPlayer] do
begin
SetLength(objReady, Length(Objects[CurrentScript]));
SetLength(toWithdraw, Length(Objects[CurrentScript]));
curScript := MSI_Scripts[Scripts[CurrentScript]];
// Loops through the player objects checking for the required tools for each
for i := 0 to High(Objects[CurrentScript]) do
begin
tools := MSI_FishingTools(Objects[CurrentScript][i]); // Gets the required fishing tools for the fishing spot
t := 0;
for j := 0 to High(tools) do
if (MSI_FindTool(tools[j], TAB_INV, x, y)) then
MSI_Items[j].InvSlot := CoordsToItem(x, y) // Set tool's inventory slot
else begin
SetLength(toWithdraw[i], t);
toWithdraw[i][t] := tools[j]; // Adds to the array if the tool isn't found
Inc(t);
end;
end;
// In a separate loop so it only opens the bank once
for i := 0 to High(Objects[CurrentScript]) do
if (Length(toWithdraw[i]) <= 0) then // If all tools are found
objReady := True
else // If 1+ tools aren't found
if (MSI_OpenBank(curScript.WhichBank, Pin)) then
objReady := MSI_Withdraw(toWithDraw[i], []);
t := 0;
for i := 0 to High(objReady) do
if (objReady[i]) then
begin
newObjs[t] := Objects[CurrentScript][i];
Inc(t);
end else
MSI_Debug(MSI_Objects[Objects[CurrentScript][i]].Name + ': Required tools not found');
// Resets the objects so if the tools aren't found it will still fish in the spots for which the tools were found
Objects[CurrentScript] := newObjs;
Result := (Length(Objects[CurrentScript]) > 0);
end;
MSI_CloseHeader('MSI_SetupFishing: ' + BoolToStr(Result));
end;
{******************************************************************************}
{ function MSI_FishingTools(Obj: Integer): TIntegerArray; }
{ By: 3Garrett3 }
{ Date: 07 Octovber 2010 }
{ Description: Figures out which tool the script needs to use }
{******************************************************************************}
function MSI_FishingTools(Obj: Integer): TIntegerArray;
begin
case (Obj) of
FISHSPOT_NET:
Result := [FISH_SMALLNET];
FISHSPOT_BAIT:
Result := [FISH_ROD_BAIT, FISH_BAIT];
FISHSPOT_LURE:
Result := [FISH_ROD_FLY, MISC_FEATHER];
FISHSPOT_CAGE:
Result := [FISH_CAGE];
FISHSPOT_HARPOON:
Result := [FISH_HARPOON];
else
MSI_Debug('Invalid Fishing Spot Argument');
end;
end;
// Mining.simba
{******************************************************************************}
{ function MSI_SetupMining(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Sets up the player for mining }
{******************************************************************************}
function MSI_SetupMining(): Boolean;
begin
Result := MSI_SetupWoodcutting(); // To avoid unnecessary repeated code
end;
// Woodcutting.simba
{******************************************************************************}
{ function MSI_SetupWoodcutting(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Sets up the player for woodcutting }
{******************************************************************************}
function MSI_SetupWoodcutting(): Boolean;
var
i, j, x, y: Integer;
tabs: TIntegerArray;
begin
// If it's already on the inventory, it will search there first
if (GetCurrentTab = TAB_INV) then
tabs := [TAB_INV, TAB_EQUIP]
else
tabs := [TAB_EQUIP, TAB_INV];
for i := 0 to 1 do
for j := MSI_BestTool downto MSI_WorstTool do // First search for the best tool
if (MSI_FindTool(j, tabs[i], x, y)) then
begin
if (tabs[i] = TAB_INV) then
MSI_Items[j].InvSlot := CoordsToItem(x, y); // Set tool's inventory slot
Result := True;
Break;
end;
with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do // CurrentScript
if (not Result) then
if (not (BankType = NoBank)) then // If CurrentScript is a banking one
if (MSI_Locations[MSI_Players[CurrentPlayer].Location].AtBank) then // If player is at a bank
Result := MSI_WithdrawBestTool();
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
end;
// Banking.simba
{******************************************************************************}
{ function MSI_WithdrawBestTool(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Withdraws the best tool for the current script }
{******************************************************************************}
function MSI_WithdrawBestTool(): Boolean;
begin
with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do
if (MSI_OpenBank(WhichBank, MSI_Players[CurrentPlayer].Pin)) then
begin
for i := MSI_BestTool downto MSI_WorstTool do
if (MSI_Withdraw([i], [1])) then
begin
Result := True;
Break;
end;
// Equip tool if possible
if (not Result) then
begin
CloseBank;
MSI_Debug('Couldn''t withdraw best tool');
end;
end else
MSI_Debug('Unable to open ' + MSI_Objects[WhichBank].Name);
end;
What do you guys think? :)