Domestic sale can only be done at the beginning of turn, does not cost action.

This commit is contained in:
Lucas Mello 2021-07-28 14:48:46 -03:00
commit d4427c81aa
5 changed files with 30 additions and 5 deletions

View file

@ -64,7 +64,7 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves {
let moves: AvailableMoves = {};
// DomesticSale
if (player.actions > 0 && G.round > 1) {
if (player.actions == 2 && !player.didDomesticSale && G.round > 1) {
if (player.containersOnFactoryStore.length > 0) {
moves[MoveName.DomesticSale] = player.containersOnFactoryStore.map((c) => c.piece);
} else if (player.containersOnWarehouseStore.length > 0) {

View file

@ -52,6 +52,7 @@ export function setup(numPlayers: number, { beginner = true }: GameOptions, seed
showAdditionalBid: false,
finalScore: 0,
isAI: false,
didDomesticSale: false,
}));
const totalContainers = players.length * 4;
@ -166,7 +167,7 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
G.containersLeft.push(move.data);
player.money += 2;
player.actions--;
player.didDomesticSale = true;
G.log.push({
type: 'move',
@ -1014,6 +1015,7 @@ function doUpkeep(G: GameState) {
G.players[G.currentPlayer!].produced = [];
G.players[G.currentPlayer!].containersOnFactoryStore.forEach((c) => (c.moved = false));
G.players[G.currentPlayer!].containersOnWarehouseStore.forEach((c) => (c.moved = false));
G.players[G.currentPlayer!].didDomesticSale = false;
if (G.currentPlayer == G.startingPlayer) {
G.round++;

View file

@ -86,6 +86,7 @@ export interface Player {
containersOnIsland: ContainerPiece[];
isAI: boolean;
finalScoreBreakdown?: string[];
didDomesticSale: boolean;
}
export enum Phase {

View file

@ -18,6 +18,7 @@ import { EventEmitter, Listener } from 'events';
import Piece from './pieces/Piece.vue';
import { Ship, Container, LoanCard } from './pieces';
import { ShipPosition } from 'container-engine/src/gamestate';
import { MoveName } from 'container-engine';
@Component
export default class DropZone extends Vue {
@ -48,6 +49,9 @@ export default class DropZone extends Vue {
@Prop()
data?: any;
@Prop()
availableMoves?: any;
listener?: Listener;
overlapping = false;
@ -128,15 +132,25 @@ export default class DropZone extends Vue {
if (this.data.type != DropZoneType.FactoryStore) return false;
} else if (container.state == ContainerState.OnFactoryStore) {
if (container.owner == this.player) {
if (this.data.type != DropZoneType.FactoryStore && this.data.type != DropZoneType.Supply)
if (this.data.type == DropZoneType.Supply) {
if (!this.availableMoves[MoveName.DomesticSale]?.find((c) => c.id === container.pieceId)) {
return false;
}
} else if (this.data.type != DropZoneType.FactoryStore) {
return false;
}
} else {
if (this.data.type != DropZoneType.WarehouseStore) return false;
}
} else if (container.state == ContainerState.OnWarehouseStore) {
if (container.owner == this.player) {
if (this.data.type != DropZoneType.WarehouseStore && this.data.type != DropZoneType.Supply)
if (this.data.type == DropZoneType.Supply) {
if (!this.availableMoves[MoveName.DomesticSale]?.find((c) => c.id === container.pieceId)) {
return false;
}
} else if (this.data.type != DropZoneType.WarehouseStore) {
return false;
}
} else {
if (this.data.type != DropZoneType.Ship) return false;
}

View file

@ -28,6 +28,7 @@
:enabled="true"
:accepts="'container'"
:data="{ type: 'supply' }"
:availableMoves="getCurrentPlayerMoves()"
/>
<template v-if="G">
@ -1129,7 +1130,7 @@ export default class Game extends Vue {
if (this.G?.currentPlayer == undefined) {
return 'Game ended!';
} else if (this.G?.currentPlayer == this.player) {
return "It's your turn!";
return 'It\'s your turn!';
} else {
if (
!this.G.log ||
@ -1325,6 +1326,13 @@ export default class Game extends Vue {
onLogChanged() {
this.emitter.emit('replaceLog', [...this.logReversed].reverse());
}
getCurrentPlayerMoves() {
if (!this.canMove())
return [];
return this.G!.players[this.G!.currentPlayer!].availableMoves!;
}
}
</script>
<style lang="scss">