Skip to content

Commit

Permalink
fix: prevent full ownership transfer when trading with partial charge…
Browse files Browse the repository at this point in the history
…s of item (#4008)

fix: only set ownership to splitted item to give
  • Loading branch information
scarf005 authored Dec 29, 2023
1 parent 232bc01 commit 6ade06b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/npctrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ void npc_trading::transfer_items( std::vector<item_pricing> &stuff, player &,
}

item &gift = *ip.locs.front();
gift.set_owner( receiver );
int charges = npc_gives ? ip.u_charges : ip.npc_charges;
const int charges = npc_gives ? ip.u_charges : ip.npc_charges;

if( ip.charges ) {
receiver.i_add( gift.split( charges ) );
auto to_give = gift.split( charges );
to_give->set_owner( receiver );

receiver.i_add( std::move( to_give ) );
} else {
gift.set_owner( receiver );
for( item *&it : ip.locs ) {
receiver.i_add( it->detach() );
}
Expand Down

0 comments on commit 6ade06b

Please sign in to comment.