Skip to content

Commit

Permalink
refactor: add minimal accomplishment and mars event data to validation
Browse files Browse the repository at this point in the history
encountered an issue where the simulated and actual accomplishment decks
were out of sync since this data is not persisted and the replay just
makes its own shuffled deck. for this purpose its being regarded as junk
data and we just look at the cards that are visible to the player
(purchased and purchasable)

ref #840
  • Loading branch information
sgfost committed Jan 10, 2023
1 parent e991b83 commit 4f7813b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
17 changes: 13 additions & 4 deletions server/src/rooms/game/state/accomplishment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
getAccomplishmentIDs,
} from "@port-of-mars/server/data/Accomplishment";
import { settings } from "@port-of-mars/server/settings";
import { AccomplishmentSetSerialized } from "@port-of-mars/server/rooms/game/state/types";
import {
AccomplishmentSetSerialized,
AccomplishmentSetSummary
} from "@port-of-mars/server/rooms/game/state/types";

const logger = settings.logging.getLogger(__filename);

Expand Down Expand Up @@ -142,18 +145,24 @@ export class AccomplishmentSet
this.purchasable.splice(0, this.purchasable.length);
purchasable.forEach((p) => this.purchasable.push(p));

this.deck = _.cloneDeep(data.remaining);
this.deck = data.remaining;
}

toJSON(): AccomplishmentSetSerialized {
return {
purchased: _.map(this.purchased, (x) => x.id),
purchasable: _.map(this.purchasable, (x) => x.id),
...this.getAccomplishmentSetSummary(),
remaining: this.deck,
role: this.role,
};
}

getAccomplishmentSetSummary(): AccomplishmentSetSummary {
return {
purchased: _.map(this.purchased, (x) => x.toJSON().id),
purchasable: _.map(this.purchasable, (x) => x.toJSON().id),
};
}

role: Role;

@type([Accomplishment])
Expand Down
4 changes: 2 additions & 2 deletions server/src/rooms/game/state/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ export class GameState
return {
systemHealth: this.systemHealth,
round: this.round,
logsLength: this.logs.length,
messagesLength: this.messages.length,
marsEventsLength: this.marsEvents.length,
logsLength: this.logs.length,
marsEventIds: _.map(this.marsEvents, (e) => e.id),
marsEventsProcessed: this.marsEventsProcessed,
players: this.players.getPlayerSetSummary(),
}
Expand Down
1 change: 1 addition & 0 deletions server/src/rooms/game/state/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class Player
timeBlocks: this.timeBlocks,
victoryPoints: this.victoryPoints,
inventory: this.inventory.toJSON(),
accomplishment: this.accomplishments.getAccomplishmentSetSummary(),
}
}

Expand Down
14 changes: 9 additions & 5 deletions server/src/rooms/game/state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export interface GameSerialized {
export interface RoundSummary {
systemHealth: number;
round: number;
logsLength: number;
messagesLength: number;
marsEventsLength: number;
logsLength: number;
marsEventIds: Array<string>;
marsEventsProcessed: number;
players: PlayerSetSummary;
}
Expand All @@ -49,13 +49,15 @@ export interface MarsEventDeckSerialized {
position: number;
}

export type PlayerSummary = Pick<PlayerSerialized,
export interface PlayerSummary extends Pick<PlayerSerialized,
| "role"
| "ready"
| "timeBlocks"
| "victoryPoints"
| "inventory"
>;
> {
accomplishment: AccomplishmentSetSummary;
}

export type PlayerSetSummary = { [role in Role]: PlayerSummary };

Expand Down Expand Up @@ -83,4 +85,6 @@ export interface AccomplishmentSetSerialized {
purchased: Array<number>;
purchasable: Array<number>;
remaining: Array<number>;
}
}

export type AccomplishmentSetSummary = Omit<AccomplishmentSetSerialized, "remaining" | "role">;

0 comments on commit 4f7813b

Please sign in to comment.