Skip to content

Commit

Permalink
Merge pull request #78684 from TRScheel/bugfix/77525/infinite-drug-eoc
Browse files Browse the repository at this point in the history
Fixes infinite sleeping pill/chamomile tea bug
  • Loading branch information
Maleclypse authored Dec 23, 2024
2 parents 0664114 + 3b693e5 commit 0f016e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
6 changes: 1 addition & 5 deletions data/json/items/comestibles/drink.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,7 @@
"name": { "str_sp": "chamomile tea" },
"copy-from": "tea",
"color": "green",
"use_action": {
"type": "effect_on_conditions",
"description": "Can be used to treat insomnia.",
"effect_on_conditions": [ "EOC_MINOR_SLEEP" ]
},
"sleepiness_mod": -20,
"stim": 0,
"spoils_in": "10 days",
"comestible_type": "MED",
Expand Down
18 changes: 6 additions & 12 deletions data/json/items/comestibles/med.json
Original file line number Diff line number Diff line change
Expand Up @@ -1488,11 +1488,8 @@
"flags": [ "IRREPLACEABLE_CONSUMABLE", "WATER_DISSOLVE", "EDIBLE_FROZEN" ],
"addiction_potential": 40,
"addiction_type": "sleeping pill",
"use_action": {
"type": "effect_on_conditions",
"description": "Can be used to treat insomnia.",
"effect_on_conditions": [ "EOC_SLEEP" ]
}
"use_action": { "type": "consume_drug", "activation_message": "You take a %s." },
"sleepiness_mod": -40
},
{
"id": "poppy_pain",
Expand Down Expand Up @@ -1531,13 +1528,10 @@
"symbol": "!",
"color": "magenta",
"healthy": -2,
"addiction_type": "opiate",
"addiction_type": [ "sleeping pill", "opiate" ],
"flags": [ "EDIBLE_FROZEN" ],
"use_action": {
"type": "effect_on_conditions",
"description": "Can be used to treat insomnia.",
"effect_on_conditions": [ "EOC_SLEEP" ]
}
"use_action": { "type": "consume_drug", "activation_message": "You take a %s." },
"sleepiness_mod": -40
},
{
"id": "poppysyrup",
Expand All @@ -1557,7 +1551,7 @@
"stim": -3,
"healthy": -1,
"addiction_potential": 15,
"addiction_type": "sleeping pill",
"addiction_type": [ "sleeping pill", "opiate" ],
"use_action": [ "FLUSLEEP" ]
},
{
Expand Down
9 changes: 9 additions & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5700,6 +5700,11 @@ void effect_on_conditons_actor::info( const item &, std::vector<iteminfo> &dump
std::optional<int> effect_on_conditons_actor::use( Character *p, item &it,
const tripoint_bub_ms &point ) const
{
if( it.type->comestible ) {
debugmsg( "Comestibles are not properly consumed via effect_on_conditions and effect_on_conditions should not be used on items of type comestible until/unless this is resolved." );
return 0;
}

if( need_worn && !p->is_worn( it ) ) {
p->add_msg_if_player( m_info, _( "You need to wear the %1$s before activating it." ), it.tname() );
return std::nullopt;
Expand Down Expand Up @@ -5731,6 +5736,10 @@ std::optional<int> effect_on_conditons_actor::use( Character *p, item &it,
}
}
// Prevents crash from trying to spend charge with item removed
// NOTE: Because this section and/or calling stack does not check if the item exists in the surrounding tiles
// it will not properly decrement any item of type `comestible` if consumed via the `E` `Consume item` menu.
// Therefore, it is not advised to use items of type `comestible` with a `use_action` of type
// `effect_on_conditions` until/unless this section is properly updated to actually consume said item.
if( p && !p->has_item( it ) ) {
return 0;
}
Expand Down

0 comments on commit 0f016e4

Please sign in to comment.