Skip to content

Commit

Permalink
[#1] Fixed killed pieces spawning in the wrong position
Browse files Browse the repository at this point in the history
  • Loading branch information
Monkey-bored committed Dec 16, 2023
1 parent 340b36d commit 55f703e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions development/src/logic/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ function actOnTurnPieceToSquare(draggedPiece: Piece, targetSquare: Square) {
if (!enPassantPosition) return;
const targetPiece = getPieceByPositionAndBoard(enPassantPosition);
if (!targetPiece) return;

killPiece(draggedPiece, targetPiece);
killPiece(draggedPiece, targetPiece, targetSquare.position);
}
move(draggedPiece, targetSquare);
} else {
Expand All @@ -290,8 +290,14 @@ function actOnTurnPieceToTrap(draggedPiece: Piece, targetItem: Item) {
endTurn();
}

function killPieceProcess(draggedPiece: Piece, targetPiece: Piece) {
function killPieceProcess(
draggedPiece: Piece,
targetPiece: Piece,
targetPosition: Position,
) {
if (targetPiece.position.board === OVERWORLD_BOARD_ID) {
targetPiece.position = targetPosition;

Logger.logKill(`A ${targetPiece.player.color} ${targetPiece.name}
was killed by a ${draggedPiece.player.color} ${draggedPiece.name}.`);

Expand Down Expand Up @@ -341,11 +347,15 @@ function killPieceProcess(draggedPiece: Piece, targetPiece: Piece) {
}
}

function killPiece(draggedPiece: Piece, targetPiece: Piece) {
function killPiece(
draggedPiece: Piece,
targetPiece: Piece,
targetPosition = targetPiece.position,
) {
deathCounter++;
isPieceKilled = true;
destroyPieceOnBoard(targetPiece);
killPieceProcess(draggedPiece, targetPiece);
killPieceProcess(draggedPiece, targetPiece, targetPosition);
}

function permanentlyKillPiece(targetPiece: Piece) {
Expand Down Expand Up @@ -437,7 +447,7 @@ function resetVariables() {
piece.enPassant = false;
}
});

if (
enPassantPosition &&
getCurrentPlayer() !== getPieceByPositionAndBoard(enPassantPosition)?.player
Expand Down

0 comments on commit 55f703e

Please sign in to comment.