master
Denis Ranneft 1 month ago
parent d34d428d8a
commit eec798e57b

@ -1814,21 +1814,21 @@ func (e *Engine) handleEnemyDeath(cs *model.CombatState, now time.Time) {
// Rewards (XP, gold, loot, level-ups) are handled by the onEnemyDeath callback // Rewards (XP, gold, loot, level-ups) are handled by the onEnemyDeath callback
// via processVictoryRewards -- the single source of truth. // via processVictoryRewards -- the single source of truth.
var victoryDrops []model.LootDrop var victoryDrops []model.LootDrop
if e.onEnemyDeath != nil && hero != nil { if e.onEnemyDeath != nil {
victoryDrops = e.onEnemyDeath(hero, enemy, now) victoryDrops = e.onEnemyDeath(hero, enemy, now)
} }
if hero != nil {
dctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) dctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
e.applyOfflineDigest(dctx, cs.HeroID, hero, now, storage.OfflineDigestDelta{ e.applyOfflineDigest(dctx, cs.HeroID, hero, now, storage.OfflineDigestDelta{
MonstersKilled: 1, MonstersKilled: 1,
XPGained: enemy.XPReward, XPGained: enemy.XPReward,
GoldGained: model.SumGoldFromLootDrops(victoryDrops), GoldGained: model.SumGoldFromLootDrops(victoryDrops),
LevelsGained: hero.Level - oldLevel, LevelsGained: hero.Level - oldLevel,
LootAppend: NonGoldLootForDigest(victoryDrops), LootAppend: NonGoldLootForDigest(victoryDrops),
}) })
cancel() cancel()
}
e.emitEvent(model.CombatEvent{ e.emitEvent(model.CombatEvent{
Type: "combat_end", Type: "combat_end",
@ -1856,7 +1856,7 @@ func (e *Engine) handleEnemyDeath(cs *model.CombatState, now time.Time) {
// Persist progression (XP, gold, level/stats after level-up, inventory, world state) // Persist progression (XP, gold, level/stats after level-up, inventory, world state)
// so a disconnect or crash does not roll back combat rewards. // so a disconnect or crash does not roll back combat rewards.
if e.heroStore != nil && hero != nil { if e.heroStore != nil {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
err := e.heroStore.Save(ctx, hero) err := e.heroStore.Save(ctx, hero)
cancel() cancel()

Loading…
Cancel
Save