Skip to content

Commit

Permalink
npctalk: fix remove_npc (#57570)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei8l authored May 11, 2022
1 parent 400bccb commit 21f9a4a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
9 changes: 4 additions & 5 deletions data/json/encounters/randenc_caravans.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{
"type": "effect_on_condition",
"id": "EOC_RandEnc_Roadstop_add",
"recurrence": 6000,
"global": true,
"eoc_type": "OM_MOVE",
"condition": {
"and": [
{ "u_near_om_location": "roadstop_a", "range": 2 },
Expand Down Expand Up @@ -32,9 +31,9 @@
},
"effect": [
{ "mapgen_update": "nest_RandEnc_roadstop_a_remove", "om_terrain": "roadstop_a" },
{ "remove_npc": "FM_caravan_merchant_random" },
{ "remove_npc": "FM_caravan_guard_A" },
{ "remove_npc": "FM_caravan_guard_B" }
{ "remove_npc": { "class": "NC_TRADER", "chat": "TALK_CARAVAN_MERCHANT_1" } },
{ "remove_npc": { "class": "NC_BOUNTY_HUNTER", "chat": "TALK_CARAVAN_GUARD_A1" } },
{ "remove_npc": { "class": "NC_BOUNTY_HUNTER", "chat": "TALK_CARAVAN_GUARD_B" } }
]
},
{
Expand Down
19 changes: 12 additions & 7 deletions data/json/encounters/randenc_refugee_center.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"type": "effect_on_condition",
"id": "EOC_RandEnc_RC_Shoppers_add",
"//": "Adds random survivors visiting the refugee center to shop",
"recurrence": 6000,
"global": true,
"eoc_type": "OM_MOVE",
"condition": {
"and": [
{ "u_near_om_location": "evac_center_13", "range": 2 },
{ "not": { "u_at_om_location": "evac_center_13" } },
"is_day",
{ "one_in_chance": 10 },
{ "u_has_var": "FMShopkeep_Mission1", "type": "mission", "context": "flag", "value": "yes" },
Expand All @@ -31,16 +32,20 @@
"is_night"
]
},
"effect": [ { "remove_npc": "RC_survivor_visiting" } ]
"effect": [
{ "remove_npc": { "class": "NC_SCAVENGER", "chat": "TALK_RC_SURVIVOR_1" } },
{ "remove_npc": { "class": "NC_SCAVENGER", "chat": "TALK_RC_SURVIVOR_2" } }
]
},
{
"type": "effect_on_condition",
"id": "EOC_RandEnc_RC_JohnBailey_add",
"//": "Specific travelling NPC John Bailey stops in at the refugee center. Regardless of where you meet him, you can't meet John more than once per 3 days.",
"recurrence": 6200,
"global": true,
"eoc_type": "OM_MOVE",
"condition": {
"and": [
{ "u_near_om_location": "evac_center_13", "range": 2 },
{ "not": { "u_at_om_location": "evac_center_13" } },
"is_day",
{ "one_in_chance": 15 },
{ "u_has_var": "FMShopkeep_Mission1", "type": "mission", "context": "flag", "value": "yes" },
Expand All @@ -65,7 +70,7 @@
"is_night"
]
},
"effect": [ { "remove_npc": "RC_John_Bailey_visiting" } ]
"effect": [ { "remove_npc": { "unique_id": "John_Bailey" } } ]
},
{
"type": "mapgen",
Expand All @@ -79,6 +84,6 @@
"method": "json",
"update_mapgen_id": "nest_RandEnc_RC_JohnBailey_add",
"//": "Adds a random NPC to the refugee center, placed somewhere it won't intersect with beggars or other random NPCs.",
"object": { "place_npcs": [ { "class": "RC_John_Bailey_visiting", "x": 19, "y": 21 } ] }
"object": { "place_npcs": [ { "class": "RC_John_Bailey_visiting", "x": 19, "y": 21, "unique_id": "John_Bailey" } ] }
}
]
24 changes: 15 additions & 9 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,14 +2610,20 @@ void talk_effect_fun_t::set_mapgen_update( const JsonObject &jo, const std::stri

void talk_effect_fun_t::set_remove_npc( const JsonObject &jo, const std::string &member )
{
std::string npc_id;
mandatory( jo, false, member, npc_id );
function = [npc_id]( const dialogue & ) {
std::vector<npc *> npc_list = g->get_npcs_if( [npc_id]( const npc & npc ) -> bool {
return npc.idz == npc_id;
} );
for( npc *npc : npc_list ) {
overmap_buffer.remove_npc( npc->getID() );
std::string nclass;
std::string chatbin;
std::string unique_id;
JsonObject const jot = jo.get_object( member );
optional( jot, false, "class", nclass );
optional( jot, false, "chat", chatbin );
optional( jot, false, "unique_id", unique_id );
function = [nclass, chatbin, unique_id]( const dialogue & ) {
for( auto const &npc : overmap_buffer.get_overmap_npcs() ) {
if( ( nclass.empty() or npc->myclass == npc_class_id( nclass ) ) and
( chatbin.empty() or npc->chatbin.first_topic == chatbin ) and
( unique_id.empty() or unique_id == npc->get_unique_id() ) ) {
overmap_buffer.remove_npc( npc->getID() );
}
}
};
}
Expand Down Expand Up @@ -4345,7 +4351,7 @@ void talk_effect_t::parse_sub_effect( const JsonObject &jo )
} else if( jo.has_member( "mapgen_update" ) ) {
subeffect_fun.set_mapgen_update( jo, "mapgen_update" );
} else if( jo.has_member( "remove_npc" ) ) {
subeffect_fun.set_mapgen_update( jo, "remove_npc" );
subeffect_fun.set_remove_npc( jo, "remove_npc" );
} else if( jo.has_member( "revert_location" ) ) {
subeffect_fun.set_revert_location( jo, "revert_location" );
} else if( jo.has_member( "place_override" ) ) {
Expand Down

0 comments on commit 21f9a4a

Please sign in to comment.