Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item Pickup Improvements #666

Merged
merged 22 commits into from
Feb 21, 2025
Merged

Conversation

braccali1
Copy link
Contributor

@braccali1 braccali1 commented Feb 6, 2025

Problem: Character was moving/casting during item pickup routine which moves the screen. The coordinates of an item move when the screen moves. This was causing attempts of PickupItem() to fail.
Solution: Added a check if player is casting or moving in PickupItem() function in pickup_item.go action step with a small sleep to minimize cpu usage. Also added this error to ItemPickup() function in item_pickup.go action to not add to the 3 attempts, similar to error ErrMonsterAroundItem and ErrItemTooFar but without debug logging because this check occurs frequently.

Problem: Refreshing game data for hover status was not returning fast enough, so extra iterations of PickupItem() were occurring when the item was actually hovered.
Solution: Add small delay after mouse move and refreshgamedata() that is right before checking hover status in PickupItem() function in pickup_item.go action step.

Problem: Spiraling too much and timeouts too long. This causes unnecessary delay between retries. Testing showed there is a very low percentage of items successfully being picked up after 6-7 spiral attempts with the above changes, but there was still some success at 8-9 attempts.
Solution: Set max spiraling attempts to 10 (9 in pickup_item.go since it starts at 0). Set the pickupTimeout to not multiple by 2 in the timeout condition check.

Testing showed no blacklisting of items with over 1000 items to pickup, > 90% success on 1st pickup attempt, and an average of 2 spirals per successful pickup attempt. Retries occur much quicker since we are spiraling much less.

EDIT:
Added 2 more retries to the main ItemPickup loop. One following the 2nd and 3rd retry character movement and one that follows the no LOS routine(move beyondposition).

EDIT 2:
Removed item too far from skipping adding to the attempts. There was a loop that could occur if an item was > 7 away but there may have been a door or stash or object in the way. The additional attempts will move more than the 1st or 2nd attempt, and the final attempt executes a movebeyondposition that should resolve the issue.

Set hard values for sleep.
update comment
reduce monstercheckinterval
Remove tab
Had a couple of blacklists. Since we are spiraling less, we can retry more with extra character movement.
Bumped up retries to 5
Added missing ctx.PauseIfNotPriority() to item_pickup.go
@davidfvsilva
Copy link
Contributor

davidfvsilva commented Feb 8, 2025

Tested this PR, and it feels much slower and adds alot of delay to runs. Also, there seems to be a large loop back to go get items that weren't picked up when clearing areas. It seems to have more trouble than usual picking things up (I didn't notice any issues with items being skipped before. The only "problem" I had was not picking up fast enough, but it still felt quick. I wouldn't want to slow it down). I'll give it another go some other time because I could be wrong, and it could have been a bnet issue when I tested. I tried this PR in p8 terror zones.

Removed ErrItemTooFar from not counting toward retries. There could be a loop where the item is too far away and the logic does not move enough or try other moving techniques to get closer. This allows other pickup attempts using moving logic and a movebeyond when the item is more then 7 away.
@braccali1
Copy link
Contributor Author

@davidfvsilva This PR has been a lot faster than the existing pickup routines in all of my testing. Are you sure there are not any other modifications in your local repo?

Added logic to attempt random movement 5 times if item is too far. Pathing to an item that is too far away could be hindered by an object. We don't want to loop forever. randommovement allows for better chances of an attempt to succeed.
@davidfvsilva
Copy link
Contributor

@davidfvsilva This PR has been a lot faster than the existing pickup routines in all of my testing. Are you sure there are not any other modifications in your local repo?

nothing for item pickup on my end, I'll test it again tomorrow on different runs. There just seemed to be some delay between items after the first item pickup when multiples were dropping.

@davidfvsilva
Copy link
Contributor

Alright, I'm testing this morning and it's looking ok for one item at a time, but there seems to be a blockage when many things drop at the same time. I'll keep testing to see if I can get more precise info.

@davidfvsilva
Copy link
Contributor

davidfvsilva commented Feb 9, 2025

For context, this is a drop from a telestomping sequence where the bot is sitting on the target, after Diablo kill, here are some logs:
time=13:52:11 level=DEBUG msg="Item Detected: VampirefangBelt [4] at X:7795 Y:5298"
time=13:52:12 level=DEBUG msg="Pickup attempt 1 failed: item is too far away (7): Vampirefang Belt"
time=13:52:13 level=DEBUG msg="Picking up: Vampirefang Belt [Magic]"
time=13:52:14 level=DEBUG msg="Pickup attempt 2 failed: failed to pick up Vampirefang Belt after 10 attempts"
time=13:52:15 level=DEBUG msg="Picking up: Vampirefang Belt [Magic]"
time=13:52:15 level=INFO msg="Picked up: Vampirefang Belt [Magic] | Item Pickup Attempt:3 | Spiral Attempt:5"
time=13:52:15 level=DEBUG msg="Item Detected: GreaterHealingPotion [2] at X:7844 Y:5285"
time=13:52:17 level=DEBUG msg="Item Detected: GreaterHealingPotion [2] at X:7844 Y:5285"
time=13:52:17 level=DEBUG msg="Picking up: Greater Healing Potion [Normal]"
time=13:52:18 level=INFO msg="Picked up: Greater Healing Potion [Normal] | Item Pickup Attempt:1 | Spiral Attempt:1"
time=13:52:18 level=DEBUG msg="Picking up: Greater Healing Potion [Normal]"
time=13:52:18 level=INFO msg="Picked up: Greater Healing Potion [Normal] | Item Pickup Attempt:1 | Spiral Attempt:0"

I'll do some more testing later, because fast pickup is totally worth it.

@davidfvsilva
Copy link
Contributor

Ok, so its actually very quick most of the time and quite reliable. The issue when theres a bunch of items falling on the floor at the same time might not be related to these changes. If anyone else can test, that would be awesome.

@davidfvsilva
Copy link
Contributor

The performance upgrade PR seems to greatly improve this issue. Looking good!

@braccali1
Copy link
Contributor Author

@davidfvsilva I found something but it does not fully resolve all pickup attempts yet, but it does make hover checking much much faster and lets spiral attempts also occur faster. refreshgamedata takes a very long time to return ishovered on items, and other objects as well. Calling context.GameReader.GameReader.GetData().HoverData.UnitID against the unitid of the item we want to pickup checks hover without waiting for a refresh of all gamedata to return. You will notice that no item pickups occur on spiral attempt 0 with the current version of this PR. I will work on testing/data gathering of different retry attempt logic and add the new hover logic soon.

Changed the way item pickup checks for hover status. Previously refreshgamedata was used to add hover status to items. Now checking hover status directly and checking if hovered unitid matches the item unitid we want to pickup. This greatly increases the speed of item pickup actions, thus an increase to spiral attempts can be added without the extra overhead of constantly refreshing all game data and waiting for it to return. Removed an unused spiral delay.
@tylerqr
Copy link

tylerqr commented Feb 14, 2025

Tested this for around 5-6 hours today. in that time, with these changes, it blacklisted 15 items. See logs attached. For comparison, when I run on main branch w/out these changes, the bot has only blacklisted 1-3 potions after running all night long.

I did notice these changes make the bot pick up faster generally, but it does seem to blacklist significantly more often. At least in my testing.
Supervisor-log-Frizz-2025-02-13-12-07-46.txt

@braccali1
Copy link
Contributor Author

@tylerqr I also got a few black lists but not nearly as many as you. I think it comes down to removing the spiral delay. I highly suggest you empty the gold or gamble on your character. The bot constantly finding gold, attempting to pickup gold, and blacklisting it is probably slowing it down considerably and is also filling the debug log with junk. I am re adding the spiral delay now.

Added the spiral delay back to assist with items getting blacklisted.
@davidfvsilva
Copy link
Contributor

Tested with latest changes, its working well.

@artosimonyan
Copy link
Collaborator

artosimonyan commented Feb 15, 2025

Looking good so far, I've tested it for 3 hours or so and no blacklists. Pickup is quite fast as well. Will test overnight to make sure everything's fine.

When testing, please make sure to test the following areas:

  • Cows
  • Chaos Sanctuary
  • Countess
  • Travincal

That should give you a solid testing scenario of all areas that might be problematic. @braccali1, while still working on it and not ready for merge, please mark the PR as draft (work in progress). Mark it back as ready for review when it's ready for merge.

Feel free to ping me in discord or tag me here when it's ready.

@braccali1 braccali1 marked this pull request as draft February 15, 2025 13:48
Added a blacklist item event. Added the event to item_pickup.go to screenshot with showitems on and area name.
@braccali1
Copy link
Contributor Author

@artosimonyan Converted to draft. Added an item blacklist event. Added the blacklist event to item_pickup.go to screenshot with showitems on and list area.

Testing those areas. Got a blacklist in trav without a line of site or wall problem. I will attempt more work around lots of items in small areas like trav.

forgot to add event import to item_pickup.go
@braccali1
Copy link
Contributor Author

I graphed spiral attempts to visualize the effects of adding more attempts.

25 spirals:
Untitled

45 spirals:
Untitled-1

Since we get around 95%+ pickup success on the first 3 attempts, changing the amount of spiral attempts on the 4th and 5th retry should give us better odds while not slowing down the majority of pickup attempts. Also changing the base coordinate 1 or 2 seems to help on 3+ pick up attempt without hitting max spiral attempts. Adding these changes for more testing.

@davidfvsilva
Copy link
Contributor

davidfvsilva commented Feb 18, 2025

Item Um Rune blacklisted ;_;
image

Most blacklists Ive seen are due to it being on the other side of a wall or structure. Maybe it can do a random movement on a few attempts in order to reposition before the grab?

By the way, it really doesn't blacklist often, it's quite rare.

@braccali1
Copy link
Contributor Author

braccali1 commented Feb 19, 2025

@davidfvsilva
Yeah doors and objects are still an issue. There is a moveto on each attempt > 1 and a movebeyond on the 5th retry.

@artosimonyan
Copy link
Collaborator

@braccali1, got reports that there are issues with walking characters. Please test it on a non-teleporting char.

@braccali1
Copy link
Contributor Author

Marking "Ready for review".

Item pickup will never be perfect with current mouse hovering for pickup. Hovering can easily be blocked by objects and other items like chests, shrines, gold, etc.. Not matter how much the character moves or how much spiraling is attempted, there will still be pickup blacklists. In my testing, without an overloaded cpu, this PR works very well.

@braccali1 braccali1 marked this pull request as ready for review February 20, 2025 18:16
@braccali1
Copy link
Contributor Author

@braccali1, got reports that there are issues with walking characters. Please test it on a non-teleporting char.

I did testing with a walking char in trav and it appears to work the same as a teleporting character. The check I added should work with casting running or walking and not add to pickup attempts. Not sure of the exact specifics of the report when walking/running, may have been a fluke or accidentally pressing a modifier key.

@artosimonyan artosimonyan merged commit 8ff9266 into hectorgimenez:main Feb 21, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants