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

[Issue Report]: Possible collision issues with trap arrows #6669

Open
FitzRoyX opened this issue Sep 29, 2023 · 9 comments · May be fixed by #6327
Open

[Issue Report]: Possible collision issues with trap arrows #6669

FitzRoyX opened this issue Sep 29, 2023 · 9 comments · May be fixed by #6327
Labels
vanilla Bugs found also in the original Diablo 1.09b release

Comments

@FitzRoyX
Copy link

Operating System

Windows x64

DevilutionX version

1.5.1

Describe

A trap arrow from a chest never hits the player if the chest is opened up close. It also almost never hits the player from a distance with telekinesis, and whether it hits you or not seems to depend on the distance you are from the chest.

traparrowsg.mp4

To Reproduce

Load save from silent arrow issue
Open chest at various distances

Expected Behavior

No response

Additional context

No response

@StephenCWills
Copy link
Member

So what's going on there is, opening the chest calls SetRndSeed() to generate the items that will be dropped from the chest. ProcessElementalArrow() generates random numbers every frame to recompute damage for no apparent reason. So the distance from the chest determines how many random numbers get generated between SetRndSeed() and the collision check.

We have it on the to-do list already to fix RNG. But someone should probably fix elemental arrow damage from traps.

@StephenCWills StephenCWills added the vanilla Bugs found also in the original Diablo 1.09b release label Sep 29, 2023
@kphoenix137
Copy link
Collaborator

So what's going on there is, opening the chest calls SetRndSeed() to generate the items that will be dropped from the chest. ProcessElementalArrow() generates random numbers every frame to recompute damage for no apparent reason. So the distance from the chest determines how many random numbers get generated between SetRndSeed() and the collision check.

We have it on the to-do list already to fix RNG. But someone should probably fix elemental arrow damage from traps.

Could it have something to do with the distance penalty to chance to hit? His description of the distance being a determining factor of if it hits you or not sounds to me like it's an intended mechanic.
hper = 100 - (tac / 2) - (dist * 2);

He's using a plate armor, which I'm assuming is Naj's Light Plate. So I'd assume he has 50 AC at bare minimum. For the sake of trying to get accurate math, I'd assume has a 3 AC thinking cap and at least 30 dexterity. So let's say his final "armor" value is 59. the arrow was even missing him 1 square away. It's hard to tell exactly how many frames passed between the arrow coming out of the chest and it colliding. Can we say 5 frames? So that math would be: hper = 100 - (59/2) - (5*2) so hper = 100 - 29 - 10 with a final result of 61% chance to hit. Perhaps he had even more armor than I'm predicting. Considering now that missiles don't check for collision multiple times per tile, this reduces the chance to actually hit in DevilutionX compared to vanilla.

Let's say for when he's far away from the chest, it takes 1 second for the arrow to reach him: hper = 100 - (59/2) - (20*2) which is hper = 100 - 29 - 40. That's a 31% chance to hit. From what I'm observing in this video, nothing unexpected is happening.

@StephenCWills
Copy link
Member

StephenCWills commented Mar 8, 2024

Aren't you missing the point? Opening the chest resets RNG state, and the arrow burns random numbers every game tick. So regardless of all the math you've done, the result is entirely deterministic and dependent on the number of game ticks until the arrow reaches the player. Never mind that the arrow misses him 100% of the time at point blank in the video.

FYI, I tested his save file when he reported this on Discord.

EDIT: I think I was remembering a different save file.

@kphoenix137
Copy link
Collaborator

Aren't you missing the point? Opening the chest resets RNG state, and the arrow burns random numbers every game tick. So regardless of all the math you've done, the result is entirely deterministic and dependent on the number of game ticks until the arrow reaches the player. Never mind that the arrow misses him 100% of the time at point blank in the video.

FYI, I tested his save file when he reported this on Discord.

EDIT: I think I was remembering a different save file.

I guess I am missing the point because I don't understand

@StephenCWills
Copy link
Member

StephenCWills commented Mar 8, 2024

Hm, okay. Let's say the arrow moves at one tile per game tick and burns one random number per game tick. The following scenarios detail how RNG is used in each game tick after the chest is open.

If you are standing next to the chest:

  1. Burn first random number for damage, second random number is used for collision.

If you are standing one tile away:

  1. Burn first random number for damage.
  2. Burn second random number for damage, third random number is used for collision.

If you are standing two tiles away:

  1. Burn first random number for damage.
  2. Burn second random number for damage.
  3. Burn third random number for damage, fourth random number is used for collision.

And so on. Now, if the sequence of random numbers produce these outcomes...

  1. Miss
  2. Miss
  3. Hit
  4. Miss

You can see how the player would only be hit by the arrow if they stood one tile away from the chest, but not if they stood next to the chest or two tiles away. Because the object seed is used to overwrite RNG state when the chest is opened, it is impossible to change this outcome. The chest will always function this way no matter how you try to manipulate the RNG before opening the chest.

@AJenbo
Copy link
Member

AJenbo commented Mar 8, 2024

Is that a problem ?? Or is they issue that they all have seed zero and so behave the same ?

@StephenCWills
Copy link
Member

I do think it's a problem that seeding the RNG to generate items has unintended side effects. I also think it's a problem that trap arrows recompute damage every frame for no reason.

That the arrow consistently hits or misses based on distance isn't necessarily a problem, though. It just highlights the underlying issues in a noticeable and unintuitive way.

@AJenbo
Copy link
Member

AJenbo commented Mar 8, 2024

We have it on the to-do list already to fix RNG

So we can close this one right ?

@StephenCWills
Copy link
Member

It's not fixed yet, but we can close it I guess. I'll put out a fix similar to #6831 eventually regardless.

That said, this is still lurking in the codebase.

mind = GenerateRnd(10) + 1 + currlevel;
maxd = GenerateRnd(10) + 1 + currlevel * 2;

It appears to be fixed in #6373, but that would need to be rebased again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vanilla Bugs found also in the original Diablo 1.09b release
Projects
None yet
4 participants