From 3b47a07bac747be2be5e9f61152faa0a3d6b8044 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Thu, 14 Nov 2013 00:50:47 +1100 Subject: Player Xp --- source/Entities/Player.h | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'source/Entities/Player.h') diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 01efa3681..81552fcf1 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -63,6 +63,27 @@ public: /// Returns the currently equipped boots; empty item if none virtual cItem GetEquippedBoots(void) const override { return m_Inventory.GetEquippedBoots(); } + + /** Sets the experience total - XpTotal, updates XpLevel and XpP as appropriate + Returns true on success + should really only be called at init or player death + */ + bool SetExperience(int a_XpTotal); + + /* Adds Xp, will not inc more than MAX_EXPERIENCE_ORB_SIZE! + Returns true on success + Updates XpLevel and XpP appropriately + */ + bool AddExperience(int a_Xp_delta); + + /// Gets the experience total - XpTotal + inline int GetExperience(void) { return m_XpTotal; } + + /// Gets the current level - XpLevel + inline int GetExperienceLevel(void) { return m_XpLevel; } + + /// Gets the experience bar percentage - XpP + inline float GetExperiencePercentage(void) { return m_XpP; } /// Starts charging the equipped bow void StartChargingBow(void); @@ -289,7 +310,7 @@ public: virtual bool IsSubmerged(void) const{ return m_IsSubmerged; } // tolua_end - + // cEntity overrides: virtual bool IsCrouched (void) const { return m_IsCrouched; } virtual bool IsSprinting(void) const { return m_IsSprinting; } @@ -378,6 +399,27 @@ protected: /// The world tick in which eating will be finished. -1 if not eating Int64 m_EatingFinishTick; + + /// Player Xp levels etc + int m_XpLevel; //store this and m_XpP to save calculating each time + float m_XpP; //between 0 & 1 + int m_XpTotal; + int m_XpNextLevelTotal; //save calculating this often + + //Xp level defines + #define XP_TO_LEVEL15 255 + #define XP_PER_LEVEL_TO15 17 + #define XP_TO_LEVEL30 825 + + /// Caculates the Xp at a given level, ref: http://minecraft.gamepedia.com/XP + inline int XpAtLevel(int level) { return (int) ((level <= 15)? (15*level) : + ((level <= 31)? (1.5*level*level - 29.5*level + 360) : + (3.5*level*level - 151.5*level + 2220))); } + + /// inverse of XpAtLevel, ref: http://minecraft.gamepedia.com/XP values are as per this with pre-calculations + inline int CalcLevelFromXp(int XpTotal) { return (int) ((XpTotal <= XP_TO_LEVEL15)? XpTotal / XP_PER_LEVEL_TO15 : //level 0-15 or... + (XpTotal <= XP_TO_LEVEL30)? ( 29.5 + sqrt( 870.25 - (6 * ( 360 - XpTotal )))) / 3 : //level 15-30 + (151.5 + sqrt( 22952.25 - (14 * (2220 - XpTotal)))) / 7); }//level 30+ bool m_IsChargingBow; int m_BowCharge; -- cgit v1.2.3 From 875bca5fb9ea509c0bac40cb3c874bf0a45db9c8 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Thu, 14 Nov 2013 01:07:24 +1100 Subject: Player Xp, includes get/set and addExperience --- source/Entities/Player.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/Entities/Player.h') diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 81552fcf1..ab8fd3b5a 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -77,7 +77,7 @@ public: bool AddExperience(int a_Xp_delta); /// Gets the experience total - XpTotal - inline int GetExperience(void) { return m_XpTotal; } + inline int GetExperienceTotal(void) { return m_XpTotal; } /// Gets the current level - XpLevel inline int GetExperienceLevel(void) { return m_XpLevel; } -- cgit v1.2.3 From bf2dc38f352b24b4df1b4b1601f234b98c6d7a5b Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Thu, 14 Nov 2013 04:25:47 +1100 Subject: Fixed problems with code style etc --- source/Entities/Player.h | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'source/Entities/Player.h') diff --git a/source/Entities/Player.h b/source/Entities/Player.h index ab8fd3b5a..e0ccaf318 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -64,26 +64,25 @@ public: /// Returns the currently equipped boots; empty item if none virtual cItem GetEquippedBoots(void) const override { return m_Inventory.GetEquippedBoots(); } - /** Sets the experience total - XpTotal, updates XpLevel and XpP as appropriate + /** Sets the experience total Returns true on success should really only be called at init or player death */ bool SetExperience(int a_XpTotal); /* Adds Xp, will not inc more than MAX_EXPERIENCE_ORB_SIZE! - Returns true on success - Updates XpLevel and XpP appropriately + Returns the new total experience, -1 on error */ - bool AddExperience(int a_Xp_delta); + int AddExperience(int a_Xp_delta); /// Gets the experience total - XpTotal inline int GetExperienceTotal(void) { return m_XpTotal; } /// Gets the current level - XpLevel - inline int GetExperienceLevel(void) { return m_XpLevel; } + int GetExperienceLevel(void); /// Gets the experience bar percentage - XpP - inline float GetExperiencePercentage(void) { return m_XpP; } + float GetExperiencePercentage(void); /// Starts charging the equipped bow void StartChargingBow(void); @@ -329,6 +328,14 @@ protected: std::string m_PlayerName; std::string m_LoadedWorldName; + /// Xp Level stuff + enum + { + XP_TO_LEVEL15 = 255, + XP_PER_LEVEL_TO15 = 17, + XP_TO_LEVEL30 = 825 + } ; + /// Player's air level (for swimming) int m_AirLevel; @@ -400,26 +407,14 @@ protected: /// The world tick in which eating will be finished. -1 if not eating Int64 m_EatingFinishTick; - /// Player Xp levels etc - int m_XpLevel; //store this and m_XpP to save calculating each time - float m_XpP; //between 0 & 1 + /// Player Xp level int m_XpTotal; - int m_XpNextLevelTotal; //save calculating this often - - //Xp level defines - #define XP_TO_LEVEL15 255 - #define XP_PER_LEVEL_TO15 17 - #define XP_TO_LEVEL30 825 /// Caculates the Xp at a given level, ref: http://minecraft.gamepedia.com/XP - inline int XpAtLevel(int level) { return (int) ((level <= 15)? (15*level) : - ((level <= 31)? (1.5*level*level - 29.5*level + 360) : - (3.5*level*level - 151.5*level + 2220))); } + static int XpAtLevel(int a_Level); /// inverse of XpAtLevel, ref: http://minecraft.gamepedia.com/XP values are as per this with pre-calculations - inline int CalcLevelFromXp(int XpTotal) { return (int) ((XpTotal <= XP_TO_LEVEL15)? XpTotal / XP_PER_LEVEL_TO15 : //level 0-15 or... - (XpTotal <= XP_TO_LEVEL30)? ( 29.5 + sqrt( 870.25 - (6 * ( 360 - XpTotal )))) / 3 : //level 15-30 - (151.5 + sqrt( 22952.25 - (14 * (2220 - XpTotal)))) / 7); }//level 30+ + static int CalcLevelFromXp(int a_XpTotal); bool m_IsChargingBow; int m_BowCharge; -- cgit v1.2.3 From c17f77cf2a6394c833bcc7e83f65e7281f2f32b5 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Thu, 14 Nov 2013 04:41:36 +1100 Subject: changed name convention --- source/Entities/Player.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/Entities/Player.h') diff --git a/source/Entities/Player.h b/source/Entities/Player.h index e0ccaf318..d998c47bb 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -76,13 +76,13 @@ public: int AddExperience(int a_Xp_delta); /// Gets the experience total - XpTotal - inline int GetExperienceTotal(void) { return m_XpTotal; } + inline int XpGetTotal(void) { return m_XpTotal; } /// Gets the current level - XpLevel - int GetExperienceLevel(void); + int XpGetLevel(void); /// Gets the experience bar percentage - XpP - float GetExperiencePercentage(void); + float XpGetPercentage(void); /// Starts charging the equipped bow void StartChargingBow(void); -- cgit v1.2.3 From 8c6bdca425a70fabaee6d3937685314dcaad04a6 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Thu, 14 Nov 2013 07:02:53 +1100 Subject: minor changes --- source/Entities/Player.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/Entities/Player.h') diff --git a/source/Entities/Player.h b/source/Entities/Player.h index d998c47bb..3623617f2 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -70,7 +70,7 @@ public: */ bool SetExperience(int a_XpTotal); - /* Adds Xp, will not inc more than MAX_EXPERIENCE_ORB_SIZE! + /* 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); -- cgit v1.2.3 From b0be6cb02d674ae93ed06354b68f76a01b3c346d Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Thu, 14 Nov 2013 07:07:57 +1100 Subject: changed function name --- source/Entities/Player.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/Entities/Player.h') diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 3623617f2..e89bd3739 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -66,7 +66,7 @@ public: /** Sets the experience total Returns true on success - should really only be called at init or player death + "should" really only be called at init or player death, plugins excepted */ bool SetExperience(int a_XpTotal); @@ -410,8 +410,8 @@ protected: /// Player Xp level int m_XpTotal; - /// Caculates the Xp at a given level, ref: http://minecraft.gamepedia.com/XP - static int XpAtLevel(int a_Level); + /// Caculates the Xp needed for a given level, ref: http://minecraft.gamepedia.com/XP + static int XpForLevel(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); -- cgit v1.2.3 From 21bd1d74a17ac92871b5fa32d4258cb669a5a9a0 Mon Sep 17 00:00:00 2001 From: Daniel O'Brien Date: Thu, 14 Nov 2013 16:20:27 +1100 Subject: luaExport --- source/Entities/Player.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/Entities/Player.h') diff --git a/source/Entities/Player.h b/source/Entities/Player.h index e89bd3739..ab2f94d4c 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -64,6 +64,9 @@ public: /// Returns the currently equipped boots; empty item if none virtual cItem GetEquippedBoots(void) const override { return m_Inventory.GetEquippedBoots(); } + + // tolua_begin + /** Sets the experience total Returns true on success "should" really only be called at init or player death, plugins excepted @@ -83,6 +86,8 @@ public: /// Gets the experience bar percentage - XpP float XpGetPercentage(void); + + // tolua_end /// Starts charging the equipped bow void StartChargingBow(void); -- cgit v1.2.3