Add Statistics and Achievements for newer Network standards
This commit is contained in:
@@ -6,199 +6,78 @@
|
||||
#include "Statistics.h"
|
||||
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wglobal-constructors"
|
||||
#endif
|
||||
|
||||
cStatInfo cStatInfo::ms_Info[statCount] =
|
||||
|
||||
|
||||
void cStatManager::SetValue(const Statistic a_Stat, const StatValue a_Value)
|
||||
{
|
||||
// The order must match the order of enum eStatistic
|
||||
|
||||
// https://minecraft.gamepedia.com/Achievements
|
||||
|
||||
/* Type | Name | Prerequisite */
|
||||
cStatInfo(achOpenInv, "achievement.openInventory"),
|
||||
cStatInfo(achMineWood, "achievement.mineWood", achOpenInv),
|
||||
cStatInfo(achCraftWorkbench, "achievement.buildWorkBench", achMineWood),
|
||||
cStatInfo(achCraftPickaxe, "achievement.buildPickaxe", achCraftWorkbench),
|
||||
cStatInfo(achCraftFurnace, "achievement.buildFurnace", achCraftPickaxe),
|
||||
cStatInfo(achAcquireIron, "achievement.acquireIron", achCraftFurnace),
|
||||
cStatInfo(achCraftHoe, "achievement.buildHoe", achCraftWorkbench),
|
||||
cStatInfo(achMakeBread, "achievement.makeBread", achCraftHoe),
|
||||
cStatInfo(achBakeCake, "achievement.bakeCake", achCraftHoe),
|
||||
cStatInfo(achCraftBetterPick, "achievement.buildBetterPickaxe", achCraftPickaxe),
|
||||
cStatInfo(achCookFish, "achievement.cookFish", achAcquireIron),
|
||||
cStatInfo(achOnARail, "achievement.onARail", achAcquireIron),
|
||||
cStatInfo(achCraftSword, "achievement.buildSword", achCraftWorkbench),
|
||||
cStatInfo(achKillMonster, "achievement.killEnemy", achCraftSword),
|
||||
cStatInfo(achKillCow, "achievement.killCow", achCraftSword),
|
||||
cStatInfo(achFlyPig, "achievement.flyPig", achKillCow),
|
||||
cStatInfo(achSnipeSkeleton, "achievement.snipeSkeleton", achKillMonster),
|
||||
cStatInfo(achDiamonds, "achievement.diamonds", achAcquireIron),
|
||||
cStatInfo(achEnterPortal, "achievement.portal", achDiamonds),
|
||||
cStatInfo(achReturnToSender, "achievement.ghast", achEnterPortal),
|
||||
cStatInfo(achBlazeRod, "achievement.blazeRod", achEnterPortal),
|
||||
cStatInfo(achBrewPotion, "achievement.potion", achBlazeRod),
|
||||
cStatInfo(achEnterTheEnd, "achievement.theEnd", achBlazeRod),
|
||||
cStatInfo(achDefeatDragon, "achievement.theEnd2", achEnterTheEnd),
|
||||
cStatInfo(achCraftEnchantTable, "achievement.enchantments", achDiamonds),
|
||||
cStatInfo(achOverkill, "achievement.overkill", achCraftEnchantTable),
|
||||
cStatInfo(achBookshelf, "achievement.bookcase", achCraftEnchantTable),
|
||||
cStatInfo(achExploreAllBiomes, "achievement.exploreAllBiomes", achEnterTheEnd),
|
||||
cStatInfo(achSpawnWither, "achievement.spawnWither", achDefeatDragon),
|
||||
cStatInfo(achKillWither, "achievement.killWither", achSpawnWither),
|
||||
cStatInfo(achFullBeacon, "achievement.fullBeacon", achKillWither),
|
||||
cStatInfo(achBreedCow, "achievement.breedCow", achKillCow),
|
||||
cStatInfo(achThrowDiamonds, "achievement.diamondsToYou", achDiamonds),
|
||||
|
||||
// https://minecraft.gamepedia.com/Statistics
|
||||
|
||||
/* Type | Name */
|
||||
cStatInfo(statGamesQuit, "stat.leaveGame"),
|
||||
cStatInfo(statMinutesPlayed, "stat.playOneMinute"),
|
||||
cStatInfo(statDistWalked, "stat.walkOneCm"),
|
||||
cStatInfo(statDistSwum, "stat.swimOneCm"),
|
||||
cStatInfo(statDistFallen, "stat.fallOneCm"),
|
||||
cStatInfo(statDistClimbed, "stat.climbOneCm"),
|
||||
cStatInfo(statDistFlown, "stat.flyOneCm"),
|
||||
cStatInfo(statDistDove, "stat.diveOneCm"),
|
||||
cStatInfo(statDistMinecart, "stat.minecartOneCm"),
|
||||
cStatInfo(statDistBoat, "stat.boatOneCm"),
|
||||
cStatInfo(statDistPig, "stat.pigOneCm"),
|
||||
cStatInfo(statDistHorse, "stat.horseOneCm"),
|
||||
cStatInfo(statJumps, "stat.jump"),
|
||||
cStatInfo(statItemsDropped, "stat.drop"),
|
||||
cStatInfo(statDamageDealt, "stat.damageDealt"),
|
||||
cStatInfo(statDamageTaken, "stat.damageTaken"),
|
||||
cStatInfo(statDeaths, "stat.deaths"),
|
||||
cStatInfo(statMobKills, "stat.mobKills"),
|
||||
cStatInfo(statAnimalsBred, "stat.animalsBred"),
|
||||
cStatInfo(statPlayerKills, "stat.playerKills"),
|
||||
cStatInfo(statFishCaught, "stat.fishCaught"),
|
||||
cStatInfo(statJunkFished, "stat.junkFished"),
|
||||
cStatInfo(statTreasureFished, "stat.treasureFished")
|
||||
};
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cStatInfo::cStatInfo()
|
||||
: m_Type(statInvalid)
|
||||
, m_Depends(statInvalid)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cStatInfo::cStatInfo(const eStatistic a_Type, const AString & a_Name, const eStatistic a_Depends)
|
||||
: m_Type(a_Type)
|
||||
, m_Name(a_Name)
|
||||
, m_Depends(a_Depends)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const AString & cStatInfo::GetName(const eStatistic a_Type)
|
||||
{
|
||||
ASSERT((a_Type > statInvalid) && (a_Type < statCount));
|
||||
|
||||
return ms_Info[a_Type].m_Name;
|
||||
m_CustomStatistics[a_Stat] = a_Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
eStatistic cStatInfo::GetType(const AString & a_Name)
|
||||
cStatManager::StatValue cStatManager::AddValue(const Statistic a_Stat, const StatValue a_Delta)
|
||||
{
|
||||
for (unsigned int i = 0; i < ARRAYCOUNT(ms_Info); ++i)
|
||||
return m_CustomStatistics[a_Stat] += a_Delta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cStatManager::SatisfiesPrerequisite(const Statistic a_Stat)
|
||||
{
|
||||
switch (a_Stat)
|
||||
{
|
||||
if (NoCaseCompare(ms_Info[i].m_Name, a_Name) == 0)
|
||||
{
|
||||
return ms_Info[i].m_Type;
|
||||
}
|
||||
case Statistic::AchMineWood: return IsStatisticPresent(Statistic::AchOpenInventory);
|
||||
case Statistic::AchBuildWorkBench: return IsStatisticPresent(Statistic::AchMineWood);
|
||||
case Statistic::AchBuildHoe: return IsStatisticPresent(Statistic::AchBuildWorkBench);
|
||||
case Statistic::AchBakeCake: return IsStatisticPresent(Statistic::AchBuildHoe);
|
||||
case Statistic::AchMakeBread: return IsStatisticPresent(Statistic::AchBuildHoe);
|
||||
case Statistic::AchBuildSword: return IsStatisticPresent(Statistic::AchBuildWorkBench);
|
||||
case Statistic::AchKillCow: return IsStatisticPresent(Statistic::AchBuildSword);
|
||||
case Statistic::AchFlyPig: return IsStatisticPresent(Statistic::AchKillCow);
|
||||
case Statistic::AchBreedCow: return IsStatisticPresent(Statistic::AchKillCow);
|
||||
case Statistic::AchKillEnemy: return IsStatisticPresent(Statistic::AchBuildSword);
|
||||
case Statistic::AchSnipeSkeleton: return IsStatisticPresent(Statistic::AchKillEnemy);
|
||||
case Statistic::AchBuildPickaxe: return IsStatisticPresent(Statistic::AchBuildWorkBench);
|
||||
case Statistic::AchBuildBetterPickaxe: return IsStatisticPresent(Statistic::AchBuildPickaxe);
|
||||
case Statistic::AchBuildFurnace: return IsStatisticPresent(Statistic::AchBuildWorkBench);
|
||||
case Statistic::AchCookFish: return IsStatisticPresent(Statistic::AchBuildFurnace);
|
||||
case Statistic::AchAcquireIron: return IsStatisticPresent(Statistic::AchBuildFurnace);
|
||||
case Statistic::AchOnARail: return IsStatisticPresent(Statistic::AchAcquireIron);
|
||||
case Statistic::AchDiamonds: return IsStatisticPresent(Statistic::AchAcquireIron);
|
||||
case Statistic::AchPortal: return IsStatisticPresent(Statistic::AchDiamonds);
|
||||
case Statistic::AchGhast: return IsStatisticPresent(Statistic::AchPortal);
|
||||
case Statistic::AchBlazeRod: return IsStatisticPresent(Statistic::AchPortal);
|
||||
case Statistic::AchPotion: return IsStatisticPresent(Statistic::AchBlazeRod);
|
||||
case Statistic::AchTheEnd: return IsStatisticPresent(Statistic::AchBlazeRod);
|
||||
case Statistic::AchTheEnd2: return IsStatisticPresent(Statistic::AchTheEnd);
|
||||
case Statistic::AchEnchantments: return IsStatisticPresent(Statistic::AchDiamonds);
|
||||
case Statistic::AchOverkill: return IsStatisticPresent(Statistic::AchEnchantments);
|
||||
case Statistic::AchBookcase: return IsStatisticPresent(Statistic::AchEnchantments);
|
||||
case Statistic::AchExploreAllBiomes: return IsStatisticPresent(Statistic::AchTheEnd);
|
||||
case Statistic::AchSpawnWither: return IsStatisticPresent(Statistic::AchTheEnd2);
|
||||
case Statistic::AchKillWither: return IsStatisticPresent(Statistic::AchSpawnWither);
|
||||
case Statistic::AchFullBeacon: return IsStatisticPresent(Statistic::AchKillWither);
|
||||
case Statistic::AchDiamondsToYou: return IsStatisticPresent(Statistic::AchDiamonds);
|
||||
}
|
||||
|
||||
return statInvalid;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
eStatistic cStatInfo::GetPrerequisite(const eStatistic a_Type)
|
||||
bool cStatManager::IsStatisticPresent(const Statistic a_Stat) const
|
||||
{
|
||||
ASSERT((a_Type > statInvalid) && (a_Type < statCount));
|
||||
|
||||
return ms_Info[a_Type].m_Depends;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cStatManager::cStatManager()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
StatValue cStatManager::GetValue(const eStatistic a_Stat) const
|
||||
{
|
||||
ASSERT((a_Stat > statInvalid) && (a_Stat < statCount));
|
||||
|
||||
return m_MainStats[a_Stat];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cStatManager::SetValue(const eStatistic a_Stat, const StatValue a_Value)
|
||||
{
|
||||
ASSERT((a_Stat > statInvalid) && (a_Stat < statCount));
|
||||
|
||||
m_MainStats[a_Stat] = a_Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
StatValue cStatManager::AddValue(const eStatistic a_Stat, const StatValue a_Delta)
|
||||
{
|
||||
ASSERT((a_Stat > statInvalid) && (a_Stat < statCount));
|
||||
|
||||
m_MainStats[a_Stat] += a_Delta;
|
||||
|
||||
return m_MainStats[a_Stat];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cStatManager::Reset(void)
|
||||
{
|
||||
for (unsigned int i = 0; i < static_cast<unsigned int>(statCount); ++i)
|
||||
const auto Result = m_CustomStatistics.find(a_Stat);
|
||||
if (Result != m_CustomStatistics.end())
|
||||
{
|
||||
m_MainStats[i] = 0;
|
||||
return Result->second > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user