Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed piece death animation not playing #293

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions core/development/logic/actions/KillPieceAction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { OVERWORLD_BOARD_ID } from '../../Constants';
import {
HEAVEN_BOARD_ID,
HELL_BOARD_ID,
OVERWORLD_BOARD_ID,
} from '../../Constants';
import { game } from '../../Game';
import { destroyPieceOnBoard } from '../../LogicAdapter';
import { King } from '../pieces/King';
Expand All @@ -21,16 +25,26 @@ export class KillPieceAction implements GameAction {
execute(): ActionResult {
if (this.killedPiece.position?.boardId === OVERWORLD_BOARD_ID) {
game.increaseDeathCounter();
destroyPieceOnBoard(this.killedPiece, this.originBoardId);

const hasPieceKilledOtherPieces = this.killedPiece.killCount > 0;
const isKilledPieceKing = this.killedPiece instanceof King;

const pieceOriginBoardId = this.killedPiece.position.boardId;
let spawnActionResult = ActionResult.FAILURE;
if (hasPieceKilledOtherPieces || isKilledPieceKing) {
return new SpawnPieceInHellAction(this.killedPiece).execute();
spawnActionResult = new SpawnPieceInHellAction(
this.killedPiece,
).execute();
} else {
return new SpawnPieceInHeavenAction(this.killedPiece).execute();
spawnActionResult = new SpawnPieceInHeavenAction(
this.killedPiece,
).execute();
}

destroyPieceOnBoard(this.killedPiece, pieceOriginBoardId);
return spawnActionResult;
} else {
destroyPieceOnBoard(this.killedPiece);
return new PermanentlyKillPieceAction(this.killedPiece).execute();
}
}
Expand Down
6 changes: 2 additions & 4 deletions core/development/logic/actions/SpawnPieceAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { game } from '../../Game';
import { destroyPieceOnBoard, spawnPieceOnBoard } from '../../LogicAdapter';
import { spawnPieceOnBoard } from '../../LogicAdapter';
import { comparePositions } from '../Utilities';
import { BasePiece } from '../pieces/abstract/BasePiece';
import { PermanentlyKillPieceAction } from './PermanentlyKillPieceAction';
Expand All @@ -18,10 +18,8 @@ export class SpawnPieceAction implements GameAction {

execute(): ActionResult {
if (!this.piece || !this.piece.position) return ActionResult.FAILURE;
destroyPieceOnBoard(this.piece);
this.piece.position.boardId = this.boardId;

this.piece.killCount = 0;
this.piece.position.boardId = this.boardId;

game.getPieces().forEach((piece) => {
const areOnTheSamePosition = comparePositions(
Expand Down
1 change: 0 additions & 1 deletion core/development/logic/items/Shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class Shield extends BaseItem {

use(position: Position): ItemActionResult {
const piece = getPieceByPosition(position);
console.log(piece);
if (!piece || !piece.position) return ItemActionResult.FAILURE;

const logCoordinates = MovementLog.convertPositionToNotation(
Expand Down