summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/Bindings.cpp127
-rw-r--r--source/Bindings.h2
-rw-r--r--source/Entities/Player.cpp41
-rw-r--r--source/Entities/Player.h4
-rw-r--r--source/Protocol/Protocol125.cpp6
-rw-r--r--source/Protocol/Protocol17x.cpp6
6 files changed, 146 insertions, 40 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index be0bbd8af..a03ee37e0 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/16/13 02:20:34.
+** Generated automatically by tolua++-1.0.92 on 11/16/13 21:19:32.
*/
#ifndef __cplusplus
@@ -7650,9 +7650,9 @@ static int tolua_AllToLua_cEntity_IsInvisible00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
-/* method: SetExperience of class cPlayer */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SetExperience00
-static int tolua_AllToLua_cPlayer_SetExperience00(lua_State* tolua_S)
+/* method: SetCurrentExperience of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SetCurrentExperience00
+static int tolua_AllToLua_cPlayer_SetCurrentExperience00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@@ -7668,17 +7668,17 @@ static int tolua_AllToLua_cPlayer_SetExperience00(lua_State* tolua_S)
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
short a_XpTotal = ((short) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetExperience'", NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetCurrentExperience'", NULL);
#endif
{
- bool tolua_ret = (bool) self->SetExperience(a_XpTotal);
+ bool tolua_ret = (bool) self->SetCurrentExperience(a_XpTotal);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'SetExperience'.",&tolua_err);
+ tolua_error(tolua_S,"#ferror in function 'SetCurrentExperience'.",&tolua_err);
return 0;
#endif
}
@@ -7718,9 +7718,75 @@ static int tolua_AllToLua_cPlayer_AddExperience00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
-/* method: XpGetTotal of class cPlayer */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_XpGetTotal00
-static int tolua_AllToLua_cPlayer_XpGetTotal00(lua_State* tolua_S)
+/* method: SpendExperience of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SpendExperience00
+static int tolua_AllToLua_cPlayer_SpendExperience00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
+ short a_Xp_delta = ((short) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SpendExperience'", NULL);
+#endif
+ {
+ short tolua_ret = (short) self->SpendExperience(a_Xp_delta);
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'SpendExperience'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: GetXpLifetimeTotal of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetXpLifetimeTotal00
+static int tolua_AllToLua_cPlayer_GetXpLifetimeTotal00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetXpLifetimeTotal'", NULL);
+#endif
+ {
+ short tolua_ret = (short) self->GetXpLifetimeTotal();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetXpLifetimeTotal'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: GetCurrentXp of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetCurrentXp00
+static int tolua_AllToLua_cPlayer_GetCurrentXp00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@@ -7734,25 +7800,25 @@ static int tolua_AllToLua_cPlayer_XpGetTotal00(lua_State* tolua_S)
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'XpGetTotal'", NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetCurrentXp'", NULL);
#endif
{
- short tolua_ret = (short) self->XpGetTotal();
+ short tolua_ret = (short) self->GetCurrentXp();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'XpGetTotal'.",&tolua_err);
+ tolua_error(tolua_S,"#ferror in function 'GetCurrentXp'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
-/* method: XpGetLevel of class cPlayer */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_XpGetLevel00
-static int tolua_AllToLua_cPlayer_XpGetLevel00(lua_State* tolua_S)
+/* method: GetXpLevel of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetXpLevel00
+static int tolua_AllToLua_cPlayer_GetXpLevel00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@@ -7766,25 +7832,25 @@ static int tolua_AllToLua_cPlayer_XpGetLevel00(lua_State* tolua_S)
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'XpGetLevel'", NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetXpLevel'", NULL);
#endif
{
- short tolua_ret = (short) self->XpGetLevel();
+ short tolua_ret = (short) self->GetXpLevel();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'XpGetLevel'.",&tolua_err);
+ tolua_error(tolua_S,"#ferror in function 'GetXpLevel'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
-/* method: XpGetPercentage of class cPlayer */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_XpGetPercentage00
-static int tolua_AllToLua_cPlayer_XpGetPercentage00(lua_State* tolua_S)
+/* method: GetXpPercentage of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetXpPercentage00
+static int tolua_AllToLua_cPlayer_GetXpPercentage00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@@ -7798,17 +7864,17 @@ static int tolua_AllToLua_cPlayer_XpGetPercentage00(lua_State* tolua_S)
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'XpGetPercentage'", NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetXpPercentage'", NULL);
#endif
{
- float tolua_ret = (float) self->XpGetPercentage();
+ float tolua_ret = (float) self->GetXpPercentage();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'XpGetPercentage'.",&tolua_err);
+ tolua_error(tolua_S,"#ferror in function 'GetXpPercentage'.",&tolua_err);
return 0;
#endif
}
@@ -30417,11 +30483,14 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_constant(tolua_S,"EATING_TICKS",cPlayer::EATING_TICKS);
tolua_constant(tolua_S,"MAX_AIR_LEVEL",cPlayer::MAX_AIR_LEVEL);
tolua_constant(tolua_S,"DROWNING_TICKS",cPlayer::DROWNING_TICKS);
- tolua_function(tolua_S,"SetExperience",tolua_AllToLua_cPlayer_SetExperience00);
+ tolua_constant(tolua_S,"MIN_EXPERIENCE",cPlayer::MIN_EXPERIENCE);
+ tolua_function(tolua_S,"SetCurrentExperience",tolua_AllToLua_cPlayer_SetCurrentExperience00);
tolua_function(tolua_S,"AddExperience",tolua_AllToLua_cPlayer_AddExperience00);
- tolua_function(tolua_S,"XpGetTotal",tolua_AllToLua_cPlayer_XpGetTotal00);
- tolua_function(tolua_S,"XpGetLevel",tolua_AllToLua_cPlayer_XpGetLevel00);
- tolua_function(tolua_S,"XpGetPercentage",tolua_AllToLua_cPlayer_XpGetPercentage00);
+ tolua_function(tolua_S,"SpendExperience",tolua_AllToLua_cPlayer_SpendExperience00);
+ tolua_function(tolua_S,"GetXpLifetimeTotal",tolua_AllToLua_cPlayer_GetXpLifetimeTotal00);
+ tolua_function(tolua_S,"GetCurrentXp",tolua_AllToLua_cPlayer_GetCurrentXp00);
+ tolua_function(tolua_S,"GetXpLevel",tolua_AllToLua_cPlayer_GetXpLevel00);
+ tolua_function(tolua_S,"GetXpPercentage",tolua_AllToLua_cPlayer_GetXpPercentage00);
tolua_function(tolua_S,"GetEyeHeight",tolua_AllToLua_cPlayer_GetEyeHeight00);
tolua_function(tolua_S,"GetEyePosition",tolua_AllToLua_cPlayer_GetEyePosition00);
tolua_function(tolua_S,"IsOnGround",tolua_AllToLua_cPlayer_IsOnGround00);
diff --git a/source/Bindings.h b/source/Bindings.h
index 42c158096..fd1ac3242 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/16/13 02:20:35.
+** Generated automatically by tolua++-1.0.92 on 11/16/13 21:19:33.
*/
/* Exported function */
diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp
index 891506802..e8fc795d7 100644
--- a/source/Entities/Player.cpp
+++ b/source/Entities/Player.cpp
@@ -66,8 +66,9 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
, m_EatingFinishTick(-1)
, m_IsChargingBow(false)
, m_BowCharge(0)
- , m_XpTotal(0)
- , m_IsExperienceDirty(false)
+ , m_CurrentXp(0)
+ , m_LifetimeTotalXp(0)
+ , m_bDirtyExperience(false)
{
LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d",
a_PlayerName.c_str(), a_Client->GetIPString().c_str(),
@@ -383,6 +384,31 @@ short cPlayer::AddExperience(short a_Xp_delta)
+short cPlayer::SpendExperience(short a_Xp_delta)
+{
+ if(a_Xp_delta < 0)
+ {
+ // Value was negative, abort and report
+ LOGWARNING("Attempt was made to decrement Xp by %d, must be positive",
+ a_Xp_delta);
+ return -1; // Should we instead just return the current Xp?
+ }
+
+ m_CurrentXp -= a_Xp_delta;
+
+ LOGD("Player \"%s\" spent %d experience, total is now: %d",
+ m_PlayerName.c_str(), a_Xp_delta, m_XpTotal);
+
+ // Set experience to be updated
+ m_bDirtyExperience = true;
+
+ return m_CurrentXp;
+}
+
+
+
+
+
void cPlayer::StartChargingBow(void)
{
LOGD("Player \"%s\" started charging their bow", m_PlayerName.c_str());
@@ -791,6 +817,11 @@ void cPlayer::Respawn(void)
m_FoodLevel = MAX_FOOD_LEVEL;
m_FoodSaturationLevel = 5;
+ // Reset Experience
+ m_CurrentXp = MIN_EXPERIENCE;
+ m_LifetimeTotalXp = MIN_EXPERIENCE;
+ // ToDo: send score to client? How?
+
m_ClientHandle->SendRespawn();
// Extinguish the fire:
@@ -1449,7 +1480,8 @@ bool cPlayer::LoadFromDisk()
m_FoodSaturationLevel = root.get("foodSaturation", MAX_FOOD_LEVEL).asDouble();
m_FoodTickTimer = root.get("foodTickTimer", 0).asInt();
m_FoodExhaustionLevel = root.get("foodExhaustion", 0).asDouble();
- m_XpTotal = (short) root.get("experience", 0).asInt();
+ m_LifetimeTotalXp = (short) root.get("xpTotal", 0).asInt();
+ m_CurrentXp = (short) root.get("xpCurrent", 0).asInt();
//SetExperience(root.get("experience", 0).asInt());
@@ -1493,7 +1525,8 @@ bool cPlayer::SaveToDisk()
root["rotation"] = JSON_PlayerRotation;
root["inventory"] = JSON_Inventory;
root["health"] = m_Health;
- root["experience"] = m_XpTotal;
+ root["xpTotal"] = m_LifetimeTotalXp;
+ root["xpCurrent"] = m_CurrentXp;
root["air"] = m_AirLevel;
root["food"] = m_FoodLevel;
root["foodSaturation"] = m_FoodSaturationLevel;
diff --git a/source/Entities/Player.h b/source/Entities/Player.h
index 2fc0d5ac9..01a864149 100644
--- a/source/Entities/Player.h
+++ b/source/Entities/Player.h
@@ -32,6 +32,7 @@ public:
EATING_TICKS = 30, ///< Number of ticks it takes to eat an item
MAX_AIR_LEVEL = 300,
DROWNING_TICKS = 10, //number of ticks per heart of damage
+ MIN_EXPERIENCE = 0,
} ;
// tolua_end
@@ -78,6 +79,9 @@ public:
*/
short AddExperience(short a_Xp_delta);
+ /// "Spend" some experience - ie on enchanting, returns new currentXp
+ short SpendExperience(short a_Xp_delta);
+
/// Gets the experience total - XpTotal for score on death
inline short GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; }
diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp
index c2dc1c9ce..54be65b12 100644
--- a/source/Protocol/Protocol125.cpp
+++ b/source/Protocol/Protocol125.cpp
@@ -695,9 +695,9 @@ void cProtocol125::SendExperience(void)
{
cCSLock Lock(m_CSPacket);
WriteByte (PACKET_EXPERIENCE);
- WriteFloat (m_Client->GetPlayer()->XpGetPercentage());
- WriteShort (m_Client->GetPlayer()->XpGetLevel());
- WriteShort (m_Client->GetPlayer()->XpGetTotal());
+ WriteFloat (m_Client->GetPlayer()->GetXpPercentage());
+ WriteShort (m_Client->GetPlayer()->GetXpLevel());
+ WriteShort (m_Client->GetPlayer()->GetCurrentXp());
Flush();
}
diff --git a/source/Protocol/Protocol17x.cpp b/source/Protocol/Protocol17x.cpp
index 7ff2b54b1..ae1df7395 100644
--- a/source/Protocol/Protocol17x.cpp
+++ b/source/Protocol/Protocol17x.cpp
@@ -600,9 +600,9 @@ void cProtocol172::SendRespawn(void)
void cProtocol172::SendExperience (void)
{
cPacketizer Pkt(*this, 0x1F); //Experience Packet
- Pkt.WriteFloat(m_Client->GetPlayer()->XpGetPercentage());
- Pkt.WriteShort(m_Client->GetPlayer()->XpGetLevel());
- Pkt.WriteShort(m_Client->GetPlayer()->XpGetTotal());
+ Pkt.WriteFloat(m_Client->GetPlayer()->GetXpPercentage());
+ Pkt.WriteShort(m_Client->GetPlayer()->GetXpLevel());
+ Pkt.WriteShort(m_Client->GetPlayer()->GetCurrentXp());
}