Skip to content

Commit

Permalink
fix(skymp5-client): prevent double hits from magic projectiles in Hit…
Browse files Browse the repository at this point in the history
…Service (#2232)
  • Loading branch information
Pospelove authored Nov 26, 2024
1 parent f74b9d8 commit 3dcaa1b
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions skymp5-client/src/services/services/hitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,31 @@ export class HitService extends ClientListener {
return;
}

if (this.sp.Weapon.from(e.source) || this.sp.Spell.from(e.source) || this.sp.Scroll.from(e.source)) {
this.controller.emitter.emit("sendMessage", {
message: { t: MsgType.OnHit, data: this.getHitData(e) },
reliability: "reliable"
});
const isWeapon = this.sp.Weapon.from(e.source);
const isSpell = !isWeapon && this.sp.Spell.from(e.source);
const isScroll = !isWeapon && !isSpell && this.sp.Scroll.from(e.source);

if (!isWeapon && !isSpell && !isScroll) {
return;
}

// prevent double hit that happens for some reason with magic projectiles
if (isSpell || isScroll) {
const aggressorId = e.aggressor.getFormID();
const now = Date.now();

const lastHitTime = this.recentMagicHits.get(aggressorId);
if (lastHitTime && now - lastHitTime < 100) {
return;
}

this.recentMagicHits.set(aggressorId, now);
}

this.controller.emitter.emit("sendMessage", {
message: { t: MsgType.OnHit, data: this.getHitData(e) },
reliability: "reliable"
});
}

private getHitData(e: HitEvent): Hit {
Expand All @@ -60,4 +79,6 @@ export class HitService extends ClientListener {
}
return hitData;
}

private recentMagicHits: Map<number, number> = new Map();
}

0 comments on commit 3dcaa1b

Please sign in to comment.