File: character_proficiency.cpp

package info (click to toggle)
cataclysm-dda 0.H-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 710,808 kB
  • sloc: cpp: 524,019; python: 11,580; sh: 1,228; makefile: 1,169; xml: 507; javascript: 150; sql: 56; exp: 41; perl: 37
file content (121 lines) | stat: -rw-r--r-- 3,663 bytes parent folder | download
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
#include "cached_options.h"
#include "character.h"
#include "event_bus.h"
#include "proficiency.h"

bool Character::has_proficiency( const proficiency_id &prof ) const
{
    return _proficiencies->has_learned( prof );
}

float Character::get_proficiency_practice( const proficiency_id &prof ) const
{
    return _proficiencies->pct_practiced( prof );
}

time_duration Character::get_proficiency_practiced_time( const proficiency_id &prof ) const
{
    return _proficiencies->pct_practiced_time( prof );
}

void Character::set_proficiency_practiced_time( const proficiency_id &prof, int turns )
{
    if( turns < 0 ) {
        _proficiencies->remove( prof );
        return;
    }
    _proficiencies->set_time_practiced( prof, time_duration::from_turns( turns ) );
}

bool Character::has_prof_prereqs( const proficiency_id &prof ) const
{
    return _proficiencies->has_prereqs( prof );
}

void Character::add_proficiency( const proficiency_id &prof, bool ignore_requirements )
{
    if( ignore_requirements ) {
        _proficiencies->direct_learn( prof );
        return;
    }
    _proficiencies->learn( prof );
}

void Character::lose_proficiency( const proficiency_id &prof, bool ignore_requirements )
{
    if( ignore_requirements ) {
        _proficiencies->direct_remove( prof );
        return;
    }
    _proficiencies->remove( prof );
}

std::vector<display_proficiency> Character::display_proficiencies() const
{
    return _proficiencies->display();
}

bool Character::practice_proficiency( const proficiency_id &prof, const time_duration &amount,
                                      const std::optional<time_duration> &max )
{
    // Proficiencies can ignore focus using the `ignore_focus` JSON property
    const bool ignore_focus = prof->ignore_focus();
    const time_duration &focused_amount = ignore_focus ? amount : time_duration::from_seconds(
            adjust_for_focus( to_seconds<float>( amount ) ) );

    const float pct_before = _proficiencies->pct_practiced( prof );
    const bool learned = _proficiencies->practice( prof, focused_amount, max );
    const float pct_after = _proficiencies->pct_practiced( prof );

    // Drain focus if necessary
    if( !ignore_focus && pct_after > pct_before ) {
        focus_pool -= focus_pool / 100;
    }

    if( learned ) {
        get_event_bus().send<event_type::gains_proficiency>( getID(), prof );
        add_msg_if_player( m_good, _( "You are now proficient in %s!" ), prof->name() );
    }
    return learned;
}

time_duration Character::proficiency_training_needed( const proficiency_id &prof ) const
{
    return _proficiencies->training_time_needed( prof );
}

std::vector<proficiency_id> Character::known_proficiencies() const
{
    return _proficiencies->known_profs();
}

std::vector<proficiency_id> Character::learning_proficiencies() const
{
    return _proficiencies->learning_profs();
}

int Character::get_proficiency_bonus( const std::string &category,
                                      proficiency_bonus_type prof_bonus ) const
{
    return _proficiencies->get_proficiency_bonus( category, prof_bonus );
}

void Character::set_proficiency_practice( const proficiency_id &id, const time_duration &amount )
{
    if( !test_mode ) {
        return;
    }

    _proficiencies->practice( id, amount, std::nullopt );
}

std::vector<proficiency_id> Character::proficiencies_offered_to( const Character *guy ) const
{
    std::vector<proficiency_id> ret;
    for( const proficiency_id &known : known_proficiencies() ) {
        if( known->is_teachable() && ( !guy || !guy->has_proficiency( known ) ) ) {
            ret.push_back( known );
        }
    }
    return ret;
}