summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-05-13 13:53:15 +0200
committerandrew <xdotftw@gmail.com>2014-05-13 13:53:15 +0200
commit466ff2204f18fda5f4f0f0b3e19f671d57747c24 (patch)
tree164ce181d4c1bde9801f51296e497a4a603796dc
parentMovement Statistics (diff)
downloadcuberite-466ff2204f18fda5f4f0f0b3e19f671d57747c24.tar
cuberite-466ff2204f18fda5f4f0f0b3e19f671d57747c24.tar.gz
cuberite-466ff2204f18fda5f4f0f0b3e19f671d57747c24.tar.bz2
cuberite-466ff2204f18fda5f4f0f0b3e19f671d57747c24.tar.lz
cuberite-466ff2204f18fda5f4f0f0b3e19f671d57747c24.tar.xz
cuberite-466ff2204f18fda5f4f0f0b3e19f671d57747c24.tar.zst
cuberite-466ff2204f18fda5f4f0f0b3e19f671d57747c24.zip
-rw-r--r--src/Entities/Player.cpp21
-rw-r--r--src/Entities/Player.h9
-rw-r--r--src/Mobs/Monster.cpp2
-rw-r--r--src/WorldStorage/StatSerializer.cpp7
-rw-r--r--src/WorldStorage/StatSerializer.h4
5 files changed, 23 insertions, 20 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 3df7c4c34..632c41936 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -820,7 +820,7 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer()))
{
- cPlayer* Attacker = (cPlayer*) a_TDI.Attacker;
+ cPlayer * Attacker = (cPlayer *)a_TDI.Attacker;
if ((m_Team != NULL) && (m_Team == Attacker->m_Team))
{
@@ -880,7 +880,7 @@ void cPlayer::KilledBy(cEntity * a_Killer)
}
else if (a_Killer->IsPlayer())
{
- cPlayer* Killer = (cPlayer*)a_Killer;
+ cPlayer * Killer = (cPlayer *)a_Killer;
GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), Killer->GetName().c_str()));
}
@@ -1150,6 +1150,7 @@ unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
{
eStatistic Prerequisite = cStatInfo::GetPrerequisite(a_Ach);
+ // Check if the prerequisites are met
if (Prerequisite != statInvalid)
{
if (m_Stats.GetValue(Prerequisite) == 0)
@@ -1166,14 +1167,16 @@ unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
}
else
{
+ // First time, announce it
cCompositeChat Msg;
Msg.AddTextPart(m_PlayerName + " has just earned the achievement ");
- Msg.AddTextPart(cStatInfo::GetName(a_Ach)); // TODO 2014-05-12 xdot: Use the proper cCompositeChat submessage type and send the actual title
+ Msg.AddTextPart(cStatInfo::GetName(a_Ach)); // TODO 2014-05-12 xdot: Use the proper cCompositeChat part (cAchievement)
m_World->BroadcastChat(Msg);
+ // Increment the statistic
StatValue New = m_Stats.AddValue(a_Ach);
- /* Achievement Get! */
+ // Achievement Get!
m_ClientHandle->SendStatistics(m_Stats);
return New;
@@ -1707,9 +1710,8 @@ bool cPlayer::LoadFromDisk()
m_LoadedWorldName = root.get("world", "world").asString();
- /* Load the player stats.
- * We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
- */
+ // Load the player stats.
+ // We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
StatSerializer.Load();
@@ -1784,9 +1786,8 @@ bool cPlayer::SaveToDisk()
return false;
}
- /* Save the player stats.
- * We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
- */
+ // Save the player stats.
+ // We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), m_PlayerName, &m_Stats);
if (!StatSerializer.Save())
{
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 3de5e9c68..78b534d83 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -181,12 +181,9 @@ public:
cStatManager & GetStatManager() { return m_Stats; }
/** Awards the player an achievement.
- *
- * If all prerequisites are met, this method will award the achievement and will broadcast a chat message.
- * If the achievement has been already awarded to the player, this method will just increment the stat counter.
- *
- * Returns the _new_ stat value. (0 = Could not award achievement)
- */
+ If all prerequisites are met, this method will award the achievement and will broadcast a chat message.
+ If the achievement has been already awarded to the player, this method will just increment the stat counter.
+ Returns the _new_ stat value. (0 = Could not award achievement) */
unsigned int AwardAchievement(const eStatistic a_Ach);
void SetIP(const AString & a_IP);
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index f3b408e68..b2e42445b 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -464,7 +464,7 @@ bool cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
return false;
}
- if ((m_SoundHurt != "") && (m_Health > 0))
+ if (!m_SoundHurt.empty() && (m_Health > 0))
{
m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
}
diff --git a/src/WorldStorage/StatSerializer.cpp b/src/WorldStorage/StatSerializer.cpp
index 66e5e1e9e..74113941c 100644
--- a/src/WorldStorage/StatSerializer.cpp
+++ b/src/WorldStorage/StatSerializer.cpp
@@ -11,15 +11,18 @@
-cStatSerializer::cStatSerializer(const AString& a_WorldName, const AString& a_PlayerName, cStatManager* a_Manager)
+cStatSerializer::cStatSerializer(const AString & a_WorldName, const AString & a_PlayerName, cStatManager * a_Manager)
: m_Manager(a_Manager)
{
+ // Even though stats are shared between worlds, they are (usually) saved
+ // inside the folder of the default world.
+
AString StatsPath;
Printf(StatsPath, "%s/stats", a_WorldName.c_str());
m_Path = StatsPath + "/" + a_PlayerName + ".json";
- /* Ensure that the directory exists. */
+ // Ensure that the directory exists.
cFile::CreateFolder(FILE_IO_PREFIX + StatsPath);
}
diff --git a/src/WorldStorage/StatSerializer.h b/src/WorldStorage/StatSerializer.h
index 43514465b..72f8d74f1 100644
--- a/src/WorldStorage/StatSerializer.h
+++ b/src/WorldStorage/StatSerializer.h
@@ -25,10 +25,12 @@ class cStatSerializer
{
public:
- cStatSerializer(const AString& a_WorldName, const AString& a_PlayerName, cStatManager* a_Manager);
+ cStatSerializer(const AString & a_WorldName, const AString & a_PlayerName, cStatManager * a_Manager);
+ /* Try to load the player statistics. Returns whether the operation was successful or not. */
bool Load(void);
+ /* Try to save the player statistics. Returns whether the operation was successful or not. */
bool Save(void);