feat: add money system with income, afford check, spend
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// ==================== 银两系统 ====================
|
||||
|
||||
export function applyDailyIncome(state, amount) {
|
||||
state.money += amount;
|
||||
if (state.money < 0) {
|
||||
state.money = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function canAfford(state, cost) {
|
||||
return state.money >= cost;
|
||||
}
|
||||
|
||||
export function spendMoney(state, amount) {
|
||||
if (!canAfford(state, amount)) {
|
||||
return false;
|
||||
}
|
||||
state.money -= amount;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user