CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.26k stars 4.11k forks source link

Conjured items with charges do not respect spell duration for summoning #37819

Open CSHague opened 4 years ago

CSHague commented 4 years ago

Describe the bug

I was trying to make a spell that conjured temporarily-existing batches of fertilizer. Unfortunately, the fertilizer stacks with charges and requires charges to be used as fertilizer in its iuse function so it cannot have a timer associated with it, as my understanding goes.

Steps To Reproduce

Created a spell: { "id": "druid_create_magic_fertilizer", "type": "SPELL", "name": "Nurture Soil", "description": "Invoke magical energy that enriches soil for plant growth.", "valid_targets": [ "none" ], "min_range": 0, "max_range": 0, "min_damage": 1, "max_damage": 11, "damage_increment": 0.5, "effect": "spawn_item", "effect_str": "magic_fertilizer", "energy_source": "MANA", "flags": [ "VERBAL", "NO_LEGS" ], "spell_class": "DRUID", "difficulty": 2, "max_level": 20, "base_casting_time": 1000, "base_energy_cost": 500, "min_duration": 2500, "max_duration": 50000, "duration_increment": 2500 }

which conjures: { "id": "magic_fertilizer", "type": "COMESTIBLE", "category": "tools", "name": { "str": "verdant glimmer" }, "description": "A glimmer of green, magical energy that pulses with the potential for vegetative growth. Sow into the soil quickly lest it dissipate.", "weight": "0 g", "volume": "0 ml", "price": 0, "stack_size": 1, "symbol": ",", "color": "light_green", "flags": [ "FERTILIZER", "INEDIBLE" ] }

What happens is the spell summons extra units of fertilizer and functions properly as fertilizer but it won't have a timer to disappear.

Expected behavior

Spell should conjure stack of fertilizer that should disappear 25 seconds per level after casting, giving the player enough time to fertilize the soil before it disappears.

Screenshots

If applicable, add screenshots to help explain your problem.

Versions and configuration

Additional context

Mentioned the issue in Discord and it was recommended that I post a bug report by a collaborator.

KorGgenT commented 4 years ago

worst case i might have to disable spawning items that count by charges? it's really odd that it doesn't "just work" though, i'll have to look into it further in order to know more about what's going on.

HarrisonGreenlee commented 4 years ago

I believe this bug is occurring because of the code in magic_spell_effect.cpp

Specifically this statement from line 669-672:

if( !granted.is_comestible() && ( !sp.has_flag( spell_flag::PERMANENT ) && !sp.is_max_level() ) ) {
        granted.set_var( "ethereal", to_turns<int>( sp.duration_turns() ) );
        granted.set_flag( "ETHEREAL_ITEM" );
}

Note that comestibles cannot gain the 'ETHEREAL' tag and therefore they will never despawn. @KorGgenT Is there any reason for this? If not I can create a PR to remove it.

KorGgenT commented 4 years ago

Ah... I think it is because in my head comestibles already had a spoils_in so i'd have wanted to use the rot code, but i'm not sure that's necessary now that i think about it again. It really needs some testing if it is to be changed though.