From bd6574230a0acbc538ce7328fc191130d3d8eac1 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 21 Dec 2013 17:31:05 +0100 Subject: Floater now dissapears when the player doesn't have an fishing rod equipped. --- src/Entities/Player.cpp | 29 +++++++++++++++++++++++++++++ src/Entities/Player.h | 3 +++ 2 files changed, 32 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 8f30cd4cc..948a259ff 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -240,6 +240,11 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) HandleFood(); } + if (m_IsFishing) + { + HandleFloater(); + } + // Send Player List (Once per m_LastPlayerListTime/1000 ms) cTimer t1; if (m_LastPlayerListTime + cPlayer::PLAYER_LIST_TIME_MS <= t1.GetNowTime()) @@ -1781,6 +1786,30 @@ void cPlayer::HandleFood(void) +void cPlayer::HandleFloater() +{ + if (GetEquippedItem().m_ItemType == E_ITEM_FISHING_ROD) + { + return; + } + class cFloaterCallback : + public cEntityCallback + { + public: + virtual bool Item(cEntity * a_Entity) override + { + a_Entity->Destroy(true); + return true; + } + } Callback; + m_World->DoWithEntityByID(m_FloaterID, Callback); + SetIsFishing(false); +} + + + + + void cPlayer::ApplyFoodExhaustionFromMovement() { if (IsGameModeCreative()) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index c0ad9eeac..66f1c07a7 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -466,6 +466,9 @@ protected: /// Called in each tick to handle food-related processing void HandleFood(void); + + /// Called in each tick if the player is fishing to make sure the floater dissapears when the player doesn't have a fishing rod as equipped item. + void HandleFloater(void); /// Called in each tick to handle air-related processing i.e. drowning void HandleAir(); -- cgit v1.2.3 From 7a299f1ba62217c6d214f6cfbd266a41938ad577 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 22 Dec 2013 14:48:22 +0100 Subject: Fishing now uses a countdown instead of a random number each tick. --- src/Entities/Floater.cpp | 37 ++++++++++++++++++++++++++----------- src/Entities/Floater.h | 4 +++- 2 files changed, 29 insertions(+), 12 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index ac7a82f91..6409fecf5 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -9,11 +9,12 @@ -cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID) : +cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID, int a_CountDownTime) : cEntity(etFloater, a_X, a_Y, a_Z, 0.98, 0.98), m_PickupCountDown(0), m_PlayerID(a_PlayerID), - m_CanPickupItem(false) + m_CanPickupItem(false), + m_CountDownTime(a_CountDownTime) { SetSpeed(a_Speed); } @@ -36,17 +37,31 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) HandlePhysics(a_Dt, a_Chunk); if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())) && m_World->GetBlockMeta((int) GetPosX(), (int) GetPosY(), (int) GetPosZ()) == 0) { - if ((!m_CanPickupItem) && (m_World->GetTickRandomNumber(100) == 0)) + if (!m_CanPickupItem) { - SetPosY(GetPosY() - 1); - m_CanPickupItem = true; - m_PickupCountDown = 20; - LOGD("Floater %i can be picked up", GetUniqueID()); - } - else - { - SetSpeedY(0.7); + if (m_CountDownTime <= 0) + { + m_World->BroadcastSoundEffect("random.splash", (int) floor(GetPosX() * 8), (int) floor(GetPosY() * 8), (int) floor(GetPosZ() * 8), 1, 1); + SetPosY(GetPosY() - 1); + m_CanPickupItem = true; + m_PickupCountDown = 20; + m_CountDownTime = 100 + m_World->GetTickRandomNumber(800); + LOGD("Floater %i can be picked up", GetUniqueID()); + } + else if (m_CountDownTime == 20) // Calculate the position where the particles should spawn and start producing them. + { + LOGD("Started producing particles for floater %i", GetUniqueID()); + m_ParticlePos.Set(GetPosX() + (-4 + m_World->GetTickRandomNumber(8)), GetPosY(), GetPosZ() + (-4 + m_World->GetTickRandomNumber(8))); + m_World->BroadcastParticleEffect("splash", m_ParticlePos.x, m_ParticlePos.y, m_ParticlePos.z, 0, 0, 0, 0, 15); + } + else if (m_CountDownTime < 20) + { + m_ParticlePos = (m_ParticlePos + (GetPosition() - m_ParticlePos) / 6); + m_World->BroadcastParticleEffect("splash", m_ParticlePos.x, m_ParticlePos.y, m_ParticlePos.z, 0, 0, 0, 0, 15); + } + m_CountDownTime--; } + SetSpeedY(0.7); } SetSpeedX(GetSpeedX() * 0.95); SetSpeedZ(GetSpeedZ() * 0.95); diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h index 9bc5039f8..4db94986c 100644 --- a/src/Entities/Floater.h +++ b/src/Entities/Floater.h @@ -14,7 +14,7 @@ class cFloater : public: - cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID); + cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID, int a_CountDownTime); virtual void SpawnOn(cClientHandle & a_Client) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; @@ -23,7 +23,9 @@ public: protected: Vector3d m_Speed; + Vector3d m_ParticlePos; int m_PickupCountDown; int m_PlayerID; + int m_CountDownTime; bool m_CanPickupItem; } ; \ No newline at end of file -- cgit v1.2.3 From caccf72b46e8e40fa17c2b55a40ed1b6dc6557f2 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 22 Dec 2013 14:54:07 +0100 Subject: Fixed compiler warnings. --- src/Entities/Floater.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index 6409fecf5..d908167df 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -52,12 +52,12 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) { LOGD("Started producing particles for floater %i", GetUniqueID()); m_ParticlePos.Set(GetPosX() + (-4 + m_World->GetTickRandomNumber(8)), GetPosY(), GetPosZ() + (-4 + m_World->GetTickRandomNumber(8))); - m_World->BroadcastParticleEffect("splash", m_ParticlePos.x, m_ParticlePos.y, m_ParticlePos.z, 0, 0, 0, 0, 15); + m_World->BroadcastParticleEffect("splash", (float) m_ParticlePos.x, (float) m_ParticlePos.y, (float) m_ParticlePos.z, 0, 0, 0, 0, 15); } else if (m_CountDownTime < 20) { m_ParticlePos = (m_ParticlePos + (GetPosition() - m_ParticlePos) / 6); - m_World->BroadcastParticleEffect("splash", m_ParticlePos.x, m_ParticlePos.y, m_ParticlePos.z, 0, 0, 0, 0, 15); + m_World->BroadcastParticleEffect("splash", (float) m_ParticlePos.x, (float) m_ParticlePos.y, (float) m_ParticlePos.z, 0, 0, 0, 0, 15); } m_CountDownTime--; } -- cgit v1.2.3 From 8d51c22b368409ef1bfcc4eff5c504209c5f24f7 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 22 Dec 2013 15:22:50 +0100 Subject: Fishing underground is slower and fishing while raining is faster. --- src/Entities/Floater.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index d908167df..5e3338968 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -59,7 +59,22 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) m_ParticlePos = (m_ParticlePos + (GetPosition() - m_ParticlePos) / 6); m_World->BroadcastParticleEffect("splash", (float) m_ParticlePos.x, (float) m_ParticlePos.y, (float) m_ParticlePos.z, 0, 0, 0, 0, 15); } + m_CountDownTime--; + if (m_World->GetHeight((int) GetPosX(), (int) GetPosZ()) == (int) GetPosY()) + { + if (m_World->IsWeatherWet() && m_World->GetTickRandomNumber(3) == 0) // 25% chance of an extra countdown when being rained on. + { + m_CountDownTime--; + } + } + else // if the floater is underground it has a 50% chance of not decreasing the countdown. + { + if (m_World->GetTickRandomNumber(1) == 0) + { + m_CountDownTime++; + } + } } SetSpeedY(0.7); } -- cgit v1.2.3 From 945ba36d1b7b1b90028148aa5637f9842858af12 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Dec 2013 20:03:09 +0000 Subject: Implemented fall particles --- src/Entities/Player.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 8f30cd4cc..aedd3b77e 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -247,6 +247,9 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) m_World->SendPlayerList(this); m_LastPlayerListTime = t1.GetNowTime(); } + + if (IsFlying()) + m_LastGroundHeight = (float)GetPosY(); } @@ -447,10 +450,19 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) if (m_LastJumpHeight > m_LastGroundHeight) Damage++; m_LastJumpHeight = (float)GetPosY(); - if ((Damage > 0) && (!IsGameModeCreative())) + if (Damage > 0) { - TakeDamage(dtFalling, NULL, Damage, Damage, 0); - } + if (!IsGameModeCreative()) + { + TakeDamage(dtFalling, NULL, Damage, Damage, 0); + } + + GetWorld()->BroadcastSoundParticleEffect( + 2006, + (int)GetPosX(), (int)GetPosY() - 1, (int)GetPosZ(), + Damage // Used as particle effect speed modifier + ); + } m_LastGroundHeight = (float)GetPosY(); } @@ -974,6 +986,9 @@ void cPlayer::SetGameMode(eGameMode a_GameMode) m_GameMode = a_GameMode; m_ClientHandle->SendGameMode(a_GameMode); + + SetFlying(false); + SetCanFly(false); } -- cgit v1.2.3 From b02a81678c22b00955bc3b2b87ceed55027bb35a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Dec 2013 20:04:17 +0000 Subject: Implemented knockback and critical hit --- src/Entities/Entity.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8fcdcc82f..0f5ed7262 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -13,6 +13,7 @@ #include "../Bindings/PluginManager.h" #include "../Tracer.h" #include "Minecart.h" +#include "Player.h" @@ -239,10 +240,14 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R TDI.Attacker = a_Attacker; TDI.RawDamage = a_RawDamage; TDI.FinalDamage = a_FinalDamage; - Vector3d Heading; - Heading.x = sin(GetRotation()); - Heading.y = 0.4; // TODO: adjust the amount of "up" knockback when testing - Heading.z = cos(GetRotation()); + + Vector3d Heading(0, 0, 0); + if (a_Attacker != NULL) + { + Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 10 : 8); + } + Heading.y += 3; + TDI.Knockback = Heading * a_KnockbackAmount; DoTakeDamage(TDI); } @@ -297,6 +302,16 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) return; } + if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) + { + // IsOnGround() only is true if the player is moving downwards + if (!((cPlayer *)a_TDI.Attacker)->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) + { + a_TDI.FinalDamage + 2; + m_World->BroadcastEntityAnimation(*this, 4); // Critical hit + } + } + m_Health -= (short)a_TDI.FinalDamage; // TODO: Apply damage to armor @@ -306,6 +321,8 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = 0; } + AddSpeed(a_TDI.Knockback * 3); + m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT); if (m_Health <= 0) -- cgit v1.2.3 From d8221854d2f529e8165d5153c767bb29a54646a8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 23 Dec 2013 09:41:45 +0000 Subject: Fixed a comment in Entity.cpp --- src/Entities/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 0f5ed7262..d82a89ab2 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -304,7 +304,7 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) { - // IsOnGround() only is true if the player is moving downwards + // IsOnGround() only is false if the player is moving downwards if (!((cPlayer *)a_TDI.Attacker)->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) { a_TDI.FinalDamage + 2; -- cgit v1.2.3 From 9c796bf6b42b54ce5efe294c03ffd28366917805 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 23 Dec 2013 09:51:41 +0000 Subject: Clarified some code in Player.cpp --- src/Entities/Player.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index aedd3b77e..0c133d3fa 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -987,8 +987,11 @@ void cPlayer::SetGameMode(eGameMode a_GameMode) m_GameMode = a_GameMode; m_ClientHandle->SendGameMode(a_GameMode); - SetFlying(false); - SetCanFly(false); + if (a_GameMode != gmCreative) + { + SetFlying(false); + SetCanFly(false); + } } -- cgit v1.2.3 From 1014c737a4f16ce374fa834822ba173c00cae678 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 23 Dec 2013 21:18:01 +0000 Subject: Improved player fall particle positions --- src/Entities/Player.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 0c133d3fa..26572f39b 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -457,11 +457,8 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) TakeDamage(dtFalling, NULL, Damage, Damage, 0); } - GetWorld()->BroadcastSoundParticleEffect( - 2006, - (int)GetPosX(), (int)GetPosY() - 1, (int)GetPosZ(), - Damage // Used as particle effect speed modifier - ); + // Apparently, Mojang changed player positions to always be rounded up. Normally, it doesn't affect much, but we need effect positions to be precise, so ceil() + GetWorld()->BroadcastSoundParticleEffect(2006, (int)floor(GetPosX()), (int)GetPosY() - 1, (int)floor(GetPosZ()), Damage /* Used as particle effect speed modifier */); } m_LastGroundHeight = (float)GetPosY(); -- cgit v1.2.3 From af6389ea7ab79663d687e22a18d21b3db86cd71c Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 24 Dec 2013 10:30:36 +0000 Subject: finally removed them all? --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 948a259ff..b923a094e 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1294,7 +1294,7 @@ AString cPlayer::GetColor(void) const { if ( m_Color != '-' ) { - return cChatColor::MakeColor( m_Color ); + return cChatColor::Color + m_Color; } if ( m_Groups.size() < 1 ) -- cgit v1.2.3 From 89f87f66a5b64619cacf86461c1a0f26563e34c5 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 24 Dec 2013 15:02:35 +0000 Subject: Improved knockback animation * Critical hits now actually increase damage * Looking down at an entity and hitting them still produces upwards motion (as per Vanilla experience) * Reduced force to be more realistic --- src/Entities/Entity.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index d82a89ab2..8a74c9da4 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -246,7 +246,7 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R { Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 10 : 8); } - Heading.y += 3; + Heading.y = 2; TDI.Knockback = Heading * a_KnockbackAmount; DoTakeDamage(TDI); @@ -307,7 +307,7 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) // IsOnGround() only is false if the player is moving downwards if (!((cPlayer *)a_TDI.Attacker)->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) { - a_TDI.FinalDamage + 2; + a_TDI.FinalDamage += 2; m_World->BroadcastEntityAnimation(*this, 4); // Critical hit } } @@ -321,7 +321,7 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = 0; } - AddSpeed(a_TDI.Knockback * 3); + AddSpeed(a_TDI.Knockback * 2); m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT); -- cgit v1.2.3 From ae6cb01e5666a8d4cedaf221f2e784f862784482 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 24 Dec 2013 15:16:30 +0000 Subject: Fixed comments in main.cpp and Player.cpp --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 26572f39b..6d199e130 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -457,7 +457,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) TakeDamage(dtFalling, NULL, Damage, Damage, 0); } - // Apparently, Mojang changed player positions to always be rounded up. Normally, it doesn't affect much, but we need effect positions to be precise, so ceil() + // Mojang uses floor() to get X and Z positions, instead of just casting it to an (int) GetWorld()->BroadcastSoundParticleEffect(2006, (int)floor(GetPosX()), (int)GetPosY() - 1, (int)floor(GetPosZ()), Damage /* Used as particle effect speed modifier */); } -- cgit v1.2.3 From 508e505aced6f80a0ed1f3d89495add658b11956 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 24 Dec 2013 23:47:04 +0000 Subject: Used IsGamemodeCreative() function --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 6d199e130..a4b580b00 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -984,7 +984,7 @@ void cPlayer::SetGameMode(eGameMode a_GameMode) m_GameMode = a_GameMode; m_ClientHandle->SendGameMode(a_GameMode); - if (a_GameMode != gmCreative) + if (!IsGameModeCreative()) { SetFlying(false); SetCanFly(false); -- cgit v1.2.3 From 40c2826a21d71dd8829a29f97fdfb36b68eaba14 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 25 Dec 2013 14:05:37 +0000 Subject: Braced up some code --- src/Entities/Player.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index a4b580b00..41c1542d3 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -249,7 +249,9 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) } if (IsFlying()) + { m_LastGroundHeight = (float)GetPosY(); + } } -- cgit v1.2.3 From 17a84111ceb1c1d28bc420eeae9262bc10b869b9 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 25 Dec 2013 17:26:17 +0100 Subject: You are now able to sweep mobs to your position using fishing rods. --- src/Entities/Floater.cpp | 137 ++++++++++++++++++++++++++++++++++++++++++++--- src/Entities/Floater.h | 17 ++++-- 2 files changed, 142 insertions(+), 12 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index 5e3338968..ab0595149 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -1,6 +1,8 @@ #include "Globals.h" +#include "../BoundingBox.h" +#include "../Chunk.h" #include "Floater.h" #include "Player.h" #include "../ClientHandle.h" @@ -9,12 +11,103 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cFloaterEntityCollisionCallback +class cFloaterEntityCollisionCallback : + public cEntityCallback +{ +public: + cFloaterEntityCollisionCallback(cFloater * a_Floater, const Vector3d & a_Pos, const Vector3d & a_NextPos) : + m_Floater(a_Floater), + m_Pos(a_Pos), + m_NextPos(a_NextPos), + m_MinCoeff(1), + m_HitEntity(NULL) + { + } + virtual bool Item(cEntity * a_Entity) override + { + if (!a_Entity->IsMob()) // Floaters can only pull mobs not other entities. + { + return false; + } + + cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight()); + + double LineCoeff; + char Face; + EntBox.Expand(m_Floater->GetWidth() / 2, m_Floater->GetHeight() / 2, m_Floater->GetWidth() / 2); + if (!EntBox.CalcLineIntersection(m_Pos, m_NextPos, LineCoeff, Face)) + { + // No intersection whatsoever + return false; + } + + if (LineCoeff < m_MinCoeff) + { + // The entity is closer than anything we've stored so far, replace it as the potential victim + m_MinCoeff = LineCoeff; + m_HitEntity = a_Entity; + } + + // Don't break the enumeration, we want all the entities + return false; + } + + /// Returns the nearest entity that was hit, after the enumeration has been completed + cEntity * GetHitEntity(void) const { return m_HitEntity; } + + /// Returns true if the callback has encountered a true hit + bool HasHit(void) const { return (m_MinCoeff < 1); } + +protected: + cFloater * m_Floater; + const Vector3d & m_Pos; + const Vector3d & m_NextPos; + double m_MinCoeff; // The coefficient of the nearest hit on the Pos line + + // Although it's bad(tm) to store entity ptrs from a callback, we can afford it here, because the entire callback + // is processed inside the tick thread, so the entities won't be removed in between the calls and the final processing + cEntity * m_HitEntity; // The nearest hit entity +} ; + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cFloaterCheckEntityExist +class cFloaterCheckEntityExist : + public cEntityCallback +{ +public: + cFloaterCheckEntityExist(void) : + m_EntityExists(false) + { + } + + bool Item(cEntity * a_Entity) override + { + m_EntityExists = true; + return false; + } + + bool DoesExist(void) const { return m_EntityExists; } +protected: + bool m_EntityExists; +} ; + + + + + cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID, int a_CountDownTime) : - cEntity(etFloater, a_X, a_Y, a_Z, 0.98, 0.98), + cEntity(etFloater, a_X, a_Y, a_Z, 0.2, 0.2), m_PickupCountDown(0), m_PlayerID(a_PlayerID), m_CanPickupItem(false), - m_CountDownTime(a_CountDownTime) + m_CountDownTime(a_CountDownTime), + m_AttachedMobID(-1) { SetSpeed(a_Speed); } @@ -37,7 +130,7 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) HandlePhysics(a_Dt, a_Chunk); if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())) && m_World->GetBlockMeta((int) GetPosX(), (int) GetPosY(), (int) GetPosZ()) == 0) { - if (!m_CanPickupItem) + if (!m_CanPickupItem && m_AttachedMobID == -1) // Check if you can't already pickup a fish and if the floater isn't attached to a mob. { if (m_CountDownTime <= 0) { @@ -78,9 +171,8 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) } SetSpeedY(0.7); } - SetSpeedX(GetSpeedX() * 0.95); - SetSpeedZ(GetSpeedZ() * 0.95); - if (CanPickup()) + + if (CanPickup()) // Make sure the floater "loses its fish" { m_PickupCountDown--; if (m_PickupCountDown == 0) @@ -89,9 +181,38 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) LOGD("The fish is gone. Floater %i can not pick an item up.", GetUniqueID()); } } - BroadcastMovementUpdate(); -} + if (GetSpeed().Length() > 4 && m_AttachedMobID == -1) + { + cFloaterEntityCollisionCallback Callback(this, GetPosition(), GetPosition() + GetSpeed() / 20); + + a_Chunk.ForEachEntity(Callback); + if (Callback.HasHit()) + { + AttachTo(Callback.GetHitEntity()); + Callback.GetHitEntity()->TakeDamage(*this); // TODO: the player attacked the mob not the floater. + m_AttachedMobID = Callback.GetHitEntity()->GetUniqueID(); + } + } + + cFloaterCheckEntityExist EntityCallback; + m_World->DoWithEntityByID(m_PlayerID, EntityCallback); + if (!EntityCallback.DoesExist()) // The owner doesn't exist anymore. Destroy the floater entity. + { + Destroy(true); + } + if (m_AttachedMobID != -1) + { + m_World->DoWithEntityByID(m_AttachedMobID, EntityCallback); // The mob the floater was attached to doesn't exist anymore. + if (!EntityCallback.DoesExist()) + { + m_AttachedMobID = -1; + } + } + SetSpeedX(GetSpeedX() * 0.95); + SetSpeedZ(GetSpeedZ() * 0.95); + BroadcastMovementUpdate(); +} \ No newline at end of file diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h index 4db94986c..4bbe3f352 100644 --- a/src/Entities/Floater.h +++ b/src/Entities/Floater.h @@ -19,13 +19,22 @@ public: virtual void SpawnOn(cClientHandle & a_Client) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - bool CanPickup(void) const { return m_CanPickupItem; } + bool CanPickup(void) const { return m_CanPickupItem; } + int GetOwnerID(void) const { return m_PlayerID; } + int GetAttachedMobID(void) const { return m_AttachedMobID; } protected: - Vector3d m_Speed; + // Position Vector3d m_ParticlePos; + + // Bool needed to check if you can get a fish. + bool m_CanPickupItem; + + // Countdown times int m_PickupCountDown; - int m_PlayerID; int m_CountDownTime; - bool m_CanPickupItem; + + // Entity IDs + int m_PlayerID; + int m_AttachedMobID; } ; \ No newline at end of file -- cgit v1.2.3 From 5eacf327b7a1fc84845e64ac8ffbc75ed5a4a77a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 25 Dec 2013 18:14:00 +0100 Subject: Fixed Parentheses. --- src/Entities/Floater.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index ab0595149..dfe77f059 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -130,7 +130,7 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) HandlePhysics(a_Dt, a_Chunk); if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())) && m_World->GetBlockMeta((int) GetPosX(), (int) GetPosY(), (int) GetPosZ()) == 0) { - if (!m_CanPickupItem && m_AttachedMobID == -1) // Check if you can't already pickup a fish and if the floater isn't attached to a mob. + if ((!m_CanPickupItem) && (m_AttachedMobID == -1)) // Check if you can't already pickup a fish and if the floater isn't attached to a mob. { if (m_CountDownTime <= 0) { @@ -182,7 +182,7 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) } } - if (GetSpeed().Length() > 4 && m_AttachedMobID == -1) + if ((GetSpeed().Length() > 4) && (m_AttachedMobID == -1)) { cFloaterEntityCollisionCallback Callback(this, GetPosition(), GetPosition() + GetSpeed() / 20); -- cgit v1.2.3 From f1142af455eea674c07ab426fe5ef7d4302b16c9 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 26 Dec 2013 14:55:19 +0000 Subject: Server now handles death messages --- src/Entities/Player.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 0fa8254ce..67d5a47ef 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -820,6 +820,22 @@ void cPlayer::KilledBy(cEntity * a_Killer) m_Inventory.Clear(); m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10); SaveToDisk(); // Save it, yeah the world is a tough place ! + + if (a_Killer == NULL) + { + GetWorld()->BroadcastChat(Printf("%s[DEATH] %s%s was killed by environmental damage", cChatColor::Red.c_str(), cChatColor::White.c_str(), GetName().c_str())); + } + else if (a_Killer->IsPlayer()) + { + GetWorld()->BroadcastChat(Printf("%s[DEATH] %s%s was killed by %s", cChatColor::Red.c_str(), cChatColor::White.c_str(), GetName().c_str(), ((cPlayer *)a_Killer)->GetName().c_str())); + } + else + { + AString KillerClass = a_Killer->GetClass(); + KillerClass.erase(KillerClass.begin()); // Erase the 'c' of the class (e.g. "cWitch" -> "Witch") + + GetWorld()->BroadcastChat(Printf("%s[DEATH] %s%s was killed by a %s", cChatColor::Red.c_str(), cChatColor::White.c_str(), GetName().c_str(), KillerClass.c_str())); + } } -- cgit v1.2.3