Skip to content

Commit

Permalink
Send item id as variable to use_action EoC (#71392)
Browse files Browse the repository at this point in the history
* send item id as variable to use_action EoC

* fix plano contacts
GuardianDll authored Feb 1, 2024
1 parent 924cbe6 commit ab5aa03
Showing 6 changed files with 30 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -4,15 +4,14 @@
"id": "EOC_CONTACTS",
"//time": "how long contact effect would last, in seconds",
"//effect": "what effect would be applied when item is activated. Currently supported only 'contacts' and 'transition_contacts'",
"//item": "item, that should be removed, if EoC is successful",
"//flag1": "what flag is required to use this lenses. lack of this flag prevent you from using the lenses",
"//flag2": "same as flag1, either this one or flag1. omit if not needed",
"//flag3": "same as flag1, either this one, or flag2 or flag1. omit if not needed",
"//plano": "used to handle the case, when lens don't have any correction power, and anyone can use it, specifically for transition_contacts_plano",
"condition": {
"and": [
{ "math": [ "u_has_flag(_flag1) + u_has_flag(_flag2) + u_has_flag(_flag3) + _plano", ">", "0" ] },
{ "expects_vars": [ "time", "effect", "item" ] }
{ "expects_vars": [ "time", "effect" ] }
]
},
"effect": { "run_eocs": [ "EOC_CONTACTS1" ] },
@@ -58,7 +57,7 @@
{ "u_lose_effect": "transition_contacts" },
{ "u_lose_effect": "transition_contacts_plano" },
{ "u_add_effect": { "context_val": "effect" }, "duration": { "math": [ "rng(_time * 0.94, _time * 1.06)" ] } },
{ "u_consume_item": { "context_val": "item" } }
{ "u_consume_item": { "context_val": "id" } }
]
}
]
Original file line number Diff line number Diff line change
@@ -2,13 +2,14 @@
{
"type": "effect_on_condition",
"id": "SALINE_INFUSION",
"//": "4 ml of saline per 1 ml of blood, rate 2L/hour. 1 ml of blood = 10 units of vitamin",
"//volume_of_saline": "Amount of saline the bag has. Converts to 'blood' as 250 ml (2500 units of vitamin) of blood volume for each liter of saline.",
"condition": { "expects_vars": [ "volume_of_saline" ] },
"effect": [
{ "math": [ "u_amount_of_saline_infused", "=", "_volume_of_saline" ] },
{ "u_assign_activity": "ACT_SALINE_INFUSE", "duration": { "math": [ "_volume_of_saline / 0.55555556" ] } },
{ "u_consume_item": { "context_val": "bag_id" } },
{ "u_consume_item": { "context_val": "id" } },
{
"set_string_var": "<context_val:bag_id>_empty",
"set_string_var": "<context_val:id>_empty",
"target_var": { "context_val": "bag_to_drop" },
"parse_tags": true
},
90 changes: 17 additions & 73 deletions data/json/items/comestibles/med.json
Original file line number Diff line number Diff line change
@@ -492,13 +492,7 @@
"id": "EOC_myopia_contacts_weekly",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": {
"flag1": "MYOPIC",
"flag2": "MYOPIC_IN_LIGHT",
"effect": "contacts",
"time": "604800",
"item": "myopia_contacts_weekly"
}
"variables": { "flag1": "MYOPIC", "flag2": "MYOPIC_IN_LIGHT", "effect": "contacts", "time": "604800" }
}
}
]
@@ -525,13 +519,7 @@
"id": "EOC_myopia_transition_contacts_weekly",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": {
"flag1": "MYOPIC",
"flag2": "MYOPIC_IN_LIGHT",
"effect": "transition_contacts",
"time": "604800",
"item": "myopia_transition_contacts_weekly"
}
"variables": { "flag1": "MYOPIC", "flag2": "MYOPIC_IN_LIGHT", "effect": "transition_contacts", "time": "604800" }
}
}
]
@@ -556,13 +544,7 @@
"id": "EOC_myopia_contacts_daily",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": {
"flag1": "MYOPIC",
"flag2": "MYOPIC_IN_LIGHT",
"effect": "contacts",
"time": "57600",
"item": "myopia_contacts_daily"
}
"variables": { "flag1": "MYOPIC", "flag2": "MYOPIC_IN_LIGHT", "effect": "contacts", "time": "57600" }
}
}
]
@@ -587,13 +569,7 @@
"id": "EOC_myopia_transition_contacts_daily",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": {
"flag1": "MYOPIC",
"flag2": "MYOPIC_IN_LIGHT",
"effect": "transition_contacts",
"time": "57600",
"item": "myopia_transition_contacts_daily"
}
"variables": { "flag1": "MYOPIC", "flag2": "MYOPIC_IN_LIGHT", "effect": "transition_contacts", "time": "57600" }
}
}
]
@@ -616,10 +592,7 @@
"effect_on_conditions": [
{
"id": "EOC_hyperopia_contacts_weekly",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": { "flag1": "HYPEROPIC", "effect": "contacts", "time": "604800", "item": "hyperopia_contacts_weekly" }
}
"effect": { "run_eoc_with": "EOC_CONTACTS", "variables": { "flag1": "HYPEROPIC", "effect": "contacts", "time": "604800" } }
}
]
}
@@ -643,12 +616,7 @@
"id": "EOC_hyperopia_transition_contacts_weekly",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": {
"flag1": "HYPEROPIC",
"effect": "transition_contacts",
"time": "604800",
"item": "hyperopia_transition_contacts_weekly"
}
"variables": { "flag1": "HYPEROPIC", "effect": "transition_contacts", "time": "604800" }
}
}
]
@@ -671,10 +639,7 @@
"effect_on_conditions": [
{
"id": "EOC_hyperopia_contacts_daily",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": { "flag1": "HYPEROPIC", "effect": "contacts", "time": "57600", "item": "hyperopia_contacts_daily" }
}
"effect": { "run_eoc_with": "EOC_CONTACTS", "variables": { "flag1": "HYPEROPIC", "effect": "contacts", "time": "57600" } }
}
]
}
@@ -698,12 +663,7 @@
"id": "EOC_hyperopia_transition_contacts_daily",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": {
"flag1": "HYPEROPIC",
"effect": "transition_contacts",
"time": "57600",
"item": "hyperopia_transition_contacts_daily"
}
"variables": { "flag1": "HYPEROPIC", "effect": "transition_contacts", "time": "57600" }
}
}
]
@@ -728,14 +688,7 @@
"id": "EOC_bifocal_contacts_weekly",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": {
"flag1": "MYOPIC",
"flag2": "MYOPIC_IN_LIGHT",
"flag3": "HYPEROPIC",
"effect": "contacts",
"time": "604800",
"item": "bifocal_contacts_weekly"
}
"variables": { "flag1": "MYOPIC", "flag2": "MYOPIC_IN_LIGHT", "flag3": "HYPEROPIC", "effect": "contacts", "time": "604800" }
}
}
]
@@ -765,8 +718,7 @@
"flag2": "MYOPIC_IN_LIGHT",
"flag3": "HYPEROPIC",
"effect": "transition_contacts",
"time": "604800",
"item": "bifocal_transition_contacts_weekly"
"time": "604800"
}
}
}
@@ -792,14 +744,7 @@
"id": "EOC_bifocal_contacts_daily",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": {
"flag1": "MYOPIC",
"flag2": "MYOPIC_IN_LIGHT",
"flag3": "HYPEROPIC",
"effect": "contacts",
"time": "57600",
"item": "bifocal_contacts_daily"
}
"variables": { "flag1": "MYOPIC", "flag2": "MYOPIC_IN_LIGHT", "flag3": "HYPEROPIC", "effect": "contacts", "time": "57600" }
}
}
]
@@ -829,8 +774,7 @@
"flag2": "MYOPIC_IN_LIGHT",
"flag3": "HYPEROPIC",
"effect": "transition_contacts",
"time": "57600",
"item": "bifocal_transition_contacts_daily"
"time": "57600"
}
}
}
@@ -850,13 +794,13 @@
{
"type": "effect_on_conditions",
"menu_text": "Apply contact lenses",
"description": "You can use this to mitigate your nearsightedness or farsightedness.",
"description": "You can use this to mitigate your the bright light discomfort.",
"effect_on_conditions": [
{
"id": "EOC_plano_transition_contacts_weekly",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": { "effect": "transition_contacts_plano", "plano": "1", "time": "604800", "item": "plano_transition_contacts_weekly" }
"variables": { "effect": "transition_contacts_plano", "plano": "1", "time": "604800" }
}
}
]
@@ -867,21 +811,21 @@
"id": "plano_transition_contacts_daily",
"type": "GENERIC",
"copy-from": "myopia_transition_contacts_weekly",
"name": { "str_sp": "bifocal transition contact lenses (daily)" },
"name": { "str_sp": "plano transition contact lenses (daily)" },
"description": "Small plastic case with two transition daily-use soft contact lenses, buffered in saline solution. This high-tech pair darkens in response to light, making it easier to see in bright environments, but it doesn't help with any sight issues. Essentially a pair of temporary sunglasses, this lenses should be discarded after <color_light_blue>16 hours</color> of use.",
"symbol": "[",
"color": "cyan",
"use_action": [
{
"type": "effect_on_conditions",
"menu_text": "Apply contact lenses",
"description": "You can use this to mitigate your nearsightedness or farsightedness.",
"description": "You can use this to mitigate the bright light discomfort.",
"effect_on_conditions": [
{
"id": "EOC_plano_transition_contacts_daily",
"effect": {
"run_eoc_with": "EOC_CONTACTS",
"variables": { "plano": "1", "effect": "transition_contacts", "time": "57600", "item": "plano_transition_contacts_daily" }
"variables": { "plano": "1", "effect": "transition_contacts_plano", "time": "57600" }
}
}
]
8 changes: 4 additions & 4 deletions data/json/items/tool/med.json
Original file line number Diff line number Diff line change
@@ -440,7 +440,7 @@
{
"id": "SALINE_INFUSION_250",
"condition": { "math": [ "u_skill('firstaid')", ">=", "3" ] },
"effect": { "run_eoc_with": "SALINE_INFUSION", "variables": { "bag_id": "saline_bag_250", "volume_of_saline": "250" } },
"effect": { "run_eoc_with": "SALINE_INFUSION", "variables": { "volume_of_saline": "250" } },
"false_effect": [ { "u_message": "You don't actually know how to use it properly.", "type": "bad" } ]
}
]
@@ -468,7 +468,7 @@
{
"id": "SALINE_INFUSION_500",
"condition": { "math": [ "u_skill('firstaid')", ">=", "4" ] },
"effect": { "run_eoc_with": "SALINE_INFUSION", "variables": { "bag_id": "saline_bag_500", "volume_of_saline": "500" } },
"effect": { "run_eoc_with": "SALINE_INFUSION", "variables": { "volume_of_saline": "500" } },
"false_effect": [ { "u_message": "You don't actually know how to use it properly.", "type": "bad" } ]
}
]
@@ -496,7 +496,7 @@
{
"id": "SALINE_INFUSION_1000",
"condition": { "math": [ "u_skill('firstaid')", ">=", "4" ] },
"effect": { "run_eoc_with": "SALINE_INFUSION", "variables": { "bag_id": "saline_bag_1000", "volume_of_saline": "1000" } },
"effect": { "run_eoc_with": "SALINE_INFUSION", "variables": { "volume_of_saline": "1000" } },
"false_effect": [ { "u_message": "You don't actually know how to use it properly.", "type": "bad" } ]
}
]
@@ -524,7 +524,7 @@
{
"id": "SALINE_INFUSION_2000",
"condition": { "math": [ "u_skill('firstaid')", ">=", "4" ] },
"effect": { "run_eoc_with": "SALINE_INFUSION", "variables": { "bag_id": "saline_bag_2000", "volume_of_saline": "2000" } },
"effect": { "run_eoc_with": "SALINE_INFUSION", "variables": { "volume_of_saline": "2000" } },
"false_effect": [ { "u_message": "You don't actually know how to use it properly.", "type": "bad" } ]
}
]
2 changes: 2 additions & 0 deletions doc/EFFECT_ON_CONDITION.md
Original file line number Diff line number Diff line change
@@ -83,6 +83,8 @@ For example, `{ "npc_has_effect": "Shadow_Reveal" }`, used by shadow lieutenant,
| mutation: "processed_eocs" | character (Character) | NONE |
| recipe: "result_eocs" | crafter (Character) | NONE |

Note, that using `use_action: "type": "effect_on_conditions"` automatically passes the context variable `id`, that stores the id of an item that was activated

## Value types

Effect on Condition uses a huge variety of different values for effects or for conditions to check against, so to standardize it, most of them are explained here
1 change: 1 addition & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
@@ -5522,6 +5522,7 @@ std::optional<int> effect_on_conditons_actor::use( Character *p, item &it,

item_location loc( *p->as_character(), &it );
dialogue d( get_talker_for( char_ptr ), get_talker_for( loc ) );
write_var_value( var_type::context, "npctalk_var_id", nullptr, &d, it.typeId().str() );
for( const effect_on_condition_id &eoc : eocs ) {
if( eoc->type == eoc_type::ACTIVATION ) {
eoc->activate( d );

0 comments on commit ab5aa03

Please sign in to comment.