From f91c4e33c57f3e23ae6d5d11b8b44a23bd7e25d0 Mon Sep 17 00:00:00 2001 From: Eric Pierce Date: Sat, 1 Feb 2020 11:32:32 -0700 Subject: [PATCH] Don't sell inhaler by individual charges When using this function to sell an inhaler to an NPC, `u.has_charges` is (apparently) returning true (since player has inhaler charges), although the inhaler itself is not counted by charges according to @BevapDin. This change makes `set_u_sell_item` follow more closely the pattern of `set_u_buy_item`, by merging the two separate `if/else` blocks into one, handling both the charge adjustment and `p.i_add` to transfer them item. Most importantly, the first condition for doing charge-based adjustment is whether `count_by_charges()` is true. I've preserved the check for `u.has_charges`, because we need to ensure the requested number of charges are available. Partial fix for #31773 --- src/npctalk.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/npctalk.cpp b/src/npctalk.cpp index b17101e27dc69..8f97436de43b8 100644 --- a/src/npctalk.cpp +++ b/src/npctalk.cpp @@ -1971,24 +1971,20 @@ void talk_effect_fun_t::set_u_sell_item( const std::string &item_name, int cost, npc &p = *d.beta; player &u = *d.alpha; item old_item = item( item_name, calendar::turn ); - if( u.has_charges( item_name, count ) ) { + if( old_item.count_by_charges() && u.has_charges( item_name, count ) ) { u.use_charges( item_name, count ); + old_item.mod_charges( count - 1 ); + p.i_add( old_item ); } else if( u.has_amount( item_name, count ) ) { u.use_amount( item_name, count ); + for( int i_cnt = 0; i_cnt < count; i_cnt++ ) { + p.i_add( old_item ); + } } else { //~ %1$s is a translated item name popup( _( "You don't have a %1$s!" ), old_item.tname() ); return; } - if( old_item.count_by_charges() ) { - old_item.mod_charges( count - 1 ); - p.i_add( old_item ); - } else { - for( int i_cnt = 0; i_cnt < count; i_cnt++ ) { - p.i_add( old_item ); - } - } - if( count == 1 ) { //~ %1%s is the NPC name, %2$s is an item popup( _( "You give %1$s a %2$s." ), p.name, old_item.tname() );