Skip to content

Commit

Permalink
Don't sell inhaler by individual charges
Browse files Browse the repository at this point in the history
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 CleverRaven#31773
  • Loading branch information
wapcaplet committed Feb 1, 2020
1 parent b9d0511 commit f91c4e3
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down

0 comments on commit f91c4e3

Please sign in to comment.