예제 #1
0
bool cSkeleton::Attack(std::chrono::milliseconds a_Dt)
{
	StopMovingToPosition();  // Todo handle this in a better way, the skeleton does some uneeded recalcs due to inStateChasing
	cFastRandom Random;
	if ((m_Target != nullptr) && (m_AttackCoolDownTicksLeft == 0))
	{
		Vector3d Inaccuracy = Vector3d(Random.NextFloat(0.5) - 0.25, Random.NextFloat(0.5) - 0.25, Random.NextFloat(0.5) - 0.25);
		Vector3d Speed = (m_Target->GetPosition() + Inaccuracy - GetPosition()) * 5;
		Speed.y = Speed.y - 1 + Random.NextInt(3);
		cArrowEntity * Arrow = new cArrowEntity(this, GetPosX(), GetPosY() + 1, GetPosZ(), Speed);
		if (Arrow == nullptr)
		{
			return false;
		}
		if (!Arrow->Initialize(*m_World))
		{
			delete Arrow;
			Arrow = nullptr;
			return false;
		}
		m_World->BroadcastSpawnEntity(*Arrow);
		ResetAttackCooldown();

		return true;
	}
	return false;
}
예제 #2
0
파일: Blaze.cpp 프로젝트: Haxi52/cuberite
bool cBlaze::Attack(std::chrono::milliseconds a_Dt)
{
	if ((m_Target != nullptr) && (m_AttackCoolDownTicksLeft == 0))
	{
		// Setting this higher gives us more wiggle room for attackrate
		Vector3d Speed = GetLookVector() * 20;
		Speed.y = Speed.y + 1;
		cFireChargeEntity * FireCharge = new cFireChargeEntity(this, GetPosX(), GetPosY() + 1, GetPosZ(), Speed);
		if (FireCharge == nullptr)
		{
			return false;
		}
		if (!FireCharge->Initialize(*m_World))
		{
			delete FireCharge;
			FireCharge = nullptr;
			return false;
		}
		m_World->BroadcastSpawnEntity(*FireCharge);
		ResetAttackCooldown();
		// ToDo: Shoot 3 fireballs instead of 1.
		return true;
	}
	return false;
}
예제 #3
0
bool cAggressiveMonster::Attack(std::chrono::milliseconds a_Dt)
{
	if ((GetTarget() == nullptr) || (m_AttackCoolDownTicksLeft != 0))
	{
		return false;
	}

	// Setting this higher gives us more wiggle room for attackrate
	ResetAttackCooldown();
	GetTarget()->TakeDamage(dtMobAttack, this, m_AttackDamage, 0);

	return true;
}
예제 #4
0
bool cSkeleton::Attack(std::chrono::milliseconds a_Dt)
{
	StopMovingToPosition();  // Todo handle this in a better way, the skeleton does some uneeded recalcs due to inStateChasing
	auto & Random = GetRandomProvider();
	if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0))
	{
		Vector3d Inaccuracy = Vector3d(Random.RandReal<double>(-0.25, 0.25), Random.RandReal<double>(-0.25, 0.25), Random.RandReal<double>(-0.25, 0.25));
		Vector3d Speed = (GetTarget()->GetPosition() + Inaccuracy - GetPosition()) * 5;
		Speed.y += Random.RandInt(-1, 1);

		auto Arrow = cpp14::make_unique<cArrowEntity>(this, GetPosX(), GetPosY() + 1, GetPosZ(), Speed);
		auto ArrowPtr = Arrow.get();
		if (!ArrowPtr->Initialize(std::move(Arrow), *m_World))
		{
			return false;
		}

		ResetAttackCooldown();
		return true;
	}
	return false;
}
예제 #5
0
파일: Blaze.cpp 프로젝트: ThuGie/MCServer
bool cBlaze::Attack(std::chrono::milliseconds a_Dt)
{
	if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0))
	{
		// Setting this higher gives us more wiggle room for attackrate
		Vector3d Speed = GetLookVector() * 20;
		Speed.y = Speed.y + 1;

		auto FireCharge = cpp14::make_unique<cFireChargeEntity>(this, GetPosX(), GetPosY() + 1, GetPosZ(), Speed);
		auto FireChargePtr = FireCharge.get();
		if (!FireChargePtr->Initialize(std::move(FireCharge), *m_World))
		{
			return false;
		}

		ResetAttackCooldown();
		// ToDo: Shoot 3 fireballs instead of 1.

		return true;
	}
	return false;
}
예제 #6
0
파일: Ghast.cpp 프로젝트: Haxi52/cuberite
bool cGhast::Attack(std::chrono::milliseconds a_Dt)
{
	if ((m_Target != nullptr) && (m_AttackCoolDownTicksLeft == 0))
	{
		// Setting this higher gives us more wiggle room for attackrate
		Vector3d Speed = GetLookVector() * 20;
		Speed.y = Speed.y + 1;
		cGhastFireballEntity * GhastBall = new cGhastFireballEntity(this, GetPosX(), GetPosY() + 1, GetPosZ(), Speed);
		if (GhastBall == nullptr)
		{
			return false;
		}
		if (!GhastBall->Initialize(*m_World))
		{
			delete GhastBall;
			GhastBall = nullptr;
			return false;
		}
		m_World->BroadcastSpawnEntity(*GhastBall);
		ResetAttackCooldown();
		return true;
	}
	return false;
}