1 #ifndef CORE_PEOPLEMON_STATS_HPP
2 #define CORE_PEOPLEMON_STATS_HPP
4 #include <BLIB/Serialization.hpp>
93 unsigned int level,
const Stats& stages = {});
130 if (!output.write<std::int16_t>(v.
hp))
return false;
131 if (!output.write<std::int16_t>(v.
atk))
return false;
132 if (!output.write<std::int16_t>(v.
def))
return false;
133 if (!output.write<std::int16_t>(v.
spatk))
return false;
134 if (!output.write<std::int16_t>(v.
spdef))
return false;
135 if (!output.write<std::int16_t>(v.
spd))
return false;
140 std::int16_t val = 0;
141 if (!input.read<std::int16_t>(val))
return false;
143 if (!input.read<std::int16_t>(val))
return false;
145 if (!input.read<std::int16_t>(val))
return false;
147 if (!input.read<std::int16_t>(val))
return false;
149 if (!input.read<std::int16_t>(val))
return false;
151 if (!input.read<std::int16_t>(val))
return false;
156 static std::size_t
size(
const Stats&) {
return sizeof(std::int16_t) * 6; }
162 struct SerializableObject<
core::pplmn::Stats> :
public SerializableObjectBase {
165 SerializableField<1, Stats, int>
hp;
166 SerializableField<2, Stats, int>
atk;
167 SerializableField<3, Stats, int>
def;
168 SerializableField<4, Stats, int>
spd;
169 SerializableField<5, Stats, int>
spatk;
170 SerializableField<6, Stats, int>
spdef;
173 : SerializableObjectBase(
"Stats")
174 , hp(
"hp", *this, &
Stats::hp, SerializableFieldBase::Required{})
175 , atk(
"atk", *this, &
Stats::atk, SerializableFieldBase::Required{})
176 , def(
"def", *this, &
Stats::def, SerializableFieldBase::Required{})
177 , spd(
"spd", *this, &
Stats::spd, SerializableFieldBase::Required{})
178 , spatk(
"spatk", *this, &
Stats::spatk, SerializableFieldBase::Required{})
179 , spdef(
"spdef", *this, &
Stats::spdef, SerializableFieldBase::Required{}) {}
Stat
Represents a single stat. Used as an offset to access Stats as an array.
Core classes and functionality for both the editor and game.
bl::serial::json::Serializer< Player > Serializer
Stats for Peoplemon. This struct is used for base stats, EVs, IVs, battle increases/decreases,...
void randomize()
Generates random IV stats.
static constexpr int MaxEVStat
The maximum amount that a single EV can be.
Stats()
Initializes all members to 0.
static constexpr int MaxIVStat
The maximum amount that a single IV can be.
int & get(Stat stat)
Returns a reference to the given stat.
static const std::array< Stat, 6 > IterableStats
Helper array to iterate over stats in loop.
static float stageMultiplier(int stage)
Returns the multiplier for a given stat increase/decrease.
static Stats computeStats(const Stats &base, const Stats &evs, const Stats &ivs, unsigned int level, const Stats &stages={})
Helper method to compute a Peoplemon's current stats.
void addEVs(const Stats &evs)
Adds the given EV points to this set of stats while obeying the constraints on EV values and sums.
static const char * statToString(Stat stat)
Converts the given stat to its string representation.
static constexpr int MaxEVSum
The maximum amount that EVs or IVs can sum to.
int sum() const
Returns the sum of the 6 stats that are used for EV calculations.
static std::size_t size(const Stats &)
static bool serialize(OutputStream &output, const Stats &v)
static bool deserialize(InputStream &input, Stats &v)
SerializableField< 1, Stats, int > hp
SerializableField< 4, Stats, int > spd
SerializableField< 2, Stats, int > atk
SerializableField< 6, Stats, int > spdef
SerializableField< 5, Stats, int > spatk
SerializableField< 3, Stats, int > def