Skip to content

Commit

Permalink
feat(combathandler): add support for TRSNPCV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Torwent committed Aug 11, 2024
1 parent 25851ee commit 0f57f82
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 8 deletions.
92 changes: 85 additions & 7 deletions optional/handlers/combathandler.simba
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ type
TRSCombatHandler = record(TSRLBaseRecord)
State: ECombatState;
Monster: TRSMonster;
MonsterV2: TRSNPCV2;

MonsterWalkerCoord, SafeSpot: TPoint;

BraceletTimer, InCombatTimer: TCountDown;
Expand Down Expand Up @@ -134,35 +136,34 @@ begin

for Self.Weapon in WEAPONS do
begin
if (Self.Weapon = 'Null') then
Break;
if (Self.Weapon = 'Null') then Break;
if Equipment.ContainsItem(Self.Weapon) then
begin
Delete(RSAlchHandler.ItemArray, RSAlchHandler.ItemArray.Find(Self.Weapon), 1);
Break;
end;
end;

Self.DebugLn('Current weapon: ' + ToStr(Self.Weapon) + '.');

for Self.Shield in SHIELDS do
begin
if (Self.Shield = 'Null') then
Break;
if (Self.Shield = 'Null') then Break;
if Equipment.ContainsItem(Self.Shield) then
begin
Delete(RSAlchHandler.ItemArray, RSAlchHandler.ItemArray.Find(Self.Shield), 1);
Break;
end;
end;

Self.DebugLn('Current shield: ' + ToStr(Self.Shield) + '.');

if Equipment.ContainsItem('Bonecrusher necklace') then
Antiban.Skills += ERSSkill.PRAYER;

for Self.SpecWeapon in SPEC_WEAPONS do
begin
if (Self.SpecWeapon = 'Null') then
Break;
if (Self.SpecWeapon = 'Null') then Break;
if Inventory.ContainsItem(Self.SpecWeapon) then
begin
Delete(RSAlchHandler.ItemArray, RSAlchHandler.ItemArray.Find(Self.SpecWeapon), 1);
Expand Down Expand Up @@ -202,7 +203,7 @@ begin
end;

Self.GearIsSetup := (Self.Weapon <> 'Null') or (Self.Shield <> 'Null') or
(Self.SpecWeapon <> 'Null') or (Self.Bracelet <> 'Null');
(Self.SpecWeapon <> 'Null') or (Self.Bracelet <> 'Null');
end;


Expand Down Expand Up @@ -267,6 +268,55 @@ begin
Self.IsSetup := True;
end;

procedure TRSCombatHandler.Setup(rsMonster: TRSNPCV2; timer: Int64 = 4000; safeSpotTile: TPoint = [-1, -1]); overload;
var
eConsumable: ERSConsumable;
begin
if Self.IsSetup then
Exit;

Self.Name := 'CombatHandler';

if Self.AttackMonsterDelay = 0 then
Self.AttackMonsterDelay := 5000;

Self.InCombatTimer.Setup(Timer);

if not RSClient.IsLoggedIn() then
Login.LoginPlayer();

ChatButtons.Open(ERSChatButton.GAME_CHAT);
Self.SlayerTaskFinishedVisible := Chat.FindMessage('Slayer master', [CHAT_COLOR_RED]);


for eConsumable := ERSConsumable(0) to ERSConsumable(High(ERSConsumable)-2) do
Self._ShouldHandleConsumable(eConsumable);

for eConsumable := ERSConsumable.STRENGTH_BOOST to ERSConsumable.BOOST do
begin
if Self.HandleConsumables[eConsumable] then
Break;
if eConsumable = ERSConsumable.BOOST then
Self._ShouldHandleConsumable(ERSConsumable.BOOST);
end;

Self.HandleCannon := Inventory.ContainsAll(DWARF_CANNON) and
Inventory.ContainsAny(CANNON_BALLS);

if Self.HandleCannon then
Self.DebugLn('Cannon and cannonballs detected. Cannon will be used.');

if not Self.AutoRetaliateChecked then
Combat.GetAutoRetaliate();

Self.MonsterV2 := rsMonster;
Self.SafeSpot := safeSpotTile;
Self.UseSafeSpot := safeSpotTile <> [-1,-1];

Self.Looted := True;
Self.IsSetup := True;
end;

procedure TRSCombatHandler.Setup(manage: Boolean; rsMonster: TRSMonster; lootValue: Int32 = 5000; timer: Int64 = 4000; safeSpotTile: TPoint = [-1, -1]); overload;
begin
if Self.IsSetup then
Expand All @@ -289,6 +339,26 @@ begin
DebugMonsterArray += rsMonster;
end;

procedure TRSCombatHandler.Setup(manage: Boolean; rsMonster: TRSNPCV2; lootValue: Int32 = 5000; timer: Int64 = 4000; safeSpotTile: TPoint = [-1, -1]); overload;
begin
if Self.IsSetup then
Exit;

Self.Setup(rsMonster, timer, safeSpotTile);

if manage then
begin
Self.ManageGear := True;
Self._SetupGear();
end;

if lootValue > 0 then
begin
Self.LootHandler.Setup(rsMonster, lootValue);
Self.LootEnabled := Self.LootHandler.IsSetup;
end;
end;


function TRSCombatHandler.GetMonsterDot(msCoord: TPoint): TPoint;
var
Expand Down Expand Up @@ -451,11 +521,19 @@ begin
if Inventory.Open() and Inventory.ClickItem(Self.Bracelet) then
Result := WaitUntil(Inventory.Count() < count, 300, 3000);

WriteLn Result;
if Result then
begin
Self.BraceletTimer.Restart();
if not Self.AutoRetaliateEnabled then
Self.InCombatTimer.Timeout := GetTickCount();
end
else if Equipment.ContainsItem(Self.Bracelet) then
begin
Result := True;
Self.BraceletTimer.Restart();
if not Self.AutoRetaliateEnabled then
Self.InCombatTimer.Timeout := GetTickCount();
end;
end;

Expand Down
91 changes: 91 additions & 0 deletions optional/handlers/loothandler.simba
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,97 @@ begin
Self.IsSetup := True;
end;

procedure TRSLootHandler.Setup(monster: TRSNPCV2; value: Int32 = 5000); overload;
var
i: Int32;
tmpDrops: TRSMonsterDropArray;
begin
if (monster.Name = '') or (value <= 0) then
Exit;

Self.Name := 'LootHandler';

Self.PriorityArray := [
'Clue scroll (easy)', 'Clue scroll (medium)', 'Clue scroll (hard)', 'Clue scroll (elite)',
'Clue scroll (master)',
'Dark totem base', 'Dark totem middle', 'Dark totem top',
'Dark totem', 'Ancient shard', 'Brimstone key',
'Mist battlestaff', 'Dust battlestaff',
'Eternal gem', 'Imbued heart', 'Crystal shard', 'Abyssal head',
'Curved bone', 'Long bone',
'Imp champion scroll', 'Goblin champion scroll', 'Skeleton champion scroll',
'Zombie champion scroll', 'Giant champion scroll',
'Hobgoblin champion scroll', 'Ghoul champion scroll',
'Earth warrior champion scroll', 'Jogre champion scroll',
'Lesser demon champion scroll',
'Giant key', 'Mossy key', 'Trident of the seas (full)' , 'Trident of the seas'
];
Self.PriorityArray := Self.PriorityArray.ToLower;

Self.HasGemBag := Inventory.ContainsItem('Open gem bag');
Self.HasHerbSack := Inventory.ContainsItem('Open herb sack');
Self.HasSoulBearer := Inventory.ContainsItem('Soul bearer');
Self.HasSeedBox := Inventory.ContainsItem('Open seed box');

Self.ValueThreshold := value;
Self.Loot._Setup();

if monster.Coordinates <> [] then
Self.Loot.Setup(monster.DotFilters[0].Circle.Radius, 0, monster.Coordinates)
else
begin
Self.Loot.Filter.Walker := monster.Filter.Walker;
Self.Loot.Filter.MinimapDot := monster.Filter.Minimap;
Self.Loot.Filter.UpText := monster.Filter.UpText;
Self.Loot.Filter.Finder := monster.Filter.Finder;
Self.Loot.Filter.Skip := False;
Self.Loot.ShapeArray += [[2, 2, 0], 0];
end;

Self.Loot.Finder.Colors := [
[6579858, 9, 0.09, 0.33], //vile and malicious ashes
[13422033, 18, 0.20, 0.30], //dragon bones (this matches a lot with proselyte. might need to be removed)
[7760980, 9, 0.06, 0.14], //rune items (this might need better colors but this one doesn't match in CoK background,
[10038382, 14, 0.08, 1.72], //ancient shard
[14390305, 26, 0.04, 0.88], //Totem parts (blue)
[1923609, 7, 0.16, 0.84], //Totem parts (green)
[4345976, 17, 0.10, 0.37], //Dark bow
[2895188, 6, 0.16, 0.41], //Abyssal whip (matches a little with primordial boots)
[1776416, 1, 0.01, 0.01], //Black mystic bottom (probably all parts too).
[3620158, 9, 0.28, 0.50], //Black mask
[10000802, 14, 0.13, 0.17], //Runes (matches with proselyte)
[1424100, 20, 0.02, 0.66], //gold coins
[808255, 11, 0.10, 2.30], //herb seeds
[482129, 11, 0.48, 1.48], //ranarr
[7311001, 7, 0.08, 0.21], //noted drops
[680832, 11, 0.04, 1.43], //battlestaff
[860512, 14, 0.21, 1.80] //ensouled hellhound head
];
Self.Loot.Filter.UpText := False;

Self.Loot.Finder.ClusterDistance := 3;
Self.Loot.Finder.Erode := 2;
Self.Loot.Finder.Grow := 4;
Self.Loot.DotType := ERSMinimapDot.ITEM;

DebugMMDotArray += Self.Loot;

tmpDrops := MonsterData.GetDrops(monster.Name);
tmpDrops.ClearDuplicates();

for i := 0 to High(tmpDrops) do
begin

if Self.IsGoodDrop(tmpDrops[i]) then
begin
Self.Drops += tmpDrops[i];
Self.Loot.UpText += tmpDrops[i].Item;
end;
end;

Self.IsSetup := True;
end;

function TRSLootHandler.HasSpace(drop: TRSMonsterDrop): Boolean;
begin
Result := not Inventory.IsFull() or (drop.Stackable and Inventory.ContainsItem(drop.Item));
Expand Down
4 changes: 3 additions & 1 deletion tools/compile_test.simba
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ Compile tests every script under the specified directory.
Returns the scripts that failed compiling.
*)
{$I SRL-T/osr.simba}
{$H-}

const
PATH: String = ScriptPath + 'waspscripts.com';
VERBOSE: Boolean = False;
BITNESS: String = '32';

var
files, failed: TStringArray;
Expand All @@ -21,7 +23,7 @@ begin
if VERBOSE then
WriteLn('Testing ', ExtractFileName(f));

if RunCommand(AppPath + 'Simba.exe', ['--compile', '"' + f + '"'], output) > 0 then
if RunCommand(AppPath + 'Simba' + BITNESS + '.exe', ['--compile', '"' + f + '"'], output) > 0 then
begin
failed += ExtractFileName(f);
if not VERBOSE then
Expand Down

0 comments on commit 0f57f82

Please sign in to comment.