From 7c4cb9a3852e33d8bcc5f8283485e833c6eab93e Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Sep 2014 20:12:56 +0200 Subject: Added CustomName to cMonster. --- src/Mobs/Monster.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index f7ee0b0c0..6a477ca1c 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -75,6 +75,8 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_IdleInterval(0) , m_DestroyTimer(0) , m_MobType(a_MobType) + , m_CustomName("") + , m_CustomNameAlwaysVisible(false) , m_SoundHurt(a_SoundHurt) , m_SoundDeath(a_SoundDeath) , m_AttackRate(3) @@ -679,6 +681,33 @@ void cMonster::InStateEscaping(float a_Dt) +void cMonster::SetCustomName(const AString & a_CustomName) +{ + m_CustomName = a_CustomName; + + // The maximal length is 64 + if (a_CustomName.length() > 64) + { + m_CustomName = a_CustomName.substr(0, 64); + } + + m_World->BroadcastEntityMetadata(*this); +} + + + + + +void cMonster::SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible) +{ + m_CustomNameAlwaysVisible = a_CustomNameAlwaysVisible; + m_World->BroadcastEntityMetadata(*this); +} + + + + + void cMonster::GetMonsterConfig(const AString & a_Name) { cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, a_Name); -- cgit v1.2.3 From dfed6f94ca78f2e104ed316d83400b0ca74cb79a Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Sep 2014 21:05:45 +0200 Subject: Added name tag --- src/Mobs/Monster.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 6a477ca1c..a89fa32a3 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -553,6 +553,25 @@ void cMonster::KilledBy(TakeDamageInfo & a_TDI) +void cMonster::OnRightClicked(cPlayer & a_Player) +{ + super::OnRightClicked(a_Player); + + const cItem & EquippedItem = a_Player.GetEquippedItem(); + if ((EquippedItem.m_ItemType == E_ITEM_NAME_TAG) && !EquippedItem.m_CustomName.empty()) + { + SetCustomName(EquippedItem.m_CustomName); + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + } + } +} + + + + + // Checks to see if EventSeePlayer should be fired // monster sez: Do I see the player void cMonster::CheckEventSeePlayer(void) -- cgit v1.2.3 From 5c53608dd0e59d67a9aad5b03a58e1ff48d619b3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 2 Sep 2014 19:34:58 +0200 Subject: Added CustomName saving. --- src/Mobs/Monster.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index a89fa32a3..b0b836dff 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -710,7 +710,10 @@ void cMonster::SetCustomName(const AString & a_CustomName) m_CustomName = a_CustomName.substr(0, 64); } - m_World->BroadcastEntityMetadata(*this); + if (m_World != NULL) + { + m_World->BroadcastEntityMetadata(*this); + } } @@ -720,7 +723,10 @@ void cMonster::SetCustomName(const AString & a_CustomName) void cMonster::SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible) { m_CustomNameAlwaysVisible = a_CustomNameAlwaysVisible; - m_World->BroadcastEntityMetadata(*this); + if (m_World != NULL) + { + m_World->BroadcastEntityMetadata(*this); + } } -- cgit v1.2.3