Skip to content

Commit

Permalink
Traps can cast spells (#38122)
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT authored and ZhilkinSerg committed Mar 17, 2020
1 parent b3d0b28 commit 4e00d6b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
18 changes: 18 additions & 0 deletions data/mods/Magiclysm/Spells/monsterspells.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions data/mods/Magiclysm/traps.json
Original file line number Diff line number Diff line change
@@ -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" }
}
]
1 change: 1 addition & 0 deletions src/trap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/trap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -116,6 +118,8 @@ struct trap {
// For disassembly?
std::vector<std::tuple<std::string, int, int>> components;
public:
// data required for trapfunc::spell()
fake_spell spell_data;
int comfort = 0;
int floor_bedding_warmth = 0;
public:
Expand Down
15 changes: 15 additions & 0 deletions src/trapfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }
}
};
Expand Down

0 comments on commit 4e00d6b

Please sign in to comment.