Emergency loan support.
This commit is contained in:
@@ -550,6 +550,11 @@ class Loans extends React.Component {
|
|||||||
this.setState({ repay: 0, takeOut: 0 });
|
this.setState({ repay: 0, takeOut: 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleEmergencyLoan = e => {
|
||||||
|
e.preventDefault();
|
||||||
|
loan(1);
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (this.props.player.debt !== prevProps.player.debt ||
|
if (this.props.player.debt !== prevProps.player.debt ||
|
||||||
this.props.game.settings.loanInterest !== prevProps.game.settings.loanInterest ||
|
this.props.game.settings.loanInterest !== prevProps.game.settings.loanInterest ||
|
||||||
@@ -559,44 +564,48 @@ class Loans extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<GroupBox title={'Loans'}>
|
<GroupBox title={'Loans'}>
|
||||||
<MoneySummary title='Cash' value={this.props.player.cash} /> {' '}
|
<MoneySummary title='Cash' value={this.props.player.cash} /> {' '}
|
||||||
<MoneySummary title='Debt' value={this.props.player.debt} />
|
<MoneySummary title='Debt' value={this.props.player.debt} />
|
||||||
/${formatMoney(this.props.game.settings.maxDebt)}
|
/${formatMoney(this.props.game.settings.maxDebt)}
|
||||||
<br />
|
<br />
|
||||||
{this.props.game.settings.loanInterest > 0 ? '(' + (this.props.game.settings.loanInterest * 100) + '% interest added to each loan)' : ''}
|
{this.props.game.settings.loanInterest > 0 ? '(' + (this.props.game.settings.loanInterest * 100) + '% interest added to each loan)' : ''}
|
||||||
<br /><br />
|
<br />
|
||||||
<form onSubmit={this.handleSubmit}>
|
{this.props.player.debt >= this.props.game.settings.maxDebt ? (
|
||||||
<Row collapse='true'>
|
<><Button onClick={this.handleEmergencyLoan}>Emergency Loan</Button> $1,000 at 100% interest</>
|
||||||
<Col width='8'>
|
) : (<></>)}
|
||||||
<div className='money'>
|
<br />
|
||||||
$:
|
<form onSubmit={this.handleSubmit}>
|
||||||
<input onChange={this.handleInput} name='repay' type='number'
|
<Row collapse='true'>
|
||||||
value={this.state.repay === 0 ? '' : this.state.repay}/>
|
<Col width='8'>
|
||||||
{'\u00A0'}K / ${this.props.player.debt / 1000}K
|
<div className='money'>
|
||||||
</div>
|
$:
|
||||||
</Col>
|
<input onChange={this.handleInput} name='repay' type='number'
|
||||||
<Col width='4'>
|
value={this.state.repay === 0 ? '' : this.state.repay}/>
|
||||||
<Button className='tiny' type='submit'>Repay</Button>
|
{'\u00A0'}K / ${this.props.player.debt / 1000}K
|
||||||
</Col>
|
</div>
|
||||||
</Row>
|
</Col>
|
||||||
<Row collapse='true'>
|
<Col width='4'>
|
||||||
<Col width='8'>
|
<Button className='tiny' type='submit'>Repay</Button>
|
||||||
<div className='money'>
|
</Col>
|
||||||
$:
|
</Row>
|
||||||
<input onChange={this.handleInput} name='takeOut' type='number'
|
<Row collapse='true'>
|
||||||
value={this.state.takeOut === 0 ? '' : this.state.takeOut} />
|
<Col width='8'>
|
||||||
{'\u00A0'}K / ${this.state.maxLoan / 1000}K
|
<div className='money'>
|
||||||
</div>
|
$:
|
||||||
</Col>
|
<input onChange={this.handleInput} name='takeOut' type='number'
|
||||||
<Col width='4'>
|
value={this.state.takeOut === 0 ? '' : this.state.takeOut} />
|
||||||
<Button className='tiny' type='submit'>Take Out</Button>
|
{'\u00A0'}K / ${this.state.maxLoan / 1000}K
|
||||||
</Col>
|
</div>
|
||||||
</Row>
|
</Col>
|
||||||
</form>
|
<Col width='4'>
|
||||||
</GroupBox>
|
<Button className='tiny' type='submit'>Take Out</Button>
|
||||||
);
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</form>
|
||||||
|
</GroupBox>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -901,12 +901,12 @@
|
|||||||
(if (> (+ (player-debt player)
|
(if (> (+ (player-debt player)
|
||||||
(farming-round (+ amount (* amount (game-setting 'loan-interest game)))))
|
(farming-round (+ amount (* amount (game-setting 'loan-interest game)))))
|
||||||
(game-setting 'max-debt game))
|
(game-setting 'max-debt game))
|
||||||
(push-message player "Exceeds max loan.")
|
(begin (safe-set! (player-cash player) (+ (player-cash player) amount))
|
||||||
|
(safe-set! (player-debt player) (+ (player-debt player) (* amount 2))))
|
||||||
(begin (safe-set! (player-cash player) (+ (player-cash player) amount))
|
(begin (safe-set! (player-cash player) (+ (player-cash player) amount))
|
||||||
(safe-set! (player-debt player) (+ (player-debt player)
|
(safe-set! (player-debt player) (+ (player-debt player)
|
||||||
(farming-round
|
(farming-round
|
||||||
(+ amount (* amount (game-setting 'loan-interest game))))))
|
(+ amount (* amount (game-setting 'loan-interest game))))))))
|
||||||
(push-message player (conc "Loan of $" amount " taken out."))))
|
|
||||||
;; repaying loan
|
;; repaying loan
|
||||||
(cond ((> (abs amount) (player-cash player))
|
(cond ((> (abs amount) (player-cash player))
|
||||||
(push-message player "Not enough cash to repay loan."))
|
(push-message player "Not enough cash to repay loan."))
|
||||||
|
|||||||
Reference in New Issue
Block a user