Skip to content

Commit

Permalink
Add param (#64070)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramza13 authored Mar 9, 2023
1 parent d49dc14 commit d1c1d78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,8 @@ Effect | Description
`give_equipment` | Allows your character to select items from the NPC's inventory and transfer them to your inventory.
`npc_gets_item` | Allows your character to select an item from your character's inventory and transfer it to the NPC's inventory. The NPC will not accept it if they do not have space or weight to carry it, and will set a reason that can be referenced in a future dynamic line with `"use_reason"`.
`npc_gets_item_to_use` | Allow your character to select an item from your character's inventory and transfer it to the NPC's inventory. The NPC will attempt to wield it and will not accept it if it is too heavy or is an inferior weapon to what they are currently using, and will set a reason that can be referenced in a future dynamic line with `"use_reason"`.
`u_spawn_item: `string or [variable object](#variable-object), (*optional* `count: `int or [variable object](#variable-object)), (*optional* `container: `string or [variable object](#variable-object)), (*optional* `use_item_group: `bool) | Your character gains the item or `count` copies of the item, contained in container if specified. If used in an NPC conversation the items are said to be given by the NPC. If a variable item is passed for the name an item of the type contained in it will be used. If `use_item_group` is true (defaults to false) it will instead pull an item from the item group given.
`u_buy_item: `string or [variable object](#variable-object), `cost: `int or [variable object](#variable-object), (*optional* `count: `int or [variable object](#variable-object)), (*optional* `container: `string or [variable object](#variable-object)), (*optional* `true_eocs: eocs_array`), (*optional* `false_eocs: eocs_array`), (*optional* `use_item_group: `bool) | The NPC will sell your character the item or `count` copies of the item, contained in `container`, and will subtract `cost` from `op_of_u.owed`. If the `op_o_u.owed` is less than `cost`, the trade window will open and the player will have to trade to make up the difference; the NPC will not give the player the item unless `cost` is satisfied. If `use_item_group` is true (defaults to false) it will instead pull an item from the item group given.
`u_spawn_item: `string or [variable object](#variable-object), (*optional* `count: `int or [variable object](#variable-object)), (*optional* `container: `string or [variable object](#variable-object)), (*optional* `use_item_group: `bool), (*optional* `suppress_message: `bool) | Your character gains the item or `count` copies of the item, contained in container if specified. If used in an NPC conversation the items are said to be given by the NPC. If a variable item is passed for the name an item of the type contained in it will be used. If `use_item_group` is true (defaults to false) it will instead pull an item from the item group given. If `suppress_message` is true (defaults to false) no message will be shown.
`u_buy_item: `string or [variable object](#variable-object), `cost: `int or [variable object](#variable-object), (*optional* `count: `int or [variable object](#variable-object)), (*optional* `container: `string or [variable object](#variable-object)), (*optional* `true_eocs: eocs_array`), (*optional* `false_eocs: eocs_array`), (*optional* `use_item_group: `bool), (*optional* `suppress_message: `bool) | The NPC will sell your character the item or `count` copies of the item, contained in `container`, and will subtract `cost` from `op_of_u.owed`. If the `op_o_u.owed` is less than `cost`, the trade window will open and the player will have to trade to make up the difference; the NPC will not give the player the item unless `cost` is satisfied. If `use_item_group` is true (defaults to false) it will instead pull an item from the item group given. If `suppress_message` is true (defaults to false) no message will be shown
`u_sell_item: `string or [variable object](#variable-object), (*optional* `cost: `int or [variable object](#variable-object)), (*optional* `count: `string or [variable object](#variable-object)), (*optional* `true_eocs: eocs_array`), (*optional* `false_eocs: eocs_array`) | Your character will give the NPC the item or `count` copies of the item, and will add `cost` to the NPC's `op_of_u.owed` if specified.<br/>If cost isn't present, the your character gives the NPC the item at no charge.<br/>This effect will fail if you do not have at least `count` copies of the item, so it should be checked with. If the item is sold, then all of the effect_on_conditions in `true_eocs` are run, otherwise all the effect_on_conditions in `false_eocs` are run.
`u_bulk_trade_accept, npc_bulk_trade_accept, u_bulk_trade_accept, npc_bulk_trade_accept: `int or [variable object](#variable-object) | Only valid after a `repeat_response`. The player trades all instances of the item from the `repeat_response` with the NPC. For `u_bulk_trade_accept`, the player loses the items from their inventory and gains the same value of the NPC's faction currency; for `npc_bulk_trade_accept`, the player gains the items from the NPC's inventory and loses the same value of the NPC's faction currency. If there is remaining value, or the NPC doesn't have a faction currency, the remainder goes into the NPC's `op_of_u.owed`. If `quantity` is specified only that many items/charges will be moved.
`u_bulk_donate, npc_bulk_donate` or `u_bulk_donate, npc_bulk_donate: `int or [variable object](#variable-object) | Only valid after a `repeat_response`. The player or NPC transfers all instances of the item from the `repeat_response`. For `u_bulk_donate`, the player loses the items from their inventory and the NPC gains them; for `npc_bulk_donate`, the player gains the items from the NPC's inventory and the NPC loses them. If a value is specified only that many items/charges will be moved.
Expand Down
17 changes: 10 additions & 7 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@ void talk_effect_fun_t<T>::set_adjust_var( const JsonObject &jo, const std::stri
}

static void receive_item( itype_id &item_name, int count, const std::string &container_name,
const dialogue &d, bool use_item_group )
const dialogue &d, bool use_item_group, bool suppress_message )
{
item new_item;
if( use_item_group ) {
Expand All @@ -2282,7 +2282,7 @@ static void receive_item( itype_id &item_name, int count, const std::string &con
d.actor( false )->i_add_or_drop( new_item );
}
}
if( d.has_beta && !d.actor( true )->disp_name().empty() ) {
if( !suppress_message && d.has_beta && !d.actor( true )->disp_name().empty() ) {
if( count == 1 ) {
//~ %1%s is the NPC name, %2$s is an item
popup( _( "%1$s gives you a %2$s." ), d.actor( true )->disp_name(), new_item.tname() );
Expand All @@ -2298,7 +2298,7 @@ static void receive_item( itype_id &item_name, int count, const std::string &con
container.put_in( new_item,
item_pocket::pocket_type::CONTAINER );
d.actor( false )->i_add_or_drop( container );
if( d.has_beta && !d.actor( true )->disp_name().empty() ) {
if( !suppress_message && d.has_beta && !d.actor( true )->disp_name().empty() ) {
//~ %1%s is the NPC name, %2$s is an item
popup( _( "%1$s gives you a %2$s." ), d.actor( true )->disp_name(), container.tname() );
}
Expand All @@ -2316,16 +2316,17 @@ void talk_effect_fun_t<T>::set_u_spawn_item( const JsonObject &jo, const std::st
container_name.str_val = "";
}
bool use_item_group = jo.get_bool( "use_item_group", false );
bool suppress_message = jo.get_bool( "suppress_message", false );
dbl_or_var<T> count;
if( !jo.has_int( "charges" ) ) {
count = get_dbl_or_var<T>( jo, "count", false, 1 );
} else {
count = get_dbl_or_var<T>( jo, "count", false, 0 );
}
function = [item_name, count, container_name, use_item_group]( const T & d ) {
function = [item_name, count, container_name, use_item_group, suppress_message]( const T & d ) {
itype_id iname = itype_id( item_name.evaluate( d ) );
receive_item( iname, count.evaluate( d ),
container_name.evaluate( d ), d, use_item_group );
container_name.evaluate( d ), d, use_item_group, suppress_message );
};
dialogue d( get_talker_for( get_avatar() ), nullptr );
likely_rewards.emplace_back( static_cast<int>( count.evaluate( d ) ),
Expand All @@ -2345,23 +2346,25 @@ void talk_effect_fun_t<T>::set_u_buy_item( const JsonObject &jo, const std::stri
count = get_dbl_or_var<T>( jo, "count", false, 0 );
}
bool use_item_group = jo.get_bool( "use_item_group", false );
bool suppress_message = jo.get_bool( "suppress_message", false );
str_or_var<T> container_name;
if( jo.has_member( "container" ) ) {
container_name = get_str_or_var<T>( jo.get_member( "container" ), "container", true );
} else {
container_name.str_val = "";
}

str_or_var<T> item_name = get_str_or_var<T>( jo.get_member( member ), member, true );
function = [item_name, cost, count, container_name, true_eocs, false_eocs,
use_item_group]( const T & d ) {
use_item_group, suppress_message]( const T & d ) {
if( !d.actor( true )->buy_from( cost.evaluate( d ) ) ) {
popup( _( "You can't afford it!" ) );
run_eoc_vector( false_eocs, d );
return;
}
itype_id iname = itype_id( item_name.evaluate( d ) );
receive_item( iname, count.evaluate( d ),
container_name.evaluate( d ), d, use_item_group );
container_name.evaluate( d ), d, use_item_group, suppress_message );
run_eoc_vector( true_eocs, d );
};
}
Expand Down

0 comments on commit d1c1d78

Please sign in to comment.