1
0

Merged branch 'howaner/Bow'.

Removed the pickup collection broadcast due to bad code.
This commit is contained in:
Mattes D 2014-06-26 18:42:28 +02:00
commit e60b73ce69
4 changed files with 61 additions and 23 deletions

View File

@ -3,6 +3,7 @@
#include "Player.h" #include "Player.h"
#include "ArrowEntity.h" #include "ArrowEntity.h"
#include "../Chunk.h" #include "../Chunk.h"
#include "FastRandom.h"
@ -24,9 +25,9 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a
SetYawFromSpeed(); SetYawFromSpeed();
SetPitchFromSpeed(); SetPitchFromSpeed();
LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}",
m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(),
GetYaw(), GetPitch() GetYaw(), GetPitch()
); );
} }
@ -44,6 +45,10 @@ cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) :
m_bIsCollected(false), m_bIsCollected(false),
m_HitBlockPos(0, 0, 0) m_HitBlockPos(0, 0, 0)
{ {
if (a_Player.IsGameModeCreative())
{
m_PickupState = psInCreative;
}
} }
@ -109,7 +114,14 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1);
// Broadcast successful hit sound // Broadcast successful hit sound
m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); m_World->BroadcastSoundEffect(
"random.successful_hit",
(int)std::floor(GetPosX() * 8.0),
(int)std::floor(GetPosY() * 8.0),
(int)std::floor(GetPosZ() * 8.0),
0.5f,
0.75f + ((float)((GetUniqueID() * 23) % 32)) / 64.0f
);
Destroy(); Destroy();
} }
@ -120,16 +132,33 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
void cArrowEntity::CollectedBy(cPlayer * a_Dest) void cArrowEntity::CollectedBy(cPlayer * a_Dest)
{ {
if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) if (m_IsInGround && !m_bIsCollected && CanPickup(*a_Dest))
{ {
int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); // Do not add the arrow to the inventory when the player is in creative:
if (NumAdded > 0) // Only play effects if there was space in inventory if (!a_Dest->IsGameModeCreative())
{ {
m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW);
// Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) if (NumAdded == 0)
m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); {
m_bIsCollected = true; // No space in the inventory
return;
}
} }
// TODO: BroadcastCollectPickup needs a cPickup, which we don't have
// m_World->BroadcastCollectPickup(*this, *a_Dest);
m_bIsCollected = true;
cFastRandom Random;
m_World->BroadcastSoundEffect(
"random.pop",
(int)std::floor(GetPosX() * 8.0),
(int)std::floor(GetPosY() * 8),
(int)std::floor(GetPosZ() * 8),
0.2F,
((Random.NextFloat(1.0F) - Random.NextFloat(1.0F)) * 0.7F + 1.0F) * 2.0F
);
} }
} }

View File

@ -1,4 +1,4 @@

#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Player.h" #include "Player.h"
@ -412,6 +412,7 @@ void cPlayer::StartChargingBow(void)
LOGD("Player \"%s\" started charging their bow", GetName().c_str()); LOGD("Player \"%s\" started charging their bow", GetName().c_str());
m_IsChargingBow = true; m_IsChargingBow = true;
m_BowCharge = 0; m_BowCharge = 0;
m_World->BroadcastEntityMetadata(*this, m_ClientHandle);
} }
@ -424,6 +425,8 @@ int cPlayer::FinishChargingBow(void)
int res = m_BowCharge; int res = m_BowCharge;
m_IsChargingBow = false; m_IsChargingBow = false;
m_BowCharge = 0; m_BowCharge = 0;
m_World->BroadcastEntityMetadata(*this, m_ClientHandle);
return res; return res;
} }
@ -436,6 +439,7 @@ void cPlayer::CancelChargingBow(void)
LOGD("Player \"%s\" cancelled charging their bow at a charge of %d", GetName().c_str(), m_BowCharge); LOGD("Player \"%s\" cancelled charging their bow at a charge of %d", GetName().c_str(), m_BowCharge);
m_IsChargingBow = false; m_IsChargingBow = false;
m_BowCharge = 0; m_BowCharge = 0;
m_World->BroadcastEntityMetadata(*this, m_ClientHandle);
} }

View File

@ -404,7 +404,7 @@ public:
// cEntity overrides: // cEntity overrides:
virtual bool IsCrouched (void) const { return m_IsCrouched; } virtual bool IsCrouched (void) const { return m_IsCrouched; }
virtual bool IsSprinting(void) const { return m_IsSprinting; } virtual bool IsSprinting(void) const { return m_IsSprinting; }
virtual bool IsRclking (void) const { return IsEating(); } virtual bool IsRclking (void) const { return IsEating() || IsChargingBow(); }
virtual void Detach(void); virtual void Detach(void);

View File

@ -48,17 +48,14 @@ public:
ASSERT(a_Player != NULL); ASSERT(a_Player != NULL);
int BowCharge = a_Player->FinishChargingBow(); int BowCharge = a_Player->FinishChargingBow();
double Force = (double)BowCharge / 20; double Force = (double)BowCharge / 20.0;
Force = (Force * Force + 2 * Force) / 3; // This formula is used by the 1.6.2 client Force = (Force * Force + 2.0 * Force) / 3.0; // This formula is used by the 1.6.2 client
if (Force < 0.1) if (Force < 0.1)
{ {
// Too little force, ignore the shot // Too little force, ignore the shot
return; return;
} }
if (Force > 1) Force = std::max(Force, 1.0);
{
Force = 1;
}
// Create the arrow entity: // Create the arrow entity:
cArrowEntity * Arrow = new cArrowEntity(*a_Player, Force * 2); cArrowEntity * Arrow = new cArrowEntity(*a_Player, Force * 2);
@ -72,8 +69,16 @@ public:
Arrow = NULL; Arrow = NULL;
return; return;
} }
a_Player->GetWorld()->BroadcastSpawnEntity(*Arrow);
a_Player->GetWorld()->BroadcastSoundEffect("random.bow", (int)a_Player->GetPosX() * 8, (int)a_Player->GetPosY() * 8, (int)a_Player->GetPosZ() * 8, 0.5, (float)Force); cFastRandom Random;
a_Player->GetWorld()->BroadcastSoundEffect(
"random.bow",
(int)std::floor(a_Player->GetPosX() * 8.0),
(int)std::floor(a_Player->GetPosY() * 8.0),
(int)std::floor(a_Player->GetPosZ() * 8.0),
1.0F,
1.0F / (Random.NextFloat(1.0F) * 0.4F + 1.2F) + (float)Force * 0.5F
);
if (!a_Player->IsGameModeCreative()) if (!a_Player->IsGameModeCreative())
{ {