nerf mélange

This commit is contained in:
Didictateur 2025-12-02 02:06:38 +01:00
parent c4f8b21373
commit 7815099ea5

View file

@ -2046,24 +2046,35 @@ io.on('connection', (socket) => {
if(allSquares.length < pieces.length){ if(allSquares.length < pieces.length){
played.payload = Object.assign({}, payload, { applied: 'melange_failed', reason: 'board_too_small' }); played.payload = Object.assign({}, payload, { applied: 'melange_failed', reason: 'board_too_small' });
} else { } else {
for(let i = allSquares.length - 1; i > 0; i--){ const j = Math.floor(Math.random() * (i + 1)); const tmp = allSquares[i]; allSquares[i] = allSquares[j]; allSquares[j] = tmp; } const occupiedByBlack = {};
const dests = allSquares.slice(0, pieces.length); pieces.forEach(p => { try{ if(p && p.color === 'b' && p.square){ occupiedByBlack[p.square] = true; } }catch(_){ } });
const newSquareByPieceId = {}; const occupiedByWhite = {};
for(let i = 0; i < pieces.length; i++){ const p = pieces[i]; newSquareByPieceId[p.id] = dests[i]; } pieces.forEach(p => { try{ if(p && p.color === 'w' && p.square){ occupiedByWhite[p.square] = true; } }catch(_){ } });
pieces.forEach(p => { try{ p.square = newSquareByPieceId[p.id] || p.square; }catch(_){ } }); const blackSquares = Object.keys(occupiedByBlack);
for(let i = blackSquares.length - 1; i > 0; i--){ const j = Math.floor(Math.random() * (i + 1)); const tmp = blackSquares[i]; blackSquares[i] = blackSquares[j]; blackSquares[j] = tmp; }
const newBlackSquareByPieceId = {};
let blackIndex = 0;
pieces.forEach(p => { try{ if(p && p.color === 'b'){ newBlackSquareByPieceId[p.id] = blackSquares[blackIndex] || p.square; blackIndex++; } }catch(_){ } });
const whiteSquares = Object.keys(occupiedByWhite);
for(let i = whiteSquares.length - 1; i > 0; i--){ const j = Math.floor(Math.random() * (i + 1)); const tmp = whiteSquares[i]; whiteSquares[i] = whiteSquares[j]; whiteSquares[j] = tmp; }
const newWhiteSquareByPieceId = {};
let whiteIndex = 0;
pieces.forEach(p => { try{ if(p && p.color === 'w'){ newWhiteSquareByPieceId[p.id] = whiteSquares[whiteIndex] || p.square; whiteIndex++; } }catch(_){ } });
pieces.forEach(p => {
try{ try{
room.activeCardEffects = room.activeCardEffects || []; if(p && p.color === 'b' && newBlackSquareByPieceId[p.id]){
room.activeCardEffects.forEach(e => { p.square = newBlackSquareByPieceId[p.id];
if(!e) return; } else if(p && p.color === 'w' && newWhiteSquareByPieceId[p.id]){
try{ if(e.pieceId && newSquareByPieceId[e.pieceId]){ e.pieceSquare = newSquareByPieceId[e.pieceId]; } }catch(_){ } p.square = newWhiteSquareByPieceId[p.id];
}); }
}catch(_){ } }catch(_){ }
played.payload = Object.assign({}, payload, { applied: 'melange', count: pieces.length }); });
board.version = (board.version || 0) + 1; board.version = (board.version || 0) + 1;
const effect = { id: played.id, type: 'melange', playerId: senderId, ts: Date.now(), note: 'pieces shuffled' }; const effect = { id: played.id, type: 'melange', playerId: senderId, ts: Date.now() };
room.activeCardEffects = room.activeCardEffects || []; room.activeCardEffects = room.activeCardEffects || [];
room.activeCardEffects.push(effect); room.activeCardEffects.push(effect);
try{ io.to(room.id).emit('card:effect:applied', { roomId: room.id, effect }); }catch(_){ } try{ io.to(room.id).emit('card:effect:applied', { roomId: room.id, effect }); }catch(_){ }
played.payload = Object.assign({}, payload, { applied: 'melange' });
} }
}catch(e){ console.error('melange error', e); } }catch(e){ console.error('melange error', e); }
} }