Skip to content

Commit

Permalink
Add Complete missions dialog function (CleverRaven#51820)
Browse files Browse the repository at this point in the history
* Complete missions

* Update npctalk.cpp

* Update npctalk.cpp
  • Loading branch information
Ramza13 authored Sep 23, 2021
1 parent 6ee1821 commit 947f8d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ Effect | Description
`take_control`. If the npc is a character then take control of them.
`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`,`success: success_bool` | Will complete mission `mission_type_id` to the player as a success if `success` is true, as a failure otherwise.
`set_queue_effect_on_condition: effect_on_condition_array`, (*optional* `time_in_future_min: time_in_future_min_int or string or variable_object`,`time_in_future_max: time_in_future_max_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 between `time_in_future_min_int` and `time_in_future_max_int` seconds, or if they are strings the future values of them or if they are variable objects the variable they name. If these are zero (their default value) the eocs will happen instantly. For instant activation eocs the current u and npc will be used. For future ones u will be the avatar and npc will be invalid. You cannot queue recurring eocs.
`set_weighted_list_eocs: array_array` | Will choose one of a list of eocs to activate based on weight. Members should be an array of first the id of an effect_on_condition or an inline effect_on_condition and second an integer weight.
Example: This will cause "EOC_SLEEP" 1/10 as often as it makes a test message appear.
Expand Down
1 change: 1 addition & 0 deletions src/dialogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct talk_effect_fun_t {
void set_add_wet( const JsonObject &jo, const std::string &member, bool is_npc );
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_make_sound( const JsonObject &jo, const std::string &member, bool is_npc );
void set_queue_effect_on_condition( const JsonObject &jo, const std::string &member );
void set_weighted_list_eocs( const JsonObject &jo, const std::string &member );
Expand Down
25 changes: 24 additions & 1 deletion src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2735,12 +2735,33 @@ void talk_effect_fun_t::set_assign_mission( const JsonObject &jo, const std::str
avatar &player_character = get_avatar();

const mission_type_id &mission_type = mission_type_id( mission_name );
std::vector<mission *> missions = player_character.get_active_missions();
mission *new_mission = mission::reserve_new( mission_type, character_id() );
new_mission->assign( player_character );
};
}

void talk_effect_fun_t::set_finish_mission( const JsonObject &jo, const std::string &member )
{
std::string mission_name = jo.get_string( member );
bool success = jo.get_bool( "success" );
function = [mission_name, success]( const dialogue & ) {
avatar &player_character = get_avatar();

const mission_type_id &mission_type = mission_type_id( mission_name );
std::vector<mission *> missions = player_character.get_active_missions();
for( mission *mission : missions ) {
if( mission->mission_id() == mission_type ) {
if( success ) {
mission->wrap_up();
} else {
mission->fail();
}
break;
}
}
};
}

void talk_effect_fun_t::set_make_sound( const JsonObject &jo, const std::string &member,
bool is_npc )
{
Expand Down Expand Up @@ -3255,6 +3276,8 @@ void talk_effect_t::parse_sub_effect( const JsonObject &jo )
subeffect_fun.set_assign_activity( jo, "npc_assign_activity", true );
} else if( jo.has_member( "assign_mission" ) ) {
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_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 947f8d7

Please sign in to comment.