tests: update shopkeeper tests
This commit is contained in:
parent
5705289a66
commit
10e18c88a7
|
@ -37,6 +37,7 @@
|
|||
"id": "test_npc_trader_class",
|
||||
"name": "test_npc_trader",
|
||||
"job_description": "I am testing bugs",
|
||||
"sells_belongings": false,
|
||||
"shopkeeper_consumption_rates": "test_shop_rates",
|
||||
"shopkeeper_item_group": [
|
||||
{ "group": "test_event_item_spawn" },
|
||||
|
|
|
@ -1752,6 +1752,11 @@ std::string Creature::get_value( const std::string &key ) const
|
|||
return ( it == values.end() ) ? "" : it->second;
|
||||
}
|
||||
|
||||
void Creature::clear_values()
|
||||
{
|
||||
values.clear();
|
||||
}
|
||||
|
||||
void Creature::mod_pain( int npain )
|
||||
{
|
||||
mod_pain_noresist( npain );
|
||||
|
|
|
@ -635,6 +635,7 @@ class Creature : public viewer
|
|||
void set_value( const std::string &key, const std::string &value );
|
||||
void remove_value( const std::string &key );
|
||||
std::string get_value( const std::string &key ) const;
|
||||
void clear_values();
|
||||
|
||||
virtual units::mass get_weight() const = 0;
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
#include "avatar.h"
|
||||
#include "cata_catch.h"
|
||||
#include "creature_tracker.h"
|
||||
#include "game.h"
|
||||
#include "item_group.h"
|
||||
#include "map_helpers.h"
|
||||
#include "npc.h"
|
||||
#include "npc_class.h"
|
||||
#include "player_helpers.h"
|
||||
|
||||
static npc_template_id const npc_template_test_npc_trader( "test_npc_trader" );
|
||||
|
||||
|
@ -21,8 +25,11 @@ static std::pair<bool, bool> has_and_can_restock( npc const &guy, item const &it
|
|||
|
||||
TEST_CASE( "npc_shopkeeper_item_groups", "[npc][trade]" )
|
||||
{
|
||||
npc guy;
|
||||
guy.load_npc_template( npc_template_test_npc_trader );
|
||||
clear_avatar();
|
||||
clear_npcs();
|
||||
tripoint const npc_pos = get_avatar().pos() + tripoint_east;
|
||||
const character_id id = get_map().place_npc( npc_pos.xy(), npc_template_test_npc_trader );
|
||||
npc &guy = *g->find_npc( id );
|
||||
|
||||
GIVEN( "item in basic group with no conditions" ) {
|
||||
item pants( "test_pants_fur" );
|
||||
|
@ -31,7 +38,21 @@ TEST_CASE( "npc_shopkeeper_item_groups", "[npc][trade]" )
|
|||
std::pair<bool, bool> har_pants = has_and_can_restock( guy, pants );
|
||||
REQUIRE( har_pants.first == true );
|
||||
REQUIRE( har_pants.second == true );
|
||||
REQUIRE( guy.wants_to_sell( pants ) );
|
||||
REQUIRE( guy.wants_to_sell( { guy, &pants } ) );
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN( "item in inventory with sell_belongings false" ) {
|
||||
g->load_npcs();
|
||||
creature_tracker &creatures = get_creature_tracker();
|
||||
REQUIRE( creatures.creature_at<npc>( npc_pos ) != nullptr );
|
||||
item backpack( "test_backpack" );
|
||||
guy.wear_item( backpack );
|
||||
item_location const loc = guy.i_add( item( "scrap" ) );
|
||||
REQUIRE( loc );
|
||||
|
||||
THEN( "item is not available for sale" ) {
|
||||
REQUIRE( !guy.wants_to_sell( loc ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +64,7 @@ TEST_CASE( "npc_shopkeeper_item_groups", "[npc][trade]" )
|
|||
THEN( "item is available for restocking but not selling" ) {
|
||||
REQUIRE( har_hammer.first == true );
|
||||
REQUIRE( har_hammer.second == true );
|
||||
REQUIRE( !guy.wants_to_sell( hammer ) );
|
||||
REQUIRE( !guy.wants_to_sell( {guy, &hammer } ) );
|
||||
}
|
||||
}
|
||||
WHEN( "condition met" ) {
|
||||
|
@ -52,7 +73,7 @@ TEST_CASE( "npc_shopkeeper_item_groups", "[npc][trade]" )
|
|||
THEN( "item is available for selling and restocking" ) {
|
||||
REQUIRE( har_hammer.first == true );
|
||||
REQUIRE( har_hammer.second == true );
|
||||
REQUIRE( guy.wants_to_sell( hammer ) );
|
||||
REQUIRE( guy.wants_to_sell( { guy, &hammer } ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +86,7 @@ TEST_CASE( "npc_shopkeeper_item_groups", "[npc][trade]" )
|
|||
THEN( "item is not available for selling or restocking" ) {
|
||||
REQUIRE( har_multitool.first == true );
|
||||
REQUIRE( har_multitool.second == false );
|
||||
REQUIRE( !guy.wants_to_sell( multitool ) );
|
||||
REQUIRE( !guy.wants_to_sell( { guy, &multitool } ) );
|
||||
}
|
||||
}
|
||||
WHEN( "condition met" ) {
|
||||
|
@ -74,7 +95,27 @@ TEST_CASE( "npc_shopkeeper_item_groups", "[npc][trade]" )
|
|||
THEN( "item is available for selling and restocking" ) {
|
||||
REQUIRE( har_multitool.first == true );
|
||||
REQUIRE( har_multitool.second == true );
|
||||
REQUIRE( guy.wants_to_sell( multitool ) );
|
||||
REQUIRE( guy.wants_to_sell( {guy, &multitool } ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN( "containter with single item and conditions only for contents" ) {
|
||||
item multitool( "test_multitool" );
|
||||
item bag( "bag_plastic" );
|
||||
ret_val<void> const ret = bag.put_in( multitool, item_pocket::pocket_type::CONTAINER );
|
||||
REQUIRE( ret.success() );
|
||||
bag.set_owner( guy );
|
||||
item_location const loc( map_cursor{ tripoint_zero}, &bag );
|
||||
WHEN( "condition for contents not met" ) {
|
||||
THEN( "container can't be sold" ) {
|
||||
REQUIRE( !guy.wants_to_sell( loc ) );
|
||||
}
|
||||
}
|
||||
WHEN( "condition for contents met" ) {
|
||||
get_avatar().set_value( "npctalk_var_bool_test_multitool_access", "yes" );
|
||||
THEN( "container can be sold" ) {
|
||||
REQUIRE( guy.wants_to_sell( loc ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,6 +131,7 @@ void clear_character( Character &dummy, bool skip_nutrition )
|
|||
|
||||
const tripoint spot( 60, 60, 0 );
|
||||
dummy.setpos( spot );
|
||||
dummy.clear_values();
|
||||
}
|
||||
|
||||
void arm_shooter( npc &shooter, const std::string &gun_type,
|
||||
|
|
Loading…
Reference in New Issue