Skip to content

Commit

Permalink
Merge pull request #56642 from haveric/offer_mission
Browse files Browse the repository at this point in the history
Add offer_mission dialogue effect
  • Loading branch information
dseguin authored Apr 20, 2022
2 parents a436676 + 8306ca8 commit 931ad4f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ Effect | Description
`take_control_menu`. Opens up a menu to choose a follower to take control of.
`assign_mission: mission_type_id string` | Will assign mission `mission_type_id` to the player.
`finish_mission: mission_type_id string`,(*optional* `success: success_bool` ), (*optional `step: step_int`) | Will complete mission `mission_type_id` to the player as a success if `success` is true, as a failure otherwise. If a `step` is provided that step of the mission will be completed.
`offer_mission" mission_type_id string or array`. Adds mission_type_id(s) to the npc's missions that they offer.
`run_eocs : effect_on_condition_array or single effect_condition_object` | Will run up all members of the `effect_on_condition_array`. Members should either be the id of an effect_on_condition or an inline effect_on_condition.
`queue_eocs : effect_on_condition_array or single effect_condition_object`, `time_in_future: time_in_future_int or string or variable_object` | Will queue up all members of the `effect_on_condition_array`. Members should either be the id of an effect_on_condition or an inline effect_on_condition. Members will be run `time_in_future` seconds or if it is a string the future values of them or if they are variable objects the variable they name. If the eoc is global the avatar will be u and npc will be invalid. Otherwise it will be queued for the current alpha if they are a character and not be queued otherwise.
`u_run_npc_eocs or npc_run_npc_eocs : effect_on_condition_array`, (*optional* `npcs_to_affect: npcs_to_affect_string_array`, (*optional* `npcs_must_see: npcs_must_see_bool`), (*optional* `npc_range: npc_range_int`) | Will run all members of the `effect_on_condition_array` on nearby npcs. Members should either be the id of an effect_on_condition or an inline effect_on_condition. If any names are listed in `npcs_to_affect` then only they will be affected. If a value is given for `npc_range` the npc must be that close to the source and if `npcs_must_see`(defaults to false) is true the npc must be able to see the source. For `u_run_npc_eocs` u is the source for `npc_run_npc_eocs` it is the npc.
Expand Down
1 change: 1 addition & 0 deletions src/dialogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct talk_effect_fun_t {
void set_assign_activity( const JsonObject &jo, const std::string &member, bool is_npc = false );
void set_assign_mission( const JsonObject &jo, const std::string &member );
void set_finish_mission( const JsonObject &jo, const std::string &member );
void set_offer_mission( const JsonObject &jo, const std::string &member );
void set_make_sound( const JsonObject &jo, const std::string &member, bool is_npc );
void set_run_eocs( const JsonObject &jo, const std::string &member );
void set_run_npc_eocs( const JsonObject &jo, const std::string &member, bool is_npc );
Expand Down
25 changes: 25 additions & 0 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3510,6 +3510,29 @@ void talk_effect_fun_t::set_finish_mission( const JsonObject &jo, const std::str
};
}

void talk_effect_fun_t::set_offer_mission( const JsonObject &jo, const std::string &member )
{
std::vector<std::string> mission_names;

if( jo.has_array( member ) ) {
for( const std::string mission_name : jo.get_array( member ) ) {
mission_names.push_back( mission_name );
}
} else if( jo.has_string( member ) ) {
mission_names.push_back( jo.get_string( member ) );
} else {
jo.throw_error( "Invalid input for set_offer_mission" );
}

function = [mission_names]( const dialogue & d ) {
npc *p = d.actor( true )->get_npc();

for( const std::string &mission_name : mission_names ) {
p->add_new_mission( mission::reserve_new( mission_type_id( mission_name ), p->getID() ) );
}
};
}

void talk_effect_fun_t::set_make_sound( const JsonObject &jo, const std::string &member,
bool is_npc )
{
Expand Down Expand Up @@ -4261,6 +4284,8 @@ void talk_effect_t::parse_sub_effect( const JsonObject &jo )
subeffect_fun.set_assign_mission( jo, "assign_mission" );
} else if( jo.has_string( "finish_mission" ) ) {
subeffect_fun.set_finish_mission( jo, "finish_mission" );
} else if( jo.has_array( "offer_mission" ) || jo.has_string( "offer_mission" ) ) {
subeffect_fun.set_offer_mission( jo, "offer_mission" );
} else if( jo.has_member( "u_make_sound" ) ) {
subeffect_fun.set_make_sound( jo, "u_make_sound", false );
} else if( jo.has_member( "npc_make_sound" ) ) {
Expand Down

0 comments on commit 931ad4f

Please sign in to comment.