summaryrefslogtreecommitdiffstats
path: root/source/Mobs
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2013-11-10 15:16:43 +0100
committerSTRWarrior <niels.breuker@hotmail.nl>2013-11-10 15:16:43 +0100
commit38f6fff3fbe7c90899b319f53b08d48714a3c845 (patch)
tree775900f13af248900d97edd726006c62348974a0 /source/Mobs
parentProtocol 1.7: Attempt at fixing SoundParticleEffect packet. (diff)
downloadcuberite-38f6fff3fbe7c90899b319f53b08d48714a3c845.tar
cuberite-38f6fff3fbe7c90899b319f53b08d48714a3c845.tar.gz
cuberite-38f6fff3fbe7c90899b319f53b08d48714a3c845.tar.bz2
cuberite-38f6fff3fbe7c90899b319f53b08d48714a3c845.tar.lz
cuberite-38f6fff3fbe7c90899b319f53b08d48714a3c845.tar.xz
cuberite-38f6fff3fbe7c90899b319f53b08d48714a3c845.tar.zst
cuberite-38f6fff3fbe7c90899b319f53b08d48714a3c845.zip
Diffstat (limited to 'source/Mobs')
-rw-r--r--source/Mobs/Wolf.cpp94
-rw-r--r--source/Mobs/Wolf.h23
2 files changed, 100 insertions, 17 deletions
diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp
index 2baeb4b7b..e9d3ce394 100644
--- a/source/Mobs/Wolf.cpp
+++ b/source/Mobs/Wolf.cpp
@@ -14,7 +14,8 @@ cWolf::cWolf(void) :
m_bIsAngry(false),
m_bIsTame(false),
m_bIsSitting(false),
- m_bIsBegging(false)
+ m_bIsBegging(false),
+ m_bOwner(NULL)
{
}
@@ -38,7 +39,7 @@ void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI)
void cWolf::OnRightClicked(cPlayer & a_Player)
{
- if ((!m_bIsTame) && (!m_bIsAngry))
+ if ((!IsTame()) && (!IsAngry()))
{
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_BONE)
{
@@ -47,10 +48,11 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
a_Player.GetInventory().RemoveOneEquippedItem();
}
- if (m_World->GetTickRandomNumber(10) == 5)
+ if (m_World->GetTickRandomNumber(7) == 0)
{
SetMaxHealth(20);
- m_bIsTame = true;
+ SetIsTame(true);
+ SetOwner(&a_Player);
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED);
}
else
@@ -59,15 +61,18 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
}
}
}
- else if (m_bIsTame)
+ else if (IsTame())
{
- if (m_bIsSitting)
+ if (m_bOwner != NULL && a_Player.GetUniqueID() == m_bOwner->GetUniqueID()) // Is the player the owner of the dog?
{
- m_bIsSitting = false;
- }
- else
- {
- m_bIsSitting = true;
+ if (IsSitting())
+ {
+ SetIsSitting(false);
+ }
+ else
+ {
+ SetIsSitting(true);
+ }
}
}
@@ -77,3 +82,70 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
+
+void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ if (!IsAngry())
+ {
+ super::cMonster::Tick(a_Dt, a_Chunk);
+ } else {
+ super::Tick(a_Dt, a_Chunk);
+ }
+
+ if (IsSitting())
+ {
+ m_bMovingToDestination = false;
+ }
+
+ cPlayer * a_Closest_Player = FindClosestPlayer();
+ if (a_Closest_Player != NULL)
+ {
+ switch (a_Closest_Player->GetEquippedItem().m_ItemType)
+ {
+ case E_ITEM_BONE:
+ case E_ITEM_RAW_BEEF:
+ case E_ITEM_STEAK:
+ case E_ITEM_RAW_CHICKEN:
+ case E_ITEM_COOKED_CHICKEN:
+ case E_ITEM_ROTTEN_FLESH:
+ {
+ if (!IsBegging())
+ {
+ SetIsBegging(true);
+ m_World->BroadcastEntityMetadata(*this);
+ }
+ Vector3f a_NewDestination = a_Closest_Player->GetPosition();
+ a_NewDestination.y = a_NewDestination.y + 1; // Look at the head of the player, not his feet.
+ m_Destination = Vector3f(a_NewDestination);
+ m_bMovingToDestination = false;
+ break;
+ }
+ default:
+ {
+ if (IsBegging())
+ {
+ SetIsBegging(false);
+ m_World->BroadcastEntityMetadata(*this);
+ }
+ }
+ }
+ }
+
+ if (IsTame())
+ {
+ if (m_bOwner != NULL)
+ {
+ Vector3f OwnerCoords = m_bOwner->GetPosition();
+ double Distance = (OwnerCoords - GetPosition()).Length();
+ if (Distance < 3)
+ {
+ m_bMovingToDestination = false;
+ } else if((Distance > 30) && (!IsSitting())) {
+ TeleportToEntity(*m_bOwner);
+ } else {
+ m_Destination = OwnerCoords;
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/source/Mobs/Wolf.h b/source/Mobs/Wolf.h
index 98074ba11..e1ce25200 100644
--- a/source/Mobs/Wolf.h
+++ b/source/Mobs/Wolf.h
@@ -2,6 +2,7 @@
#pragma once
#include "PassiveAggressiveMonster.h"
+#include "../Entities/Entity.h"
@@ -19,11 +20,21 @@ public:
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
-
- bool IsSitting(void) const { return m_bIsSitting; }
- bool IsTame(void) const { return m_bIsTame; }
- bool IsBegging(void) const { return m_bIsBegging; }
- bool IsAngry(void) const { return m_bIsAngry; }
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+
+ // Get functions
+ bool IsSitting(void) const { return m_bIsSitting; }
+ bool IsTame(void) const { return m_bIsTame; }
+ bool IsBegging(void) const { return m_bIsBegging; }
+ bool IsAngry(void) const { return m_bIsAngry; }
+ cEntity * GetOwner(void) const { return m_bOwner; }
+
+ // Set functions
+ void SetIsSitting(bool a_IsSitting) { m_bIsSitting = a_IsSitting; }
+ void SetIsTame(bool a_IsTame) { m_bIsTame = a_IsTame; }
+ void SetIsBegging(bool a_IsBegging) { m_bIsBegging = a_IsBegging; }
+ void SetIsAngry(bool a_IsAngry) { m_bIsAngry = a_IsAngry; }
+ void SetOwner(cEntity * a_Entity) { m_bOwner = a_Entity; }
private:
@@ -31,7 +42,7 @@ private:
bool m_bIsTame;
bool m_bIsBegging;
bool m_bIsAngry;
-
+ cEntity * m_bOwner;
} ;