From 37069288d5801acce0ad34878a78aa0daf004135 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 14 Dec 2013 18:03:00 +0100 Subject: Added SendEntityEffect and SendRemoveEntityEffect. Also a Player now gets the hunger effect when he has food poison. --- src/Entities/Player.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 85833f31d..20c4818b2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -557,9 +557,13 @@ void cPlayer::FoodPoison(int a_NumTicks) m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { - // TODO: Send the poisoning indication to the client - how? + m_ClientHandle->SendRemoveEntityEffect(*this, 17); SendHealth(); } + else + { + m_ClientHandle->SendEntityEffect(*this, 17, 0, 20); + } } @@ -1704,6 +1708,10 @@ void cPlayer::HandleFood(void) m_FoodPoisonedTicksRemaining--; m_FoodExhaustionLevel += 0.025; // 0.5 per second = 0.025 per tick } + else + { + m_ClientHandle->SendRemoveEntityEffect(*this, 17); // remove the "Hunger" effect. + } // Apply food exhaustion that has accumulated: if (m_FoodExhaustionLevel >= 4) -- cgit v1.2.3 From 71250b275f2c1b16ff81c74c6e3f5bc2794ebb97 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 14 Dec 2013 22:23:20 +0100 Subject: Added E_EFFECT_ --- src/Entities/Player.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 20c4818b2..b2485a8e2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -557,12 +557,12 @@ void cPlayer::FoodPoison(int a_NumTicks) m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { - m_ClientHandle->SendRemoveEntityEffect(*this, 17); + m_ClientHandle->SendRemoveEntityEffect(*this, E_EFFECT_HUNGER); SendHealth(); } else { - m_ClientHandle->SendEntityEffect(*this, 17, 0, 20); + m_ClientHandle->SendEntityEffect(*this, E_EFFECT_HUNGER, 0, 20); } } @@ -1710,7 +1710,7 @@ void cPlayer::HandleFood(void) } else { - m_ClientHandle->SendRemoveEntityEffect(*this, 17); // remove the "Hunger" effect. + m_ClientHandle->SendRemoveEntityEffect(*this, E_EFFECT_HUNGER); // remove the "Hunger" effect. } // Apply food exhaustion that has accumulated: -- cgit v1.2.3 From 9c2089dc5a89acc2351fa089558d1e375c1d09f6 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 10:52:54 +0100 Subject: cPlayer is using the broadcast functions. --- src/Entities/Player.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index b2485a8e2..e057c25fe 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -557,12 +557,12 @@ void cPlayer::FoodPoison(int a_NumTicks) m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { - m_ClientHandle->SendRemoveEntityEffect(*this, E_EFFECT_HUNGER); + m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); SendHealth(); } else { - m_ClientHandle->SendEntityEffect(*this, E_EFFECT_HUNGER, 0, 20); + m_World->BroadcastEntityEffect(*this, E_EFFECT_HUNGER, 0, 400); // Give the player the "Hunger" effect for 20 seconds. } } @@ -1710,7 +1710,7 @@ void cPlayer::HandleFood(void) } else { - m_ClientHandle->SendRemoveEntityEffect(*this, E_EFFECT_HUNGER); // remove the "Hunger" effect. + m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); // Remove the "Hunger" effect. } // Apply food exhaustion that has accumulated: -- cgit v1.2.3 From b10d0b95cbdce1d476f14415901c89bf324c0c18 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 14:48:17 +0100 Subject: Added m_IsFlying and m_CanFly. Both have a Get and Set function. Added cClientHandle::SendPlayerAbilities() function --- src/Entities/Player.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index e057c25fe..c2a76342d 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -63,6 +63,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_IsSprinting(false) , m_IsSwimming(false) , m_IsSubmerged(false) + , m_IsFlying(false) + , m_CanFly(false) , m_EatingFinishTick(-1) , m_IsChargingBow(false) , m_BowCharge(0) @@ -751,6 +753,36 @@ void cPlayer::SetSprint(bool a_IsSprinting) +void cPlayer::SetCanFly(bool a_CanFly) +{ + if (a_CanFly == m_CanFly) + { + return; + } + + m_CanFly = a_CanFly; + m_ClientHandle->SendPlayerAbilities(); +} + + + + + +void cPlayer::SetFlying(bool a_IsFlying) +{ + if (a_IsFlying == m_IsFlying) + { + return; + } + + m_IsFlying = a_IsFlying; + m_ClientHandle->SendPlayerAbilities(); +} + + + + + void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if (a_TDI.DamageType != dtInVoid) -- cgit v1.2.3 From 0efd74f114dad98c4fadc0318718f2e0203bca8b Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 18:54:54 +0100 Subject: This adds a function that allows you to 'shoot' a player towards a direction. --- src/Entities/Player.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c2a76342d..ab7075121 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1069,6 +1069,16 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const +void cPlayer::ShootTo(Vector3d a_Direction) +{ + SetSpeed(a_Direction); + m_ClientHandle->SendEntityVelocity(*this); +} + + + + + void cPlayer::MoveTo( const Vector3d & a_NewPos ) { if ((a_NewPos.y < -990) && (GetPosY() > -100)) -- cgit v1.2.3 From 5e75408b3becd5de0ef88223c789fa6f95ff6619 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 20:19:58 +0100 Subject: Renamed ShootTo function to ForceSetSpeed. --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ab7075121..38b911fd2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1069,7 +1069,7 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const -void cPlayer::ShootTo(Vector3d a_Direction) +void cPlayer::ForceSetSpeed(Vector3d a_Direction) { SetSpeed(a_Direction); m_ClientHandle->SendEntityVelocity(*this); -- cgit v1.2.3 From 007d668c1bdd29bc6d28de0db2681f5c2f77ed5c Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 21:25:13 +0100 Subject: Server saves if a player is flying. --- src/Entities/Player.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 38b911fd2..5165c2f8a 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1517,6 +1517,7 @@ bool cPlayer::LoadFromDisk() 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(); //SetExperience(root.get("experience", 0).asInt()); @@ -1567,7 +1568,8 @@ bool cPlayer::SaveToDisk() root["foodSaturation"] = m_FoodSaturationLevel; root["foodTickTimer"] = m_FoodTickTimer; root["foodExhaustion"] = m_FoodExhaustionLevel; - root["world"] = GetWorld()->GetName(); + root["world"] = GetWorld()->GetName(); + root["isflying"] = IsFlying(); if (m_GameMode == GetWorld()->GetGameMode()) { -- cgit v1.2.3 From f521cbeb31e90e4c5c25edb6686544530ddbaf99 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 16 Dec 2013 10:41:35 +0100 Subject: Fixed cClientHandle::Tick() being called from two threads. When the player was initialized, the Tick() function continued to stream chunk, while the cWorld called Tick() from its tick thread. Final fix for #187. --- src/Entities/Player.cpp | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 5165c2f8a..7e7d77433 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -137,28 +137,6 @@ cPlayer::~cPlayer(void) -bool cPlayer::Initialize(cWorld * a_World) -{ - ASSERT(a_World != NULL); - - if (super::Initialize(a_World)) - { - // Remove the client handle from the server, it will be ticked from this object from now on - if (m_ClientHandle != NULL) - { - cRoot::Get()->GetServer()->ClientMovedToWorld(m_ClientHandle); - } - - GetWorld()->AddPlayer(this); - return true; - } - return false; -} - - - - - void cPlayer::Destroyed() { CloseWindow(false); -- cgit v1.2.3