summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortycho <work.tycho@gmail.com>2015-05-29 01:12:56 +0200
committertycho <work.tycho@gmail.com>2015-05-29 01:12:56 +0200
commit4956e8700d9a578fc65481c0fcfddf812366f08b (patch)
tree47ae313c74a228d254b08c5a146bbd2ea10e08b7 /src
parentFix comments (diff)
parentFixed Info.lua documentation (diff)
downloadcuberite-4956e8700d9a578fc65481c0fcfddf812366f08b.tar
cuberite-4956e8700d9a578fc65481c0fcfddf812366f08b.tar.gz
cuberite-4956e8700d9a578fc65481c0fcfddf812366f08b.tar.bz2
cuberite-4956e8700d9a578fc65481c0fcfddf812366f08b.tar.lz
cuberite-4956e8700d9a578fc65481c0fcfddf812366f08b.tar.xz
cuberite-4956e8700d9a578fc65481c0fcfddf812366f08b.tar.zst
cuberite-4956e8700d9a578fc65481c0fcfddf812366f08b.zip
Diffstat (limited to 'src')
-rw-r--r--src/ClientHandle.cpp9
-rw-r--r--src/Entities/ArrowEntity.cpp9
-rw-r--r--src/Mobs/AggressiveMonster.cpp3
-rw-r--r--src/Mobs/Monster.cpp11
-rw-r--r--src/Mobs/Monster.h9
-rw-r--r--src/Mobs/Skeleton.cpp7
6 files changed, 29 insertions, 19 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 765ccdee2..9644679d7 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1902,7 +1902,7 @@ void cClientHandle::Tick(float a_Dt)
if (m_TicksSinceLastPacket > 600) // 30 seconds time-out
{
SendDisconnect("Nooooo!! You timed out! D: Come back!");
- Destroy();
+ return;
}
if (m_Player == nullptr)
@@ -2013,7 +2013,6 @@ void cClientHandle::ServerTick(float a_Dt)
if (m_TicksSinceLastPacket > 600) // 30 seconds
{
SendDisconnect("Nooooo!! You timed out! D: Come back!");
- Destroy();
}
}
@@ -2186,6 +2185,7 @@ void cClientHandle::SendDisconnect(const AString & a_Reason)
{
LOGD("Sending a DC: \"%s\"", StripColorCodes(a_Reason).c_str());
m_Protocol->SendDisconnect(a_Reason);
+ Destroy();
m_HasSentDC = true;
}
}
@@ -2922,7 +2922,6 @@ void cClientHandle::PacketBufferFull(void)
// Too much data in the incoming queue, the server is probably too busy, kick the client:
LOGERROR("Too much data in queue for client \"%s\" @ %s, kicking them.", m_Username.c_str(), m_IPString.c_str());
SendDisconnect("Server busy");
- Destroy();
}
@@ -2936,7 +2935,6 @@ void cClientHandle::PacketUnknown(UInt32 a_PacketType)
AString Reason;
Printf(Reason, "Unknown [C->S] PacketType: 0x%x", a_PacketType);
SendDisconnect(Reason);
- Destroy();
}
@@ -2947,7 +2945,6 @@ void cClientHandle::PacketError(UInt32 a_PacketType)
{
LOGERROR("Protocol error while parsing packet type 0x%02x; disconnecting client \"%s\"", a_PacketType, m_Username.c_str());
SendDisconnect("Protocol error");
- Destroy();
}
@@ -2963,7 +2960,7 @@ void cClientHandle::SocketClosed(void)
LOGD("Client %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str());
cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, "Player disconnected");
}
- if (m_State < csDestroying)
+ if ((m_State < csDestroying) && (m_Player != nullptr))
{
cWorld * World = m_Player->GetWorld();
if (World != nullptr)
diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp
index 0618ac2fc..492cf2a56 100644
--- a/src/Entities/ArrowEntity.cpp
+++ b/src/Entities/ArrowEntity.cpp
@@ -84,7 +84,7 @@ void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFa
int X = BlockHit.x, Y = BlockHit.y, Z = BlockHit.z;
m_HitBlockPos = Vector3i(X, Y, Z);
-
+
// Broadcast arrow hit sound
m_World->BroadcastSoundEffect("random.bowhit", (double)X, (double)Y, (double)Z, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
@@ -115,7 +115,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
Damage += ExtraDamage;
}
- int KnockbackAmount = 1;
+ // int KnockbackAmount = 1;
unsigned int PunchLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPunch);
if (PunchLevel > 0)
{
@@ -130,8 +130,9 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
a_EntityHit.SetSpeed(FinalSpeed);
}
- a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount);
-
+ // a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount); // TODO fix knockback.
+ a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 0); // Until knockback is fixed.
+
if (IsOnFire() && !a_EntityHit.IsSubmerged() && !a_EntityHit.IsSwimming())
{
a_EntityHit.StartBurning(100);
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index 7eccf0265..7fde1e56b 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -80,9 +80,10 @@ void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
Vector3d AttackDirection(m_Target->GetPosition() + Vector3d(0, m_Target->GetHeight(), 0) - MyHeadPosition);
- if (ReachedFinalDestination() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast<int>(AttackDirection.Length())))
+ if (TargetIsInRange() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast<int>(AttackDirection.Length())))
{
// Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls)
+ StopMovingToPosition();
Attack(a_Dt);
}
}
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 44a037805..8d71c54e8 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -517,8 +517,15 @@ void cMonster::SetPitchAndYawFromDestination()
}
-
- Vector3d BodyDistance = m_NextWayPointPosition - GetPosition();
+ Vector3d BodyDistance;
+ if (!m_IsFollowingPath && (m_Target != nullptr))
+ {
+ BodyDistance = m_Target->GetPosition() - GetPosition();
+ }
+ else
+ {
+ BodyDistance = m_NextWayPointPosition - GetPosition();
+ }
double BodyRotation, BodyPitch;
BodyDistance.Normalize();
VectorToEuler(BodyDistance.x, BodyDistance.y, BodyDistance.z, BodyRotation, BodyPitch);
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 50bc02558..1076c9544 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -193,13 +193,16 @@ protected:
If no suitable position is found, returns cChunkDef::Height. */
int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ);
- /** Returns if the ultimate, final destination has been reached */
- bool ReachedFinalDestination(void) { return ((m_FinalDestination - GetPosition()).SqrLength() < (m_AttackRange * m_AttackRange)); }
+ /** Returns if the ultimate, final destination has been reached. */
+ bool ReachedFinalDestination(void) { return ((m_FinalDestination - GetPosition()).Length() < GetWidth()/2); }
+
+ /** Returns whether or not the target is close enough for attack. */
+ bool TargetIsInRange(void) { return ((m_FinalDestination - GetPosition()).SqrLength() < (m_AttackRange * m_AttackRange)); }
/** Returns if the intermediate waypoint of m_NextWayPointPosition has been reached */
bool ReachedNextWaypoint(void) { return ((m_NextWayPointPosition - GetPosition()).SqrLength() < 0.25); }
- /** Returns if a monster can reach a given height by jumping */
+ /** Returns if a monster can reach a given height by jumping. */
inline bool DoesPosYRequireJump(int a_PosY)
{
return ((a_PosY > POSY_TOINT) && (a_PosY == POSY_TOINT + 1));
diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp
index 9a99a107c..767e5b95c 100644
--- a/src/Mobs/Skeleton.cpp
+++ b/src/Mobs/Skeleton.cpp
@@ -50,12 +50,13 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cSkeleton::Attack(std::chrono::milliseconds a_Dt)
{
+ cFastRandom Random;
m_AttackInterval += (static_cast<float>(a_Dt.count()) / 1000) * m_AttackRate;
if ((m_Target != nullptr) && (m_AttackInterval > 3.0))
{
- // Setting this higher gives us more wiggle room for attackrate
- Vector3d Speed = GetLookVector() * 20;
- Speed.y = Speed.y + 1;
+ 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)
{