diff options
author | Daniel O'Brien <marmot.daniel@gmail.com> | 2013-11-16 12:43:42 +0100 |
---|---|---|
committer | Daniel O'Brien <marmot.daniel@gmail.com> | 2013-11-16 12:43:42 +0100 |
commit | d2d8b1d0736c2af002dc3b91f5281fa4d866470f (patch) | |
tree | 771ef54d39eae6af463807d27c799421fd1e6d51 | |
parent | updated plugin again... (diff) | |
download | cuberite-d2d8b1d0736c2af002dc3b91f5281fa4d866470f.tar cuberite-d2d8b1d0736c2af002dc3b91f5281fa4d866470f.tar.gz cuberite-d2d8b1d0736c2af002dc3b91f5281fa4d866470f.tar.bz2 cuberite-d2d8b1d0736c2af002dc3b91f5281fa4d866470f.tar.lz cuberite-d2d8b1d0736c2af002dc3b91f5281fa4d866470f.tar.xz cuberite-d2d8b1d0736c2af002dc3b91f5281fa4d866470f.tar.zst cuberite-d2d8b1d0736c2af002dc3b91f5281fa4d866470f.zip |
-rw-r--r-- | source/Entities/Player.cpp | 12 | ||||
-rw-r--r-- | source/Entities/Player.h | 3 |
2 files changed, 11 insertions, 4 deletions
diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 38b41fb19..129d7df56 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -359,16 +359,22 @@ bool cPlayer::SetCurrentExperience(short int a_CurrentXp) short cPlayer::DeltaExperience(short a_Xp_delta) { //ToDo: figure out a better name?... - if(a_Xp_delta > (SHRT_MAX - m_LifetimeTotalXp) || (m_CurrentXp + a_Xp_delta) < MIN_EXPERIENCE) + if(a_Xp_delta > (SHRT_MAX - m_LifetimeTotalXp)) { - // Value was negative, abort and report - LOGWARNING("Attempt was made to increment Xp by %d, which was invalid", + // Value was bad, abort and report + LOGWARNING("Attempt was made to increment Xp by %d, which was bad", a_Xp_delta); return -1; // Should we instead just return the current Xp? } m_CurrentXp += a_Xp_delta; + // Make sure they didn't subtract too much + if(m_CurrentXp < 0) + { + m_CurrentXp = 0; + } + // Update total for score calculation if(a_Xp_delta > 0) { diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 5abca9899..bda25715d 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -74,7 +74,8 @@ public: */ bool SetCurrentExperience(short a_XpTotal); - /* changes Xp by Xp_delta, you "shouldn't" not inc more than MAX_EXPERIENCE_ORB_SIZE + /* changes Xp by Xp_delta, you "shouldn't" inc more than MAX_EXPERIENCE_ORB_SIZE + Wont't allow xp to go negative Returns the new current experience, -1 on error */ short DeltaExperience(short a_Xp_delta); |