Commit ee4d70dc authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: local-multi mode celebrations, capture feedback, and dice shake

- afterMove: use boardSlot for firework/flash colors (not player index)
- afterMove: in local-multi, ANY human capturing triggers celebration
  (not just player 0)
- botLoop: capture detection checks all human players in local-multi
  (not just myPlayerIndex=0)
- animateDice: shake dice-area for all human players in local-multi
  (previously only shook for player 0, panel for others)
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 41f869f8
...@@ -446,8 +446,10 @@ async function botLoop(el) { ...@@ -446,8 +446,10 @@ async function botLoop(el) {
rules.applyMove(game, game.currentPlayer, move); rules.applyMove(game, game.currentPlayer, move);
if (move.type === 'capture') { if (move.type === 'capture') {
const capturedMe = move._capturedPlayers && move._capturedPlayers.includes(myPlayerIndex); const capturedHuman = move._capturedPlayers && move._capturedPlayers.some(p =>
if (capturedMe) { game.mode === 'local-multi' ? game.humanPlayers.includes(p) : p === myPlayerIndex
);
if (capturedHuman) {
audio.play('lose', 'game'); audio.play('lose', 'game');
juice.hapticError(); juice.hapticError();
juice.shake(el, 8, 400); juice.shake(el, 8, 400);
...@@ -836,17 +838,17 @@ function fireworkBurst(x, y, color) { ...@@ -836,17 +838,17 @@ function fireworkBurst(x, y, color) {
function afterMove(el, move) { function afterMove(el, move) {
game.rolled = false; game.rolled = false;
const mover = game.currentPlayer; const mover = game.currentPlayer;
const moverSlot = game.players[mover]?.boardSlot ?? mover;
const isHumanMover = game.mode === 'local-multi' ? game.humanPlayers.includes(mover) : mover === myPlayerIndex;
if (move.type === 'capture') { if (move.type === 'capture') {
if (mover === myPlayerIndex) { if (isHumanMover) {
// I captured someone — celebrate!
audio.play('capture', 'reward'); audio.play('capture', 'reward');
juice.hapticSuccess(); juice.hapticSuccess();
juice.confetti(window.innerWidth / 2, window.innerHeight / 2, 30); juice.confetti(window.innerWidth / 2, window.innerHeight / 2, 30);
juice.starBurst(window.innerWidth / 2, window.innerHeight / 2, 10); juice.starBurst(window.innerWidth / 2, window.innerHeight / 2, 10);
juice.screenFlash('rgba(76,175,80,0.2)', 400); juice.screenFlash('rgba(76,175,80,0.2)', 400);
} else { } else {
// A bot/opponent captured — check if MY pawn was the victim
const capturedMe = move._capturedPlayers && move._capturedPlayers.includes(myPlayerIndex); const capturedMe = move._capturedPlayers && move._capturedPlayers.includes(myPlayerIndex);
if (capturedMe) { if (capturedMe) {
audio.play('lose', 'game'); audio.play('lose', 'game');
...@@ -859,12 +861,12 @@ function afterMove(el, move) { ...@@ -859,12 +861,12 @@ function afterMove(el, move) {
} }
} }
} else if (move.type === 'finish') { } else if (move.type === 'finish') {
if (mover === myPlayerIndex) { if (isHumanMover) {
audio.play('sfx_piece_home', 'reward'); audio.play('sfx_piece_home', 'reward');
juice.hapticSuccess(); juice.hapticSuccess();
const boardRect = canvas.getBoundingClientRect(); const boardRect = canvas.getBoundingClientRect();
fireworkBurst(boardRect.left + boardRect.width / 2, boardRect.top + boardRect.height / 2, COLORS[mover]); fireworkBurst(boardRect.left + boardRect.width / 2, boardRect.top + boardRect.height / 2, COLORS[moverSlot]);
juice.screenFlash(COLORS[mover] + '22', 500); juice.screenFlash(COLORS[moverSlot] + '22', 500);
} else { } else {
audio.play('sfx_piece_home', 'game'); audio.play('sfx_piece_home', 'game');
} }
...@@ -1269,7 +1271,7 @@ function animateDice(el, playerIdx) { ...@@ -1269,7 +1271,7 @@ function animateDice(el, playerIdx) {
return new Promise(resolve => { return new Promise(resolve => {
const mainDice = el.querySelector('#dice-box'); const mainDice = el.querySelector('#dice-box');
const miniDice = el.querySelector(`#dice-${playerIdx}`); const miniDice = el.querySelector(`#dice-${playerIdx}`);
const isMe = playerIdx === myPlayerIndex; const isMe = game.mode === 'local-multi' ? game.humanPlayers.includes(playerIdx) : playerIdx === myPlayerIndex;
// Show mini dice in rolling state // Show mini dice in rolling state
if (miniDice) { if (miniDice) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment