summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Mobs/Wolf.cpp127
-rw-r--r--source/Mobs/Wolf.h33
-rw-r--r--source/Protocol/Protocol17x.cpp2
3 files changed, 136 insertions, 26 deletions
diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp
index 2baeb4b7b..ac094e870 100644
--- a/source/Mobs/Wolf.cpp
+++ b/source/Mobs/Wolf.cpp
@@ -4,6 +4,7 @@
#include "Wolf.h"
#include "../World.h"
#include "../Entities/Player.h"
+#include "../Root.h"
@@ -11,10 +12,12 @@
cWolf::cWolf(void) :
super("Wolf", mtWolf, "mob.wolf.hurt", "mob.wolf.death", 0.6, 0.8),
- m_bIsAngry(false),
- m_bIsTame(false),
- m_bIsSitting(false),
- m_bIsBegging(false)
+ m_IsAngry(false),
+ m_IsTame(false),
+ m_IsSitting(false),
+ m_IsBegging(false),
+ m_Owner(""),
+ m_Collar(14)
{
}
@@ -25,9 +28,9 @@ cWolf::cWolf(void) :
void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI)
{
super::DoTakeDamage(a_TDI);
- if (!m_bIsTame)
+ if (!m_IsTame)
{
- m_bIsAngry = true;
+ m_IsAngry = true;
}
m_World->BroadcastEntityMetadata(*this); // Broadcast health and possibly angry face
}
@@ -38,7 +41,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 +50,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.GetName());
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED);
}
else
@@ -59,15 +63,26 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
}
}
}
- else if (m_bIsTame)
+ else if (IsTame())
{
- if (m_bIsSitting)
+ if (a_Player.GetName() == m_Owner) // Is the player the owner of the dog?
{
- m_bIsSitting = false;
- }
- else
- {
- m_bIsSitting = true;
+ if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE)
+ {
+ m_Collar = 15 - a_Player.GetEquippedItem().m_ItemDamage;
+ if (!a_Player.IsGameModeCreative())
+ {
+ a_Player.GetInventory().RemoveOneEquippedItem();
+ }
+ }
+ else if (IsSitting())
+ {
+ SetIsSitting(false);
+ }
+ else
+ {
+ SetIsSitting(true);
+ }
}
}
@@ -77,3 +92,83 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
+
+void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ if (!IsAngry())
+ {
+ 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);
+ }
+ }
+ }
+ }
+
+ class cCallback :
+ public cPlayerListCallback
+ {
+ virtual bool Item(cPlayer * Player) override
+ {
+ OwnerCoords = Player->GetPosition();
+ return false;
+ }
+ public:
+ Vector3f OwnerCoords;
+ } ;
+ cCallback Callback;
+ m_World->DoWithPlayer(m_Owner, Callback);
+ Vector3f OwnerCoords = Callback.OwnerCoords;
+
+ if (IsTame())
+ {
+ if (m_Owner != "")
+ {
+ double Distance = (OwnerCoords - GetPosition()).Length();
+ if (Distance < 3)
+ {
+ m_bMovingToDestination = false;
+ } else if((Distance > 30) && (!IsSitting())) {
+ TeleportToCoords(OwnerCoords.x, OwnerCoords.y, OwnerCoords.z);
+ } else {
+ m_Destination = OwnerCoords;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/source/Mobs/Wolf.h b/source/Mobs/Wolf.h
index 98074ba11..bc26fbf9b 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,19 +20,31 @@ 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_IsSitting; }
+ bool IsTame(void) const { return m_IsTame; }
+ bool IsBegging(void) const { return m_IsBegging; }
+ bool IsAngry(void) const { return m_IsAngry; }
+ AString GetOwner(void) const { return m_Owner; }
+ int GetCollarColor(void) const { return m_Collar; }
+
+ // Set functions
+ void SetIsSitting(bool a_IsSitting) { m_IsSitting = a_IsSitting; }
+ void SetIsTame(bool a_IsTame) { m_IsTame = a_IsTame; }
+ void SetIsBegging(bool a_IsBegging) { m_IsBegging = a_IsBegging; }
+ void SetIsAngry(bool a_IsAngry) { m_IsAngry = a_IsAngry; }
+ void SetOwner(AString a_NewOwner) { m_Owner = a_NewOwner; }
private:
- bool m_bIsSitting;
- bool m_bIsTame;
- bool m_bIsBegging;
- bool m_bIsAngry;
-
+ bool m_IsSitting;
+ bool m_IsTame;
+ bool m_IsBegging;
+ bool m_IsAngry;
+ AString m_Owner;
+ int m_Collar;
} ;
diff --git a/source/Protocol/Protocol17x.cpp b/source/Protocol/Protocol17x.cpp
index ebf8f6c33..5022d6dbc 100644
--- a/source/Protocol/Protocol17x.cpp
+++ b/source/Protocol/Protocol17x.cpp
@@ -1752,6 +1752,8 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
WriteFloat((float)(a_Mob.GetHealth()));
WriteByte(0x13);
WriteByte(Wolf.IsBegging() ? 1 : 0);
+ WriteByte(0x14);
+ WriteByte(Wolf.GetCollarColor());
break;
}