includes held cards in total available resources
This commit is contained in:
@@ -7,7 +7,24 @@ export const tooExpensive = (card: CardData, state: AppState): boolean => {
|
||||
if (!currentPlayer) return true;
|
||||
|
||||
for (let [gemType, cost] of Object.entries(card.resourceCost)) {
|
||||
for (let [heldResource, quantity] of Object.entries(currentPlayer.inventory)) {
|
||||
let totalBuyingPower = {
|
||||
ruby: 0,
|
||||
sapphire: 0,
|
||||
emerald: 0,
|
||||
diamond: 0,
|
||||
onyx: 0,
|
||||
gold: 0,
|
||||
}
|
||||
|
||||
for (let [key,quantity] of Object.entries(currentPlayer.inventory)) {
|
||||
totalBuyingPower[key as keyof ResourceCost] += quantity;
|
||||
}
|
||||
|
||||
for (let each of currentPlayer.cards) {
|
||||
totalBuyingPower[each.gemValue as keyof ResourceCost] += 1;
|
||||
}
|
||||
|
||||
for (let [heldResource, quantity] of Object.entries(totalBuyingPower)) {
|
||||
if (gemType === heldResource && quantity < cost) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ export default function Player({ player, state, setState, setActionState }: Play
|
||||
{/* Static Data */}
|
||||
<section className="player-constants">
|
||||
<p>Name: {player.name}</p>
|
||||
<p>Score: {player.points}</p>
|
||||
<p>Is {player.starter || "not"} round starter</p>
|
||||
</section>
|
||||
|
||||
{/* Dynamic data from state */}
|
||||
<section className="turn-and-action-based">
|
||||
<p>Score: {dynamic?.points}</p>
|
||||
<p>{dynamic?.turnActive ? prompt : '...'}</p>
|
||||
<button onClick={() => setActionSelection(0)}>Get Chips</button>
|
||||
<button onClick={() => setActionSelection(1)}>Buy Card</button>
|
||||
@@ -49,7 +49,7 @@ export default function Player({ player, state, setState, setActionState }: Play
|
||||
|
||||
<div className="player-chips">
|
||||
<p>Chips:</p>
|
||||
{ dynamic && Object.entries(dynamic?.inventory).map(([key,value]) => {
|
||||
{ dynamic && Object.entries(dynamic.inventory).map(([key,value]) => {
|
||||
return value > 0 && <p key={v4()}>{key}: {value}</p>
|
||||
})}
|
||||
</div>
|
||||
@@ -60,7 +60,7 @@ export default function Player({ player, state, setState, setActionState }: Play
|
||||
return (
|
||||
<div key={v4()} className="mini-card" style={{backgroundColor: 'white'}}>
|
||||
<p>{data.gemValue} card</p>
|
||||
<p>{data.points || null}</p>
|
||||
<p>{data.points + " points" || null}</p>
|
||||
</div>
|
||||
)})
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { ResourceCost } from "../../util/types";
|
||||
import { useEffect } from "react";
|
||||
import { v4 } from "uuid";
|
||||
import "./AvailableChips.css"
|
||||
import { setStateGetChips } from "../../util/stateSetters";
|
||||
|
||||
export default function AvailableChips({ state, setState, liftSelection }: ResourceProps) {
|
||||
useEffect(() => {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { v4 } from "uuid";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ResourceCost, StateProps } from "../../util/types";
|
||||
import { setStateGetChips } from "../../util/stateSetters";
|
||||
import { StateProps } from "../../util/propTypes";
|
||||
import { GetChipsHTML } from "./ViewHTML";
|
||||
|
||||
export default function SelectionView({ state, setState }: StateProps) {
|
||||
|
||||
@@ -31,7 +31,6 @@ const setNobles = (state: AppState, setState: setStateType) => {
|
||||
}
|
||||
|
||||
export const setCardRows = (state: AppState) => {
|
||||
console.log('set cards');
|
||||
let newDeck = state.gameboard.cardRows;
|
||||
for (const [key, value] of Object.entries(state.gameboard.deck)) {
|
||||
while (newDeck[key as keyof FullDeck].length < 4) {
|
||||
|
||||
Reference in New Issue
Block a user