You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

99 lines
1.8 KiB

#pragma once
#include "engine/random.hpp"
namespace devilution {
struct Damage {
int minValue;
int maxValue;
Damage() = default;
constexpr Damage(int fixedValue)
: Damage(fixedValue, fixedValue)
{
}
constexpr Damage(int minValue, int maxValue)
: minValue(minValue)
, maxValue(maxValue)
{
}
[[nodiscard]] bool IsFixed() const
{
return minValue == maxValue;
}
int GetValue() const
{
return IsFixed()
? minValue
: minValue + GenerateRnd(maxValue - minValue + 1);
}
constexpr bool operator==(const Damage &other) const
{
return minValue == other.minValue && maxValue == other.maxValue;
}
constexpr bool operator!=(const Damage &other) const
{
return !(*this == other);
}
constexpr Damage operator+=(Damage damage)
{
minValue += damage.minValue;
maxValue += damage.maxValue;
return *this;
}
constexpr Damage operator-=(Damage damage)
{
minValue -= damage.minValue;
maxValue -= damage.maxValue;
return *this;
}
constexpr Damage operator*=(const int factor)
{
minValue *= factor;
maxValue *= factor;
return *this;
}
constexpr Damage operator/=(const int factor)
{
minValue /= factor;
maxValue /= factor;
return *this;
}
constexpr friend Damage operator+(Damage damage, Damage anotherDamage)
{
damage += anotherDamage;
return damage;
}
constexpr friend Damage operator-(Damage damage, Damage anotherDamage)
{
damage -= anotherDamage;
return damage;
}
constexpr friend Damage operator*(Damage damage, const int factor)
{
damage *= factor;
return damage;
}
constexpr friend Damage operator/(Damage damage, const int factor)
{
damage /= factor;
return damage;
}
};
} // namespace devilution