From cf975e24ad1487a4219fee9021210eb9e294cfc0 Mon Sep 17 00:00:00 2001 From: Curtis Merrill Date: Wed, 11 Mar 2020 02:56:16 -0400 Subject: [PATCH] Traps can cast spells (#38122) --- data/mods/Magiclysm/Spells/monsterspells.json | 18 ++++++++++++++++++ data/mods/Magiclysm/traps.json | 15 +++++++++++++++ src/trap.cpp | 1 + src/trap.h | 4 ++++ src/trapfunc.cpp | 15 +++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 data/mods/Magiclysm/traps.json diff --git a/data/mods/Magiclysm/Spells/monsterspells.json b/data/mods/Magiclysm/Spells/monsterspells.json index 6b214b04d9076..f9e5eab85b216 100644 --- a/data/mods/Magiclysm/Spells/monsterspells.json +++ b/data/mods/Magiclysm/Spells/monsterspells.json @@ -17,6 +17,24 @@ "effect": "projectile_attack", "extra_effects": [ { "id": "light_healing", "hit_self": true } ] }, + { + "id": "bear_trap", + "type": "SPELL", + "name": "Bear Trap", + "description": "A trap that summons bears! Not what you were expecting, is it?", + "valid_targets": [ "ground" ], + "flags": [ "HOSTILE_SUMMON", "LOUD" ], + "min_damage": 3, + "max_damage": 3, + "min_aoe": 5, + "max_aoe": 5, + "sound_description": "\"It's a trap!\"", + "min_duration": 30000, + "max_duration": 30000, + "sound_type": "speech", + "effect": "summon", + "effect_str": "mon_bear" + }, { "id": "rocket_punch", "type": "SPELL", diff --git a/data/mods/Magiclysm/traps.json b/data/mods/Magiclysm/traps.json new file mode 100644 index 0000000000000..278152784cf32 --- /dev/null +++ b/data/mods/Magiclysm/traps.json @@ -0,0 +1,15 @@ +[ + { + "type": "trap", + "id": "tr_bear", + "name": "bear trap", + "color": "blue", + "symbol": "^", + "action": "spell", + "visibility": 2, + "trap_radius": 2, + "avoidance": 99, + "difficulty": 99, + "spell_data": { "id": "bear_trap" } + } +] diff --git a/src/trap.cpp b/src/trap.cpp index 55e33760dc4b0..d872af3744749 100644 --- a/src/trap.cpp +++ b/src/trap.cpp @@ -122,6 +122,7 @@ void trap::load( const JsonObject &jo, const std::string & ) optional( jo, was_loaded, "funnel_radius", funnel_radius_mm, 0 ); optional( jo, was_loaded, "comfort", comfort, 0 ); optional( jo, was_loaded, "floor_bedding_warmth", floor_bedding_warmth, 0 ); + optional( jo, was_loaded, "spell_data", spell_data ); assign( jo, "trigger_weight", trigger_weight ); for( const JsonValue entry : jo.get_array( "drops" ) ) { std::string item_type; diff --git a/src/trap.h b/src/trap.h index d93fcb6d76e85..038a66793e6f8 100644 --- a/src/trap.h +++ b/src/trap.h @@ -10,6 +10,7 @@ #include "color.h" #include "int_id.h" +#include "magic.h" #include "string_id.h" #include "translations.h" #include "type_id.h" @@ -62,6 +63,7 @@ bool shadow( const tripoint &p, Creature *c, item *i ); bool map_regen( const tripoint &p, Creature *c, item *i ); bool drain( const tripoint &p, Creature *c, item *i ); bool snake( const tripoint &p, Creature *c, item *i ); +bool cast_spell( const tripoint &p, Creature *critter, item * ); } // namespace trapfunc struct vehicle_handle_trap_data { @@ -116,6 +118,8 @@ struct trap { // For disassembly? std::vector> components; public: + // data required for trapfunc::spell() + fake_spell spell_data; int comfort = 0; int floor_bedding_warmth = 0; public: diff --git a/src/trapfunc.cpp b/src/trapfunc.cpp index 62624a49fa47b..6730a6f14e0a3 100644 --- a/src/trapfunc.cpp +++ b/src/trapfunc.cpp @@ -17,6 +17,7 @@ #include "messages.h" #include "monster.h" #include "mtype.h" +#include "npc.h" #include "output.h" #include "overmapbuffer.h" #include "rng.h" @@ -1398,6 +1399,19 @@ bool trapfunc::drain( const tripoint &, Creature *c, item * ) return false; } +bool trapfunc::cast_spell( const tripoint &p, Creature *critter, item * ) +{ + if( critter == nullptr ) { + return false; + } + const spell trap_spell = g->m.tr_at( p ).spell_data.get_spell( 0 ); + npc dummy; + trap_spell.cast_all_effects( dummy, critter->pos() ); + trap_spell.make_sound( p, 20 ); + g->m.remove_trap( p ); + return true; +} + bool trapfunc::snake( const tripoint &p, Creature *, item * ) { //~ the sound a snake makes @@ -1471,6 +1485,7 @@ const trap_function &trap_function_from_string( const std::string &function_name { "shadow", trapfunc::shadow }, { "map_regen", trapfunc::map_regen }, { "drain", trapfunc::drain }, + { "spell", trapfunc::cast_spell }, { "snake", trapfunc::snake } } };