Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

traps can cast spells #38122

Merged
merged 3 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 additions & 0 deletions data/mods/Magiclysm/traps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"type": "trap",
"id": "tr_bear",
"name": "bear trap",
"looks_like": "tr_beartrap",
KorGgenT marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -119,6 +119,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 @@ -1399,6 +1400,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 @@ -1472,6 +1486,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