Skip to content

Commit

Permalink
fix: read notes
Browse files Browse the repository at this point in the history
This PR has changed a lot of things and might have temporary unwanted consequences.

- all geometry related files were moved to it's own directory
- TCuboid was reworked to work properly and everywhere it was used was updated to work with it. This could have weird side effects when interacting with TRSWalkerObjects
- CombatHandler and LootHandler had some untested tweaks. Everything should work in theory fine, probably better than before but if combat script doesn't work, roll back wasplib for now.
  • Loading branch information
Torwent committed Sep 11, 2023
1 parent 1837ff9 commit 0cb4089
Show file tree
Hide file tree
Showing 18 changed files with 517 additions and 212 deletions.
20 changes: 20 additions & 0 deletions osr/dotfilters.simba
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ Methods to handle DotFilters. Dot filters are filters that filter in or out ERSM
{$I WaspLib/osr.simba}
{$ENDIF}

function TRSMinimap.GetDots(dots: ERSMinimapDots; box: TBox): TPointArray; overload;
var
bmp: TMufasaBitmap;
begin
if box = [] then
box := Self.Bounds();
bmp.FromClient(box);

Result := GetDotsBitmap(bmp, dots);
Result := Result.Offset([Self.X1, Self.Y1]);

bmp.Free();
end;

function TRSMinimap.GetDots(dot: ERSMinimapDot; box: TBox): TPointArray; overload;
begin
Result := GetDots([dot], box);
end;


(*
type TRSDotFilter
~~~~~~~~~~~~~~~~~
Expand Down
93 changes: 62 additions & 31 deletions osr/handlers/combathandler.simba
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const
type CombatHandler = record(TSRLBaseRecord) class var
State: String;
Monster: TRSMonster;
MonsterWalkerCoord: TPoint;

BraceletTimer, InCombatTimer: TCountDown;

Expand All @@ -92,7 +93,7 @@ type CombatHandler = record(TSRLBaseRecord) class var
HandleHealth, HandlePrayer, HandlePoison, HandleVenom, HandleAntifire,
HandleBoosts, HandleCannon, CannonIsSetup, DoingSpec,
SlayerTaskFinishedVisible, SlayerTaskFinished, LootEnabled, BuryBones,
IsSetup: Boolean;
IsFighting, FinishedCombat, IsSetup: Boolean;

LootHandler: TRSLootHandler;
end;
Expand Down Expand Up @@ -193,7 +194,7 @@ begin
(CombatHandler.SpecWeapon <> 'Null') or (CombatHandler.Bracelet <> 'Null');
end;

procedure CombatHandler.Setup(rsMonster: TRSMonster; timer: Int64 = 4000); static;
procedure CombatHandler.Setup(rsMonster: TRSMonster; timer: Int64 = 12000); static;
begin
if CombatHandler.IsSetup then
Exit;
Expand Down Expand Up @@ -281,17 +282,20 @@ begin
DebugMonsterArray += rsMonster;
end;


procedure CombatHandler.MarkCurrentEnemy(); static;
begin

end;


function CombatHandler.AttackMonster(): Boolean; static;
var
splats: TRSHitsplatArray;
begin
splats := MainScreen.FindHitsplats();
if splats <> [] then
begin
CombatHandler.MonsterWalkerCoord := ScriptWalker^.MSToWorld(splats[0].Position, Round(CombatHandler.Monster.ShapeArray[0].Tile.Z/2));
Result := MainScreen.WaitInCombat(CombatHandler.AttackMonsterDelay);
end;

if CombatHandler.Monster.SelectOption(['Attack'], 3) then
begin
CombatHandler.MonsterWalkerCoord := ScriptWalker^.MSToWorld(Mouse.Position(), Round(CombatHandler.Monster.ShapeArray[0].Tile.Z/2));
Minimap.WaitMoving();
Result := MainScreen.WaitInCombat(CombatHandler.AttackMonsterDelay);
end;
Expand All @@ -311,6 +315,7 @@ begin

if CombatHandler.Monster.WalkSelectOption(['Attack'], 3) then
begin
CombatHandler.MonsterWalkerCoord := ScriptWalker^.MSToWorld(Mouse.Position(), Round(CombatHandler.Monster.ShapeArray[0].Tile.Z/2));
Minimap.WaitMoving();
Result := MainScreen.WaitInCombat(CombatHandler.AttackMonsterDelay);
end;
Expand All @@ -324,12 +329,24 @@ begin
end;


function CombatHandler.FightingMonster(): Boolean; static;
var
cuboid: TCuboidEx;
begin
cuboid := ScriptWalker^.GetCuboidMS(CombatHandler.MonsterWalkerCoord, CombatHandler.Monster.ShapeArray[0]);
Result := MainScreen.FindHPBars(cuboid.Bounds()) <> [];
end;


function CombatHandler.Loot(): Boolean; static;
var
match: TRSItemFinderMatch;
cuboid: TCuboidEx;
begin
if Result := CombatHandler.LootHandler.CheckLoot() then
cuboid := ScriptWalker^.GetCuboidMS(CombatHandler.MonsterWalkerCoord, CombatHandler.Monster.ShapeArray[0]);
if Result := CombatHandler.LootHandler.CheckLoot(cuboid) then
begin
CombatHandler.FinishedCombat := False;
Wait(400, 600);

if not RSAlchHandler.Disabled then
Expand All @@ -341,9 +358,6 @@ begin
RSAlchHandler.CastAlchemy();
end;
end;

if not CombatHandler.AutoRetaliateEnabled then
CombatHandler.InCombatTimer.Timeout := GetTickCount();
end;
end;

Expand Down Expand Up @@ -626,21 +640,24 @@ begin
if CombatHandler.BuryBones and Inventory.ContainsAny(REMAINS) then
Exit('BURY_BONES');

if not MainScreen.InCombat() then
Exit('ATTACK_MONSTER');
if CombatHandler.IsFighting then
Exit('WAIT_IN_COMBAT');

Result := 'WAIT_IN_COMBAT';
if CombatHandler.LootEnabled and CombatHandler.FinishedCombat then
Exit('DO_LOOT');

Result := 'ATTACK_MONSTER';
end;


//Check for pending action combat handler is taking care of and do them.
procedure CombatHandler.DoActions(HandlerState: String = ''); static;
procedure CombatHandler.DoActions(handlerState: String = ''); static;
begin
if HandlerState = '' then
HandlerState := CombatHandler.GetState();
CombatHandler.State := HandlerState;
if handlerState = '' then
handlerState := CombatHandler.GetState();
CombatHandler.State := handlerState;

case HandlerState of
case handlerState of
'EAT_FOOD': Inventory.Consume(ERSConsumable.FOOD_CONSUMABLE);
'DRINK_PRAYER': Inventory.Consume(ERSConsumable.PRAYER_CONSUMABLE);
'DRINK_ANTIFIRE': Inventory.Consume(ERSConsumable.ANTI_FIRE_CONSUMABLE);
Expand All @@ -654,20 +671,13 @@ begin
'REEQUIP_GEAR': CombatHandler.ReGear();
'BURY_BONES': CombatHandler.DoBuryBones();
'ATTACK_MONSTER': CombatHandler.WalkAttackMonster();
'WAIT_IN_COMBAT': MainScreen.WaitInCombat(CombatHandler.InCombatTimer.Length);
'WAIT_IN_COMBAT': CombatHandler.FinishedCombat := MainScreen.WaitNotInCombat(CombatHandler.InCombatTimer.Length);
'DO_LOOT': CombatHandler.Loot();
'LOW_HEALTH', 'LOW_PRAYER', 'NO_ANTIFIRE', 'PLAYER_DEAD':
CombatHandler.Terminate;
CombatHandler.Terminate();
else
raise 'CombatHandler.DoActions received non-registered HandlerState: ' + HandlerState;
end;

if CombatHandler.LootEnabled and not CombatHandler.DoingSpec then
case HandlerState of
'EAT_FOOD', 'DRINK_PRAYER', 'DRINK_ANTIFIRE', 'DRINK_ANTIVENOM',
'DRINK_ANTIPOISON', 'DRINK_BOOST', 'ENABLE_QPRAY', 'NEED_BRACELET',
'BURY_BONES', 'ATTACK_MONSTER', 'WAIT_IN_COMBAT':
CombatHandler.Loot();
end;
end;


Expand Down Expand Up @@ -703,6 +713,27 @@ begin
or XPBar.EarnedXP() or (Self.FindHitsplats() <> []);
end;

function TRSMainScreen.InCombat(): Boolean; override;
var
gotXP, hasSplats: Boolean;
begin
if CombatHandler.InCombatTimer.IsFinished() and not XPBar.EarnedXP() then
begin
CombatHandler.IsFighting := False;
Exit;
end;

gotXP := XPBar.EarnedXP();
hasSplats := Self.FindHitsplats() <> [];
Result := gotXP or hasSplats or CombatHandler.FightingMonster();
CombatHandler.IsFighting := Result;
if Result then
WL.Activity.Restart();

if gotXP or hasSplats then
CombatHandler.InCombatTimer.Restart();
end;



//TODO: NEED TO REVIEW EVERYTHING BELOW. This is probably all useless or not used.
Expand Down
35 changes: 34 additions & 1 deletion osr/handlers/loothandler.simba
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ 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)',
Expand Down Expand Up @@ -196,10 +198,41 @@ end;
function TRSLootHandler.CheckLoot(b: TBox): Boolean; overload;
begin
Mouse.Move(b);

Result := Self.HandleLooting();
end;

function TRSLootHandler.CheckLoot(cuboid: TCuboidEx): Boolean; overload;
var
p: TPoint;
mmTile, dots, filteredDots, tmp: TPointArray;
angle: Double;
begin
for p in cuboid.Bottom.ToTPA() do
mmTile += Mainscreen.PointToMM(p, 0).ToPoint();

dots := Minimap.GetDots(ERSMinimapDot.ITEM, mmTile.Bounds());

if dots = [] then
Exit;

for p in dots do
if SRL.PointInPoly(p, mmTile) then
filteredDots += p;

if filteredDots = [] then
Exit;

angle := Minimap.GetCompassAngle(False);

tmp := filteredDots.Rotate(-angle, Minimap.Center());
p := tmp.NearestPoint([Minimap.Bounds().X1, Minimap.Bounds().Y2]);
p := p.Rotate(angle, Minimap.Center());

p := Minimap.PointToMsRect(filteredDots.NearestPoint(p), 1, 1, angle).Mean();

Result := Self.CheckLoot(p);
end;

function TRSLootHandler.CheckLoot(): Boolean; overload;
begin
if not Self.Loot.Hover(0) then
Expand Down
Loading

0 comments on commit 0cb4089

Please sign in to comment.