From 57690b81a24a29d70cb6f4196a6e0f521a3cb61b Mon Sep 17 00:00:00 2001 From: changyong guo Date: Thu, 2 Aug 2018 22:59:10 +0800 Subject: Experience orb (#4259) * Replace cWorld::FindClosesPlayer with cWorld::DoWithClosestPlayer * Implement experience reward splitting into the orb sizes used in vanilla * Modified speed calculation in cExpOrb::Tick to make the orbs fly towards the player Fixes #4216 --- src/Mobs/Monster.cpp | 12 +++++------- src/Mobs/Ocelot.cpp | 10 +++++----- src/Mobs/PassiveMonster.cpp | 11 ++++++----- src/Mobs/Wolf.cpp | 13 +++++++------ 4 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/Mobs') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 3c202d693..5327da832 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -660,7 +660,7 @@ void cMonster::KilledBy(TakeDamageInfo & a_TDI) } if ((a_TDI.Attacker != nullptr) && (!IsBaby())) { - m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward); + m_World->SpawnSplitExperienceOrbs(GetPosX(), GetPosY(), GetPosZ(), Reward); } m_DestroyTimer = std::chrono::milliseconds(0); } @@ -712,13 +712,11 @@ void cMonster::OnRightClicked(cPlayer & a_Player) // monster sez: Do I see the player void cMonster::CheckEventSeePlayer(cChunk & a_Chunk) { - // TODO: Rewrite this to use cWorld's DoWithPlayers() - cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), static_cast(m_SightDistance), false); - - if (Closest != nullptr) + m_World->DoWithNearestPlayer(GetPosition(), static_cast(m_SightDistance), [&](cPlayer & a_Player) -> bool { - EventSeePlayer(Closest, a_Chunk); - } + EventSeePlayer(&a_Player, a_Chunk); + return true; + }, false); } diff --git a/src/Mobs/Ocelot.cpp b/src/Mobs/Ocelot.cpp index 02af45a7d..855a11627 100644 --- a/src/Mobs/Ocelot.cpp +++ b/src/Mobs/Ocelot.cpp @@ -47,12 +47,11 @@ void cOcelot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_CheckPlayerTickCount == 23) { - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), 10, true); - if (a_Closest_Player != nullptr) + m_World->DoWithNearestPlayer(GetPosition(), 10, [&](cPlayer & a_Player) -> bool { cItems Items; GetBreedingItems(Items); - if (Items.ContainsType(a_Closest_Player->GetEquippedItem().m_ItemType)) + if (Items.ContainsType(a_Player.GetEquippedItem().m_ItemType)) { if (!IsBegging()) { @@ -60,7 +59,7 @@ void cOcelot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) m_World->BroadcastEntityMetadata(*this); } - MoveToPosition(a_Closest_Player->GetPosition()); + MoveToPosition(a_Player.GetPosition()); } else { @@ -70,8 +69,9 @@ void cOcelot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) m_World->BroadcastEntityMetadata(*this); } } - } + return true; + }, true); m_CheckPlayerTickCount = 0; } else diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index c9345662d..cd0f59153 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -136,16 +136,17 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) GetFollowedItems(FollowedItems); if (FollowedItems.Size() > 0) { - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast(m_SightDistance)); - if (a_Closest_Player != nullptr) + m_World->DoWithNearestPlayer(GetPosition(), static_cast(m_SightDistance), [&](cPlayer & a_Player) -> bool { - cItem EquippedItem = a_Closest_Player->GetEquippedItem(); + cItem EquippedItem = a_Player.GetEquippedItem(); if (FollowedItems.ContainsType(EquippedItem)) { - Vector3d PlayerPos = a_Closest_Player->GetPosition(); + Vector3d PlayerPos = a_Player.GetPosition(); MoveToPosition(PlayerPos); } - } + + return true; + }); } } diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 401175bf0..74924ab11 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -271,10 +271,9 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) if (GetTarget() == nullptr) { - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast(m_SightDistance)); - if (a_Closest_Player != nullptr) + m_World->DoWithNearestPlayer(GetPosition(), static_cast(m_SightDistance), [&](cPlayer & a_Player) -> bool { - switch (a_Closest_Player->GetEquippedItem().m_ItemType) + switch (a_Player.GetEquippedItem().m_ItemType) { case E_ITEM_BONE: case E_ITEM_RAW_BEEF: @@ -291,12 +290,12 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) m_World->BroadcastEntityMetadata(*this); } - m_FinalDestination = a_Closest_Player->GetPosition(); // So that we will look at a player holding food + m_FinalDestination = a_Player.GetPosition(); // So that we will look at a player holding food // Don't move to the player if the wolf is sitting. if (!IsSitting()) { - MoveToPosition(a_Closest_Player->GetPosition()); + MoveToPosition(a_Player.GetPosition()); } break; @@ -310,7 +309,9 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } } } - } + + return true; + }); } else { -- cgit v1.2.3