Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When you use item with transform action it consumes charges as defined in target item, not itself #47887

Open
Salty-Panda opened this issue Mar 5, 2021 · 2 comments
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

Comments

@Salty-Panda
Copy link
Contributor

Salty-Panda commented Mar 5, 2021

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 in use_action json. ONLY THEN it reads charges_per_use.

So when you use a cellphone it works as follows:
Player activates cellphone, turn it into cellphone_on, consume charges as specified in cellphone_on.
Player activates cellphone_on, turn it into cellphone, consume charges as specified in cellphone.

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's charges_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.

@anothersimulacrum anothersimulacrum added <Bug> This needs to be fixed [C++] Changes (can be) made in C++. Previously named `Code` labels Mar 5, 2021
@wapcaplet wapcaplet added Items / Item Actions / Item Qualities Items and how they work and interact <Bug> This needs to be fixed [C++] Changes (can be) made in C++. Previously named `Code` and removed <Bug> This needs to be fixed [C++] Changes (can be) made in C++. Previously named `Code` labels Mar 5, 2021
Zeropol added a commit to Zeropol/Cataclysm-DDA that referenced this issue Mar 30, 2021
Powered_earmuff consumme the charges in powered_earmuffs_on on activation.

Quick fix CleverRaven#48261
See CleverRaven#47887
See CleverRaven#47870
@actual-nh
Copy link
Contributor

I am considering adding the 0.F milestone to this one.

@DalenTalas
Copy link

I've noticed the "1 charge to turn off" part with flashlights. The "0 charges to turn on" I have not tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
No open projects
0.F Release Planning
  
Awaiting triage
Development

No branches or pull requests

7 participants