diff --git a/data/mods/Magiclysm/Spells/monsterspells.json b/data/mods/Magiclysm/Spells/monsterspells.json index 7976d85806aee..713afe9505de4 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 256a5f505217f..adbf172facd78 100644 --- a/src/trap.cpp +++ b/src/trap.cpp @@ -116,6 +116,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 61b1daefeb034..0969e13227ab6 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" @@ -1376,6 +1377,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 @@ -1449,6 +1463,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 } } };