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 airshipSheetUrl from './assets/airships.svg?url';
|
||||||
import explosionSheetUrl from './assets/explosions.svg?url';
|
import explosionSheetUrl from './assets/explosions.svg?url';
|
||||||
import { airshipLog, registerDebugSnapshot } from './diagnostics.js';
|
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 WORLD_SIZE = 2400;
|
||||||
const PLAYER_MAX_SPEED = 180;
|
const PLAYER_MAX_SPEED = 180;
|
||||||
@ -571,30 +571,17 @@ class GameScene extends Phaser.Scene {
|
|||||||
gameState: this.gameState,
|
gameState: this.gameState,
|
||||||
};
|
};
|
||||||
|
|
||||||
const acceptedHits = [];
|
const result = reducePlayerVolleyHits({
|
||||||
const ignoredHits = [];
|
hull: this.playerHull,
|
||||||
|
hits,
|
||||||
|
seenVolleyIds: this.damagedPlayerVolleys,
|
||||||
|
maxHull: PLAYER_MAX_HULL,
|
||||||
|
fallbackDamage: PIRATE_SHOT_DAMAGE,
|
||||||
|
});
|
||||||
|
|
||||||
for (const hit of hits) {
|
this.damagedPlayerVolleys = result.seenVolleyIds;
|
||||||
const volleyId = hit.volleyId;
|
this.playerHull = result.hull;
|
||||||
if (volleyId != null && this.damagedPlayerVolleys.has(volleyId)) {
|
const { acceptedHits, ignoredHits, totalDamage, gameOver } = result;
|
||||||
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;
|
|
||||||
|
|
||||||
if (acceptedHits.length > 0) {
|
if (acceptedHits.length > 0) {
|
||||||
const impact = acceptedHits[0];
|
const impact = acceptedHits[0];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user