Show IFS card buying errors and allow buying with emergency loan.

logins
Thomas Hintz 5 years ago
parent 89e67b3150
commit 93cc806eb2

@ -40,7 +40,7 @@ import Tractor from '../tractor/Tractor.jsx'
import { GAME_STATES, ALERTS } from '../../constants.js'
import { itemCard, itemCardShort, fateCard, ridgeNames } from 'game.js'
import { setSelectedCard, setMessagePanelSpace, setMPDims, movePlayer,
nextUIAction, alert, alertHandled } from './actions.js'
nextUIAction, alert, alertHandled, setCardError } from './actions.js'
import { buy, roll, endTurn, loan, trade, submitTradeAccept,
submitTradeDeny, submitTradeCancel, audit,
buyUncleBert, skip } from './interface.js'
@ -1673,20 +1673,23 @@ class BoardApp extends React.Component {
</div>
<div className={this.tabClass(SCREENS.cards)}>
<Row>
<div className='cell medium-auto'>
<CardList ui={this.props.ui} cardId={this.state.card.id}
setCard={this.setCard} />
</div>
<div className='cell medium-auto'>
<Card ui={this.props.ui}
playerCash={this.props.player.cash}
playerDebt={this.props.player.debt}
card={this.state.card}
cost={this.state.card.total / 1000}
min={(this.state.card.total * this.props.game.settings.downPayment) / 1000}
max={Math.floor(Math.min(this.props.player.cash / 1000, this.state.card.total / 1000))}
cash={(this.state.card.total * this.props.game.settings.downPayment) / 1000} />
</div>
<Col width="12">
<div>
<CardList ui={this.props.ui} cardId={this.state.card.id}
setCard={this.setCard} />
</div>
<div>
<Card ui={this.props.ui}
setCardError={this.props.setCardError}
playerCash={this.props.player.cash}
playerDebt={this.props.player.debt}
card={this.state.card}
cost={this.state.card.total / 1000}
min={(this.state.card.total * this.props.game.settings.downPayment) / 1000}
max={Math.floor(Math.min(this.props.player.cash / 1000, this.state.card.total / 1000))}
cash={(this.state.card.total * this.props.game.settings.downPayment) / 1000} />
</div>
</Col>
</Row>
</div>
<div className={this.tabClass(SCREENS.loans)}>
@ -1730,7 +1733,7 @@ class BoardApp extends React.Component {
export default connect(
state => state.farm,
{ setMessagePanelSpace, setMPDims, nextUIAction, movePlayer, alert, alertHandled }
{ setMessagePanelSpace, setMPDims, nextUIAction, movePlayer, alert, alertHandled, setCardError }
)(BoardApp)
class Card extends React.Component {
@ -1755,6 +1758,7 @@ class Card extends React.Component {
parseInt(target.value)), this.props.max);
if (isNaN(value)) { value = this.props.min; }
this.setState({ cash: value });
this.props.setCardError(false);
}
handleSubmit = e => {
@ -1799,6 +1803,13 @@ class Card extends React.Component {
</div>
</Col>
</Row>
{this.props.ui.cardError ? (
<Row>
<Col width="12">
<span className="error">{this.props.ui.cardError}</span>
</Col>
</Row>
) : (<></>)}
</form>
</div>); break;
@ -1831,9 +1842,9 @@ class CardListComp extends React.Component {
cards = ui.cards,
cardOps = cards.map((c, i) =>
(<li key={i} className={c.id == this.props.cardId ? 'card-select-selected' : ''}
onClick={() => this.props.setCard(c)}>
{c.summary}
</li>));
onClick={() => { this.props.setCard(c); this.props.setCardError(false); }}>
{c.summary}
</li>));
return (
<GroupBox title='Cards'>
@ -1847,5 +1858,5 @@ class CardListComp extends React.Component {
const CardList = connect(
null,
{ setSelectedCard }
{ setSelectedCard, setCardError }
)(CardListComp)

@ -21,6 +21,7 @@ export const UPDATE_PLAYER = 'update-player';
export const GAME_STATE = 'game-state';
export const SET_SELECTED_CARD = 'set-selected-card';
export const SET_CARDS = 'set-cards';
export const SET_CARD_ERROR = 'set-card-error';
export const SPACE_PUSH_PLAYER = 'space-push-player';
export const SPACE_CLEAR_PLAYERS = 'space-clear-players';
export const SET_OLD_MESSAGES = 'set-old-messages';

@ -20,13 +20,13 @@ import { UPDATE_GAME, UPDATE_PLAYER, GAME_STATE, SET_SELECTED_CARD, SET_CARDS,
SPACE_PUSH_PLAYER, SPACE_CLEAR_PLAYERS, SET_OLD_MESSAGES, MESSAGE_PANEL_SPACE,
MP_MOUSE, SET_MP_DIMS, MARK_ACTION_CHANGE_HANDLED, SET_NEXT_ACTION,
MOVE_PLAYER, NEXT_UI_ACTION, NEXT_UI_ACTION_SILENT, ALERT, ALERT_HANDLED,
AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE } from './actionTypes.js'
AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE, SET_CARD_ERROR } from './actionTypes.js'
export { updateGame, updatePlayer, gameState, setSelectedCard, setCards,
spacePushPlayer, spaceClearPlayers, setOldMessages, setMessagePanelSpace,
mpMouse, setMPDims, movePlayer, setNextAction, nextUIAction,
markActionChangeHandled, nextUIActionSilent, alert, alertHandled,
autoSkip, message, setHarvestTable }
autoSkip, message, setHarvestTable, setCardError }
function updateGame(update) {
return { type: UPDATE_GAME,
@ -54,6 +54,10 @@ function setCards(cards) {
cards };
}
function setCardError(error) {
return { type: SET_CARD_ERROR, error };
}
function spacePushPlayer(id, player) {
return { type: SPACE_PUSH_PLAYER,
id,

@ -24,7 +24,7 @@ import * as websocket from '../../websocket.js'
import { updateGame, updatePlayer, gameState, setSelectedCard, setCards,
movePlayer, setOldMessages, markActionChangeHandled,
mpMouse, rolled, setNextAction, nextUIAction, nextUIActionSilent, alert,
autoSkip, message, alertHandled, setHarvestTable } from './actions.js'
autoSkip, message, alertHandled, setHarvestTable, setCardError } from './actions.js'
import { itemCard, fateCard } from 'game.js'
export { initialize, buy, roll, endTurn, loan, trade, submitTradeAccept,
@ -63,6 +63,9 @@ function handleMessage(evt) {
store.dispatch(setNextAction(false, false));
store.dispatch(nextUIAction());
}
if (data.event === 'buy' && data.error) {
store.dispatch(setCardError(data.error));
}
store.dispatch(updatePlayer(data.player));
if (data.event === 'init') {
store.dispatch(movePlayer(data.player.space, 0, data.player.color));

@ -21,7 +21,7 @@ import { UPDATE_GAME, UPDATE_PLAYER, GAME_STATE, SET_SELECTED_CARD, SET_CARDS,
SET_OLD_MESSAGES, MESSAGE_PANEL_SPACE, MP_MOUSE,
SET_MP_DIMS, MOVE_PLAYER, SET_NEXT_ACTION, NEXT_UI_ACTION,
MARK_ACTION_CHANGE_HANDLED, NEXT_UI_ACTION_SILENT, ALERT, ALERT_HANDLED,
AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE } from './actionTypes.js'
AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE, SET_CARD_ERROR } from './actionTypes.js'
import { GAME_STATES } from '../../constants.js'
import { spaceContent, corners } from 'game.js'
@ -107,6 +107,7 @@ const initialState = {
},
ui: { card: { type: 'no-card', contents: '', total: 0 },
cards: [],
cardError: false,
action: false,
actionValue: null,
nextAction: false,
@ -140,6 +141,8 @@ export default function(state = initialState, action) {
return { ...state, ui: { ...state.ui, card: action.card }};
case SET_CARDS:
return { ...state, ui: { ...state.ui, cards: action.cards }};
case SET_CARD_ERROR:
return { ...state, ui: { ...state.ui, cardError: action.error }};
case MOVE_PLAYER:
return { ...state, spaces: state.spaces
.map((item, index) => {

@ -375,28 +375,20 @@
(ridges '(ridge1 ridge2 ridge3 ridge4)))
(cond ((and (member unnormalized-crop ridges)
(not (ridge-available? game unnormalized-crop)))
(push-message player (conc "Ridge already leased."))
#f)
"Ridge already leased.")
((> (player-space player) 14)
(push-message player (conc "Crops may only be bought in winter."))
#f)
"Crops may only be bought in winter.")
((> cash-value (player-cash player))
(push-message player (conc "Could not buy " unnormalized-crop ". Not enough cash."))
#f)
(conc "Could not buy " unnormalized-crop ". Not enough cash."))
((< cash-value (* total-cost (game-setting 'down-payment game)))
(push-message player
(conc "Could not buy " unnormalized-crop ". Not enough down payment."))
#f)
((> (- total-cost cash-value) (- (game-setting 'max-debt game) (player-debt player)))
(push-message player
(conc "Could not buy " unnormalized-crop ". Not enough credit."))
#f)
(conc "Could not buy " unnormalized-crop ". Not enough down payment."))
((> (- total-cost cash-value) (max 0 (- (game-setting 'max-debt game) (player-debt player))))
(conc "Could not buy " unnormalized-crop ". Not enough credit."))
((and (eq? unnormalized-crop 'cows)
(= (- (player-asset 'cows player)
(fold + 0 (map cdr (player-ridges player))))
20))
(push-message player (conc "Could not buy " unnormalized-crop " because it would exceed maximum allowed on farm."))
#f)
(conc "Could not buy " unnormalized-crop " because it would exceed maximum allowed on farm."))
(else
(let ((assets (player-assets player)))
(safe-set!
@ -408,7 +400,6 @@
(when (member unnormalized-crop ridges)
(safe-set! (player-ridges player)
(alist-update unnormalized-crop amount (player-ridges player))))
(push-message player (conc "You bought " amount " " crop "."))
#t)))))
(define (make-player-year-rule id rule)
@ -880,26 +871,29 @@
((string=? type "buy")
(let* ((id (alist-ref 'id msg))
(otb (find (lambda (x) (= id (alist-ref 'id x)))
(player-otbs player))))
(when (buy-crop (normalize-crop
(string->symbol (alist-ref 'crop otb)))
(string->symbol (alist-ref 'crop otb))
(alist-ref 'amount otb)
(* (or (and (number? (alist-ref 'cash msg))
(alist-ref 'cash msg))
0)
1000)
player
game)
(safe-set! (game-otbs game)
(append (game-otbs game)
(filter (lambda (x) (= id (alist-ref 'id x)))
(player-otbs player))))
(safe-set! (player-otbs player)
(filter (lambda (x) (not (= id (alist-ref 'id x))))
(player-otbs player)))))
(message-players! game player '() type: "update")
(create-ws-response player "buy" '()))
(player-otbs player)))
(bought-crop (buy-crop (normalize-crop
(string->symbol (alist-ref 'crop otb)))
(string->symbol (alist-ref 'crop otb))
(alist-ref 'amount otb)
(* (or (and (number? (alist-ref 'cash msg))
(alist-ref 'cash msg))
0)
1000)
player
game)))
(if (eq? bought-crop #t)
(begin
(safe-set! (game-otbs game)
(append (game-otbs game)
(filter (lambda (x) (= id (alist-ref 'id x)))
(player-otbs player))))
(safe-set! (player-otbs player)
(filter (lambda (x) (not (= id (alist-ref 'id x))))
(player-otbs player)))
(message-players! game player '() type: "update")
(create-ws-response player "buy" '()))
(create-ws-response player "buy" `((error . ,bought-crop))))))
((string=? type "buy-uncle-bert")
(safe-set! (player-cash player) (- (player-cash player) 10000))
(safe-set! (player-assets player)
@ -1873,7 +1867,6 @@
;; mark spaces
;; support trading farmers fates
;; test tractor/harvester a lot better
;; trade notification keeps popping up
;; you can see how much money you make before you harvest

@ -558,7 +558,7 @@ $tab-margin: 0.3rem;
flex-grow: 2;
}
@include breakpoint(large) {
width: 40rem;
width: 26rem;
}
}
@ -804,3 +804,8 @@ $intro-time: 6s;
bottom: 0;
opacity: 0.5;
right: 4px; }
.error {
font-size: 1.2rem;
color: red;
font-weight: bold }

@ -46,8 +46,7 @@ module.exports = {
chunkFilename: '[id].css',
}),
new CopyPlugin([
{ from: './src/server/farm.scm', to: './farm.scm' },
{ from: './src/server/farm', to: './farm' },
{ from: './src/server/', to: './' },
{ from: './assets/game/', to: './assets/game/' }
]),
new webpack.LoaderOptionsPlugin({

Loading…
Cancel
Save