server icon indicating copy to clipboard operation
server copied to clipboard

[core] [lua] Add ranged attack and accuracy distance correction

Open TracentEden2 opened this issue 11 months ago • 7 comments

I affirm:

  • [x] I understand that if I do not agree to the following points by completing the checkboxes my PR will be ignored.
  • [x] I understand I should leave resolving conversations to the LandSandBoat team so that reviewers won't miss what was said.
  • [x] I have read and understood the Contributing Guide and the Code of Conduct.
  • [x] I have tested my code and the things my code has changed since the last commit in the PR and will test after any later commits.

What does this pull request do?

This PR adds distance correction to ranged attacks, I am posting here as draft for any initial feedback, as probably some potential improvements that could be made.

This is done through several different steps

  1. Add a new subskill to SUBSKILLTYPE to differentiate between short bows and long bows which have different distance corrections. The types after this change include SUBSKILL_XBOW_SHORTBOW, SUBSKILL_GUN, SUBSKILL_CNN, SUBSKILL_SHURIKEN, SUBSKILL_LONGBOW. Also update the item_weapon.sql file to indicate longbows with this new subskill.

  2. Add an exception to the equip code in charutils.cpp to account for the fact that now long bows will have a different subskill than arrows (which will still use SUBSKILL_XBOW_SHORTBOW). This prevents arrows from unequipping when equipping long bows and vice versa.

  3. Update the RACC and RATT functions of battleentity.cpp to take a distance parameter and a bool parameter for indicating if the RACC or RATT calculation should include a distance correction.

  4. Add a GetRangedDistanceCorrection function to battleutils.cpp that calculates a fraction (value between 0 and 1) to scale RACC and RATT for some given distance. The actual calculation is delegated to a function in a distance_correction.lua file that uses curves fitted to values from wiki. You can see the curve fitting vs. wiki values for the main weapon types in the graphs below (wiki values above and fittings below). This will make it easier to leverage when damage moves to Lua space. Also note that distance correction also applies to mobs, but not to automations (as of 2010), thus the correction is not used for automations (though the automation distance formula is kept in the Lua for completeness sake).

Also several other small improvements were made such as also having the SUBSKILLTYPE enum in lua space to avoid the use of several magic numbers. Changing getRACC in lua_baseentity.cpp to use the battleentity.cpp RACC function rather than recalculating RACC.

image

This is a PR from ASB coming upstream.

Steps to test these changes

TracentEden2 avatar Mar 02 '24 16:03 TracentEden2

Also, I didn't see if there was a setting or module to disable this, seems like an easy add that lots of people will want

zach2good avatar Mar 02 '24 16:03 zach2good

Also, I didn't see if there was a setting or module to disable this, seems like an easy add that lots of people will want

Added a setting, thanks!

TracentEden2 avatar Mar 02 '24 19:03 TracentEden2

Also, I didn't see if there was a setting or module to disable this, seems like an easy add that lots of people will want

definitely, a lot of folks including myself see the "sweet spot" things as a nerf and one of SE's poorer decisions. Since its an actual thing SE changed like move speed, I lean towards setting on this one.

TeoTwawki avatar Mar 02 '24 19:03 TeoTwawki

For this PR I am waiting on more retail testing from Kanryu as to specific types of weapons and sweet spots (might need to separate out also shortbows and xbows, and RACC and RATT)

TracentEden avatar Mar 05 '24 21:03 TracentEden