Fixes
This commit is contained in:
parent
aea866f5b1
commit
466ff2204f
@ -820,7 +820,7 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
|
|||||||
|
|
||||||
if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer()))
|
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))
|
if ((m_Team != NULL) && (m_Team == Attacker->m_Team))
|
||||||
{
|
{
|
||||||
@ -880,7 +880,7 @@ void cPlayer::KilledBy(cEntity * a_Killer)
|
|||||||
}
|
}
|
||||||
else if (a_Killer->IsPlayer())
|
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()));
|
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);
|
eStatistic Prerequisite = cStatInfo::GetPrerequisite(a_Ach);
|
||||||
|
|
||||||
|
// Check if the prerequisites are met
|
||||||
if (Prerequisite != statInvalid)
|
if (Prerequisite != statInvalid)
|
||||||
{
|
{
|
||||||
if (m_Stats.GetValue(Prerequisite) == 0)
|
if (m_Stats.GetValue(Prerequisite) == 0)
|
||||||
@ -1166,14 +1167,16 @@ unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// First time, announce it
|
||||||
cCompositeChat Msg;
|
cCompositeChat Msg;
|
||||||
Msg.AddTextPart(m_PlayerName + " has just earned the achievement ");
|
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);
|
m_World->BroadcastChat(Msg);
|
||||||
|
|
||||||
|
// Increment the statistic
|
||||||
StatValue New = m_Stats.AddValue(a_Ach);
|
StatValue New = m_Stats.AddValue(a_Ach);
|
||||||
|
|
||||||
/* Achievement Get! */
|
// Achievement Get!
|
||||||
m_ClientHandle->SendStatistics(m_Stats);
|
m_ClientHandle->SendStatistics(m_Stats);
|
||||||
|
|
||||||
return New;
|
return New;
|
||||||
@ -1707,9 +1710,8 @@ bool cPlayer::LoadFromDisk()
|
|||||||
|
|
||||||
m_LoadedWorldName = root.get("world", "world").asString();
|
m_LoadedWorldName = root.get("world", "world").asString();
|
||||||
|
|
||||||
/* Load the player stats.
|
// Load the player stats.
|
||||||
* We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
|
// We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
|
||||||
*/
|
|
||||||
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
|
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
|
||||||
StatSerializer.Load();
|
StatSerializer.Load();
|
||||||
|
|
||||||
@ -1784,9 +1786,8 @@ bool cPlayer::SaveToDisk()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the player stats.
|
// Save the player stats.
|
||||||
* We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
|
// 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);
|
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), m_PlayerName, &m_Stats);
|
||||||
if (!StatSerializer.Save())
|
if (!StatSerializer.Save())
|
||||||
{
|
{
|
||||||
|
@ -181,12 +181,9 @@ public:
|
|||||||
cStatManager & GetStatManager() { return m_Stats; }
|
cStatManager & GetStatManager() { return m_Stats; }
|
||||||
|
|
||||||
/** Awards the player an achievement.
|
/** Awards the player an achievement.
|
||||||
*
|
If all prerequisites are met, this method will award the achievement and will broadcast a chat message.
|
||||||
* 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.
|
||||||
* 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) */
|
||||||
*
|
|
||||||
* Returns the _new_ stat value. (0 = Could not award achievement)
|
|
||||||
*/
|
|
||||||
unsigned int AwardAchievement(const eStatistic a_Ach);
|
unsigned int AwardAchievement(const eStatistic a_Ach);
|
||||||
|
|
||||||
void SetIP(const AString & a_IP);
|
void SetIP(const AString & a_IP);
|
||||||
|
@ -464,7 +464,7 @@ bool cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
|
|||||||
return false;
|
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);
|
m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
|
||||||
}
|
}
|
||||||
|
@ -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)
|
: m_Manager(a_Manager)
|
||||||
{
|
{
|
||||||
|
// Even though stats are shared between worlds, they are (usually) saved
|
||||||
|
// inside the folder of the default world.
|
||||||
|
|
||||||
AString StatsPath;
|
AString StatsPath;
|
||||||
Printf(StatsPath, "%s/stats", a_WorldName.c_str());
|
Printf(StatsPath, "%s/stats", a_WorldName.c_str());
|
||||||
|
|
||||||
m_Path = StatsPath + "/" + a_PlayerName + ".json";
|
m_Path = StatsPath + "/" + a_PlayerName + ".json";
|
||||||
|
|
||||||
/* Ensure that the directory exists. */
|
// Ensure that the directory exists.
|
||||||
cFile::CreateFolder(FILE_IO_PREFIX + StatsPath);
|
cFile::CreateFolder(FILE_IO_PREFIX + StatsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,12 @@ class cStatSerializer
|
|||||||
{
|
{
|
||||||
public:
|
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);
|
bool Load(void);
|
||||||
|
|
||||||
|
/* Try to save the player statistics. Returns whether the operation was successful or not. */
|
||||||
bool Save(void);
|
bool Save(void);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user