From b546c20d0f1233749010e9d03226d2b17a5ff121 Mon Sep 17 00:00:00 2001 From: Red Shakespeare <44523519+RedShakespeare@users.noreply.github.com> Date: Mon, 4 May 2020 03:57:38 +0800 Subject: [PATCH] [Magiclysm] Allow spells to spawn items with their containers (#40097) * Allow spells to spawn items with their containers Add a "WITH_CONTAINER" flag for spells to spawn items with containers. * Update flags.json Add description about flag "WITH_CONTAINER" --- data/json/flags.json | 6 ++++++ src/magic.cpp | 1 + src/magic.h | 1 + src/magic_spell_effect.cpp | 3 +++ 4 files changed, 11 insertions(+) diff --git a/data/json/flags.json b/data/json/flags.json index 0801f22b43b95..69faf4953558c 100644 --- a/data/json/flags.json +++ b/data/json/flags.json @@ -687,6 +687,12 @@ "context": [ "SPELL" ], "//": "pain altering spells can't be resisted (like with the deadened trait)" }, + { + "id": "WITH_CONTAINER", + "type": "json_flag", + "context": [ "SPELL" ], + "//": "items spawned by spells are put in their containers." + }, { "id": "NON_THRESH", "type": "json_flag", diff --git a/src/magic.cpp b/src/magic.cpp index 103ed22731f6f..f6d12a7ba52ed 100644 --- a/src/magic.cpp +++ b/src/magic.cpp @@ -115,6 +115,7 @@ std::string enum_to_string( spell_flag data ) case spell_flag::RANDOM_TARGET: return "RANDOM_TARGET"; case spell_flag::MUTATE_TRAIT: return "MUTATE_TRAIT"; case spell_flag::PAIN_NORESIST: return "PAIN_NORESIST"; + case spell_flag::WITH_CONTAINER: return "WITH_CONTAINER"; case spell_flag::WONDER: return "WONDER"; case spell_flag::LAST: break; } diff --git a/src/magic.h b/src/magic.h index b36eadc8691f1..45fae237e8b8e 100644 --- a/src/magic.h +++ b/src/magic.h @@ -56,6 +56,7 @@ enum spell_flag { MUTATE_TRAIT, // overrides the mutate spell_effect to use a specific trait_id instead of a category WONDER, // instead of casting each of the extra_spells, it picks N of them and casts them (where N is std::min( damage(), number_of_spells )) PAIN_NORESIST, // pain altering spells can't be resisted (like with the deadened trait) + WITH_CONTAINER, // items spawned with container LAST }; diff --git a/src/magic_spell_effect.cpp b/src/magic_spell_effect.cpp index 9ece4403a018d..acf08815f6cac 100644 --- a/src/magic_spell_effect.cpp +++ b/src/magic_spell_effect.cpp @@ -673,6 +673,9 @@ void spell_effect::spawn_ethereal_item( const spell &sp, Creature &caster, const if( granted.count_by_charges() && sp.damage() > 0 ) { granted.charges = sp.damage(); } + if( sp.has_flag( spell_flag::WITH_CONTAINER ) ) { + granted = granted.in_its_container(); + } if( g->u.can_wear( granted ).success() ) { granted.set_flag( "FIT" ); g->u.wear_item( granted, false );