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

Hold mouse button to keep attacking (Diablo 2-style) #2349

Merged

Conversation

FluffyQuack
Copy link
Contributor

@FluffyQuack FluffyQuack commented Jul 10, 2021

Here's my unfinished implementation of holding down a mouse button to keep attacking or casting spells.

Notes:

  • All of the //Fluffy comments are only there so I can keep track of what code snippets I've changed (I've got the memory of a forgetful goldfish).
  • I tried to implement this the same way as Diablo 2. The game remembers what you have targeted when you start holding down a mouse button, so the selection will stick even if your target moves or if you move the mouse around.
  • The above feature has resulted in a bunch of bugs for selection. Ie, it should de-select a thing if that thing no longer exists.
  • I haven't tested this with gamepad controls. I haven't even looked at the gamepad controls code.
  • I arbitrarily set the auto-clicking to happen at 200ms intervals. Wasn't sure how that's best configured.
  • The player will typically do an extra attack as an enemy dies (the same can happen if you mash click, so I think this is more related to how the game queues input actions than this PR).

@AJenbo
Copy link
Member

AJenbo commented Jul 11, 2021

* All of the `//Fluffy` comments are only there so I can keep track of what code snippets I've changed (I've got the memory of a forgetful goldfish).

Can't say my memory regarding lines I have changed is much better, but I use Git to track what I have changed :)

@AJenbo
Copy link
Member

AJenbo commented Jul 11, 2021

* I arbitrarily set the auto-clicking to happen at 200ms intervals. Wasn't sure how that's best configured.

Check destAction each tick, if it's empty then fire the event again.

@AJenbo
Copy link
Member

AJenbo commented Jul 11, 2021

The player will typically do an extra attack as an enemy dies (the same can happen if you mash click, so I think this is more related to how the game queues input actions than this PR).

See #962

@FluffyQuack
Copy link
Contributor Author

Can't say my memory regarding lines I have changed is much better, but I use Git to track what I have changed :)

I like having the information right in front of me in the code. It's also useful in case I need to do big merges. I'll remove them when this feature is done.

@FluffyQuack
Copy link
Contributor Author

FluffyQuack commented Jul 11, 2021

Check destAction each tick, if it's empty then fire the event again.

Maybe I could use that for when a specific enemy is targeted, but then use the timer for shift attacks (using only destAction check for shift attacks means any shift attack becomes 2 attacks: one instant and one queued). Edit: Actually, it should always be a combination of both, otherwise clicks with and without shift becomes double attacks.

@AJenbo
Copy link
Member

AJenbo commented Jul 11, 2021

Can't say my memory regarding lines I have changed is much better, but I use Git to track what I have changed :)

I like having the information right in front of me in the code. It's also useful in case I need to do big merges. I'll remove them when this feature is done.

MSVC lets you have the names in the left margin if that is any help:
image

@AJenbo
Copy link
Member

AJenbo commented Jul 11, 2021

Check destAction each tick, if it's empty then fire the event again.

Maybe I could use that for when a specific enemy is targeted, but then use the timer for shift attacks (using only destAction check for shift attacks means any shift attack becomes 2 attacks: one instant and one queued). Edit: Actually, it should always be a combination of both, otherwise clicks with and without shift becomes double attacks.

ok, maybe add pmode to the mix :)

@FluffyQuack
Copy link
Contributor Author

FluffyQuack commented Jul 11, 2021

Aside from tweaking some comments, this is close to being done I think.

I can think of one known issue right now:

  • Some spells make no sense to spam and might result in the player accidentally casting the spell multiple times. For instance, town portal, disarm, or repair. Not sure how to fix that besides hardcoding a list of spells that can't be spammed by holding right-click.

@julealgon
Copy link
Contributor

I hadn't checked this change but I'm surprised to hear talks of a "timer". Is this just a slightly different way to "simulate clicks in time intervals"? Why are we using any sort of timer here at all?

@FluffyQuack
Copy link
Contributor Author

I hadn't checked this change but I'm surprised to hear talks of a "timer". Is this just a slightly different way to "simulate clicks in time intervals"? Why are we using any sort of timer here at all?

It's used to prevent a single click from becoming multiple attacks. Otherwise, this ends up happening: you intend to press the mouse button once, it ends up being registered as pressed down for 2 gameplay ticks, thus you do an attack instantly and queue up another one.

@julealgon
Copy link
Contributor

it ends up being registered as pressed down for 2 gameplay ticks

This is the problem though, it should not. We need to add support at the engine level for detection of "holds vs presses" and treat them differently.

I think any other solution will end up resulting in hacks somewhere.

@FluffyQuack
Copy link
Contributor Author

This is the problem though, it should not. We need to add support at the engine level for detection of "holds vs presses" and treat them differently.

I think any other solution will end up resulting in hacks somewhere.

It's just a couple of lines of code. It's easy to change if we ever have a different way of detecting mouse click holds.

Copy link
Contributor

@julealgon julealgon left a comment

Choose a reason for hiding this comment

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

Not a fan of how invasive this is, the fact that hold detection is intertwinned with other logic, all the hardcodes, and the fact that we are not treating "continuous attack" as a separate action.

Won't block the change but I don't think this is the way to go still.

@AJenbo
Copy link
Member

AJenbo commented Jul 12, 2021

It's not clear to me if this is a general issue with the latest master or specifically with the hold mouse feature, but putting it here for now: #2280 (reply in thread)

@FluffyQuack FluffyQuack force-pushed the PR-202107MasterBranch-HoldClickToDoStuff branch from 1e5dcfc to 1b488e7 Compare July 13, 2021 21:38
@AJenbo
Copy link
Member

AJenbo commented Jul 16, 2021

Looks reasonable to me, @FluffyQuack would you strip the name comments from this :)

@AJenbo AJenbo enabled auto-merge (squash) July 16, 2021 13:27
@FluffyQuack
Copy link
Contributor Author

I changed the comments and I renamed the enum to be similar to how I think new enums are created in the project.

In the long run, I think the track_process() and track_repeat_walk() functions should be simplified. I'd personally make it function similar to how I did the "hold click to attack" as I find it more straightforward.

@AJenbo
Copy link
Member

AJenbo commented Jul 16, 2021

In the long run, I think the track_process() and track_repeat_walk() functions should be simplified.

yes, and not time based.

@AJenbo AJenbo merged commit ba60907 into diasurgical:master Jul 16, 2021
@FluffyQuack FluffyQuack deleted the PR-202107MasterBranch-HoldClickToDoStuff branch July 16, 2021 14:35
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.

3 participants