summaryrefslogtreecommitdiffstats
path: root/source/Entities/Player.cpp
diff options
context:
space:
mode:
authorDaniel O'Brien <marmot.daniel@gmail.com>2013-11-15 12:42:09 +0100
committerDaniel O'Brien <marmot.daniel@gmail.com>2013-11-15 12:42:09 +0100
commit1b2e6e74736f975386879aa5eb064df5b2f88dac (patch)
tree4ae0a0e6af71b9b0827ed2858feba251f8d065b3 /source/Entities/Player.cpp
parentMerge remote-tracking branch 'upstream/master' into playerxp (diff)
downloadcuberite-1b2e6e74736f975386879aa5eb064df5b2f88dac.tar
cuberite-1b2e6e74736f975386879aa5eb064df5b2f88dac.tar.gz
cuberite-1b2e6e74736f975386879aa5eb064df5b2f88dac.tar.bz2
cuberite-1b2e6e74736f975386879aa5eb064df5b2f88dac.tar.lz
cuberite-1b2e6e74736f975386879aa5eb064df5b2f88dac.tar.xz
cuberite-1b2e6e74736f975386879aa5eb064df5b2f88dac.tar.zst
cuberite-1b2e6e74736f975386879aa5eb064df5b2f88dac.zip
Diffstat (limited to 'source/Entities/Player.cpp')
-rw-r--r--source/Entities/Player.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp
index f5c28b326..00c2ea76c 100644
--- a/source/Entities/Player.cpp
+++ b/source/Entities/Player.cpp
@@ -262,7 +262,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
-int cPlayer::CalcLevelFromXp(int a_XpTotal)
+short cPlayer::CalcLevelFromXp(short a_XpTotal)
{
//level 0 to 15
if(a_XpTotal <= XP_TO_LEVEL15)
@@ -273,18 +273,18 @@ int cPlayer::CalcLevelFromXp(int a_XpTotal)
//level 30+
if(a_XpTotal > XP_TO_LEVEL30)
{
- return (int) (151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7;
+ return (short) (151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7;
}
//level 16 to 30
- return (int) ( 29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal )))) / 3;
+ return (short) ( 29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal )))) / 3;
}
-int cPlayer::XpForLevel(int a_Level)
+short cPlayer::XpForLevel(short a_Level)
{
//level 0 to 15
if(a_Level <= 15)
@@ -295,18 +295,18 @@ int cPlayer::XpForLevel(int a_Level)
//level 30+
if(a_Level >= 31)
{
- return (int) ( (3.5 * a_Level * a_Level) - (151.5 * a_Level) + 2220 );
+ return (short) ( (3.5 * a_Level * a_Level) - (151.5 * a_Level) + 2220 );
}
//level 16 to 30
- return (int) ( (1.5 * a_Level * a_Level) - (29.5 * a_Level) + 360 );
+ return (short) ( (1.5 * a_Level * a_Level) - (29.5 * a_Level) + 360 );
}
-int cPlayer::XpGetLevel()
+short cPlayer::XpGetLevel()
{
return CalcLevelFromXp(m_XpTotal);
}
@@ -317,8 +317,8 @@ int cPlayer::XpGetLevel()
float cPlayer::XpGetPercentage()
{
- int currentLevel = CalcLevelFromXp(m_XpTotal);
- int currentLevel_XpBase = XpForLevel(currentLevel);
+ short int currentLevel = CalcLevelFromXp(m_XpTotal);
+ short int currentLevel_XpBase = XpForLevel(currentLevel);
return (float)(m_XpTotal - currentLevel_XpBase) /
(float)(XpForLevel(1+currentLevel) - currentLevel_XpBase);
@@ -328,9 +328,9 @@ float cPlayer::XpGetPercentage()
-bool cPlayer::SetExperience(int a_XpTotal)
+bool cPlayer::SetExperience(short int a_XpTotal)
{
- if(!(a_XpTotal >= 0) || (a_XpTotal > (INT_MAX - m_XpTotal)))
+ if(!(a_XpTotal >= 0) || (a_XpTotal > (SHRT_MAX - m_XpTotal)))
{
LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_XpTotal);
return false; //oops, they gave us a dodgey number
@@ -338,6 +338,9 @@ bool cPlayer::SetExperience(int a_XpTotal)
m_XpTotal = a_XpTotal;
+ //send details to client
+ m_ClientHandle->SendSetExperience();
+
return true;
}
@@ -345,7 +348,7 @@ bool cPlayer::SetExperience(int a_XpTotal)
-int cPlayer::AddExperience(int a_Xp_delta)
+short cPlayer::AddExperience(short a_Xp_delta)
{
if(a_Xp_delta < 0)
{
@@ -359,6 +362,9 @@ int cPlayer::AddExperience(int a_Xp_delta)
m_XpTotal += a_Xp_delta;
+ //send details to client
+ m_ClientHandle->SendSetExperience();
+
return m_XpTotal;
}
@@ -1420,7 +1426,7 @@ bool cPlayer::LoadFromDisk()
m_FoodTickTimer = root.get("foodTickTimer", 0).asInt();
m_FoodExhaustionLevel = root.get("foodExhaustion", 0).asDouble();
- SetExperience(root.get("experience", 0).asInt());
+ //SetExperience(root.get("experience", 0).asInt());
m_GameMode = (eGameMode) root.get("gamemode", eGameMode_NotSet).asInt();