summaryrefslogtreecommitdiffstats
path: root/sigencore/Player.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sigencore/Player.cpp')
-rw-r--r--sigencore/Player.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/sigencore/Player.cpp b/sigencore/Player.cpp
index f2b8460a..b289018a 100644
--- a/sigencore/Player.cpp
+++ b/sigencore/Player.cpp
@@ -62,9 +62,20 @@ void Sigencore::Player::giveMoney(const int amount)
m_money = qMax(m_sigmod->rules()->maxMoney(), m_money + amount);
}
-void Sigencore::Player::takeMoney(const int amount)
+bool Sigencore::Player::giveMoney(const int amount, const bool allOrNothing)
{
- m_money = qMin(0, m_money - amount);
+ int playerMin = 0;
+ int playerMax = m_sigmod->rules()->maxMoney();
+ valueOfType("money-minimum", &playerMin);
+ valueOfType("money-maximum", &playerMax);
+ const int newUnbounded = m_money + amount;
+ const int newAmount = qMin(qMax(0, playerMin), qMax(playerMax, newAmount));
+ if (allOrNothing || (newUnbounded == newAmount))
+ {
+ m_money = newAmount;
+ emit(moneyChanged(m_money));
+ }
+ return qAbs(newUnbounded - newAmount);
}
Sigencore::TeamMember* Sigencore::Player::findMember(const QUuid& id) const