diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-02-09 03:35:20 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-02-09 04:25:35 -0500 |
| commit | 0d2d9dccdccfaa13b5977e8b8ab18445d157d2f6 (patch) | |
| tree | e7c64fa031f5cf769282d71c7c7f7a0bfae95a56 | |
| parent | 4357fd55cc601d9f185a163da5c546a27f2c47bf (diff) | |
Fixed money handling in Player to allow for overrides
| -rw-r--r-- | sigencore/Player.cpp | 15 | ||||
| -rw-r--r-- | sigencore/Player.h | 2 |
2 files changed, 14 insertions, 3 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 diff --git a/sigencore/Player.h b/sigencore/Player.h index 2f52ae58..6d4a534b 100644 --- a/sigencore/Player.h +++ b/sigencore/Player.h @@ -55,7 +55,7 @@ class SIGENCORE_EXPORT Player : public Client int giveItems(Sigscript::ItemWrapper* item, const int count, const bool allOrNothing = true); - bool giveMoney(const int amount, const bool ignoreOverflow = true); + bool giveMoney(const int amount, const bool allOrNothing = true); virtual TeamMember::Action requestAction(const TeamMember* teamMember) const = 0; signals: |
