1
0

Add more statistic tracking (#4837)

+ Added possible 1.8 stats
+ Added stat tracking for 1.8.2
+ Added stat tracking for 1.9
+ Added the breed cow achievement

Co-authored-by: 12xx12 <12xx12100@gmail.com>
This commit is contained in:
12xx12 2020-09-05 17:13:44 +02:00 committed by GitHub
parent 2d197e147e
commit c2f8ceb554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 88 additions and 6 deletions

View File

@ -303,6 +303,8 @@ bool cBeaconEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
bool cBeaconEntity::UsedBy(cPlayer * a_Player) bool cBeaconEntity::UsedBy(cPlayer * a_Player)
{ {
a_Player->GetStatManager().AddValue(Statistic::InteractWithBeacon);
cWindow * Window = GetWindow(); cWindow * Window = GetWindow();
if (Window == nullptr) if (Window == nullptr)
{ {

View File

@ -156,6 +156,8 @@ bool cBrewingstandEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
bool cBrewingstandEntity::UsedBy(cPlayer * a_Player) bool cBrewingstandEntity::UsedBy(cPlayer * a_Player)
{ {
a_Player->GetStatManager().AddValue(Statistic::InteractWithBrewingstand);
cWindow * Window = GetWindow(); cWindow * Window = GetWindow();
if (Window == nullptr) if (Window == nullptr)
{ {

View File

@ -105,6 +105,15 @@ bool cChestEntity::UsedBy(cPlayer * a_Player)
} }
} }
if (m_BlockType == E_BLOCK_CHEST)
{
a_Player->GetStatManager().AddValue(Statistic::OpenChest);
}
else // E_BLOCK_TRAPPED_CHEST
{
a_Player->GetStatManager().AddValue(Statistic::TriggerTrappedChest);
}
// If the window is not created, open it anew: // If the window is not created, open it anew:
cWindow * Window = PrimaryChest->GetWindow(); cWindow * Window = PrimaryChest->GetWindow();
if (Window == nullptr) if (Window == nullptr)

View File

@ -153,6 +153,15 @@ void cDropSpenserEntity::SendTo(cClientHandle & a_Client)
bool cDropSpenserEntity::UsedBy(cPlayer * a_Player) bool cDropSpenserEntity::UsedBy(cPlayer * a_Player)
{ {
if (m_BlockType == E_BLOCK_DISPENSER)
{
a_Player->GetStatManager().AddValue(Statistic::InspectDispenser);
}
else // E_BLOCK_DROPPER
{
a_Player->GetStatManager().AddValue(Statistic::InspectDropper);
}
cWindow * Window = GetWindow(); cWindow * Window = GetWindow();
if (Window == nullptr) if (Window == nullptr)
{ {

View File

@ -61,6 +61,9 @@ bool cEnderChestEntity::UsedBy(cPlayer * a_Player)
// Obstruction, don't open // Obstruction, don't open
return false; return false;
} }
a_Player->GetStatManager().AddValue(Statistic::OpenEnderchest);
// If the window is not created, open it anew: // If the window is not created, open it anew:
cWindow * Window = GetWindow(); cWindow * Window = GetWindow();
if (Window == nullptr) if (Window == nullptr)

View File

@ -59,6 +59,8 @@ bool cFlowerPotEntity::UsedBy(cPlayer * a_Player)
return false; return false;
} }
a_Player->GetStatManager().AddValue(Statistic::PotFlower);
cItem SelectedItem = a_Player->GetInventory().GetEquippedItem(); cItem SelectedItem = a_Player->GetInventory().GetEquippedItem();
if (IsFlower(SelectedItem.m_ItemType, SelectedItem.m_ItemDamage)) if (IsFlower(SelectedItem.m_ItemType, SelectedItem.m_ItemDamage))
{ {

View File

@ -139,6 +139,8 @@ bool cFurnaceEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
bool cFurnaceEntity::UsedBy(cPlayer * a_Player) bool cFurnaceEntity::UsedBy(cPlayer * a_Player)
{ {
a_Player->GetStatManager().AddValue(Statistic::InteractWithFurnace);
cWindow * Window = GetWindow(); cWindow * Window = GetWindow();
if (Window == nullptr) if (Window == nullptr)
{ {

View File

@ -106,6 +106,8 @@ void cHopperEntity::SendTo(cClientHandle & a_Client)
bool cHopperEntity::UsedBy(cPlayer * a_Player) bool cHopperEntity::UsedBy(cPlayer * a_Player)
{ {
a_Player->GetStatManager().AddValue(Statistic::InspectHopper);
// If the window is not created, open it anew: // If the window is not created, open it anew:
cWindow * Window = GetWindow(); cWindow * Window = GetWindow();
if (Window == nullptr) if (Window == nullptr)

View File

@ -70,6 +70,8 @@ bool cJukeboxEntity::UsedBy(cPlayer * a_Player)
const cItem & HeldItem = a_Player->GetEquippedItem(); const cItem & HeldItem = a_Player->GetEquippedItem();
if (PlayRecord(HeldItem.m_ItemType) && !a_Player->IsGameModeCreative()) if (PlayRecord(HeldItem.m_ItemType) && !a_Player->IsGameModeCreative())
{ {
a_Player->GetStatManager().AddValue(Statistic::PlayRecord);
a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().RemoveOneEquippedItem();
return true; return true;
} }

View File

@ -4,6 +4,7 @@
#include "NoteEntity.h" #include "NoteEntity.h"
#include "../World.h" #include "../World.h"
#include "json/value.h" #include "json/value.h"
#include "../Entities/Player.h"
@ -33,7 +34,7 @@ void cNoteEntity::CopyFrom(const cBlockEntity & a_Src)
bool cNoteEntity::UsedBy(cPlayer * a_Player) bool cNoteEntity::UsedBy(cPlayer * a_Player)
{ {
UNUSED(a_Player); a_Player->GetStatManager().AddValue(Statistic::TuneNoteblock);
IncrementNote(); IncrementNote();
MakeSound(); MakeSound();
return true; return true;

View File

@ -128,6 +128,7 @@ bool cBlockBedHandler::OnUse(
SetBedPos(a_Player, a_BlockPos); SetBedPos(a_Player, a_BlockPos);
SetBedOccupationState(a_ChunkInterface, a_Player.GetLastBedPos(), true); SetBedOccupationState(a_ChunkInterface, a_Player.GetLastBedPos(), true);
a_Player.SetIsInBed(true); a_Player.SetIsInBed(true);
a_Player.GetStatManager().AddValue(Statistic::SleepInBed);
// Fast-forward the time if all players in the world are in their beds: // Fast-forward the time if all players in the world are in their beds:
auto TimeFastForwardTester = [](cPlayer & a_OtherPlayer) auto TimeFastForwardTester = [](cPlayer & a_OtherPlayer)

View File

@ -36,6 +36,7 @@ public:
return false; return false;
} }
a_Player.GetStatManager().AddValue(Statistic::EatCakeSlice);
if (Meta >= 5) if (Meta >= 5)
{ {
a_ChunkInterface.DigBlock(a_WorldInterface, a_BlockPos); a_ChunkInterface.DigBlock(a_WorldInterface, a_BlockPos);

View File

@ -54,6 +54,7 @@ public:
if (!a_Player.IsGameModeCreative()) if (!a_Player.IsGameModeCreative())
{ {
a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_WATER_BUCKET)); a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_WATER_BUCKET));
a_Player.GetStatManager().AddValue(Statistic::UseCauldron);
} }
} }
break; break;
@ -68,6 +69,7 @@ public:
{ {
a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_BUCKET)); a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_BUCKET));
} }
a_Player.GetStatManager().AddValue(Statistic::FillCauldron);
} }
break; break;
} }

View File

@ -34,6 +34,8 @@ public:
const Vector3i a_CursorPos const Vector3i a_CursorPos
) override ) override
{ {
a_Player.GetStatManager().AddValue(Statistic::InteractWithCraftingTable);
cWindow * Window = new cCraftingWindow(); cWindow * Window = new cCraftingWindow();
a_Player.OpenWindow(*Window); a_Player.OpenWindow(*Window);
return true; return true;

View File

@ -2109,6 +2109,7 @@ void cClientHandle::Tick(float a_Dt)
LOGD("Client %s @ %s (%p) has been queued for destruction, destroying now.", LOGD("Client %s @ %s (%p) has been queued for destruction, destroying now.",
m_Username.c_str(), m_IPString.c_str(), static_cast<void *>(this) m_Username.c_str(), m_IPString.c_str(), static_cast<void *>(this)
); );
GetPlayer()->GetStatManager().AddValue(Statistic::LeaveGame);
Destroy(); Destroy();
return; return;
} }

View File

@ -334,7 +334,12 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
} }
m_Stats.AddValue(Statistic::PlayOneMinute, 1); m_Stats.AddValue(Statistic::PlayOneMinute);
m_Stats.AddValue(Statistic::TimeSinceDeath);
if (IsCrouched())
{
m_Stats.AddValue(Statistic::SneakTime);
}
// Handle the player detach, when the player is in spectator mode // Handle the player detach, when the player is in spectator mode
if ( if (
@ -1235,6 +1240,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
} }
m_Stats.AddValue(Statistic::Deaths); m_Stats.AddValue(Statistic::Deaths);
m_Stats.SetValue(Statistic::TimeSinceDeath, 0);
m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::otDeathCount, 1); m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::otDeathCount, 1);
} }
@ -2675,14 +2681,33 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos, bool a_PreviousIs
} }
else if (IsInWater()) else if (IsInWater())
{ {
// TODO: implement differentiation between diving and swimming if (m_IsHeadInWater)
m_Stats.AddValue(Statistic::WalkUnderWaterOneCm, Value); {
m_Stats.AddValue(Statistic::WalkUnderWaterOneCm, Value);
}
else
{
m_Stats.AddValue(Statistic::WalkOnWaterOneCm, Value);
}
AddFoodExhaustion(0.00015 * static_cast<double>(Value)); AddFoodExhaustion(0.00015 * static_cast<double>(Value));
} }
else if (IsOnGround()) else if (IsOnGround())
{ {
m_Stats.AddValue(Statistic::WalkOneCm, Value); if (IsCrouched())
AddFoodExhaustion((IsSprinting() ? 0.001 : 0.0001) * static_cast<double>(Value)); {
m_Stats.AddValue(Statistic::CrouchOneCm, Value);
AddFoodExhaustion(0.0001 * static_cast<double>(Value));
}
if (IsSprinting())
{
m_Stats.AddValue(Statistic::SprintOneCm, Value);
AddFoodExhaustion(0.001 * static_cast<double>(Value));
}
else
{
m_Stats.AddValue(Statistic::WalkOneCm, Value);
AddFoodExhaustion(0.0001 * static_cast<double>(Value));
}
} }
else else
{ {

View File

@ -57,6 +57,7 @@ void cPassiveMonster::ResetLoveMode()
m_LoveTimer = 0; m_LoveTimer = 0;
m_MatingTimer = 0; m_MatingTimer = 0;
m_LoveCooldown = 20 * 60 * 5; // 5 minutes m_LoveCooldown = 20 * 60 * 5; // 5 minutes
m_Feeder = cUUID();
// when an animal is in love mode, the client only stops sending the hearts if we let them know it's in cooldown, which is done with the "age" metadata // when an animal is in love mode, the client only stops sending the hearts if we let them know it's in cooldown, which is done with the "age" metadata
m_World->BroadcastEntityMetadata(*this); m_World->BroadcastEntityMetadata(*this);
@ -125,6 +126,15 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_World->SpawnExperienceOrb(Pos.x, Pos.y, Pos.z, GetRandomProvider().RandInt(1, 6)); m_World->SpawnExperienceOrb(Pos.x, Pos.y, Pos.z, GetRandomProvider().RandInt(1, 6));
m_World->DoWithPlayerByUUID(m_Feeder, [&] (cPlayer & a_Player)
{
a_Player.GetStatManager().AddValue(Statistic::AnimalsBred);
if (GetMobType() == eMonsterType::mtCow)
{
a_Player.AwardAchievement(Statistic::AchBreedCow);
}
return true;
});
m_LovePartner->ResetLoveMode(); m_LovePartner->ResetLoveMode();
ResetLoveMode(); ResetLoveMode();
} }
@ -241,6 +251,8 @@ void cPassiveMonster::OnRightClicked(cPlayer & a_Player)
} }
} }
} }
// Stores feeder UUID for statistic tracking
m_Feeder = a_Player.GetUUID();
} }

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include "Monster.h" #include "Monster.h"
#include "../UUID.h"
@ -60,6 +61,9 @@ protected:
/** The monster's breeding partner. */ /** The monster's breeding partner. */
cPassiveMonster * m_LovePartner; cPassiveMonster * m_LovePartner;
/** Remembers the player is was last fed by for statistics tracking */
cUUID m_Feeder;
/** If above 0, the monster is in love mode, and will breed if a nearby monster is also in love mode. Decrements by 1 per tick till reaching zero. */ /** If above 0, the monster is in love mode, and will breed if a nearby monster is also in love mode. Decrements by 1 per tick till reaching zero. */
int m_LoveTimer; int m_LoveTimer;