summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2015-03-10 20:05:46 +0100
committerHowaner <franzi.moos@googlemail.com>2015-03-10 20:05:46 +0100
commitab420f6cfc8519fb2ec0caa7fb242517244ffcea (patch)
treec31c3538db081516d81959ed8ad00259175441a9 /src/Entities
parentChanged return type from AbsorbWater() to void. (diff)
parentFixed client kick/crash if many block changes happend (diff)
downloadcuberite-Sponge.tar
cuberite-Sponge.tar.gz
cuberite-Sponge.tar.bz2
cuberite-Sponge.tar.lz
cuberite-Sponge.tar.xz
cuberite-Sponge.tar.zst
cuberite-Sponge.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp22
-rw-r--r--src/Entities/Entity.h3
-rw-r--r--src/Entities/Player.cpp129
-rw-r--r--src/Entities/Player.h38
4 files changed, 110 insertions, 82 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index c51a27961..1bc4690e1 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1632,8 +1632,12 @@ void cEntity::TeleportToEntity(cEntity & a_Entity)
void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
{
- SetPosition(a_PosX, a_PosY, a_PosZ);
- m_World->BroadcastTeleportEntity(*this);
+ // ask the plugins to allow teleport to the new position.
+ if (!cRoot::Get()->GetPluginManager()->CallHookEntityTeleport(*this, m_LastPos, Vector3d(a_PosX, a_PosY, a_PosZ)))
+ {
+ SetPosition(a_PosX, a_PosY, a_PosZ);
+ m_World->BroadcastTeleportEntity(*this);
+ }
}
@@ -1913,10 +1917,7 @@ void cEntity::AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ)
void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ)
{
- m_Speed.x += a_AddSpeedX;
- m_Speed.y += a_AddSpeedY;
- m_Speed.z += a_AddSpeedZ;
- WrapSpeed();
+ DoSetSpeed(m_Speed.x + a_AddSpeedX, m_Speed.y + a_AddSpeedY, m_Speed.z + a_AddSpeedZ);
}
@@ -1925,8 +1926,7 @@ void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeed
void cEntity::AddSpeedX(double a_AddSpeedX)
{
- m_Speed.x += a_AddSpeedX;
- WrapSpeed();
+ AddSpeed(a_AddSpeedX, 0, 0);
}
@@ -1935,8 +1935,7 @@ void cEntity::AddSpeedX(double a_AddSpeedX)
void cEntity::AddSpeedY(double a_AddSpeedY)
{
- m_Speed.y += a_AddSpeedY;
- WrapSpeed();
+ AddSpeed(0, a_AddSpeedY, 0);
}
@@ -1945,8 +1944,7 @@ void cEntity::AddSpeedY(double a_AddSpeedY)
void cEntity::AddSpeedZ(double a_AddSpeedZ)
{
- m_Speed.z += a_AddSpeedZ;
- WrapSpeed();
+ AddSpeed(0, 0, a_AddSpeedZ);
}
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index de9b88dfb..809e974d2 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -443,6 +443,9 @@ public:
/** Set the invulnerable ticks from the entity */
void SetInvulnerableTicks(int a_InvulnerableTicks) { m_InvulnerableTicks = a_InvulnerableTicks; }
+
+ /** Returns whether the entity is on ground or not */
+ virtual bool IsOnGround(void) const { return m_bOnGround; }
// tolua_end
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 1ca131375..0d36d0b23 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -47,7 +47,7 @@ const int cPlayer::EATING_TICKS = 30;
-cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) :
+cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) :
super(etPlayer, 0.6, 1.8),
m_bVisible(true),
m_FoodLevel(MAX_FOOD_LEVEL),
@@ -105,15 +105,15 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) :
SetPosX(World->GetSpawnX());
SetPosY(World->GetSpawnY());
SetPosZ(World->GetSpawnZ());
- SetBedPos(Vector3i((int)World->GetSpawnX(), (int)World->GetSpawnY(), (int)World->GetSpawnZ()));
+ SetBedPos(Vector3i(static_cast<int>(World->GetSpawnX()), static_cast<int>(World->GetSpawnY()), static_cast<int>(World->GetSpawnZ())));
LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
);
}
- m_LastJumpHeight = (float)(GetPosY());
- m_LastGroundHeight = (float)(GetPosY());
+ m_LastJumpHeight = static_cast<float>(GetPosY());
+ m_LastGroundHeight = static_cast<float>(GetPosY());
m_Stance = GetPosY() + 1.62;
if (m_GameMode == gmNotSet)
@@ -174,7 +174,7 @@ void cPlayer::Destroyed()
void cPlayer::SpawnOn(cClientHandle & a_Client)
{
- if (!m_bVisible || (m_ClientHandle == (&a_Client)))
+ if (!m_bVisible || (m_ClientHandle.get() == (&a_Client)))
{
return;
}
@@ -232,7 +232,7 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
bool CanMove = true;
- if (!GetPosition().EqualsEps(m_LastPos, 0.01)) // Non negligible change in position from last tick?
+ if (!GetPosition().EqualsEps(m_LastPos, 0.02)) // Non negligible change in position from last tick? 0.02 tp prevent continous calling while floating sometimes.
{
// Apply food exhaustion from movement:
ApplyFoodExhaustionFromMovement();
@@ -246,7 +246,7 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
if (CanMove)
{
- BroadcastMovementUpdate(m_ClientHandle);
+ BroadcastMovementUpdate(m_ClientHandle.get());
}
if (m_Health > 0) // make sure player is alive
@@ -278,7 +278,7 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
if (IsFlying())
{
- m_LastGroundHeight = (float)GetPosY();
+ m_LastGroundHeight = static_cast<float>(GetPosY());
}
if (m_TicksUntilNextSave == 0)
@@ -296,7 +296,7 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
-short cPlayer::CalcLevelFromXp(short a_XpTotal)
+int cPlayer::CalcLevelFromXp(int a_XpTotal)
{
// level 0 to 15
if (a_XpTotal <= XP_TO_LEVEL15)
@@ -307,18 +307,18 @@ short cPlayer::CalcLevelFromXp(short a_XpTotal)
// level 30+
if (a_XpTotal > XP_TO_LEVEL30)
{
- return (short) (151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7;
+ return static_cast<int>((151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7);
}
// level 16 to 30
- return (short) ( 29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal)))) / 3;
+ return static_cast<int>((29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal)))) / 3);
}
-short cPlayer::XpForLevel(short a_Level)
+int cPlayer::XpForLevel(int a_Level)
{
// level 0 to 15
if (a_Level <= 15)
@@ -329,18 +329,18 @@ short cPlayer::XpForLevel(short a_Level)
// level 30+
if (a_Level >= 31)
{
- return (short) ( (3.5 * a_Level * a_Level) - (151.5 * a_Level) + 2220);
+ return static_cast<int>((3.5 * a_Level * a_Level) - (151.5 * a_Level) + 2220);
}
// level 16 to 30
- return (short) ( (1.5 * a_Level * a_Level) - (29.5 * a_Level) + 360);
+ return static_cast<int>((1.5 * a_Level * a_Level) - (29.5 * a_Level) + 360);
}
-short cPlayer::GetXpLevel()
+int cPlayer::GetXpLevel()
{
return CalcLevelFromXp(m_CurrentXp);
}
@@ -351,20 +351,20 @@ short cPlayer::GetXpLevel()
float cPlayer::GetXpPercentage()
{
- short int currentLevel = CalcLevelFromXp(m_CurrentXp);
- short int currentLevel_XpBase = XpForLevel(currentLevel);
+ int currentLevel = CalcLevelFromXp(m_CurrentXp);
+ int currentLevel_XpBase = XpForLevel(currentLevel);
- return (float)(m_CurrentXp - currentLevel_XpBase) /
- (float)(XpForLevel(1+currentLevel) - currentLevel_XpBase);
+ return static_cast<float>(m_CurrentXp - currentLevel_XpBase) /
+ static_cast<float>(XpForLevel(1+currentLevel) - currentLevel_XpBase);
}
-bool cPlayer::SetCurrentExperience(short int a_CurrentXp)
+bool cPlayer::SetCurrentExperience(int a_CurrentXp)
{
- if (!(a_CurrentXp >= 0) || (a_CurrentXp > (std::numeric_limits<short>().max() - m_LifetimeTotalXp)))
+ if (!(a_CurrentXp >= 0) || (a_CurrentXp > (std::numeric_limits<int>().max() - m_LifetimeTotalXp)))
{
LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_CurrentXp);
return false; // oops, they gave us a dodgey number
@@ -382,19 +382,20 @@ bool cPlayer::SetCurrentExperience(short int a_CurrentXp)
-short cPlayer::DeltaExperience(short a_Xp_delta)
+int cPlayer::DeltaExperience(int a_Xp_delta)
{
- if (a_Xp_delta > (std::numeric_limits<short>().max() - m_CurrentXp))
+ if (a_Xp_delta > (std::numeric_limits<int>().max() - m_CurrentXp))
{
// Value was bad, abort and report
- LOGWARNING("Attempt was made to increment Xp by %d, which overflowed the short datatype. Ignoring.", a_Xp_delta);
+ LOGWARNING("Attempt was made to increment Xp by %d, which overflowed the int datatype. Ignoring.", 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
- m_CurrentXp = std::max<short>(m_CurrentXp, 0);
+ m_CurrentXp = std::max(m_CurrentXp, 0);
+
// Update total for score calculation
if (a_Xp_delta > 0)
@@ -419,7 +420,7 @@ void cPlayer::StartChargingBow(void)
LOGD("Player \"%s\" started charging their bow", GetName().c_str());
m_IsChargingBow = true;
m_BowCharge = 0;
- m_World->BroadcastEntityMetadata(*this, m_ClientHandle);
+ m_World->BroadcastEntityMetadata(*this, m_ClientHandle.get());
}
@@ -432,7 +433,7 @@ int cPlayer::FinishChargingBow(void)
int res = m_BowCharge;
m_IsChargingBow = false;
m_BowCharge = 0;
- m_World->BroadcastEntityMetadata(*this, m_ClientHandle);
+ m_World->BroadcastEntityMetadata(*this, m_ClientHandle.get());
return res;
}
@@ -446,7 +447,7 @@ void cPlayer::CancelChargingBow(void)
LOGD("Player \"%s\" cancelled charging their bow at a charge of %d", GetName().c_str(), m_BowCharge);
m_IsChargingBow = false;
m_BowCharge = 0;
- m_World->BroadcastEntityMetadata(*this, m_ClientHandle);
+ m_World->BroadcastEntityMetadata(*this, m_ClientHandle.get());
}
@@ -466,7 +467,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
{
if (GetPosY() > m_LastJumpHeight)
{
- m_LastJumpHeight = (float)GetPosY();
+ m_LastJumpHeight = static_cast<float>(GetPosY());
}
cWorld * World = GetWorld();
if ((GetPosY() >= 0) && (GetPosY() < cChunkDef::Height))
@@ -483,13 +484,13 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
(BlockType == E_BLOCK_VINES)
)
{
- m_LastGroundHeight = (float)GetPosY();
+ m_LastGroundHeight = static_cast<float>(GetPosY());
}
}
}
else
{
- float Dist = (float)(m_LastGroundHeight - floor(GetPosY()));
+ float Dist = static_cast<float>(m_LastGroundHeight - floor(GetPosY()));
if (Dist >= 2.0) // At least two blocks - TODO: Use m_LastJumpHeight instead of m_LastGroundHeight above
{
@@ -497,12 +498,12 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
m_Stats.AddValue(statDistFallen, (StatValue)floor(Dist * 100 + 0.5));
}
- int Damage = (int)(Dist - 3.f);
+ int Damage = static_cast<int>(Dist - 3.f);
if (m_LastJumpHeight > m_LastGroundHeight)
{
Damage++;
}
- m_LastJumpHeight = (float)GetPosY();
+ m_LastJumpHeight = static_cast<float>(GetPosY());
if (Damage > 0)
{
@@ -510,10 +511,10 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
TakeDamage(dtFalling, nullptr, Damage, Damage, 0);
// Fall particles
- GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, (int)GetPosY() - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */);
+ GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, static_cast<int>(GetPosY()) - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */);
}
- m_LastGroundHeight = (float)GetPosY();
+ m_LastGroundHeight = static_cast<float>(GetPosY());
}
}
@@ -551,7 +552,7 @@ void cPlayer::SetFoodLevel(int a_FoodLevel)
void cPlayer::SetFoodSaturationLevel(double a_FoodSaturationLevel)
{
- m_FoodSaturationLevel = Clamp(a_FoodSaturationLevel, 0.0, (double) m_FoodLevel);
+ m_FoodSaturationLevel = Clamp(a_FoodSaturationLevel, 0.0, static_cast<double>(m_FoodLevel));
}
@@ -1274,13 +1275,17 @@ unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
{
- SetPosition(a_PosX, a_PosY, a_PosZ);
- m_LastGroundHeight = (float)a_PosY;
- m_LastJumpHeight = (float)a_PosY;
- m_bIsTeleporting = true;
+ // ask plugins to allow teleport to the new position.
+ if (!cRoot::Get()->GetPluginManager()->CallHookEntityTeleport(*this, m_LastPos, Vector3d(a_PosX, a_PosY, a_PosZ)))
+ {
+ SetPosition(a_PosX, a_PosY, a_PosZ);
+ m_LastGroundHeight = static_cast<float>(a_PosY);
+ m_LastJumpHeight = static_cast<float>(a_PosY);
+ m_bIsTeleporting = true;
- m_World->BroadcastTeleportEntity(*this, GetClientHandle());
- m_ClientHandle->SendPlayerMoveLook();
+ m_World->BroadcastTeleportEntity(*this, GetClientHandle());
+ m_ClientHandle->SendPlayerMoveLook();
+ }
}
@@ -1391,7 +1396,7 @@ void cPlayer::SetVisible(bool a_bVisible)
if (!a_bVisible && m_bVisible)
{
m_bVisible = false;
- m_World->BroadcastDestroyEntity(*this, m_ClientHandle); // Destroy on all clients
+ m_World->BroadcastDestroyEntity(*this, m_ClientHandle.get()); // Destroy on all clients
}
}
@@ -1714,9 +1719,9 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
Json::Value & JSON_PlayerRotation = root["rotation"];
if (JSON_PlayerRotation.size() == 3)
{
- SetYaw ((float)JSON_PlayerRotation[(unsigned)0].asDouble());
- SetPitch ((float)JSON_PlayerRotation[(unsigned)1].asDouble());
- SetRoll ((float)JSON_PlayerRotation[(unsigned)2].asDouble());
+ SetYaw (static_cast<float>(JSON_PlayerRotation[(unsigned)0].asDouble()));
+ SetPitch (static_cast<float>(JSON_PlayerRotation[(unsigned)1].asDouble()));
+ SetRoll (static_cast<float>(JSON_PlayerRotation[(unsigned)2].asDouble()));
}
m_Health = root.get("health", 0).asInt();
@@ -1725,9 +1730,9 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
m_FoodSaturationLevel = root.get("foodSaturation", MAX_FOOD_LEVEL).asDouble();
m_FoodTickTimer = root.get("foodTickTimer", 0).asInt();
m_FoodExhaustionLevel = root.get("foodExhaustion", 0).asDouble();
- m_LifetimeTotalXp = (short) root.get("xpTotal", 0).asInt();
- m_CurrentXp = (short) root.get("xpCurrent", 0).asInt();
- m_IsFlying = root.get("isflying", 0).asBool();
+ m_LifetimeTotalXp = root.get("xpTotal", 0).asInt();
+ m_CurrentXp = root.get("xpCurrent", 0).asInt();
+ m_IsFlying = root.get("isflying", 0).asBool();
m_GameMode = (eGameMode) root.get("gamemode", eGameMode_NotSet).asInt();
@@ -1812,18 +1817,18 @@ bool cPlayer::SaveToDisk()
root["world"] = m_World->GetName();
if (m_GameMode == m_World->GetGameMode())
{
- root["gamemode"] = (int) eGameMode_NotSet;
+ root["gamemode"] = static_cast<int>(eGameMode_NotSet);
}
else
{
- root["gamemode"] = (int) m_GameMode;
+ root["gamemode"] = static_cast<int>(m_GameMode);
}
}
else
{
// This happens if the player is saved to new format after loading from the old format
root["world"] = m_LoadedWorldName;
- root["gamemode"] = (int) eGameMode_NotSet;
+ root["gamemode"] = static_cast<int>(eGameMode_NotSet);
}
Json::StyledWriter writer;
@@ -1839,7 +1844,7 @@ bool cPlayer::SaveToDisk()
);
return false;
}
- if (f.Write(JsonData.c_str(), JsonData.size()) != (int)JsonData.size())
+ if (f.Write(JsonData.c_str(), JsonData.size()) != static_cast<int>(JsonData.size()))
{
LOGWARNING("Error writing player \"%s\" to file \"%s\" - cannot save data. Player will lose their progress. ",
GetName().c_str(), SourceFile.c_str()
@@ -1894,7 +1899,7 @@ void cPlayer::UseEquippedItem(int a_Amount)
if (GetInventory().DamageEquippedItem(a_Amount))
{
- m_World->BroadcastSoundEffect("random.break", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
+ m_World->BroadcastSoundEffect("random.break", GetPosX(), GetPosY(), GetPosZ(), 0.5f, static_cast<float>(0.75 + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
}
}
@@ -2042,17 +2047,17 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos)
else if (IsSubmerged())
{
m_Stats.AddValue(statDistDove, Value);
- AddFoodExhaustion(0.00015 * (double)Value);
+ AddFoodExhaustion(0.00015 * static_cast<double>(Value));
}
else if (IsSwimming())
{
m_Stats.AddValue(statDistSwum, Value);
- AddFoodExhaustion(0.00015 * (double)Value);
+ AddFoodExhaustion(0.00015 * static_cast<double>(Value));
}
else if (IsOnGround())
{
m_Stats.AddValue(statDistWalked, Value);
- AddFoodExhaustion((m_IsSprinting ? 0.001 : 0.0001) * (double)Value);
+ AddFoodExhaustion((m_IsSprinting ? 0.001 : 0.0001) * static_cast<double>(Value));
}
else
{
@@ -2294,6 +2299,16 @@ void cPlayer::Detach()
+void cPlayer::RemoveClientHandle(void)
+{
+ ASSERT(m_ClientHandle != nullptr);
+ m_ClientHandle.reset();
+}
+
+
+
+
+
AString cPlayer::GetUUIDFileName(const AString & a_UUID)
{
AString UUID = cMojangAPI::MakeUUIDDashed(a_UUID);
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index d3ed46db6..e02c66bd3 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -40,7 +40,7 @@ public:
CLASS_PROTODEF(cPlayer)
- cPlayer(cClientHandle * a_Client, const AString & a_PlayerName);
+ cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName);
virtual ~cPlayer();
@@ -72,22 +72,22 @@ public:
Returns true on success
"should" really only be called at init or player death, plugins excepted
*/
- bool SetCurrentExperience(short a_XpTotal);
+ bool SetCurrentExperience(int a_XpTotal);
/* 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);
+ int DeltaExperience(int a_Xp_delta);
/** Gets the experience total - XpTotal for score on death */
- inline short GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; }
+ inline int GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; }
/** Gets the currrent experience */
- inline short GetCurrentXp(void) { return m_CurrentXp; }
+ inline int GetCurrentXp(void) { return m_CurrentXp; }
/** Gets the current level - XpLevel */
- short GetXpLevel(void);
+ int GetXpLevel(void);
/** Gets the experience bar percentage - XpP */
float GetXpPercentage(void);
@@ -95,13 +95,13 @@ public:
/** Caculates the amount of XP needed for a given level
Ref: http://minecraft.gamepedia.com/XP
*/
- static short XpForLevel(short int a_Level);
+ static int XpForLevel(int a_Level);
/** Inverse of XpForLevel
Ref: http://minecraft.gamepedia.com/XP
values are as per this with pre-calculations
*/
- static short CalcLevelFromXp(short int a_CurrentXp);
+ static int CalcLevelFromXp(int a_CurrentXp);
// tolua_end
@@ -121,7 +121,7 @@ public:
inline void SetStance( const double a_Stance) { m_Stance = a_Stance; }
double GetEyeHeight(void) const; // tolua_export
Vector3d GetEyePosition(void) const; // tolua_export
- inline bool IsOnGround(void) const {return m_bTouchGround; } // tolua_export
+ virtual bool IsOnGround(void) const override { return m_bTouchGround; }
inline double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc.
inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export
inline const cInventory & GetInventory(void) const { return m_Inventory; }
@@ -222,7 +222,15 @@ public:
/** Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow */
void CloseWindowIfID(char a_WindowID, bool a_CanRefuse = true);
- cClientHandle * GetClientHandle(void) const { return m_ClientHandle; }
+ /** Returns the raw client handle associated with the player. */
+ cClientHandle * GetClientHandle(void) const { return m_ClientHandle.get(); }
+
+ // tolua_end
+
+ /** Returns the SharedPtr to client handle associated with the player. */
+ cClientHandlePtr GetClientHandlePtr(void) const { return m_ClientHandle; }
+
+ // tolua_begin
void SendMessage (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtCustom); }
void SendMessageInfo (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtInformation); }
@@ -467,6 +475,10 @@ public:
virtual bool IsRclking (void) const { return IsEating() || IsChargingBow(); }
virtual void Detach(void);
+
+ /** Called by cClientHandle when the client is being destroyed.
+ The player removes its m_ClientHandle ownership so that the ClientHandle gets deleted. */
+ void RemoveClientHandle(void);
protected:
@@ -537,7 +549,7 @@ protected:
std::chrono::steady_clock::time_point m_LastPlayerListTime;
- cClientHandle * m_ClientHandle;
+ cClientHandlePtr m_ClientHandle;
cSlotNums m_InventoryPaintSlots;
@@ -569,8 +581,8 @@ protected:
Int64 m_EatingFinishTick;
/** Player Xp level */
- short int m_LifetimeTotalXp;
- short int m_CurrentXp;
+ int m_LifetimeTotalXp;
+ int m_CurrentXp;
// flag saying we need to send a xp update to client
bool m_bDirtyExperience;