genshinsim / gcsim

monte carlo combat simulation for genshin impact
MIT License
282 stars 91 forks source link

icd bug in implementation of the artifact "Echoes of an Offering" #2165

Closed yihuajack closed 4 months ago

yihuajack commented 5 months ago

The description of the 4-piece bonus of the artifact "Echoes of an Offering" is:

When Normal Attacks hit opponents, there is a 36% chance that it will trigger Valley Rite, which will increase Normal Attack DMG by 70% of ATK. This effect will be dispelled 0.05s after a Normal Attack deals DMG. If a Normal Attack fails to trigger Valley Rite, the odds of it triggering the next time will increase by 20%. This trigger can occur once every 0.2s.

In a test of Yoimiya with 4 pieces of this artifact:

91ce33ec3517679047bcc3e6c94a941e

The first damage and the second damage of the first normal attack of Yoimiya occur at 10.55s (frame 633) and 10.70s (frame 642) respectively; the time interval is 0.15s (9 frames), less than 0.2s; however, gcsim raises the artifact event at both the two frames, which is wrong. The information on the two artifact events is as follows:

{
  "char_index": 0,
  "ended": 633,
  "event": "artifact",
  "frame": 633,
  "logs": {
    "probabability_now": 0.56
  },
  "msg": "echoes 4pc failed to proc due to chance"
}
{
  "char_index": 0,
  "ended": 642,
  "event": "artifact",
  "frame": 642,
  "logs": {
    "dmg_added": 1905.0087396599981,
    "buff_expiry": 645,
    "icd_up": 654
  },
  "msg": "echoes 4pc adding dmg"
}

The buff_expiry and icd_up are correct for the second one (4pc succeeds, 0.05s/3 frames expiring, 0.2s/12 frames cd), but the first one (4pc fails) just does nothing. For reference, the script is saved here: https://gcsim.app/sh/hRN6wBBkRTDT.

The issue may correspond to code in gcsim/internal/artifacts/echoes/echoes.go:

s.icd = c.F + 12

The icd check is only done when a normal attack made by the equipped character is at the time >= procExpireF and icd, and does not fail to get a bonus due to the probability check. The expected behavior is that even if the attack failed to get a bonus due to the probability check, the icd check should still be done.

srliao commented 4 months ago

I'm not entirely sure if failing the probability test should trigger the ICD. Would need to investigate some more. Would you be any chance of any sort of test/proof?

yihuajack commented 4 months ago

There is a reference research by homdgcat: https://bbs.nga.cn/read.php?tid=34695286. According to this article, the actual effect of the artifact is slightly different than the official description of the artifact: there exists a possibility that two attacks in 0.2s are both gained by the artifact in certain circumstances. If the article is true, the effects of this artifact could be much more complex than the effects of the current implementation of the artifact.

A brief translation is provided here: Opening (usually when the character enters the game)

  1. According to 0.36 probability random
    • if successful, apply < damage module >, set the number of layers to 0
    • if failed, set the number of layers to 0
  2. Apply the management module, and the management module will always exist

Management Module

  1. If a normal attack hits the monster, then < decision module > is applied.

Decision Module This module will not be applied again within 0.2 seconds after being applied.

  1. According to the probability of random 0.36 + number of layers * 0.2
    • If successful, the < damage module > will be applied after 1 frame, the number of layers will be set to 0
    • If it fails, then layer +1

Damage Module During the existence of this module, all normal attack damage is increased. After applying this module, the management module will stop working immediately, if the management module is applied later, it will also stop working. If the normal attack deals damage to the monster, then do the following two operations simultaneously:

  1. After 0.05 seconds, remove this module
  2. After 0.2 seconds, according to the probability of 0.36 random
    • if successful, the < damage module > is applied, and the number of layers is set to 0
    • if it fails, the number of layers is set to 1, and the management module immediately retakes the effect
yihuajack commented 4 months ago

Whether the damage of a normal attack is increased has been decided before. Suppose the damage module is applied, normal attack I happens at t=0s, normal attack II happens at t=0.1s, normal attack III happens at t=0.25s. Then, normal attack I will be increased, normal attack II will not be increased, normal attack III has a probability of 0.36 to be gained. During this procedure, normal attack I triggers Valley Rite, and normal attack II does not make a decision of Valley Rite because the time interval is less than 0.2s. The damage of normal attack III might be increased because the damage module automatically starts a decision of Valley Rite at t=0.2s.

yihuajack commented 4 months ago

Though the internal might be different, I think it is equivalent to the fixed implementation, which decides the buff at the time of the normal attack. The current fix allows the circumstances described above and can achieve the expected behavior.