Skip to content

Commit

Permalink
Test reaches click on card stage! But expectation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
AMMayberry1 committed Jul 12, 2024
1 parent 836272a commit 56acf4e
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 192 deletions.
6 changes: 3 additions & 3 deletions bin/fetchdata_swu.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ function filterValues(card) {

let internalName = filteredObj.title;
if (filteredObj.subtitle) {
internalName += "|" + filteredObj.subtitle;
internalName += "#" + filteredObj.subtitle;
}
filteredObj.internalName = internalName.toLowerCase().replace(/[^\w\s|]|_/g, "").replace(/\s/g, "-");
filteredObj.internalName = internalName.toLowerCase().replace(/[^\w\s#]|_/g, "").replace(/\s/g, "-");

// keep original card for debug logging, will be removed before card is written to file
delete card.attributes.variants;
Expand Down Expand Up @@ -100,7 +100,7 @@ async function main() {
console.log(`Duplicate cards found, with set codes: ${JSON.stringify(duplicatesWithSetCode, null, 2)}`);
}

await Promise.all(uniqueCards.map(async (card) => fs.writeFile(path.join(pathToJSON, `Card/${card.id}.json`), JSON.stringify([card], null, 2))));
await Promise.all(uniqueCards.map(async (card) => fs.writeFile(path.join(pathToJSON, `Card/${card.internalName}.json`), JSON.stringify([card], null, 2))));

fs.writeFile(path.join(pathToJSON, '_cardMap.json'), JSON.stringify(cardMap, null, 2))
}
Expand Down
2 changes: 1 addition & 1 deletion server/swu/game/card/deckcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ class DeckCard extends BaseCard {
// TODO: add base / leader actions if this doesn't already cover them

// otherwise (i.e. card is in hand), return play card action(s) + other available card actions
return [this.getPlayActions(), super.getActions()];
return this.getPlayActions().concat(super.getActions());
}

/**
Expand Down
22 changes: 6 additions & 16 deletions server/swu/game/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,14 @@ class Game extends EventEmitter {
/**
* Checks who the next legal active player for the action phase should be and updates @member {activePlayer}. If none available, sets it to null.
*/
checkRotateActivePlayer() {
if (this.actionPhaseActivePlayer.opponent.canTakeActionsThisPhase) {
rotateActivePlayer() {
if (!this.actionPhaseActivePlayer.opponent.passedActionPhase) {
this.actionPhaseActivePlayer = this.actionPhaseActivePlayer.opponent;
return;
}

if (this.actionPhaseActivePlayer.canTakeActionsThisPhase) {
return;
} else if (this.actionPhaseActivePlayer.passedActionPhase) {
this.actionPhaseActivePlayer = null;
}

this.actionPhaseActivePlayer = null;
// by default, if the opponent has passed and the active player has not, they remain the active player and play continues
}

/**
Expand Down Expand Up @@ -755,8 +752,8 @@ class Game extends EventEmitter {
* @returns {undefined}
*/
beginRound() {
this.resetLimitedForPlayer();
this.roundNumber++;
this.actionPhaseActivePlayer = this.initiativePlayer;
this.raiseEvent(EventNames.OnBeginRound);
this.queueStep(new ActionPhase(this));
this.queueStep(new RegroupPhase(this));
Expand All @@ -768,13 +765,6 @@ class Game extends EventEmitter {
this.raiseEvent(EventNames.OnRoundEnded);
}

resetLimitedForPlayer() {
var players = this.getPlayers();
players.forEach((player) => {
player.limitedPlayed = 0;
});
}

/*
* Adds a step to the pipeline queue
* @param {BaseStep} step
Expand Down
5 changes: 3 additions & 2 deletions server/swu/game/gamesteps/actionwindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const { UiPrompt } = require('./UiPrompt.js');
const { EventNames, Locations, Players, EffectNames, isArena, WildcardLocations } = require('../Constants');

class ActionWindow extends UiPrompt {
constructor(game, activePlayer, title, windowName) {
constructor(game, title, windowName, activePlayer = null) {
super(game);

this.title = title;
this.windowName = windowName;
this.activePlayer = activePlayer;
this.activePlayer = activePlayer ?? this.game.initiativePlayer;
this.activePlayerConsecutiveActions = 0;
this.opportunityCounter = 0;
this.prevPlayerPassed = false;
Expand Down Expand Up @@ -79,6 +79,7 @@ class ActionWindow extends UiPrompt {
this.activePlayer.actionPhasePriority = false;
}

// TODO: do we need promptedActionWindows?
if(!this.activePlayer.promptedActionWindows[this.windowName]) {
this.pass();
}
Expand Down
25 changes: 10 additions & 15 deletions server/swu/game/gamesteps/phases/ActionPhase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,20 @@ export class ActionPhase extends Phase {
constructor(game: Game) {
super(game, Phases.Action);
this.initialise([
new SimpleStep(this.game, () => this.queueActions())
new SimpleStep(this.game, () => this.#queueNextAction())
]);
}

queueActions() {
// player with initiative acts first
this.game.actionPhaseActivePlayer = this.game.initiativePlayer;
for (const player of this.game.getPlayers()) {
player.canTakeActionsThisPhase = true;
}

// loop until neither player can take actions anymore due to passing
do {
this.game.queueStep(new ActionWindow(this.game, 'Action Window'));
this.game.checkRotateActivePlayer();
} while (this.game.actionPhaseActivePlayer !== null);
#queueNextAction() {
this.game.queueStep(new ActionWindow(this.game, 'Action Window', 'action'));
this.game.queueStep(() => this.#rotateActiveQueueNextAction());
}

for (const player of this.game.getPlayers()) {
player.canTakeActionsThisPhase = null;
#rotateActiveQueueNextAction() {
// breaks the action loop if both players have passed
this.game.rotateActivePlayer();
if (this.game.actionPhaseActivePlayer !== null) {
this.game.queueStep(() => this.#queueNextAction());
}
}
}
2 changes: 2 additions & 0 deletions server/swu/game/gamesteps/phases/SetupPhase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type Game from '../../game';
import { Phase } from '../Phase';
import { SimpleStep } from '../SimpleStep';
import ResourcePrompt from '../basic_steps/resourceprompt';
import Player from '../../player';

export class SetupPhase extends Phase {
constructor(game: Game) {
Expand All @@ -28,6 +29,7 @@ export class SetupPhase extends Phase {
putBaseInPlay() {
for (const player of this.game.getPlayers()) {
player.moveCard(player.base, Locations.Base);
player.damageToBase = 0;
}
}

Expand Down
28 changes: 13 additions & 15 deletions server/swu/game/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Player extends GameObject {

this.leader = null;
this.base = null;
this.damageToBase = null;

this.clock = clockFor(this, clockdetails);

Expand Down Expand Up @@ -879,22 +880,19 @@ class Player extends GameObject {
}
}

// TODO: switch to beginAction
// /**
// * Called at the start of the Dynasty Phase. Resets a lot of the single round parameters
// */
// beginDynasty() {
// if (this.resetTimerAtEndOfRound) {
// this.noTimer = false;
// }

// this.resetConflictOpportunities();
/**
* Called at the start of the Action Phase. Resets a lot of the single round parameters
*/
beginAction() {
if (this.resetTimerAtEndOfRound) {
this.noTimer = false;
}

// this.cardsInPlay.each((card) => {
// card.new = false;
// });
// this.passedDynasty = false;
// }
this.getCardsInPlay().each((card) => {
card.new = false;
});
this.passedActionPhase = false;
}

// showDeck() {
// this.showDeck = true;
Expand Down
5 changes: 4 additions & 1 deletion test/swu/helpers/deckbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const _ = require('underscore');

// defaults to fill in with if not explicitly provided by the test case
const defaultLeader = 'darth-vader|dark-lord-of-the-sith';
const defaultLeader = 'darth-vader#dark-lord-of-the-sith';
const defaultBase = 'kestro-city';
const deckFillerCard = 'underworld-thug';
const deckBufferSize = 8; // buffer decks to prevent re-shuffling
Expand Down Expand Up @@ -59,6 +59,9 @@ class DeckBuilder {
if(player.hand) {
allCards.push(...player.hand);
}
if(player.resources) {
allCards.push(...player.resources);
}
//Add cards to prevent reshuffling due to running out of cards
for(let i = initialDeckSize; i < deckSize; i++) {
allCards.push(deckFillerCard);
Expand Down
24 changes: 12 additions & 12 deletions test/swu/helpers/gameflowwrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class GameFlowWrapper {
}

get firstPlayer() {
return _.find(this.allPlayers, player => player.firstPlayer);
return _.find(this.allPlayers, player => player.initiativePlayer);
}

eachPlayerInInitiativeOrder(handler) {
var playersInOrder = _.sortBy(this.allPlayers, player => !player.firstPlayer);
var playersInOrder = _.sortBy(this.allPlayers, player => !player.initiativePlayer);

_.each(playersInOrder, player => handler(player));
}
Expand Down Expand Up @@ -83,16 +83,16 @@ class GameFlowWrapper {
* Both players pass for the rest of the action window
*/
noMoreActions() {
if(this.game.currentPhase === 'dynasty') {
// Players that have already passed aren't prompted again in dynasty
this.eachPlayerStartingWithPrompted(player => {
if(!player.player.passedDynasty) {
player.clickPrompt('Pass');
}
});
} else {
this.eachPlayerStartingWithPrompted(player => player.clickPrompt('Pass'));
}
// if(this.game.currentPhase === 'dynasty') {
// // Players that have already passed aren't prompted again in dynasty
// this.eachPlayerStartingWithPrompted(player => {
// if(!player.player.passedDynasty) {
// player.clickPrompt('Pass');
// }
// });
// } else {
// this.eachPlayerStartingWithPrompted(player => player.clickPrompt('Pass'));
// }
}

/**
Expand Down
13 changes: 7 additions & 6 deletions test/swu/helpers/integrationhelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const GameFlowWrapper = require('./gameflowwrapper.js');

const deckBuilder = new DeckBuilder();

// TODO: why not just call these directly
const ProxiedGameFlowWrapperMethods = [
'eachPlayerInFirstPlayerOrder',
'startGame',
Expand Down Expand Up @@ -168,15 +169,15 @@ global.integration = function (definitions) {
}

//Player stats
// TODO: base damage
this.player1.fate = options.player1.fate;
this.player2.fate = options.player2.fate;
this.player1.honor = options.player1.honor;
this.player2.honor = options.player2.honor;
this.player1.damageToBase = options.player1.damageToBase ?? 0;
this.player2.damageToBase = options.player2.damageToBase ?? 0;
//Field
this.player1.inPlay = options.player1.inPlay;
this.player2.inPlay = options.player2.inPlay;
//Conflict deck related
//Resources
this.player1.resources = options.player1.resources;
this.player2.resources = options.player2.resources;
//Deck + discard
this.player1.hand = options.player1.hand;
this.player2.hand = options.player2.hand;
this.player1.discard = options.player1.discard;
Expand Down
Loading

0 comments on commit 56acf4e

Please sign in to comment.