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

Add enchantment for range dodges #75968

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions doc/MAGIC.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ Character status value | Description
`POWER_TRICKLE` | Generates this amount of millijoules each second. Default value is zero, so better to use `add`
`RANGE` | Modifies your characters range with firearms
`RANGED_DAMAGE` | Adds damage to ranged attacks.
`RANGE_DODGE` | Chance to dodge projectile attack, no matter of it's speed; Consumes dodges similarly to melee dodges, and fails, if character has no dodges left. `add` and `multiply` behave equally. `add: 0.5` would result in 50% chance to avoid projectile
`READING_EXP` | Changes the minimum you learn from each reading increment.
`READING_SPEED_MULTIPLIER` | Changes how fast you can read books; Lesser value means faster book reading, with cap of 1 second.
`RECOIL_MODIFIER` | Affects recoil when shooting a gun. Positive value increase the dispersion, negative decrease one.
Expand Down
46 changes: 31 additions & 15 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,25 @@ void Creature::messaging_projectile_attack( const Creature *source,
}
}

void Creature::print_proj_avoid_msg( Creature *source, viewer &player_view ) const
{
// "Avoid" rather than "dodge", because it includes removing self from the line of fire
// rather than just Matrix-style bullet dodging
if( source != nullptr && player_view.sees( *source ) ) {
add_msg_player_or_npc(
m_warning,
_( "You avoid %s projectile!" ),
get_option<bool>( "LOG_MONSTER_ATTACK_MONSTER" ) ? _( "<npcname> avoids %s projectile." ) : "",
source->disp_name( true ) );
} else {
add_msg_player_or_npc(
m_warning,
_( "You avoid an incoming projectile!" ),
get_option<bool>( "LOG_MONSTER_ATTACK_MONSTER" ) ? _( "<npcname> avoids an incoming projectile." ) :
"" );
}
}

/**
* Attempts to harm a creature with a projectile.
*
Expand Down Expand Up @@ -1243,26 +1262,23 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack
on_try_dodge(); // There's a dodge roll in accuracy_projectile_attack()
}

Character *guy = as_character();
if( guy ) {
double range_dodge_chance = guy->enchantment_cache->modify_value( enchant_vals::mod::RANGE_DODGE,
1.0f ) - 1.0f;
if( x_in_y( range_dodge_chance, 1.0f ) ) {
on_try_dodge();
print_proj_avoid_msg( source, player_view );
return;
}
}

if( goodhit >= 1.0 && !magic ) {
attack.missed_by = 1.0; // Arbitrary value
if( !print_messages ) {
return;
}
// "Avoid" rather than "dodge", because it includes removing self from the line of fire
// rather than just Matrix-style bullet dodging
if( source != nullptr && player_view.sees( *source ) ) {
add_msg_player_or_npc(
m_warning,
_( "You avoid %s projectile!" ),
get_option<bool>( "LOG_MONSTER_ATTACK_MONSTER" ) ? _( "<npcname> avoids %s projectile." ) : "",
source->disp_name( true ) );
} else {
add_msg_player_or_npc(
m_warning,
_( "You avoid an incoming projectile!" ),
get_option<bool>( "LOG_MONSTER_ATTACK_MONSTER" ) ? _( "<npcname> avoids an incoming projectile." ) :
"" );
}
print_proj_avoid_msg( source, player_view );
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,7 @@ class Creature : public viewer
// do messaging and SCT for projectile hit
void messaging_projectile_attack( const Creature *source,
const projectile_attack_results &hit_selection, int total_damage ) const;
void print_proj_avoid_msg( Creature *source, viewer &player_view ) const;
};
std::unique_ptr<talker> get_talker_for( Creature &me );
std::unique_ptr<talker> get_talker_for( const Creature &me );
Expand Down
1 change: 1 addition & 0 deletions src/magic_enchantment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace io
case enchant_vals::mod::REGEN_HP: return "REGEN_HP";
case enchant_vals::mod::REGEN_HP_AWAKE: return "REGEN_HP_AWAKE";
case enchant_vals::mod::MUT_INSTABILITY_MOD: return "MUT_INSTABILITY_MOD";
case enchant_vals::mod::RANGE_DODGE: return "RANGE_DODGE";
case enchant_vals::mod::HUNGER: return "HUNGER";
case enchant_vals::mod::THIRST: return "THIRST";
case enchant_vals::mod::SLEEPINESS: return "SLEEPINESS";
Expand Down
1 change: 1 addition & 0 deletions src/magic_enchantment.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum class mod : int {
FAT_TO_MAX_HP,
CARDIO_MULTIPLIER,
MUT_INSTABILITY_MOD,
RANGE_DODGE,
MAX_HP, // for all limbs! use with caution
REGEN_HP,
REGEN_HP_AWAKE,
Expand Down
Loading