When you use item with transform action it consumes charges as defined in target item, not itself #47887
Labels
<Bug>
This needs to be fixed
[C++]
Changes (can be) made in C++. Previously named `Code`
Items / Item Actions / Item Qualities
Items and how they work and interact
Projects
Describe the bug
Wanted to make a flotation vest you can inflate using CO2 cartridge (#47871).
I already made one PR fixing bug that was making some items don't consume charges on activation, but there is another:
When you activate an item, the game calls
Character::invoke_item
which turns the original item into a target item specified inuse_action
json. ONLY THEN it readscharges_per_use
.So when you use a
cellphone
it works as follows:Player activates
cellphone
, turn it intocellphone_on
, consume charges as specified incellphone_on
.Player activates
cellphone_on
, turn it intocellphone
, consume charges as specified incellphone
.Currently, it works properly only because target items use
copy-from: origin item
.When I make something like this: vest ( inflate using 1 charge) -> inflated vest ( deflate using 0 charges ) it doesn't work.
I either can't deflate it if it doesn't have any charges or it consumes itself ( game treats it as a single-use tool if
charges_per_use
are read to be 0 ) instead of inflating.If you have an idea "take this switch into account and specify those values in opposite way", it doesn't work. Item itself gets consumed, game elsewhere tries to read the value from the right item, if finds 0 and considers the item as "delete on use".
Steps To Reproduce
Go into json for
mp3
.See it has
"charges_per_use": 1
Go into
mp3_on
See it uses
"copy-from": "mp3"
so it has the same charges per use.In
mp3_on
add"charges_per_use": 0
Logically now it should cost 1 charge to activate MP3 and 0 to deactivate it,
But actually, it's 0 charges to activate and 1 charge to deactivate.
( Load or wait until #47870 bugfix gets merged if you want to be able to test it on ANY item that transforms and consumes charges. Now it works if the item is handled in iuse.cpp in a dedicated function )
Expected behavior
Transform action consumes charges as specified in the item that describes such action, not the item you get as result.
Versions and configuration
Tested today on upstream/master
Additional content
In character.cpp there is
cata::optional<int> charges_used = actually_used->type->invoke( *this->as_player(), *actually_used, pt, method );
which handles "change item into target part and return target'scharges_per_use
.A bit lower it calls
consume_charges
.Transforming items and returning target's charges_per use is handled in iuse.cpp for specific items like mp3, and in iuse_actor.cpp ( Character::invoke_item ) for the rest.
The text was updated successfully, but these errors were encountered: