Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Fixed bug where player could summon creature with insufficient actions
Browse files Browse the repository at this point in the history
  • Loading branch information
browntj16 committed Apr 30, 2024
1 parent 2b10ac3 commit e4c2b71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,9 @@ function GameBoard({ game, setBegin }: { game: Game, setBegin: any}) {
function SummoningButtons({cardPos, game, setSummonState, playerid, log, setLog}: {cardPos: number, game: Game, setSummonState: any,
board: any, playerid: number, log: any, setLog: any}){
function handle(boardPos: number, playerid: number){

globalTempVariable = boardPos;
game.playCard(game.getPlayerById(playerid).hand[cardPos], playerid);
let name = game.board.getBoardPosByOwnerId(playerid, boardPos)?.creature.name;
//let name = game.summonCardFromHand(playerid,boardPos, cardPos);
if(name){
setLog([...log, <div>{game.getPlayerById(playerid).username} summoned the "{name}" at zone {boardPos+1}</div>])
if(game.playCard(game.getPlayerById(playerid).hand[cardPos], playerid)){
setLog([...log, <div>{game.getPlayerById(playerid).username} summoned the "{game.board.getBoardPosByOwnerId(playerid, boardPos)?.creature.name}" at zone {boardPos+1}</div>])
}
else{
setLog([...log, <div>{game.getPlayerById(playerid).username} attempted to summon a creature, but lacks the actions</div>])
Expand Down
9 changes: 7 additions & 2 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,11 @@ export class Game extends AbstractGame {
}

override playCard(card: Card, playerId: number): boolean {
if (this.turnPhase != TurnPhases.Play &&
(Game.getInstance().getPlayerById(playerId) == null && Game.getInstance().getPlayerById(playerId).actions >= card.getCost())) {
console.log(Game.getInstance().getPlayerById(playerId).actions < card.getCost())
//removed check for turnphase since frontend sorta already does this
// Game.getInstance().getPlayerById(playerId) == null <- this statement always resolved to false, even when player was not null
// remmoved for now
if (((Game.getInstance().getPlayerById(playerId).actions < card.getCost()))) {
// console.log("Unable to play card " + card.name + "! Potential causes: this.turnPhase == TurnPhases.Play: " + (this.turnPhase == TurnPhases.Play) +
// ", Player from playerId == null: " + (Game.getInstance().getPlayerById(playerId) == null) +
// ", Player has enough actions: " + (Game.getInstance().getPlayerById(playerId).actions >= card.getCost()));
Expand All @@ -574,6 +577,8 @@ export class Game extends AbstractGame {
new GetBoardPosTargetEvent(
GetCardTargetEvent,
(pos: BoardPos) => {
//found error with summoning card here. if we are trying to summon to a zone that a creature is in then we return false
// wont change until i know that this was unintentional
if (!pos.creature.equals(Creature.getNull())) {
return false;
} else {
Expand Down

0 comments on commit e4c2b71

Please sign in to comment.