Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address training exploits #71487

Merged
merged 10 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions data/json/monsters/mammal.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"aggression": 5,
"morale": 5,
"aggro_character": false,
"melee_skill": 5,
"melee_skill": 3,
"melee_dice": 1,
"stomach_size": 30,
"melee_dice_sides": 1,
Expand Down Expand Up @@ -2544,7 +2544,7 @@
"color": "brown",
"aggression": -45,
"morale": -50,
"melee_skill": 5,
"melee_skill": 3,
"melee_dice": 1,
"melee_dice_sides": 6,
"melee_damage": [ { "damage_type": "cut", "amount": 2 } ],
Expand Down Expand Up @@ -2850,7 +2850,7 @@
"aggression": 20,
"morale": 40,
"aggro_character": false,
"melee_skill": 5,
"melee_skill": 3,
"melee_dice": 1,
"melee_dice_sides": 2,
"melee_damage": [ { "damage_type": "cut", "amount": 1 } ],
Expand Down
11 changes: 8 additions & 3 deletions data/json/monsters/nether.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,21 @@
"color": "white",
"aggression": 100,
"morale": 100,
"melee_skill": 8,
"melee_skill": 7,
"melee_dice": 2,
"melee_dice_sides": 4,
"melee_damage": [ { "damage_type": "cut", "amount": 0 } ],
"melee_damage": [ { "damage_type": "cut", "amount": 2 } ],
"dodge": 2,
"bleed_rate": 50,
"harvest": "demihuman",
"families": [ "prof_intro_biology", "prof_physiology" ],
"weakpoint_sets": [ "wps_humanoid_body" ],
"special_attacks": [ [ "FEAR_PARALYZE", 0 ] ],
"special_attacks": [
[
"FEAR_PARALYZE",
0
]
],
worm-girl marked this conversation as resolved.
Show resolved Hide resolved
"death_function": { "effect": { "id": "death_amigara" } },
"dissect": "dissect_human_sample_single",
"flags": [ "SMELLS", "HEARS", "SEES", "STUMBLES", "HARDTOSHOOT" ],
Expand Down
2 changes: 1 addition & 1 deletion data/json/monsters/zed_fusion.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"color": "red",
"aggression": 40,
"morale": 40,
"melee_skill": 9,
"melee_skill": 4,
"melee_dice": 2,
"melee_dice_sides": 6,
"melee_damage": [ { "damage_type": "cut", "amount": 0 } ],
Expand Down
12 changes: 9 additions & 3 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ static const efftype_id effect_disrupted_sleep( "disrupted_sleep" );
static const efftype_id effect_downed( "downed" );
static const efftype_id effect_drunk( "drunk" );
static const efftype_id effect_earphones( "earphones" );
static const efftype_id effect_fearparalyze( "fearparalyze" );
static const efftype_id effect_flu( "flu" );
static const efftype_id effect_foodpoison( "foodpoison" );
static const efftype_id effect_fungus( "fungus" );
Expand Down Expand Up @@ -1929,7 +1930,7 @@ void Character::on_try_dodge()
set_activity_level( EXTRA_EXERCISE );
}

void Character::on_dodge( Creature *source, float difficulty )
void Character::on_dodge( Creature *source, float difficulty, float training_level )
{
// Make sure we're not practicing dodge in situation where we can't dodge
// We can ignore dodges_left because it was already checked in get_dodge()
Expand All @@ -1946,8 +1947,13 @@ void Character::on_dodge( Creature *source, float difficulty )

// Even if we are not to train still call practice to prevent skill rust
difficulty = std::max( difficulty, 0.0f );
practice( skill_dodge, difficulty * 2, difficulty );

// If training_level is set, treat that as the difficulty instead
if( training_level != 0.0 ) {
difficulty = training_level;
worm-girl marked this conversation as resolved.
Show resolved Hide resolved
}

practice( skill_dodge, difficulty * 2, difficulty );
martial_arts_data->ma_ondodge_effects( *this );

// For adjacent attackers check for techniques usable upon successful dodge
Expand Down Expand Up @@ -2684,7 +2690,7 @@ bool Character::practice( const skill_id &id, int amount, int cap, bool suppress
{
SkillLevel &level = get_skill_level_object( id );
const Skill &skill = id.obj();
if( !level.can_train() || in_sleep_state() ||
if( !level.can_train() || in_sleep_state() || has_effect( effect_fearparalyze ) ||
worm-girl marked this conversation as resolved.
Show resolved Hide resolved
( static_cast<int>( get_skill_level( id ) ) >= MAX_SKILL ) ) {
// Do not practice if: cannot train, asleep, or at effective skill cap
// Leaving as a skill method rather than global for possible future skill cap setting
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ class Character : public Creature, public visitable
float get_stamina_dodge_modifier() const;

/** Called after the player has successfully dodged an attack */
void on_dodge( Creature *source, float difficulty ) override;
void on_dodge( Creature *source, float difficulty, float training_level = 0.0 ) override;
/** Called after the player has tryed to dodge an attack */
void on_try_dodge() override;

Expand Down
13 changes: 7 additions & 6 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ bool Creature::attack_air( const tripoint &p )
return true;
}

bool Creature::dodge_check( float hit_roll, bool force_try )
bool Creature::dodge_check( float hit_roll, bool force_try, float )
{
// If successfully uncanny dodged, no need to calculate dodge chance
if( uncanny_dodge() ) {
Expand All @@ -1444,12 +1444,13 @@ bool Creature::dodge_check( float hit_roll, bool force_try )
return false;
}

bool Creature::dodge_check( monster *z )
bool Creature::dodge_check( monster *z, float training_level )
{
return dodge_check( z->get_hit() );
return dodge_check( z->get_hit(), training_level );
}

bool Creature::dodge_check( monster *z, bodypart_id bp, const damage_instance &dam_inst )
bool Creature::dodge_check( monster *z, bodypart_id bp, const damage_instance &dam_inst,
float training_level )
{

if( is_monster() ) {
Expand All @@ -1470,9 +1471,9 @@ bool Creature::dodge_check( monster *z, bodypart_id bp, const damage_instance &d

//If attack might remove more than half of the part's hp, dodge no matter the odds
if( dmg_ratio >= 0.5f ) {
return dodge_check( z->get_hit(), true );
return dodge_check( z->get_hit(), true, training_level );
} else if( dmg_ratio > 0.0f ) { // else apply usual rules
return dodge_check( z->get_hit() );
return dodge_check( z->get_hit(), training_level );
}

return false;
Expand Down
12 changes: 8 additions & 4 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,13 @@ class Creature : public viewer
*/
void longpull( const std::string &name, const tripoint &p );

bool dodge_check( float hit_roll, bool force_try = false );
bool dodge_check( monster *z );
bool dodge_check( monster *z, bodypart_id bp, const damage_instance &dam_inst );
/**
* If training_level is anything but 0, the check will only train target's skill to that level
*/
bool dodge_check( float hit_roll, bool force_try = false, float training_level = 0 );
worm-girl marked this conversation as resolved.
Show resolved Hide resolved
bool dodge_check( monster *z, float training_level = 0 );
bool dodge_check( monster *z, bodypart_id bp, const damage_instance &dam_inst,
float training_level = 0 );

// Temporarily reveals an invisible player when a monster tries to enter their location
bool stumble_invis( const Creature &player, bool stumblemsg = true );
Expand All @@ -510,7 +514,7 @@ class Creature : public viewer
* This creature just dodged an attack - possibly special/ranged attack - from source.
* Players should train dodge, monsters may use some special defenses.
*/
virtual void on_dodge( Creature *source, float difficulty ) = 0;
virtual void on_dodge( Creature *source, float difficulty, float training_level = 0.0 ) = 0;
/**
* Invoked when the creature attempts to dodge, regardless of success or failure.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3606,7 +3606,7 @@ float monster::speed_rating() const
return ret;
}

void monster::on_dodge( Creature *, float )
void monster::on_dodge( Creature *, float, float )
{
// Currently does nothing, later should handle faction relations
}
Expand Down
2 changes: 1 addition & 1 deletion src/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class monster : public Creature

float stability_roll() const override;
// We just dodged an attack from something
void on_dodge( Creature *source, float difficulty ) override;
void on_dodge( Creature *source, float difficulty, float training_level = 0.0 ) override;
void on_try_dodge() override {}
// Something hit us (possibly null source)
void on_hit( Creature *source, bodypart_id bp_hit,
Expand Down
Loading