summaryrefslogtreecommitdiffstats
path: root/src/Entities/Player.cpp
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-05-12 16:05:09 +0200
committerandrew <xdotftw@gmail.com>2014-05-12 16:05:09 +0200
commitb3d2b5b2c94193fd9364b26293b7d96b748ff96d (patch)
tree215519ba96caea0269641209452661b8bd6e14da /src/Entities/Player.cpp
parentFixed compilation (diff)
downloadcuberite-b3d2b5b2c94193fd9364b26293b7d96b748ff96d.tar
cuberite-b3d2b5b2c94193fd9364b26293b7d96b748ff96d.tar.gz
cuberite-b3d2b5b2c94193fd9364b26293b7d96b748ff96d.tar.bz2
cuberite-b3d2b5b2c94193fd9364b26293b7d96b748ff96d.tar.lz
cuberite-b3d2b5b2c94193fd9364b26293b7d96b748ff96d.tar.xz
cuberite-b3d2b5b2c94193fd9364b26293b7d96b748ff96d.tar.zst
cuberite-b3d2b5b2c94193fd9364b26293b7d96b748ff96d.zip
Diffstat (limited to 'src/Entities/Player.cpp')
-rw-r--r--src/Entities/Player.cpp70
1 files changed, 66 insertions, 4 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 1df473eb2..48bb509b9 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -17,6 +17,7 @@
#include "../Vector3.h"
#include "../WorldStorage/StatSerializer.h"
+#include "../CompositeChat.h"
#include "inifile/iniFile.h"
#include "json/json.h"
@@ -876,10 +877,6 @@ void cPlayer::KilledBy(cEntity * a_Killer)
cPlayer* Killer = (cPlayer*)a_Killer;
GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), Killer->GetName().c_str()));
-
- Killer->GetStatManager().AddValue(statPlayerKills);
-
- m_World->GetScoreBoard().AddPlayerScore(Killer->GetName(), cObjective::otPlayerKillCount, 1);
}
else
{
@@ -898,6 +895,33 @@ void cPlayer::KilledBy(cEntity * a_Killer)
+void cPlayer::Killed(cEntity * a_Victim)
+{
+ cScoreboard & ScoreBoard = m_World->GetScoreBoard();
+
+ if (a_Victim->IsPlayer())
+ {
+ m_Stats.AddValue(statPlayerKills);
+
+ ScoreBoard.AddPlayerScore(GetName(), cObjective::otPlayerKillCount, 1);
+ }
+ else if (a_Victim->IsMob())
+ {
+ if (((cMonster *)a_Victim)->GetMobFamily() == cMonster::mfHostile)
+ {
+ AwardAchievement(achKillMonster);
+ }
+
+ m_Stats.AddValue(statMobKills);
+ }
+
+ ScoreBoard.AddPlayerScore(GetName(), cObjective::otTotalKillCount, 1);
+}
+
+
+
+
+
void cPlayer::Respawn(void)
{
m_Health = GetMaxHealth();
@@ -1116,6 +1140,44 @@ void cPlayer::SetIP(const AString & a_IP)
+unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
+{
+ eStatistic Prerequisite = cStatInfo::GetPrerequisite(a_Ach);
+
+ if (Prerequisite != statInvalid)
+ {
+ if (m_Stats.GetValue(Prerequisite) == 0)
+ {
+ return 0;
+ }
+ }
+
+ StatValue Old = m_Stats.GetValue(a_Ach);
+
+ if (Old > 0)
+ {
+ return m_Stats.AddValue(a_Ach);
+ }
+ else
+ {
+ 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
+ m_World->BroadcastChat(Msg);
+
+ StatValue New = m_Stats.AddValue(a_Ach);
+
+ /* Achievement Get! */
+ m_ClientHandle->SendStatistics(m_Stats);
+
+ return New;
+ }
+}
+
+
+
+
+
void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
{
SetPosition(a_PosX, a_PosY, a_PosZ);