forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character_martial_arts.cpp
162 lines (137 loc) · 4.08 KB
/
character_martial_arts.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "character_martial_arts.h"
#include <algorithm>
#include "action.h"
#include "character.h"
#include "color.h"
#include "enums.h"
#include "json.h"
#include "martialarts.h"
#include "messages.h"
#include "output.h"
#include "string_id.h"
#include "translations.h"
static const matype_id style_kicks( "style_kicks" );
static const matype_id style_none( "style_none" );
character_martial_arts::character_martial_arts()
{
keep_hands_free = false;
style_selected = style_none;
ma_styles = { {
style_none, style_kicks
}
};
}
bool character_martial_arts::selected_allow_melee() const
{
return style_selected->allow_melee;
}
bool character_martial_arts::selected_strictly_melee() const
{
return style_selected->strictly_melee;
}
bool character_martial_arts::selected_has_weapon( const itype_id &weap ) const
{
return style_selected->has_weapon( weap );
}
bool character_martial_arts::selected_force_unarmed() const
{
return style_selected->force_unarmed;
}
bool character_martial_arts::knows_selected_style() const
{
return has_martialart( style_selected );
}
bool character_martial_arts::selected_is_none() const
{
return style_selected == style_none;
}
void character_martial_arts::learn_current_style_CQB( bool is_avatar )
{
add_martialart( style_selected );
if( is_avatar ) {
add_msg( m_good, _( "You have learned %s from extensive practice with the CQB Bionic." ),
style_selected->name );
}
}
void character_martial_arts::learn_style( const matype_id &mastyle, bool is_avatar )
{
add_martialart( mastyle );
if( is_avatar ) {
add_msg( m_good, _( "You learn %s." ),
mastyle->name );
add_msg( m_info, _( "%s to select martial arts style." ),
press_x( ACTION_PICK_STYLE ) );
}
}
void character_martial_arts::set_style( const matype_id &mastyle, bool force )
{
if( force || has_martialart( mastyle ) ) {
style_selected = mastyle;
}
}
void character_martial_arts::reset_style()
{
style_selected = style_none;
}
void character_martial_arts::selected_style_check()
{
// check if player knows current style naturally, otherwise drop them back to style_none
if( style_selected != style_none && style_selected != style_kicks ) {
bool has_style = false;
for( const matype_id &elem : ma_styles ) {
if( elem == style_selected ) {
has_style = true;
}
}
if( !has_style ) {
reset_style();
}
}
}
std::string character_martial_arts::enumerate_known_styles( const itype_id &weap ) const
{
return enumerate_as_string( ma_styles.begin(), ma_styles.end(),
[weap]( const matype_id & mid ) {
return mid->has_weapon( weap ) ? colorize( mid->name.translated(), c_cyan ) : std::string();
} );
}
std::string character_martial_arts::selected_style_name( const Character &owner ) const
{
if( style_selected->force_unarmed || style_selected->weapon_valid( owner.primary_weapon() ) ) {
return style_selected->name.translated();
} else if( owner.is_armed() ) {
return _( "Normal" );
} else {
return _( "No Style" );
}
}
std::vector<matype_id> character_martial_arts::get_unknown_styles( const character_martial_arts
&from ) const
{
std::vector<matype_id> ret;
for( const matype_id &i : from.ma_styles ) {
if( !has_martialart( i ) ) {
ret.push_back( i );
}
}
return ret;
}
std::vector<matype_id> character_martial_arts::get_known_styles() const
{
return ma_styles;
}
void character_martial_arts::serialize( JsonOut &json ) const
{
json.start_object();
json.member( "ma_styles", ma_styles );
json.member( "keep_hands_free", keep_hands_free );
json.member( "style_selected", style_selected );
json.end_object();
}
void character_martial_arts::deserialize( JsonIn &jsin )
{
JsonObject data = jsin.get_object();
data.read( "ma_styles", ma_styles );
data.read( "keep_hands_free", keep_hands_free );
data.read( "style_selected", style_selected );
}