示例#1
0
void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
{
	if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat())
	{
		// Not an entity that interacts with an arrow
		return;
	}
	
	int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5);
	if (m_IsCritical)
	{
		Damage += m_World->GetTickRandomNumber(Damage / 2 + 2);
	}
	a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1);
	
	// Broadcast successful hit sound
	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();
}
示例#2
0
void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
{
	if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer())
	{
		// Not an entity that interacts with an arrow
		return;
	}
	
	int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5);
	if (m_IsCritical)
	{
		Damage += m_World->GetTickRandomNumber(Damage / 2 + 2);
	}
	a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1);
	
	Destroy();
}
示例#3
0
void cProtocol125::WriteEntityMetadata(const cEntity & a_Entity)
{
	if (a_Entity.IsMinecart())
	{
		WriteByte(0x51);
		// No idea how Mojang makes their carts shakey shakey, so here is a complicated one-liner expression that does something similar
		WriteInt( (((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * ((const cMinecart &)a_Entity).LastDamage()) * 4 );
		WriteByte(0x52);
		WriteInt(1); // Shaking direction, doesn't seem to affect anything
		WriteByte(0x73);
		WriteFloat((float)(((const cMinecart &)a_Entity).LastDamage() + 10)); // Damage taken / shake effect multiplyer
		
		if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpFurnace)
		{
			WriteByte(0x10);
			WriteByte(((const cMinecartWithFurnace &)a_Entity).IsFueled() ? 1 : 0); // Fueled?
		}
	}
	else if ((a_Entity.IsProjectile() && ((cProjectileEntity &)a_Entity).GetProjectileKind() == cProjectileEntity::pkArrow))
	{
		WriteByte(0x10);
		WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0); // Critical hitting arrow?
	}
}