未验证 提交 88fb51ce 编写于 作者: D Dillon Matchett 提交者: GitHub

Snippets can now call EOC effects (#54139)

上级 22e5a184
......@@ -91,6 +91,7 @@
{ "group": "CODY_MILLER_trade", "chance": 100, "x": 12, "y": 10 },
{ "group": "CODY_MILLER_trade", "chance": 100, "x": 12, "y": 11 }
],
"place_item": [ { "item": "blacksmith_prototypes", "chance": 100, "x": 17, "y": 7 } ],
"place_npcs": [ { "class": "cody_miller", "x": 16, "y": 7 } ],
"faction_owner": [ { "id": "isolated_artisans", "x": [ 0, 23 ], "y": [ 0, 23 ] } ]
}
......
......@@ -32,6 +32,11 @@
},
"topic": "TALK_BLACKSMITH_JAY"
},
{
"text": "[Motioning to the engineer scribbles] What is it that you are working on?",
"condition": { "u_has_var": "seen_blacksmith_sketches", "type": "dialogue", "context": "artisans", "value": "yes" },
"topic": "TALK_BLACKSMITH_PROTOTYPE_NOT_FEELING_IT"
},
{
"text": "[100 merch] I'd like to become a member of the co-op.",
"condition": {
......@@ -244,5 +249,25 @@
{ "text": "Not really interested.", "topic": "TALK_DONE" },
{ "text": "I'll think about it", "topic": "TALK_BLACKSMITH_SERVICES" }
]
},
{
"id": "TALK_BLACKSMITH_PROTOTYPE_NOT_FEELING_IT",
"type": "talk_topic",
"dynamic_line": [
"Oh, these. With the end of the world, Jay and I had been talking about some new projects for the wasteland warriors. Anyways it doesn't matter anymore since, well it doesn't matter."
],
"responses": [
{
"text": "Are you and Jay close?",
"condition": { "not": { "u_has_var": "blacksmith_accepted_quest", "type": "dialogue", "context": "artisans", "value": "yes" } },
"topic": "TALK_BLACKSMITH_JAY"
},
{
"text": "I'm sure we'll fix things soon!",
"condition": { "u_has_var": "blacksmith_accepted_quest", "type": "dialogue", "context": "artisans", "value": "yes" },
"topic": "TALK_BLACKSMITH_SERVICES"
},
{ "text": "Alright.", "topic": "TALK_BLACKSMITH_SERVICES" }
]
}
]
......@@ -199,5 +199,22 @@
"contents-item": [ "shoulder_strap", "holo_sight", "muzzle_brake", "bars", "rail_laser_sight" ]
}
]
},
{
"type": "GENERIC",
"id": "blacksmith_prototypes",
"category": "books",
"symbol": ",",
"color": "white",
"looks_like": "paper",
"name": { "str_sp": "engineering notes" },
"snippet_category": "artisan_docs",
"description": "A collection of sketches and CAD designs marked up with pencil. There are two peoples handwriting.",
"price": 0,
"price_postapoc": 0,
"material": [ "paper" ],
"weight": "3 g",
"volume": "1 ml",
"flags": [ "TRADER_AVOID" ]
}
]
......@@ -300,5 +300,31 @@
"text": { "//~": "Usual enthusiastic slimespring small voices! :D", "str": "\"we're a team, we've got this!\"" }
}
]
},
{
"type": "snippet",
"category": "artisan_docs",
"text": [
{
"id": "artisan_prototypes_1",
"effect_on_examine": [ { "u_add_var": "seen_blacksmith_sketches", "type": "dialogue", "context": "artisans", "value": "yes" } ],
"text": "A collection of sketches and CAD designs marked up with a pencil. They depict a classic rifle and several diagrams of curved wooden maces. The word 'OBREZ?' is written clearly on the front sheet. There are two distinct sets of handwriting making notes."
},
{
"id": "artisan_prototypes_2",
"effect_on_examine": [ { "u_add_var": "seen_blacksmith_sketches", "type": "dialogue", "context": "artisans", "value": "yes" } ],
"text": "A collection of sketches and CAD designs marked up with a pencil. They depict a large mace with an internal gas reservoir and venting holes between the steel segments. There are additional diagrams labeled 'IGNITION SYSTEM' and 'TRIGGER?'. There are two distinct sets of handwriting making notes."
},
{
"id": "artisan_prototypes_3",
"effect_on_examine": [ { "u_add_var": "seen_blacksmith_sketches", "type": "dialogue", "context": "artisans", "value": "yes" } ],
"text": "A collection of sketches and CAD designs marked up with a pencil. They depict a bladed weapon with some audio equipment implanted. Doodles of hair metal rock stars line the page, as well as the words 'LETS, HEAR IT FOR FRANKY'. There are two distinct sets of handwriting making notes."
},
{
"id": "artisan_prototypes_4",
"effect_on_examine": [ { "u_add_var": "seen_blacksmith_sketches", "type": "dialogue", "context": "artisans", "value": "yes" } ],
"text": "A collection of sketches and CAD designs marked up with a pencil. They depict a sledgehammer with a moving center. There is a references doc for a powder actuated nail gun stapled to the sheets. There are two distinct sets of handwriting making notes."
}
]
}
]
......@@ -821,6 +821,20 @@ void avatar::wake_up()
Character::wake_up();
}
void avatar::add_snippet( snippet_id snippet )
{
if( has_seen_snippet( snippet ) ) {
return;
}
snippets_read.emplace( snippet );
}
bool avatar::has_seen_snippet( const snippet_id &snippet ) const
{
return snippets_read.count( snippet ) > 0;
}
void avatar::vomit()
{
if( stomach.contains() != 0_ml ) {
......
......@@ -205,6 +205,10 @@ class avatar : public Character
void identify( const item &item ) override;
void clear_identified();
void add_snippet( snippet_id snippet );
bool has_seen_snippet( const snippet_id &snippet ) const;
const std::unordered_set<snippet_id> get_snippets();
// the encumbrance on your limbs reducing your dodging ability
int limb_dodge_encumbrance() const;
......@@ -389,6 +393,9 @@ class avatar : public Character
// Items the player has identified.
std::unordered_set<itype_id> items_identified;
// Snippets the player has seen
std::unordered_set<snippet_id> snippets_read;
object_type grab_type;
monster_visible_info mon_visible;
......
......@@ -1994,6 +1994,20 @@ void item::basic_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
if( snippet.has_value() ) {
// Just use the dynamic description
info.emplace_back( "DESCRIPTION", snippet.value().translated() );
// only ever do the effect for a snippet the first time you see it
if( !get_avatar().has_seen_snippet( snip_id ) ) {
// Have looked at the item so call the on examine EOC for the snippet
const cata::optional<talk_effect_t> examine_effect = SNIPPET.get_EOC_by_id( snip_id );
if( examine_effect.has_value() ) {
// activate the effect
dialogue d( get_talker_for( get_avatar() ), nullptr );
examine_effect.value().apply( d );
}
//note that you have seen the snippet
get_avatar().add_snippet( snip_id );
}
} else if( idescription != item_vars.end() ) {
info.emplace_back( "DESCRIPTION", idescription->second );
} else if( has_itype_variant() ) {
......
......@@ -66,6 +66,10 @@ void snippet_library::add_snippet_from_json( const std::string &category, const
}
snippets_by_category[category].ids.emplace_back( id );
snippets_by_id[id] = text;
if( jo.has_member( "effect_on_examine" ) ) {
//JsonObject effect_obj = jo.get_object( "effect_on_examine" );
EOC_by_id[id] = talk_effect_t( jo, "effect_on_examine" );
}
} else {
snippets_by_category[category].no_id.emplace_back( text );
}
......@@ -92,6 +96,15 @@ cata::optional<translation> snippet_library::get_snippet_by_id( const snippet_id
return it->second;
}
cata::optional<talk_effect_t> snippet_library::get_EOC_by_id( const snippet_id &id ) const
{
const auto it = EOC_by_id.find( id );
if( it == EOC_by_id.end() ) {
return cata::nullopt;
}
return it->second;
}
const translation &snippet_library::get_snippet_ref_by_id( const snippet_id &id ) const
{
const auto it = snippets_by_id.find( id );
......
......@@ -10,6 +10,7 @@
#include "optional.h"
#include "translations.h"
#include "dialogue.h"
#include "type_id.h"
class JsonArray;
......@@ -45,6 +46,11 @@ class snippet_library
* call `expand()` to do that.
*/
cata::optional<translation> get_snippet_by_id( const snippet_id &id ) const;
/**
* Returns the EOC connected with the snippet referenced by the id, or cata::nullopt if there
* is no snippet with such id.
*/
cata::optional<talk_effect_t> get_EOC_by_id( const snippet_id &id ) const;
/**
* Returns a reference to the snippet with the id, or a reference to an
* empty translation object if no such snippet exist.
......@@ -103,6 +109,7 @@ class snippet_library
private:
std::unordered_map<snippet_id, translation> snippets_by_id;
std::unordered_map<snippet_id, talk_effect_t> EOC_by_id;
struct category_snippets {
std::vector<snippet_id> ids;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册