Skip to content

Commit 3cc355f

Browse files
Move damage sequence check before OnEnemyHit emit and attack mods (#2551)
Co-authored-by: Charlie Zheng <charlie.x.3000@gmail.com>
1 parent d039211 commit 3cc355f

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

pkg/enemy/attack.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ var particleIDToElement = []attributes.Element{
2424
}
2525

2626
func (e *Enemy) HandleAttack(atk *info.AttackEvent) float64 {
27-
// at this point attack will land
28-
e.Core.Combat.Events.Emit(event.OnEnemyHit, e, atk)
27+
grpMult := 1.0
28+
if !atk.Info.SourceIsSim {
29+
grpMult = e.GroupTagDamageMult(atk.Info.ICDTag, atk.Info.ICDGroup, atk.Info.ActorIndex)
30+
}
31+
if grpMult > 0 {
32+
e.Core.Combat.Events.Emit(event.OnEnemyHit, e, atk)
33+
}
2934

3035
var amp string
3136
var cata string
@@ -52,7 +57,7 @@ func (e *Enemy) HandleAttack(atk *info.AttackEvent) float64 {
5257
evt.Write("pre_damage_mods", preDmgModDebug)
5358
}
5459

55-
dmg, crit = e.attack(atk, evt)
60+
dmg, crit = e.attack(atk, evt, grpMult)
5661

5762
// delay damage event to end of the frame
5863
e.Core.Combat.Tasks.Add(func() {
@@ -84,7 +89,7 @@ func (e *Enemy) HandleAttack(atk *info.AttackEvent) float64 {
8489
return dmg
8590
}
8691

87-
func (e *Enemy) attack(atk *info.AttackEvent, evt glog.Event) (float64, bool) {
92+
func (e *Enemy) attack(atk *info.AttackEvent, evt glog.Event, grpMult float64) (float64, bool) {
8893
// if target is frozen prior to attack landing, set impulse to 0
8994
// let the break freeze attack to trigger actual impulse
9095
if e.GetAuraDurability(info.ReactionModKeyFrozen) > info.ZeroDur {
@@ -135,7 +140,7 @@ func (e *Enemy) attack(atk *info.AttackEvent, evt glog.Event) (float64, bool) {
135140
}
136141
}
137142

138-
damage, isCrit := e.calc(atk, evt)
143+
damage, isCrit := e.calc(atk, evt, grpMult)
139144

140145
// check for hitlag
141146
if e.Core.Combat.EnableHitlag {

pkg/enemy/damage.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"github.com/genshinsim/gcsim/pkg/core/info"
88
)
99

10-
func (e *Enemy) calc(atk *info.AttackEvent, evt glog.Event) (float64, bool) {
10+
func (e *Enemy) calc(atk *info.AttackEvent, evt glog.Event, grpMult float64) (float64, bool) {
1111
var isCrit bool
1212

1313
if atk.Info.AttackTag == attacks.AttackTagDirectLunarCharged ||
1414
atk.Info.AttackTag == attacks.AttackTagDirectLunarBloom {
15-
e.calcDirectLunar(atk, evt)
15+
e.calcDirectLunar(atk, evt, grpMult)
1616
}
1717

1818
elePer := 0.0
@@ -112,11 +112,7 @@ func (e *Enemy) calc(atk *info.AttackEvent, evt glog.Event) (float64, bool) {
112112
}
113113

114114
// reduce damage by damage group
115-
x := 1.0
116-
if !atk.Info.SourceIsSim {
117-
x = e.GroupTagDamageMult(atk.Info.ICDTag, atk.Info.ICDGroup, atk.Info.ActorIndex)
118-
damage *= x
119-
}
115+
damage *= grpMult
120116

121117
elevation := atk.Info.Elevation
122118
damage *= 1 + elevation
@@ -128,7 +124,7 @@ func (e *Enemy) calc(atk *info.AttackEvent, evt glog.Event) (float64, bool) {
128124
atk.Info.ActorIndex,
129125
).
130126
Write("src_frame", atk.SourceFrame).
131-
Write("damage_grp_mult", x).
127+
Write("damage_grp_mult", grpMult).
132128
Write("damage", damage).
133129
Write("abil", atk.Info.Abil).
134130
Write("talent", atk.Info.Mult).
@@ -184,7 +180,7 @@ func (e *Enemy) calc(atk *info.AttackEvent, evt glog.Event) (float64, bool) {
184180
return damage, isCrit
185181
}
186182

187-
func (e *Enemy) calcDirectLunar(atk *info.AttackEvent, evt glog.Event) (float64, bool) {
183+
func (e *Enemy) calcDirectLunar(atk *info.AttackEvent, evt glog.Event, grpMult float64) (float64, bool) {
188184
var isCrit bool
189185

190186
// no DMG% for direct lunar damage
@@ -246,11 +242,7 @@ func (e *Enemy) calcDirectLunar(atk *info.AttackEvent, evt glog.Event) (float64,
246242
damage *= resmod
247243

248244
// reduce damage by damage group
249-
x := 1.0
250-
if !atk.Info.SourceIsSim {
251-
x = e.GroupTagDamageMult(atk.Info.ICDTag, atk.Info.ICDGroup, atk.Info.ActorIndex)
252-
damage *= x
253-
}
245+
damage *= grpMult
254246

255247
elevation := atk.Info.Elevation
256248
damage *= 1 + elevation
@@ -281,7 +273,7 @@ func (e *Enemy) calcDirectLunar(atk *info.AttackEvent, evt glog.Event) (float64,
281273
atk.Info.ActorIndex,
282274
).
283275
Write("src_frame", atk.SourceFrame).
284-
Write("damage_grp_mult", x).
276+
Write("damage_grp_mult", grpMult).
285277
Write("damage", damage).
286278
Write("abil", atk.Info.Abil).
287279
Write("talent", atk.Info.Mult).

0 commit comments

Comments
 (0)