forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skill_boost.cpp
63 lines (52 loc) · 1.34 KB
/
skill_boost.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "skill_boost.h"
#include <cmath>
#include <algorithm>
#include <set>
#include "generic_factory.h"
#include "json.h"
namespace
{
generic_factory<skill_boost> all_skill_boosts( "skill boost", "stat" );
} // namespace
const std::vector<skill_boost> &skill_boost::get_all()
{
return all_skill_boosts.get_all();
}
std::optional<skill_boost> skill_boost::get( const std::string &stat_str )
{
for( const skill_boost &boost : get_all() ) {
if( boost.stat() == stat_str ) {
return std::optional<skill_boost>( boost );
}
}
return std::nullopt;
}
void skill_boost::load_boost( const JsonObject &jo, const std::string &src )
{
all_skill_boosts.load( jo, src );
}
void skill_boost::load( const JsonObject &jo, const std::string & )
{
mandatory( jo, was_loaded, "skills", _skills );
mandatory( jo, was_loaded, "skill_offset", _offset );
mandatory( jo, was_loaded, "scaling_power", _power );
}
void skill_boost::reset()
{
all_skill_boosts.reset();
}
std::string skill_boost::stat() const
{
return id.str();
}
const std::vector<std::string> &skill_boost::skills() const
{
return _skills;
}
float skill_boost::calc_bonus( int skill_total ) const
{
if( skill_total + _offset <= 0 ) {
return 0.0;
}
return std::max( 0.0, std::floor( std::pow( skill_total + _offset, _power ) ) );
}