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

New enchantment value: AVOID_FRIENDRY_FIRE #69500

Merged
merged 4 commits into from
Nov 21, 2023
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 @@ -777,6 +777,7 @@ Character status value | Description
`ARMOR_STAB` |
`ATTACK_NOISE` | Affects the amount of noise you make while melee attacking.
`ATTACK_SPEED` | Affects attack speed of item even if it's not the one you're wielding.
`AVOID_FRIENDRY_FIRE` | Flat chance for your character to avoid friendry fire if there is a friend in the line of fire. From 0.0 (no chance) to 1.0 (never frindly fire).
`BIONIC_POWER` |
`BONUS_BLOCK` | Affects the number of blocks you can perform.
`BONUS_DODGE` | Affects the number of dodges you can perform.
Expand Down
5 changes: 5 additions & 0 deletions src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
// Or was just IFFing, giving lots of warnings and time to get out of the line of fire
continue;
}
// avoid friendly fire
if( critter->attitude_to( *origin ) == Creature::Attitude::FRIENDLY &&
origin->check_avoid_friendly_fire() ) {
continue;
}
attack.missed_by = cur_missed_by;
bool print_messages = true;
// If the attack is shot, once we're past point-blank,
Expand Down
6 changes: 6 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,12 @@ bool Character::uncanny_dodge()
return false;
}

bool Character::check_avoid_friendly_fire() const
{
double chance = enchantment_cache->modify_value( enchant_vals::mod::AVOID_FRIENDRY_FIRE, 0.0 );
return rng( 0, 99 ) < chance * 100.0;
}

void Character::handle_skill_warning( const skill_id &id, bool force_warning )
{
//remind the player intermittently that no skill gain takes place
Expand Down
1 change: 1 addition & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ class Character : public Creature, public visitable
int get_spell_resist() const override;
/** Handles the uncanny dodge bionic and effects, returns true if the player successfully dodges */
bool uncanny_dodge() override;
bool check_avoid_friendly_fire() const override;
float get_hit_base() const override;

/** Returns the player's sight range */
Expand Down
3 changes: 3 additions & 0 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ class Creature : public viewer
virtual bool uncanny_dodge() {
return false;
}
virtual bool check_avoid_friendly_fire() const {
return false;
}
void set_reachable_zone( int zone ) {
reachable_zone = zone;
}
Expand Down
1 change: 1 addition & 0 deletions src/magic_enchantment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ namespace io
case enchant_vals::mod::EVASION: return "EVASION";
case enchant_vals::mod::OVERKILL_DAMAGE: return "OVERKILL_DAMAGE";
case enchant_vals::mod::RANGE: return "RANGE";
case enchant_vals::mod::AVOID_FRIENDRY_FIRE: return "AVOID_FRIENDRY_FIRE";
case enchant_vals::mod::NUM_MOD: break;
}
cata_fatal( "Invalid enchant_vals::mod" );
Expand Down
1 change: 1 addition & 0 deletions src/magic_enchantment.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ enum class mod : int {
EVASION,
OVERKILL_DAMAGE,
RANGE,
AVOID_FRIENDRY_FIRE,
NUM_MOD
};
} // namespace enchant_vals
Expand Down