Apply player damage once per projectile
This commit is contained in:
parent
1a99e1c362
commit
564c6a82b5
@ -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, reducePlayerVolleyHits } from './game-logic.js';
|
||||
import { normalizePlayerDamage, reducePlayerProjectileHits } from './game-logic.js';
|
||||
|
||||
const WORLD_SIZE = 2400;
|
||||
const PLAYER_MAX_SPEED = 180;
|
||||
@ -18,7 +18,6 @@ const SHOT_LIFETIME = 900;
|
||||
const PLAYER_MAX_HULL = 100;
|
||||
const PIRATE_MAX_HULL = 120;
|
||||
const PIRATE_SHOT_DAMAGE = 6;
|
||||
const PLAYER_HIT_COOLDOWN_MS = 300;
|
||||
const MAX_PIRATES = 6;
|
||||
const AUTO_RESET_MS = 2200;
|
||||
|
||||
@ -44,10 +43,7 @@ class GameScene extends Phaser.Scene {
|
||||
this.playerHull = PLAYER_MAX_HULL;
|
||||
this.gameState = 'playing';
|
||||
this.lastPlayerShot = 0;
|
||||
this.lastPlayerHitAt = -Infinity;
|
||||
this.pendingPlayerHits = [];
|
||||
this.nextPirateVolleyId = 1;
|
||||
this.damagedPlayerVolleys = new Set();
|
||||
this.lastDiagnosticsAt = -Infinity;
|
||||
this.wave = 1;
|
||||
this.defeated = 0;
|
||||
@ -461,7 +457,6 @@ class GameScene extends Phaser.Scene {
|
||||
fireBroadside(ship, side, group, texture, damage, velocityScale) {
|
||||
if (!ship?.body) return;
|
||||
const actor = group === this.pirateShots ? 'pirate' : 'player';
|
||||
const volleyId = actor === 'pirate' ? this.nextPirateVolleyId++ : null;
|
||||
const base = headingRad(ship) + side * Math.PI / 2;
|
||||
|
||||
airshipLog('combat:broadside-fired', {
|
||||
@ -471,7 +466,6 @@ class GameScene extends Phaser.Scene {
|
||||
x: Math.round(ship.x),
|
||||
y: Math.round(ship.y),
|
||||
angle: Math.round(ship.angle),
|
||||
volleyId,
|
||||
}, 'debug');
|
||||
const offsets = [-7, 0, 7];
|
||||
|
||||
@ -484,7 +478,6 @@ class GameScene extends Phaser.Scene {
|
||||
shot.body.setAllowGravity(false);
|
||||
shot.setData('bornAt', this.time.now);
|
||||
shot.setData('damage', damage);
|
||||
if (volleyId !== null) shot.setData('volleyId', volleyId);
|
||||
shot.setVelocity(
|
||||
Math.cos(angle) * SHOT_SPEED * velocityScale + ship.body.velocity.x * 0.25,
|
||||
Math.sin(angle) * SHOT_SPEED * velocityScale + ship.body.velocity.y * 0.25,
|
||||
@ -541,14 +534,12 @@ class GameScene extends Phaser.Scene {
|
||||
this.pendingPlayerHits.push({
|
||||
shot,
|
||||
damage,
|
||||
volleyId: shot.getData('volleyId'),
|
||||
x: shot.x,
|
||||
y: shot.y,
|
||||
});
|
||||
|
||||
airshipLog('combat:player-hit-queued', {
|
||||
damage,
|
||||
volleyId: shot.getData('volleyId'),
|
||||
pendingHits: this.pendingPlayerHits.length,
|
||||
shotAgeMs: this.time.now - (shot.getData('bornAt') || this.time.now),
|
||||
hull: this.playerHull,
|
||||
@ -571,28 +562,25 @@ class GameScene extends Phaser.Scene {
|
||||
gameState: this.gameState,
|
||||
};
|
||||
|
||||
const result = reducePlayerVolleyHits({
|
||||
const result = reducePlayerProjectileHits({
|
||||
hull: this.playerHull,
|
||||
hits,
|
||||
seenVolleyIds: this.damagedPlayerVolleys,
|
||||
maxHull: PLAYER_MAX_HULL,
|
||||
fallbackDamage: PIRATE_SHOT_DAMAGE,
|
||||
});
|
||||
|
||||
this.damagedPlayerVolleys = result.seenVolleyIds;
|
||||
this.playerHull = result.hull;
|
||||
const { acceptedHits, ignoredHits, totalDamage, gameOver } = result;
|
||||
const { totalDamage, appliedHits, gameOver } = result;
|
||||
|
||||
if (acceptedHits.length > 0) {
|
||||
const impact = acceptedHits[0];
|
||||
if (appliedHits > 0) {
|
||||
try {
|
||||
this.spawnExplosion(impact.x, impact.y, 0.32);
|
||||
for (const impact of hits) {
|
||||
this.spawnExplosion(impact.x, impact.y, 0.32);
|
||||
}
|
||||
this.flashShip(this.player, 0xffcccc);
|
||||
airshipLog('combat:player-hit-fx', {
|
||||
x: Math.round(impact.x),
|
||||
y: Math.round(impact.y),
|
||||
impacts: hits.length,
|
||||
scale: 0.32,
|
||||
volleyId: impact.volleyId ?? null,
|
||||
}, 'debug');
|
||||
} catch (error) {
|
||||
airshipLog('combat:player-hit-fx-error', {
|
||||
@ -603,10 +591,8 @@ class GameScene extends Phaser.Scene {
|
||||
|
||||
airshipLog('combat:player-hit-processed', {
|
||||
queuedHits: hits.length,
|
||||
appliedHits: acceptedHits.length,
|
||||
ignoredHits: ignoredHits.length,
|
||||
acceptedVolleyIds: acceptedHits.map((hit) => hit.volleyId ?? null),
|
||||
ignoredVolleyIds: ignoredHits.map((hit) => hit.volleyId ?? null),
|
||||
appliedHits,
|
||||
ignoredHits: 0,
|
||||
damage: totalDamage,
|
||||
hullBefore: beforeHull,
|
||||
hullAfter: this.playerHull,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user