Skip to content

Commit

Permalink
Add new mission/talk effect u_learn_recipe (CleverRaven#33574)
Browse files Browse the repository at this point in the history
* Add u_learn_recipe effect and u_know_recipe condition

* Add new mission MISSION_LEARN_ABOUT_CATTAIL_JELLY
  • Loading branch information
ralreegorganon authored and misterprimus committed Sep 21, 2019
1 parent 6168395 commit 33902a1
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
41 changes: 41 additions & 0 deletions data/json/npcs/missiondef.json
Original file line number Diff line number Diff line change
Expand Up @@ -771,5 +771,46 @@
"success_lie": "I know time is relative and all that.",
"failure": "I'm not quite sure how you failed to survive AND are talking to me."
}
},
{
"id": "MISSION_LEARN_ABOUT_CATTAIL_JELLY",
"type": "mission_definition",
"name": "Gather cattail stalks to create cattail jelly",
"description": "Gather <color_light_blue>80 cattail stalks</color> from the swamp and bring them back to <color_light_red>learn how to craft cattail jelly</color>. Raise your <color_light_blue>survival skill to at least 1</color> by harvesting cattail stalks. <color_light_blue>Bring back the provided bag</color> as well.",
"goal": "MGOAL_CONDITION",
"goal_condition": {
"and": [
{ "u_has_item": "duffelbag" },
{ "u_has_items": { "item": "cattail_stalk", "count": 80 } },
{ "u_has_skill": { "skill": "survival", "level": 1 } }
]
},
"difficulty": 1,
"value": 0,
"origins": [ "ORIGIN_OPENER_NPC", "ORIGIN_ANY_NPC" ],
"start": {
"effect": [ { "u_buy_item": "duffelbag" } ],
"assign_mission_target": { "om_terrain": "forest_water", "reveal_radius": 3 }
},
"end": {
"effect": [
{ "u_sell_item": "duffelbag" },
{ "u_sell_item": "cattail_stalk", "count": 80 },
{ "npc_consume_item": "cattail_stalk", "count": 80 },
{ "u_learn_recipe": "cattail_jelly" },
{ "u_buy_item": "cattail_jelly", "container": "bag_zipper", "count": 7 }
]
},
"dialogue": {
"describe": "Medical services are a little sparse following <the_cataclysm>, but people have been surviving using their wits and the bounty of Mother Nature for a long time. Care to learn a little?",
"offer": "Did you know that cattails are a source of a jelly that works as an antiseptic and analgesic? Something like that is likely to be mighty helpful out here. I want you to take this bag, head to the nearest swamp, collect 80 cattail stalks, and bring them back here. In exchange, I'll show you how to harvest the jelly.",
"accepted": "Great! This bag should be big enough to hold all of the stalks we'll need. Don't forget to bring it back.",
"rejected": "Your loss.",
"advice": "The cattails grow in the fresh water in swamps. You can't miss them.",
"inquire": "Got those cattail stalks yet? Don't forget to bring back my bag and improve your survival skill to at least 1 as well.",
"success": "Great! Hand them over and I'll show you how this works.",
"success_lie": "OK, then hand them over.",
"failure": "Well, that's a shame."
}
}
]
2 changes: 2 additions & 0 deletions doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ Effect | Description
`u_lose_var`, `npc_lose_var`: `var_name`, `type: type_str`, `context: context_str` | Your character or the NPC will clear any stored variable that has the same `var_name`, `type_str`, and `context_str`.
`barber_hair` | Opens a menu allowing the player to choose a new hair style.
`barber_beard` | Opens a menu allowing the player to choose a new beard style.
`u_learn_recipe: recipe_string` | Your character will learn and memorize the recipe `recipe_string`.

#### Trade / Items

Expand Down Expand Up @@ -564,6 +565,7 @@ Condition | Type | Description
`"u_has_weapon"`<br/>`"npc_has_weapon"` | simple string | `true` if the player character or NPC is wielding a weapon.
`"u_driving"`<br/>`"npc_driving"` | simple string | `true` if the player character or NPC is operating a vehicle. <b>Note</b> NPCs cannot currently operate vehicles.
`"u_has_skill"`<br/>`"npc_has_skill"` | dictionary | `u_has_skill` or `npc_has_skill` must be a dictionary with a `skill` string and a `level` int.<br/>`true` if the player character or NPC has at least the value of `level` in `skill`.
`"u_know_recipe"` | string | `true` if the player character knows the recipe specified in `u_know_recipe`. It only counts as known if it is actually memorized--holding a book with the recipe in it will not count.

#### Player Only conditions

Expand Down
14 changes: 14 additions & 0 deletions src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "mission.h"
#include "npc.h"
#include "overmapbuffer.h"
#include "recipe.h"
#include "string_id.h"
#include "type_id.h"
#include "vehicle.h"
Expand Down Expand Up @@ -800,6 +801,17 @@ void conditional_t<T>::set_has_skill( JsonObject &jo, const std::string &member,
}
}

template<class T>
void conditional_t<T>::set_u_know_recipe( JsonObject &jo, const std::string &member )
{
const std::string &known_recipe_id = jo.get_string( member );
condition = [known_recipe_id]( const T & d ) {
player *actor = d.alpha;
const recipe &r = recipe_id( known_recipe_id ).obj();
return actor->knows_recipe( &r );
};
}

template<class T>
conditional_t<T>::conditional_t( JsonObject jo )
{
Expand Down Expand Up @@ -967,6 +979,8 @@ conditional_t<T>::conditional_t( JsonObject jo )
set_has_skill( jo, "u_has_skill" );
} else if( jo.has_member( "npc_has_skill" ) ) {
set_has_skill( jo, "npc_has_skill", is_npc );
} else if( jo.has_member( "u_know_recipe" ) ) {
set_u_know_recipe( jo, "u_know_recipe" );
} else {
for( const std::string &sub_member : dialogue_data::simple_string_conds ) {
if( jo.has_string( sub_member ) ) {
Expand Down
3 changes: 2 additions & 1 deletion src/condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const std::unordered_set<std::string> complex_conds = { {
"npc_aim_rule", "npc_engagement_rule", "npc_rule", "npc_override",
"npc_cbm_reserve_rule", "npc_cbm_recharge_rule",
"days_since_cataclysm", "is_season", "mission_goal", "u_has_var", "npc_has_var",
"u_has_skill", "npc_has_skill"
"u_has_skill", "npc_has_skill", "u_know_recipe"
}
};
} // namespace dialogue_data
Expand Down Expand Up @@ -131,6 +131,7 @@ struct conditional_t {
void set_has_reason();
void set_is_gender( bool is_male, bool is_npc = false );
void set_has_skill( JsonObject &jo, const std::string &member, bool is_npc = false );
void set_u_know_recipe( JsonObject &jo, const std::string &member );

bool operator()( const T &d ) const {
if( !condition ) {
Expand Down
13 changes: 13 additions & 0 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "npctrade.h"
#include "output.h"
#include "overmapbuffer.h"
#include "recipe.h"
#include "rng.h"
#include "skill.h"
#include "sounds.h"
Expand Down Expand Up @@ -2108,6 +2109,15 @@ const std::vector<std::pair<int, std::string>> &talk_effect_fun_t::get_likely_re
return likely_rewards;
}

void talk_effect_fun_t::set_u_learn_recipe( const std::string &learned_recipe_id )
{
function = [learned_recipe_id]( const dialogue & d ) {
const recipe &r = recipe_id( learned_recipe_id ).obj();
d.alpha->learn_recipe( &r );
popup( _( "You learn how to craft %s." ), r.result_name() );
};
}

void talk_effect_t::set_effect_consequence( const talk_effect_fun_t &fun, dialogue_consequence con )
{
effects.push_back( fun );
Expand Down Expand Up @@ -2312,6 +2322,9 @@ void talk_effect_t::parse_sub_effect( JsonObject jo )
translation name;
jo.read( "name", name );
subeffect_fun.set_u_buy_monster( monster_type_id, cost, count, pacified, name );
} else if( jo.has_string( "u_learn_recipe" ) ) {
const std::string recipe_id = jo.get_string( "u_learn_recipe" );
subeffect_fun.set_u_learn_recipe( recipe_id );
} else {
jo.throw_error( "invalid sub effect syntax :" + jo.str() );
}
Expand Down

0 comments on commit 33902a1

Please sign in to comment.