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

NPCs taking canned food donations no longer remove the food from the can #72759

Merged
merged 1 commit into from
Apr 4, 2024
Merged
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
33 changes: 29 additions & 4 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3996,12 +3996,31 @@ talk_effect_fun_t::func f_bulk_trade_accept( const JsonObject &jo, std::string_v
item tmp( d.cur_item );
int quantity = dov_quantity.evaluate( d );
int seller_has = 0;
int seller_has_loose = 0;
std::vector<item> seller_cans;
auto is_canned_item = [&tmp]( const item & e ) {
std::vector<const item_pocket *> pockets = e.get_all_contained_pockets();
return pockets.size() == 1 &&
pockets[0]->size() == 1 &&
pockets[0]->sealed() &&
pockets[0]->front().type == tmp.type;
};
if( tmp.count_by_charges() ) {
seller_has = seller->charges_of( d.cur_item );
} else {
seller_has = seller->items_with( [&tmp]( const item & e ) {
return tmp.type == e.type;
std::vector<item *> cans_tmp = seller->items_with( is_canned_item );
for( item *it : cans_tmp ) {
seller_cans.emplace_back( *it );
}
seller_has_loose = seller->items_with( [&tmp,
&cans_tmp]( const item & e ) {
return tmp.type == e.type &&
!std::any_of( cans_tmp.begin(), cans_tmp.end(), [&e]( const item * n ) {
return &n->get_all_contained_pockets()[0]->front() == &e;
} );
} ).size();
seller_has = cans_tmp.size() + seller_has_loose;

}
seller_has = ( quantity == -1 ) ? seller_has : std::min( seller_has, quantity );
tmp.charges = seller_has;
Expand Down Expand Up @@ -4047,9 +4066,15 @@ talk_effect_fun_t::func f_bulk_trade_accept( const JsonObject &jo, std::string_v
if( tmp.count_by_charges() ) {
seller->use_charges( d.cur_item, seller_has );
} else {
seller->use_amount( d.cur_item, seller_has );
seller->use_amount( d.cur_item, seller_has_loose );
seller->remove_items_with( is_canned_item );
katemonster33 marked this conversation as resolved.
Show resolved Hide resolved
}
if( seller_cans.size() != size_t( seller_has ) ) {
buyer->i_add( tmp );
}
for( const item &it : seller_cans ) {
buyer->i_add( it );
}
buyer->i_add( tmp );
};
}

Expand Down
Loading