2014-04-07 09:31:15 -04:00
|
|
|
|
|
|
|
// Statistics.h
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
#include "Registries/Statistics.h"
|
2014-04-07 09:31:15 -04:00
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
/* Hello fellow developer !
|
|
|
|
In case you are trying to add new statistics to Cuberite you need to do a few things:
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
1. add a new entry to the enum class Statistic in Registries\Statistics.h file
|
|
|
|
2. add this to serialization functions in WorldStorage\NamespaceSerializer.cpp
|
|
|
|
The String in the above is used for saving on disk!
|
|
|
|
so use the same string!
|
2014-04-07 09:31:15 -04:00
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
In case you want to add a mapping of network IDs to the used stats
|
|
|
|
you will find a lua script in ../Tools/BlockTypePaletteGenerator/ExportStatMapping.lua
|
|
|
|
it will provide you with information how to use it. you need a registries.json
|
|
|
|
exported from the server https://wiki.vg/Data_Generators
|
2014-04-07 09:31:15 -04:00
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
Greetings 12xx12 */
|
2014-04-07 09:31:15 -04:00
|
|
|
|
2014-05-11 07:57:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Class that manages the statistics and achievements of a single player. */
|
|
|
|
class cStatManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
typedef unsigned StatValue;
|
|
|
|
typedef std::unordered_map<Statistic, StatValue> CustomStore;
|
2014-05-11 07:57:06 -04:00
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
/** Set the value of the specified statistic. */
|
|
|
|
void SetValue(Statistic a_Stat, StatValue a_Value);
|
2014-05-11 07:57:06 -04:00
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
/** Increments the specified statistic. Returns the new value. */
|
|
|
|
StatValue AddValue(Statistic a_Stat, StatValue a_Delta = 1);
|
2014-05-11 07:57:06 -04:00
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
/** Returns whether the prerequisite for awarding an achievement are satisfied. */
|
|
|
|
bool SatisfiesPrerequisite(Statistic a_Stat);
|
2014-05-11 07:57:06 -04:00
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
/** Invokes the given callbacks for each category of tracked statistics. */
|
|
|
|
template <class CustomCallback>
|
|
|
|
void ForEachStatisticType(CustomCallback a_Custom) const
|
|
|
|
{
|
|
|
|
a_Custom(m_CustomStatistics);
|
|
|
|
}
|
2014-05-11 07:57:06 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
/** Returns if a statistic is both present and has nonzero value. */
|
|
|
|
bool IsStatisticPresent(Statistic a_Stat) const;
|
2014-05-11 07:57:06 -04:00
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
// TODO: Block tallies, entities killed, all the others
|
2014-05-11 07:57:06 -04:00
|
|
|
|
2020-08-12 04:54:36 -04:00
|
|
|
CustomStore m_CustomStatistics;
|
|
|
|
};
|