|
|
|
@ -1582,6 +1582,7 @@ func (e *Engine) processCombatTickLocked(now time.Time) {
|
|
|
|
if hm, ok := e.movements[heroID]; ok {
|
|
|
|
if hm, ok := e.movements[heroID]; ok {
|
|
|
|
hm.Die()
|
|
|
|
hm.Die()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e.persistHeroDeathLocked(heroID, cs.Hero)
|
|
|
|
dctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
dctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
e.applyOfflineDigest(dctx, heroID, cs.Hero, now, storage.OfflineDigestDelta{Deaths: 1})
|
|
|
|
e.applyOfflineDigest(dctx, heroID, cs.Hero, now, storage.OfflineDigestDelta{Deaths: 1})
|
|
|
|
cancel()
|
|
|
|
cancel()
|
|
|
|
@ -1614,6 +1615,21 @@ func (e *Engine) processAttackEvent(evt *model.AttackEvent, cs *model.CombatStat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// persistHeroDeathLocked writes the dead hero snapshot immediately so DB state
|
|
|
|
|
|
|
|
// never lags behind the live in-memory death state.
|
|
|
|
|
|
|
|
// Caller must hold e.mu.
|
|
|
|
|
|
|
|
func (e *Engine) persistHeroDeathLocked(heroID int64, hero *model.Hero) {
|
|
|
|
|
|
|
|
if e.heroStore == nil || hero == nil {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
|
|
|
|
err := e.heroStore.Save(ctx, hero)
|
|
|
|
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
if err != nil && e.logger != nil {
|
|
|
|
|
|
|
|
e.logger.Error("persist hero after death", "hero_id", heroID, "error", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// sendDebuffAppliedForString pushes debuff_applied when a debuff proc string is non-empty.
|
|
|
|
// sendDebuffAppliedForString pushes debuff_applied when a debuff proc string is non-empty.
|
|
|
|
func (e *Engine) sendDebuffAppliedForString(heroID int64, debuffTypeStr string, now time.Time) {
|
|
|
|
func (e *Engine) sendDebuffAppliedForString(heroID int64, debuffTypeStr string, now time.Time) {
|
|
|
|
if e.sender == nil || debuffTypeStr == "" {
|
|
|
|
if e.sender == nil || debuffTypeStr == "" {
|
|
|
|
@ -1748,6 +1764,7 @@ func (e *Engine) processEnemyAttack(cs *model.CombatState, now time.Time) {
|
|
|
|
if hm, ok := e.movements[cs.HeroID]; ok {
|
|
|
|
if hm, ok := e.movements[cs.HeroID]; ok {
|
|
|
|
hm.Die()
|
|
|
|
hm.Die()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e.persistHeroDeathLocked(cs.HeroID, cs.Hero)
|
|
|
|
dctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
dctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
e.applyOfflineDigest(dctx, cs.HeroID, cs.Hero, now, storage.OfflineDigestDelta{Deaths: 1})
|
|
|
|
e.applyOfflineDigest(dctx, cs.HeroID, cs.Hero, now, storage.OfflineDigestDelta{Deaths: 1})
|
|
|
|
cancel()
|
|
|
|
cancel()
|
|
|
|
|