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

feat: Pathfinding v3 + Attack rework #3676

Merged
merged 61 commits into from
Dec 28, 2024
Merged

feat: Pathfinding v3 + Attack rework #3676

merged 61 commits into from
Dec 28, 2024

Conversation

Henrybk
Copy link
Contributor

@Henrybk Henrybk commented Oct 8, 2022

This is a rework of the current pathfinding algorithm based on my finding looking into the hercules emulator.

This PR actually has a lot of changes so I will be updating this comment little by little while rewiewing the code, for now this is only a draft.

Main changes:
1- Implements the Drunk plugin logic directly into the pathfinding algorithm, in the form of the config key route_randomFactor
(example: https://www.youtube.com/watch?v=sLRZoqQKMeQ)

2- Separates the avoidWalls logic from the weight logic, creating a new variable exclusive for custom weight maps, making, possible and easy the creation of plugins such as my NewAStarAvoid (included) (example: https://www.youtube.com/watch?v=Rov7DZ8wL9s&t=5s)

3- Implements a second pathfinding mode that simulates the client pathfinding by using the same heuristic as it to aquire the most precise position for a given character (calcPosFromPathfinding), this is used to calculate interception points in meetingPosition and alike.

4- Implements 2 new checks based on the client code to define one an actor can move to another spot (Field::canMove) or attack a target at another spot (Utils::canAttack), should never fail.

5- Actually uses client distance to calculate interactions, which is diferent from distance and blockDistance, removing the diference between melee and ranged.

6- Uses the emulator chase logic to approach targets, how this works:
When you send an attack packet to the emulator it checks if you are moving to the target, if you are then it stores the attack intention and checks in the emulator itself after every tick if the attack can be started and starts it when possible.
By using this information we can send after every move packet a new attack packet to start the chase logic and make the emulator attack for us.

Extra changes:
1- AI::findAction rework, added skip parameter.
2- Moved checkMonsterCleanness , provoke check and sitting->stand to before attack::main
3- Unified giveUp logic (except provoke and KS. Maybe TODO?)
4- Unified range and LOS checks in Utils::canAttack and removed them from AI::Attack
5- runFromTarget now loops distance from runFromTarget_dist up to clientSight instead of 0->14
6- Added attackBeyondMaxDistance_waitForAgressive for melee
7- Recalculate slave route whenever the character moves
8- Never move slave to the same cell as the character
9- Add setRoute2 to Wx to print both attack and move route
10- Optimization in meetingPosition to never check the same cell twice

TODO:

  • add checks for config key useweapon
  • add checks for use skill ( openkore is using autoattack everytime even when only skill is necessary)
  • Test route_randomFactor (drunk walk)
  • Test melee character without skills
  • Test melee character with skills
  • Test ranged character without skills and without runFromTarget
  • Test ranged character without skills and with runFromTarget
  • Test ranged character with skills and without runFromTarget
  • Test ranged character with skills and with runFromTarget
  • Test ranged character with ONLY skills and without runFromTarget
  • Test ranged character with ONLY skills and with runFromTarget
  • After above is tested, move new Atack.pm logic to SlaveAttack.pm

BUGS:

  1. Even though you can only attack from 1 diagonal cell away or 2 ortogonal cells away, and can't from 1 diagonal + 1 ortogonal, sometimes if the mob is moving when it is attacked the game/bot will glitch and they will attack each other from (1 diagonal + 1 ortogonal) like the example bellow, currently this bugs kore. We should add a way to check for these situations.
    This seems to be caused by rathena range increase when following and continous attacking
    4069ea746e82717bdc8aead0674c796f
  • Fixed

Future insights:

  • Attacking with aspd bound skills (double strafe, mamonite) is slower than normal attacking by ~20%, maybe that can be improved

Video showing it working:
Youtube

@Henrybk Henrybk marked this pull request as draft October 8, 2022 18:25
@Henrybk
Copy link
Contributor Author

Henrybk commented Oct 9, 2022

I am satisfied with the code as of now, so I am changing this PR from draft to Ready for review.
Needs testing.

@Henrybk Henrybk marked this pull request as ready for review October 9, 2022 13:24
@Henrybk Henrybk self-assigned this Oct 9, 2022
@hexhexD
Copy link
Member

hexhexD commented Jan 8, 2023

I have been using this patch for few days on my bot that's running 24/7. It's rock solid. 👍

);

my $sendAttack = 0;
if ($self->{actor}->isa('Actor::You') && $config{"attackSendAttackWithMove"}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A $config{"attackUseWeapon"} seems necessary here.

@LastRoze
Copy link
Contributor

I have been using this patch for few days on my bot that's running 24/7. It's rock solid. 👍

I use Henry's repo with his pathing branch and the XSTool.dll failed to load, can you share the working repo, so I can test this too, thanks.

@alisonrag alisonrag changed the title New Pathfinding v3 feat: Pathfinding v3 Feb 22, 2023
@Henrybk
Copy link
Contributor Author

Henrybk commented Dec 22, 2024

Will also make some optimizations by moving some heavily used functions to XS/C++, initially only checkLOS, maybe later also distances, canMove and canAttack

@Henrybk
Copy link
Contributor Author

Henrybk commented Dec 22, 2024

Tested homunculus basic attacking and char random_walking while the homunculus is killing mobs, working well enough, can be improved a bit in the future, added TODO messages for the future.

Still needs to be tested:

  • Homunculus skills
  • Homunculus runfromtarget
  • Homunculus dancing (melee and ranged)
  • Mercenary basic
  • Mercenary skills
  • Mercenary runfromtarget

@ya4ept ya4ept marked this pull request as draft December 22, 2024 22:55
@Henrybk
Copy link
Contributor Author

Henrybk commented Dec 24, 2024

Oops I did not meant to push the test branch merge of the fix slaves PR, guess I'll have to put this one in a pause until that one is merged.

@Henrybk
Copy link
Contributor Author

Henrybk commented Dec 24, 2024

All testing complete (albeit done with the slave PR merged here) should be good to merge after a bit of cleaning, commenting and tagging messages.

If anyone intends to test this now would be a good time.

@Henrybk
Copy link
Contributor Author

Henrybk commented Dec 27, 2024

Ready for testing, changing it from Draft to Pull Request

@Henrybk Henrybk marked this pull request as ready for review December 27, 2024 21:47
avoid stucks on attack defining max attack distance using information from server
@alisonrag
Copy link
Contributor

alisonrag commented Dec 28, 2024

  • after merge the following PR we must update the related calls from calcPosition to calcPositionFromPathfind

#3923

@Henrybk Henrybk merged commit 435ddcd into OpenKore:master Dec 28, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants