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

feat(port): prompt before attacking neutral/fleeing monsters except it actually works #4149

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
3 changes: 2 additions & 1 deletion data/json/effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"type": "effect_type",
"id": "hit_by_player",
"name": [ "Hit By Player" ],
"desc": [ "AI tag for when monsters are hit by player. This is a bug if you have it." ]
"desc": [ "AI tag for when monsters are hit by player. This is a bug if you have it." ],
"max_duration": "10 m"
},
{
"type": "effect_type",
Expand Down
9 changes: 9 additions & 0 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class player;
static const efftype_id effect_amigara( "amigara" );
static const efftype_id effect_glowing( "glowing" );
static const efftype_id effect_harnessed( "harnessed" );
static const efftype_id effect_hit_by_player( "hit_by_player" );
static const efftype_id effect_onfire( "onfire" );
static const efftype_id effect_pet( "pet" );
static const efftype_id effect_relax_gas( "relax_gas" );
Expand Down Expand Up @@ -289,6 +290,14 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
return false;
}
}
// Ask for confirmation before attacking a neutral creature unless we've already taken a swing at it
if( ( att == MATT_IGNORE || att == MATT_FLEE ) &&
get_option<bool>( "QUERY_BEFORE_ATTACKING_NEUTRAL" ) &&
!critter.has_effect( effect_hit_by_player ) &&
!query_yn( _( "You may be attacked! Proceed?" ) ) ) {
return false;
}

you.melee_attack( critter, true );
if( critter.is_hallucination() ) {
critter.die( &you );
Expand Down
4 changes: 2 additions & 2 deletions src/melee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ void Character::melee_attack( Creature &t, bool allow_special, const matec_id *f
{
melee::melee_stats.attack_count += 1;
int hit_spread = t.deal_melee_attack( this, hit_roll() );
if( !t.is_player() ) {
// TODO: Per-NPC tracking? Right now monster hit by either npc or player will draw aggro...
// Old check for if the target is player retained in case you somehow hit yourself
if( !t.is_player() && is_player() ) {
t.add_effect( effect_hit_by_player, 10_minutes ); // Flag as attacked by us for AI
}
if( is_mounted() ) {
Expand Down
4 changes: 2 additions & 2 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,8 +1652,8 @@ void monster::melee_attack( Creature &target, float accuracy )

if( target.is_player() ||
( target.is_npc() && g->u.attitude_to( target ) == Attitude::A_FRIENDLY ) ) {
// Make us a valid target for a few turns
add_effect( effect_hit_by_player, 3_turns );
// Make us a valid target
add_effect( effect_hit_by_player, 10_minutes );
}

if( has_flag( MF_HIT_AND_RUN ) ) {
Expand Down
6 changes: 6 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,12 @@ void options_manager::add_options_general()
0, 3600, 200
);

add( "QUERY_BEFORE_ATTACKING_NEUTRAL", general,
translate_marker( "Query before attacking neutral monsters" ),
translate_marker( "If true, you will be prompted to confirm before attacking neutral or fleeing monsters that you have yet to engage in combat with." ),
true
);

add_empty_line();

add( "TURN_DURATION", general, translate_marker( "Realtime turn progression" ),
Expand Down
Loading