From 160c2625800781bd562e9ebd8c3ec55f2947ba08 Mon Sep 17 00:00:00 2001 From: David Seguin Date: Tue, 11 Jan 2022 14:58:29 -0500 Subject: [PATCH 1/2] Hallucinations: Misc monster fixes - Prevents hallucinations from attacking non-hallucinations - Prevents hallucinations from opening doors - Prevents hallucinations from shoving vehicles --- src/monmove.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/monmove.cpp b/src/monmove.cpp index 4bfe59a3ec72a..be1a316a0b5bf 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -916,7 +916,7 @@ void monster::move() } tripoint_abs_ms next_step; - const bool can_open_doors = has_flag( MF_CAN_OPEN_DOORS ); + const bool can_open_doors = has_flag( MF_CAN_OPEN_DOORS ) && !is_hallucination(); const bool staggers = has_flag( MF_STUMBLES ); if( moved ) { // Implement both avoiding obstacles and staggering. @@ -981,6 +981,10 @@ void monster::move() const Creature *target = creatures.creature_at( candidate, is_hallucination() ); if( target != nullptr ) { + if( is_hallucination() != target->is_hallucination() && !target->is_avatar() ) { + // Hallucinations should only be capable of targetting the player or other hallucinations. + continue; + } const Attitude att = attitude_to( *target ); if( att == Attitude::HOSTILE ) { // When attacking an adjacent enemy, we're direct. @@ -2106,7 +2110,7 @@ void monster::shove_vehicle( const tripoint &remote_destination, const tripoint &nearby_destination ) { map &here = get_map(); - if( this->has_flag( MF_PUSH_VEH ) ) { + if( this->has_flag( MF_PUSH_VEH ) && !is_hallucination() ) { optional_vpart_position vp = here.veh_at( nearby_destination ); if( vp ) { vehicle &veh = vp->vehicle(); From 9ef39a65e89f9d748374d7f423c9be8acf97d9ac Mon Sep 17 00:00:00 2001 From: David Seguin Date: Tue, 11 Jan 2022 16:32:02 -0500 Subject: [PATCH 2/2] Hallucinations: Misc NPC fixes - Prevent hallucinations from opening doors - Prevent player from stealing from hallucinations - Prevent player from trading with ally hallucinations - Prevent player from asking ally hallucinations to drop items - Prevent hallucinations from training the player (and vis-versa) --- data/json/npcs/TALK_COMMON_ALLY.json | 8 +++++--- src/game.cpp | 8 +++++++- src/melee.cpp | 2 +- src/npcmove.cpp | 3 ++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/data/json/npcs/TALK_COMMON_ALLY.json b/data/json/npcs/TALK_COMMON_ALLY.json index 38c0a5a61cd1f..a86055ea095f7 100644 --- a/data/json/npcs/TALK_COMMON_ALLY.json +++ b/data/json/npcs/TALK_COMMON_ALLY.json @@ -122,6 +122,7 @@ { "npc_need": "hunger", "amount": 160 }, { "npc_need": "fatigue", "level": "TIRED" }, { "npc_has_effect": "asked_to_train" }, + { "npc_has_trait": "HALLUCINATION" }, "u_driving", "npc_driving" ] @@ -132,7 +133,7 @@ }, { "text": "Can you host a training seminar?", - "condition": { "not": "is_by_radio" }, + "condition": { "and": [ { "not": "is_by_radio" }, { "not": { "npc_has_trait": "HALLUCINATION" } } ] }, "trial": { "type": "CONDITION", "condition": { @@ -156,7 +157,8 @@ { "not": "u_driving" }, { "not": "npc_driving" }, { "not": "is_by_radio" }, - { "not": { "u_has_effect": "asked_to_train" } } + { "not": { "u_has_effect": "asked_to_train" } }, + { "not": { "npc_has_trait": "HALLUCINATION" } } ] }, "topic": "TALK_TRAIN_NPC" @@ -202,7 +204,7 @@ }, { "text": "Drop off any items you're not using.", - "condition": { "not": "is_by_radio" }, + "condition": { "and": [ { "not": "is_by_radio" }, { "not": { "npc_has_trait": "HALLUCINATION" } } ] }, "topic": "TALK_DONE", "effect": "drop_items_in_place" }, diff --git a/src/game.cpp b/src/game.cpp index 1fecd3bd2a4bc..7ace1bbe798c4 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -160,6 +160,7 @@ #include "string_input_popup.h" #include "submap.h" #include "talker.h" +#include "text_snippets.h" #include "tileray.h" #include "timed_event.h" #include "translations.h" @@ -5277,7 +5278,12 @@ bool game::npc_menu( npc &who ) } else if( choice == steal && query_yn( _( "You may be attacked! Proceed?" ) ) ) { u.steal( who ); } else if( choice == trade ) { - npc_trading::trade( who, 0, _( "Trade" ) ); + if( who.is_hallucination() ) { + who.say( SNIPPET.random_from_category( "" ).value_or( + translation() ).translated() ); + } else { + npc_trading::trade( who, 0, _( "Trade" ) ); + } } return true; diff --git a/src/melee.cpp b/src/melee.cpp index 2799ff9421517..fed1ea2be8eb4 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -2839,7 +2839,7 @@ void avatar::steal( npc &target ) int their_roll = dice( 5, target.get_per() ); const item *it = loc.get_item(); - if( my_roll >= their_roll ) { + if( my_roll >= their_roll && !target.is_hallucination() ) { add_msg( _( "You sneakily steal %1$s from %2$s!" ), it->tname(), target.get_name() ); i_add( target.i_rem( it ) ); diff --git a/src/npcmove.cpp b/src/npcmove.cpp index fe5af77d66a2c..dd9d0eb8bbb8b 100644 --- a/src/npcmove.cpp +++ b/src/npcmove.cpp @@ -2241,7 +2241,8 @@ bool npc::update_path( const tripoint &p, const bool no_bashing, bool force ) bool npc::can_open_door( const tripoint &p, const bool inside ) const { - return !rules.has_flag( ally_rule::avoid_doors ) && get_map().open_door( p, inside, true ); + return !is_hallucination() && !rules.has_flag( ally_rule::avoid_doors ) && + get_map().open_door( p, inside, true ); } bool npc::can_move_to( const tripoint &p, bool no_bashing ) const