Use tested per-volley player damage logic
This commit is contained in:
parent
2dc9bba7f9
commit
0ca8ffdd90
@ -3,7 +3,7 @@ import './style.css';
|
||||
import airshipSheetUrl from './assets/airships.svg?url';
|
||||
import explosionSheetUrl from './assets/explosions.svg?url';
|
||||
import { airshipLog, registerDebugSnapshot } from './diagnostics.js';
|
||||
import { normalizePlayerDamage, processQueuedPlayerHits } from './game-logic.js';
|
||||
import { normalizePlayerDamage, reducePlayerVolleyHits } from './game-logic.js';
|
||||
|
||||
const WORLD_SIZE = 2400;
|
||||
const PLAYER_MAX_SPEED = 180;
|
||||
@ -571,30 +571,17 @@ class GameScene extends Phaser.Scene {
|
||||
gameState: this.gameState,
|
||||
};
|
||||
|
||||
const acceptedHits = [];
|
||||
const ignoredHits = [];
|
||||
const result = reducePlayerVolleyHits({
|
||||
hull: this.playerHull,
|
||||
hits,
|
||||
seenVolleyIds: this.damagedPlayerVolleys,
|
||||
maxHull: PLAYER_MAX_HULL,
|
||||
fallbackDamage: PIRATE_SHOT_DAMAGE,
|
||||
});
|
||||
|
||||
for (const hit of hits) {
|
||||
const volleyId = hit.volleyId;
|
||||
if (volleyId != null && this.damagedPlayerVolleys.has(volleyId)) {
|
||||
ignoredHits.push(hit);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (volleyId != null) {
|
||||
this.damagedPlayerVolleys.add(volleyId);
|
||||
if (this.damagedPlayerVolleys.size > 128) {
|
||||
const oldestVolleyId = this.damagedPlayerVolleys.values().next().value;
|
||||
this.damagedPlayerVolleys.delete(oldestVolleyId);
|
||||
}
|
||||
}
|
||||
|
||||
acceptedHits.push(hit);
|
||||
}
|
||||
|
||||
const totalDamage = acceptedHits.reduce((sum, hit) => sum + normalizePlayerDamage(hit.damage, PIRATE_SHOT_DAMAGE), 0);
|
||||
this.playerHull = Math.max(0, this.playerHull - totalDamage);
|
||||
const gameOver = this.playerHull <= 0;
|
||||
this.damagedPlayerVolleys = result.seenVolleyIds;
|
||||
this.playerHull = result.hull;
|
||||
const { acceptedHits, ignoredHits, totalDamage, gameOver } = result;
|
||||
|
||||
if (acceptedHits.length > 0) {
|
||||
const impact = acceptedHits[0];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user