From ea778c70278aa4032565c1c7a450f345a38c1105 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Fri, 15 Nov 2013 01:46:41 +1100 Subject: fixed XpGetPercentage --- source/Entities/Player.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 098417dc5..f5c28b326 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -318,8 +318,10 @@ int cPlayer::XpGetLevel() float cPlayer::XpGetPercentage() { int currentLevel = CalcLevelFromXp(m_XpTotal); + int currentLevel_XpBase = XpForLevel(currentLevel); - return (float)m_XpTotal / (float)XpForLevel(1+currentLevel); + return (float)(m_XpTotal - currentLevel_XpBase) / + (float)(XpForLevel(1+currentLevel) - currentLevel_XpBase); } -- cgit v1.2.3 From f6e16ce15082d867ed182690e3a80435cf60dc84 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Fri, 15 Nov 2013 08:35:02 +1100 Subject: cProtocol add SendExperience() and debugging --- source/Protocol/Protocol.h | 3 ++- source/Protocol/Protocol125.cpp | 15 +++++++++++++++ source/Protocol/Protocol125.h | 1 + source/Protocol/Protocol17x.cpp | 12 ++++++++++++ source/Protocol/Protocol17x.h | 1 + source/Protocol/ProtocolRecognizer.cpp | 10 ++++++++++ source/Protocol/ProtocolRecognizer.h | 1 + 7 files changed, 42 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index 5023ea227..c00c3cad4 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -22,9 +22,9 @@ class cWindow; class cInventory; class cPawn; class cPickup; +class cWorld; class cMonster; class cChunkDataSerializer; -class cWorld; class cFallingBlock; @@ -85,6 +85,7 @@ public: virtual void SendPlayerPosition (void) = 0; virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; virtual void SendRespawn (void) = 0; + virtual void SendSetExperience (void) = 0; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) = 0; // a_Src coords are Block * 8 virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) = 0; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0; diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 9f2770815..08a2b8656 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -72,6 +72,7 @@ enum PACKET_ENT_STATUS = 0x26, PACKET_ATTACH_ENTITY = 0x27, PACKET_METADATA = 0x28, + PACKET_EXPERIENCE = 0x2b, PACKET_PRE_CHUNK = 0x32, PACKET_MAP_CHUNK = 0x33, PACKET_MULTI_BLOCK = 0x34, @@ -690,6 +691,20 @@ void cProtocol125::SendRespawn(void) +void cProtocol125::SendSetExperience(void) +{ + cCSLock Lock(m_CSPacket); + WriteByte (PACKET_EXPERIENCE); + WriteFloat (m_Client->GetPlayer()->XpGetPercentage()); + WriteShort (m_Client->GetPlayer()->XpGetLevel()); + WriteShort (m_Client->GetPlayer()->XpGetTotal()); + Flush(); +} + + + + + void cProtocol125::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) { // Not needed in this protocol version diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index db913bb57..48309a961 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -62,6 +62,7 @@ public: virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendRespawn (void) override; + virtual void SendSetExperience (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; diff --git a/source/Protocol/Protocol17x.cpp b/source/Protocol/Protocol17x.cpp index 628b8e071..b14c52cba 100644 --- a/source/Protocol/Protocol17x.cpp +++ b/source/Protocol/Protocol17x.cpp @@ -597,6 +597,18 @@ void cProtocol172::SendRespawn(void) +void cProtocol172::SendSetExperience (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()); +} + + + + + void cProtocol172::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) // a_Src coords are Block * 8 { cPacketizer Pkt(*this, 0x29); // Sound Effect packet diff --git a/source/Protocol/Protocol17x.h b/source/Protocol/Protocol17x.h index 844069403..99ae3a087 100644 --- a/source/Protocol/Protocol17x.h +++ b/source/Protocol/Protocol17x.h @@ -72,6 +72,7 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendRespawn (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 + virtual void SendSetExperience (void) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp index 9234785b5..283c20811 100644 --- a/source/Protocol/ProtocolRecognizer.cpp +++ b/source/Protocol/ProtocolRecognizer.cpp @@ -466,6 +466,16 @@ void cProtocolRecognizer::SendRespawn(void) +void cProtocolRecognizer::SendSetExperience(void) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendSetExperience(); +} + + + + + void cProtocolRecognizer::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) { ASSERT(m_Protocol != NULL); diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index c085e2cd8..a32772282 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -97,6 +97,7 @@ public: virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendRespawn (void) override; + virtual void SendSetExperience (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; -- cgit v1.2.3 From 1b2e6e74736f975386879aa5eb064df5b2f88dac Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Fri, 15 Nov 2013 22:42:09 +1100 Subject: added cProtocol function to pass xp to client --- source/Bindings.cpp | 12 ++++++------ source/Bindings.h | 2 +- source/ClientHandle.cpp | 9 +++++++++ source/ClientHandle.h | 1 + source/Entities/Player.cpp | 32 +++++++++++++++++++------------- source/Entities/Player.h | 14 +++++++------- 6 files changed, 43 insertions(+), 27 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index c7f6ada19..cc892a70f 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/14/13 17:13:46. +** Generated automatically by tolua++-1.0.92 on 11/15/13 18:43:44. */ #ifndef __cplusplus @@ -7708,7 +7708,7 @@ static int tolua_AllToLua_cPlayer_SetExperience00(lua_State* tolua_S) #endif { cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); - int a_XpTotal = ((int) tolua_tonumber(tolua_S,2,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); #endif @@ -7742,12 +7742,12 @@ static int tolua_AllToLua_cPlayer_AddExperience00(lua_State* tolua_S) #endif { cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); - int a_Xp_delta = ((int) tolua_tonumber(tolua_S,2,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 'AddExperience'", NULL); #endif { - int tolua_ret = (int) self->AddExperience(a_Xp_delta); + short tolua_ret = (short) self->AddExperience(a_Xp_delta); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } @@ -7779,7 +7779,7 @@ static int tolua_AllToLua_cPlayer_XpGetTotal00(lua_State* tolua_S) if (!self) tolua_error(tolua_S,"invalid 'self' in function 'XpGetTotal'", NULL); #endif { - int tolua_ret = (int) self->XpGetTotal(); + short tolua_ret = (short) self->XpGetTotal(); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } @@ -7811,7 +7811,7 @@ static int tolua_AllToLua_cPlayer_XpGetLevel00(lua_State* tolua_S) if (!self) tolua_error(tolua_S,"invalid 'self' in function 'XpGetLevel'", NULL); #endif { - int tolua_ret = (int) self->XpGetLevel(); + short tolua_ret = (short) self->XpGetLevel(); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } diff --git a/source/Bindings.h b/source/Bindings.h index eb6c566a7..b17fd02ae 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/14/13 17:13:47. +** Generated automatically by tolua++-1.0.92 on 11/15/13 18:43:45. */ /* Exported function */ diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index f8fd4a8b7..73852b886 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -1873,6 +1873,15 @@ void cClientHandle::SendRespawn(void) +void cClientHandle::SendSetExperience(void) +{ + m_Protocol->SendSetExperience(); +} + + + + + void cClientHandle::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) { m_Protocol->SendSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch); diff --git a/source/ClientHandle.h b/source/ClientHandle.h index 3844937ad..4b37d39b5 100644 --- a/source/ClientHandle.h +++ b/source/ClientHandle.h @@ -120,6 +120,7 @@ public: void SendPlayerPosition (void); void SendPlayerSpawn (const cPlayer & a_Player); void SendRespawn (void); + void SendSetExperience (void); void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch); // a_Src coords are Block * 8 void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data); void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock); 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(); diff --git a/source/Entities/Player.h b/source/Entities/Player.h index ab2f94d4c..1e43dd954 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -71,18 +71,18 @@ public: Returns true on success "should" really only be called at init or player death, plugins excepted */ - bool SetExperience(int a_XpTotal); + bool SetExperience(short a_XpTotal); /* Adds Xp, "should" not inc more than MAX_EXPERIENCE_ORB_SIZE unless you're a plugin being funny, *cough* cheating Returns the new total experience, -1 on error */ - int AddExperience(int a_Xp_delta); + short AddExperience(short a_Xp_delta); /// Gets the experience total - XpTotal - inline int XpGetTotal(void) { return m_XpTotal; } + inline short XpGetTotal(void) { return m_XpTotal; } /// Gets the current level - XpLevel - int XpGetLevel(void); + short XpGetLevel(void); /// Gets the experience bar percentage - XpP float XpGetPercentage(void); @@ -413,13 +413,13 @@ protected: Int64 m_EatingFinishTick; /// Player Xp level - int m_XpTotal; + short int m_XpTotal; /// Caculates the Xp needed for a given level, ref: http://minecraft.gamepedia.com/XP - static int XpForLevel(int a_Level); + static short XpForLevel(short int a_Level); /// inverse of XpAtLevel, ref: http://minecraft.gamepedia.com/XP values are as per this with pre-calculations - static int CalcLevelFromXp(int a_XpTotal); + static short CalcLevelFromXp(short int a_XpTotal); bool m_IsChargingBow; int m_BowCharge; -- cgit v1.2.3 From 04dff4882a3d75f3a0d432fb3377cc3f59fdf251 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Sat, 16 Nov 2013 02:23:50 +1100 Subject: finished #143 I believe --- source/Bindings.cpp | 2 +- source/Bindings.h | 2 +- source/ClientHandle.cpp | 7 +++++-- source/ClientHandle.h | 2 +- source/Entities/Player.cpp | 19 ++++++++++++++++--- source/Entities/Player.h | 2 ++ source/Protocol/Protocol.h | 2 +- source/Protocol/Protocol125.cpp | 2 +- source/Protocol/Protocol125.h | 2 +- source/Protocol/Protocol17x.cpp | 2 +- source/Protocol/Protocol17x.h | 2 +- source/Protocol/ProtocolRecognizer.cpp | 4 ++-- source/Protocol/ProtocolRecognizer.h | 2 +- 13 files changed, 34 insertions(+), 16 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index a2dcc58c6..be0bbd8af 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/15/13 10:14:19. +** Generated automatically by tolua++-1.0.92 on 11/16/13 02:20:34. */ #ifndef __cplusplus diff --git a/source/Bindings.h b/source/Bindings.h index 13f398a4d..42c158096 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/15/13 10:14:20. +** Generated automatically by tolua++-1.0.92 on 11/16/13 02:20:35. */ /* Exported function */ diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index 73852b886..daf09d4ea 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -260,6 +260,9 @@ void cClientHandle::Authenticate(void) // Send health m_Player->SendHealth(); + + // Send experience + m_Player->SendExperience(); // Send gamemode (1.6.1 movementSpeed): SendGameMode(m_Player->GetGameMode()); @@ -1873,9 +1876,9 @@ void cClientHandle::SendRespawn(void) -void cClientHandle::SendSetExperience(void) +void cClientHandle::SendExperience(void) { - m_Protocol->SendSetExperience(); + m_Protocol->SendExperience(); } diff --git a/source/ClientHandle.h b/source/ClientHandle.h index 4b37d39b5..d3e257aee 100644 --- a/source/ClientHandle.h +++ b/source/ClientHandle.h @@ -120,7 +120,7 @@ public: void SendPlayerPosition (void); void SendPlayerSpawn (const cPlayer & a_Player); void SendRespawn (void); - void SendSetExperience (void); + void SendExperience (void); void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch); // a_Src coords are Block * 8 void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data); void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock); diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 00c2ea76c..651a0b2a6 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -339,7 +339,7 @@ bool cPlayer::SetExperience(short int a_XpTotal) m_XpTotal = a_XpTotal; //send details to client - m_ClientHandle->SendSetExperience(); + SendExperience(); return true; } @@ -363,7 +363,7 @@ short cPlayer::AddExperience(short a_Xp_delta) m_XpTotal += a_Xp_delta; //send details to client - m_ClientHandle->SendSetExperience(); + SendExperience(); return m_XpTotal; } @@ -615,6 +615,18 @@ void cPlayer::SendHealth(void) +void cPlayer::SendExperience(void) +{ + if (m_ClientHandle != NULL) + { + m_ClientHandle->SendExperience(); + } +} + + + + + void cPlayer::ClearInventoryPaintSlots(void) { // Clear the list of slots that are being inventory-painted. Used by cWindow only @@ -1419,12 +1431,13 @@ bool cPlayer::LoadFromDisk() SetRoll ((float)JSON_PlayerRotation[(unsigned int)2].asDouble()); } - m_Health = root.get("health", 0).asInt(); + m_Health = root.get("health", 0).asInt(); m_AirLevel = root.get("air", MAX_AIR_LEVEL).asInt(); m_FoodLevel = root.get("food", MAX_FOOD_LEVEL).asInt(); 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 = root.get("experience", 0).asInt(); //SetExperience(root.get("experience", 0).asInt()); diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 1e43dd954..aeec9f361 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -269,6 +269,8 @@ public: void UseEquippedItem(void); void SendHealth(void); + + void SendExperience(void); // In UI windows, the item that the player is dragging: bool IsDraggingItem(void) const { return !m_DraggingItem.IsEmpty(); } diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index c00c3cad4..98eeec789 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -85,7 +85,7 @@ public: virtual void SendPlayerPosition (void) = 0; virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; virtual void SendRespawn (void) = 0; - virtual void SendSetExperience (void) = 0; + virtual void SendExperience (void) = 0; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) = 0; // a_Src coords are Block * 8 virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) = 0; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0; diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 08a2b8656..c2dc1c9ce 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -691,7 +691,7 @@ void cProtocol125::SendRespawn(void) -void cProtocol125::SendSetExperience(void) +void cProtocol125::SendExperience(void) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_EXPERIENCE); diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index 48309a961..cd208eaba 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -62,7 +62,7 @@ public: virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendRespawn (void) override; - virtual void SendSetExperience (void) override; + virtual void SendExperience (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; diff --git a/source/Protocol/Protocol17x.cpp b/source/Protocol/Protocol17x.cpp index b14c52cba..7ff2b54b1 100644 --- a/source/Protocol/Protocol17x.cpp +++ b/source/Protocol/Protocol17x.cpp @@ -597,7 +597,7 @@ void cProtocol172::SendRespawn(void) -void cProtocol172::SendSetExperience (void) +void cProtocol172::SendExperience (void) { cPacketizer Pkt(*this, 0x1F); //Experience Packet Pkt.WriteFloat(m_Client->GetPlayer()->XpGetPercentage()); diff --git a/source/Protocol/Protocol17x.h b/source/Protocol/Protocol17x.h index 99ae3a087..6e8574d98 100644 --- a/source/Protocol/Protocol17x.h +++ b/source/Protocol/Protocol17x.h @@ -72,7 +72,7 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendRespawn (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 - virtual void SendSetExperience (void) override; + virtual void SendExperience (void) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp index 283c20811..64bd83075 100644 --- a/source/Protocol/ProtocolRecognizer.cpp +++ b/source/Protocol/ProtocolRecognizer.cpp @@ -466,10 +466,10 @@ void cProtocolRecognizer::SendRespawn(void) -void cProtocolRecognizer::SendSetExperience(void) +void cProtocolRecognizer::SendExperience(void) { ASSERT(m_Protocol != NULL); - m_Protocol->SendSetExperience(); + m_Protocol->SendExperience(); } diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index a32772282..c2beb2014 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -97,7 +97,7 @@ public: virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendRespawn (void) override; - virtual void SendSetExperience (void) override; + virtual void SendExperience (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; -- cgit v1.2.3 From a94a6d48a0d6121c6951f01a81474e718f045430 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Sat, 16 Nov 2013 02:32:04 +1100 Subject: alignment fixes :) --- source/ClientHandle.h | 2 +- source/Entities/Player.cpp | 2 +- source/Protocol/Protocol.h | 2 +- source/Protocol/Protocol125.h | 2 +- source/Protocol/Protocol17x.h | 2 +- source/Protocol/ProtocolRecognizer.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/ClientHandle.h b/source/ClientHandle.h index d3e257aee..b887bb11a 100644 --- a/source/ClientHandle.h +++ b/source/ClientHandle.h @@ -120,7 +120,7 @@ public: void SendPlayerPosition (void); void SendPlayerSpawn (const cPlayer & a_Player); void SendRespawn (void); - void SendExperience (void); + void SendExperience (void); void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch); // a_Src coords are Block * 8 void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data); void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock); diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 651a0b2a6..f25483375 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -1437,7 +1437,7 @@ 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 = root.get("experience", 0).asInt(); + m_XpTotal = (short) root.get("experience", 0).asInt(); //SetExperience(root.get("experience", 0).asInt()); diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index 98eeec789..542060ece 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -85,7 +85,7 @@ public: virtual void SendPlayerPosition (void) = 0; virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; virtual void SendRespawn (void) = 0; - virtual void SendExperience (void) = 0; + virtual void SendExperience (void) = 0; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) = 0; // a_Src coords are Block * 8 virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) = 0; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0; diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index cd208eaba..c5f44c818 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -62,7 +62,7 @@ public: virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendRespawn (void) override; - virtual void SendExperience (void) override; + virtual void SendExperience (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; diff --git a/source/Protocol/Protocol17x.h b/source/Protocol/Protocol17x.h index 6e8574d98..e3f2ad922 100644 --- a/source/Protocol/Protocol17x.h +++ b/source/Protocol/Protocol17x.h @@ -72,7 +72,7 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendRespawn (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 - virtual void SendExperience (void) override; + virtual void SendExperience (void) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index c2beb2014..03f48fb35 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -97,7 +97,7 @@ public: virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendRespawn (void) override; - virtual void SendExperience (void) override; + virtual void SendExperience (void) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; -- cgit v1.2.3 From c0c8fe1bcd68c35435eafdfd3dbb9793fba970cd Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Sat, 16 Nov 2013 20:29:57 +1100 Subject: fix possible threadlock issue, changed function names to be closer to standard --- source/Entities/Player.cpp | 48 +++++++++++++++++++++++++++++----------------- source/Entities/Player.h | 23 ++++++++++++++-------- 2 files changed, 45 insertions(+), 26 deletions(-) (limited to 'source') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index f25483375..891506802 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -67,6 +67,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_IsChargingBow(false) , m_BowCharge(0) , m_XpTotal(0) + , m_IsExperienceDirty(false) { LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", a_PlayerName.c_str(), a_Client->GetIPString().c_str(), @@ -222,6 +223,12 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) { m_BowCharge += 1; } + + //handle updating experience + if (m_bDirtyExperience) + { + SendExperience(); + } if (m_bDirtyPosition) { @@ -306,21 +313,21 @@ short cPlayer::XpForLevel(short a_Level) -short cPlayer::XpGetLevel() +short cPlayer::GetXpLevel() { - return CalcLevelFromXp(m_XpTotal); + return CalcLevelFromXp(m_CurrentXp); } -float cPlayer::XpGetPercentage() +float cPlayer::GetXpPercentage() { - short int currentLevel = CalcLevelFromXp(m_XpTotal); + short int currentLevel = CalcLevelFromXp(m_CurrentXp); short int currentLevel_XpBase = XpForLevel(currentLevel); - return (float)(m_XpTotal - currentLevel_XpBase) / + return (float)(m_CurrentXp - currentLevel_XpBase) / (float)(XpForLevel(1+currentLevel) - currentLevel_XpBase); } @@ -328,18 +335,18 @@ float cPlayer::XpGetPercentage() -bool cPlayer::SetExperience(short int a_XpTotal) +bool cPlayer::SetCurrentExperience(short int a_XpTotal) { - if(!(a_XpTotal >= 0) || (a_XpTotal > (SHRT_MAX - m_XpTotal))) + if(!(a_XpTotal >= 0) || (a_XpTotal > (SHRT_MAX - m_CurrentXp))) { LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_XpTotal); return false; //oops, they gave us a dodgey number } - m_XpTotal = a_XpTotal; + m_CurrentXp = a_XpTotal; - //send details to client - SendExperience(); + // Set experience to be updated + m_bDirtyExperience = true; return true; } @@ -352,20 +359,24 @@ short cPlayer::AddExperience(short a_Xp_delta) { if(a_Xp_delta < 0) { - //value was negative, abort and report + // Value was negative, abort and report LOGWARNING("Attempt was made to increment Xp by %d, must be positive", a_Xp_delta); - return -1; //should we instead just return the current Xp? + return -1; // Should we instead just return the current Xp? } - - LOGD("Player \"%s\" earnt %d experience", m_PlayerName.c_str(), a_Xp_delta); - m_XpTotal += a_Xp_delta; + m_CurrentXp += a_Xp_delta; + + // Update total for score calculation + m_LifetimeTotalXp += a_Xp_delta; + + LOGD("Player \"%s\" earnt %d experience, total is now: %d", + m_PlayerName.c_str(), a_Xp_delta, m_XpTotal); - //send details to client - SendExperience(); + // Set experience to be updated + m_bDirtyExperience = true; - return m_XpTotal; + return m_CurrentXp; } @@ -620,6 +631,7 @@ void cPlayer::SendExperience(void) if (m_ClientHandle != NULL) { m_ClientHandle->SendExperience(); + m_bDirtyExperience = false; } } diff --git a/source/Entities/Player.h b/source/Entities/Player.h index aeec9f361..2fc0d5ac9 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -71,21 +71,24 @@ public: Returns true on success "should" really only be called at init or player death, plugins excepted */ - bool SetExperience(short a_XpTotal); + bool SetCurrentExperience(short a_XpTotal); /* Adds Xp, "should" not inc more than MAX_EXPERIENCE_ORB_SIZE unless you're a plugin being funny, *cough* cheating - Returns the new total experience, -1 on error + Returns the new current experience, -1 on error */ short AddExperience(short a_Xp_delta); - /// Gets the experience total - XpTotal - inline short XpGetTotal(void) { return m_XpTotal; } + /// Gets the experience total - XpTotal for score on death + inline short GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; } + + /// Gets the currrent experience + inline short GetCurrentXp(void) { return m_CurrentXp; } /// Gets the current level - XpLevel - short XpGetLevel(void); + short GetXpLevel(void); /// Gets the experience bar percentage - XpP - float XpGetPercentage(void); + float GetXpPercentage(void); // tolua_end @@ -415,13 +418,17 @@ protected: Int64 m_EatingFinishTick; /// Player Xp level - short int m_XpTotal; + short int m_LifetimeTotalXp; + short int m_CurrentXp; + + // flag saying we need to send a xp update to client + bool m_bDirtyExperience; /// Caculates the Xp needed for a given level, ref: http://minecraft.gamepedia.com/XP static short XpForLevel(short int a_Level); /// inverse of XpAtLevel, ref: http://minecraft.gamepedia.com/XP values are as per this with pre-calculations - static short CalcLevelFromXp(short int a_XpTotal); + static short CalcLevelFromXp(short int a_XpCurrent); bool m_IsChargingBow; int m_BowCharge; -- cgit v1.2.3 From 359539293782713d47e51775b65ee91fc89994e4 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Sat, 16 Nov 2013 21:38:57 +1100 Subject: fixed bug and added SpendExperience() --- source/Bindings.cpp | 127 +++++++++++++++++++++++++++++++--------- source/Bindings.h | 2 +- source/Entities/Player.cpp | 41 +++++++++++-- source/Entities/Player.h | 4 ++ source/Protocol/Protocol125.cpp | 6 +- source/Protocol/Protocol17x.cpp | 6 +- 6 files changed, 146 insertions(+), 40 deletions(-) (limited to 'source') 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()); } -- cgit v1.2.3 From b72ced31649f8a851ffe60778e8a603bda941dc9 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Sat, 16 Nov 2013 22:00:45 +1100 Subject: removed SpendExperience and changed AddExperience to handle removing Xp --- source/Bindings.cpp | 51 ++++++++-------------------------------------- source/Bindings.h | 2 +- source/Entities/Player.cpp | 37 ++++++++------------------------- source/Entities/Player.h | 7 ++----- 4 files changed, 19 insertions(+), 78 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index a03ee37e0..9fdd28383 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 21:19:32. +** Generated automatically by tolua++-1.0.92 on 11/16/13 21:58:48. */ #ifndef __cplusplus @@ -7684,9 +7684,9 @@ static int tolua_AllToLua_cPlayer_SetCurrentExperience00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: AddExperience of class cPlayer */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_AddExperience00 -static int tolua_AllToLua_cPlayer_AddExperience00(lua_State* tolua_S) +/* method: DeltaExperience of class cPlayer */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_DeltaExperience00 +static int tolua_AllToLua_cPlayer_DeltaExperience00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -7702,51 +7702,17 @@ static int tolua_AllToLua_cPlayer_AddExperience00(lua_State* tolua_S) 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 'AddExperience'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeltaExperience'", NULL); #endif { - short tolua_ret = (short) self->AddExperience(a_Xp_delta); + short tolua_ret = (short) self->DeltaExperience(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 'AddExperience'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* 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); + tolua_error(tolua_S,"#ferror in function 'DeltaExperience'.",&tolua_err); return 0; #endif } @@ -30485,8 +30451,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_constant(tolua_S,"DROWNING_TICKS",cPlayer::DROWNING_TICKS); 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,"SpendExperience",tolua_AllToLua_cPlayer_SpendExperience00); + tolua_function(tolua_S,"DeltaExperience",tolua_AllToLua_cPlayer_DeltaExperience00); 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); diff --git a/source/Bindings.h b/source/Bindings.h index fd1ac3242..996207055 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 21:19:33. +** Generated automatically by tolua++-1.0.92 on 11/16/13 21:58:48. */ /* Exported function */ diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index e8fc795d7..bdcf0aae9 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -338,7 +338,7 @@ float cPlayer::GetXpPercentage() bool cPlayer::SetCurrentExperience(short int a_XpTotal) { - if(!(a_XpTotal >= 0) || (a_XpTotal > (SHRT_MAX - m_CurrentXp))) + if(!(a_XpTotal >= 0) || (a_XpTotal > (SHRT_MAX - m_LifetimeTotalXp))) { LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_XpTotal); return false; //oops, they gave us a dodgey number @@ -356,12 +356,13 @@ bool cPlayer::SetCurrentExperience(short int a_XpTotal) -short cPlayer::AddExperience(short a_Xp_delta) +short cPlayer::DeltaExperience(short a_Xp_delta) { - if(a_Xp_delta < 0) + //ToDo: figure out a better name?... + if(a_Xp_delta > (SHRT_MAX - m_LifetimeTotalXp) || (m_CurrentXp + a_Xp_delta) < MIN_EXPERIENCE) { // Value was negative, abort and report - LOGWARNING("Attempt was made to increment Xp by %d, must be positive", + LOGWARNING("Attempt was made to increment Xp by %d, which was invalid", a_Xp_delta); return -1; // Should we instead just return the current Xp? } @@ -369,34 +370,12 @@ short cPlayer::AddExperience(short a_Xp_delta) m_CurrentXp += a_Xp_delta; // Update total for score calculation - m_LifetimeTotalXp += a_Xp_delta; - - LOGD("Player \"%s\" earnt %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; -} - - - - - -short cPlayer::SpendExperience(short a_Xp_delta) -{ - if(a_Xp_delta < 0) + 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_LifetimeTotalXp += a_Xp_delta; } - m_CurrentXp -= a_Xp_delta; - - LOGD("Player \"%s\" spent %d experience, total is now: %d", + LOGD("Player \"%s\" earnt %d experience, total is now: %d", m_PlayerName.c_str(), a_Xp_delta, m_XpTotal); // Set experience to be updated diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 01a864149..463a6d8dc 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -74,13 +74,10 @@ public: */ bool SetCurrentExperience(short a_XpTotal); - /* Adds Xp, "should" not inc more than MAX_EXPERIENCE_ORB_SIZE unless you're a plugin being funny, *cough* cheating + /* changes Xp by Xp_delta, you "shouldn't" not inc more than MAX_EXPERIENCE_ORB_SIZE Returns the new current experience, -1 on error */ - short AddExperience(short a_Xp_delta); - - /// "Spend" some experience - ie on enchanting, returns new currentXp - short SpendExperience(short a_Xp_delta); + short DeltaExperience(short a_Xp_delta); /// Gets the experience total - XpTotal for score on death inline short GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; } -- cgit v1.2.3 From b3bb34974fddfae6cea9ca59d71f95e32621793d Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Sat, 16 Nov 2013 22:17:46 +1100 Subject: updated plugin again... --- source/Entities/Player.cpp | 8 ++++---- source/Entities/Player.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index bdcf0aae9..38b41fb19 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -336,15 +336,15 @@ float cPlayer::GetXpPercentage() -bool cPlayer::SetCurrentExperience(short int a_XpTotal) +bool cPlayer::SetCurrentExperience(short int a_CurrentXp) { - if(!(a_XpTotal >= 0) || (a_XpTotal > (SHRT_MAX - m_LifetimeTotalXp))) + if(!(a_CurrentXp >= 0) || (a_CurrentXp > (SHRT_MAX - m_LifetimeTotalXp))) { - LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_XpTotal); + LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_CurrentXp); return false; //oops, they gave us a dodgey number } - m_CurrentXp = a_XpTotal; + m_CurrentXp = a_CurrentXp; // Set experience to be updated m_bDirtyExperience = true; diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 463a6d8dc..5abca9899 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -429,7 +429,7 @@ protected: static short XpForLevel(short int a_Level); /// inverse of XpAtLevel, ref: http://minecraft.gamepedia.com/XP values are as per this with pre-calculations - static short CalcLevelFromXp(short int a_XpCurrent); + static short CalcLevelFromXp(short int a_CurrentXp); bool m_IsChargingBow; int m_BowCharge; -- cgit v1.2.3 From d2d8b1d0736c2af002dc3b91f5281fa4d866470f Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Sat, 16 Nov 2013 22:43:42 +1100 Subject: edited comment and changed error behavior of DeltaXp --- source/Entities/Player.cpp | 12 +++++++++--- source/Entities/Player.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'source') 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); -- cgit v1.2.3 From c7f38761ed1cc524e98db754cadb2c6af1578b88 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Sat, 16 Nov 2013 22:46:27 +1100 Subject: removed magic number --- source/Entities/Player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 129d7df56..ccc7b89f1 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -370,9 +370,9 @@ short cPlayer::DeltaExperience(short a_Xp_delta) m_CurrentXp += a_Xp_delta; // Make sure they didn't subtract too much - if(m_CurrentXp < 0) + if(m_CurrentXp < MIN_EXPERIENCE) { - m_CurrentXp = 0; + m_CurrentXp = MIN_EXPERIENCE; } // Update total for score calculation -- cgit v1.2.3 From cd1c4058940c12a88419c1d417ff2534050a0565 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Sun, 17 Nov 2013 00:13:53 +1100 Subject: minor change in LOGD call --- source/Entities/Player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index ccc7b89f1..436ae0cfc 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -381,8 +381,8 @@ short cPlayer::DeltaExperience(short a_Xp_delta) m_LifetimeTotalXp += a_Xp_delta; } - LOGD("Player \"%s\" earnt %d experience, total is now: %d", - m_PlayerName.c_str(), a_Xp_delta, m_XpTotal); + LOGD("Player \"%s\" gained/lost %d experience, total is now: %d", + m_PlayerName.c_str(), a_Xp_delta, m_CurrentXp); // Set experience to be updated m_bDirtyExperience = true; -- cgit v1.2.3