Skip to content

Commit

Permalink
Magiclysm: Holographic transposition spell (#36714)
Browse files Browse the repository at this point in the history
* Holographic transposition spell

* Add spawn for the holographic transposition scroll

* Remove outdated flag

* Remove unused function parameter

* Changes suggested by code review.

* Update data/mods/Magiclysm/items/spell_scrolls.json

Co-Authored-By: Jianxiang Wang (王健翔) <[email protected]>

* Fix misplaced coma in spell_scrolls.json

* Apply suggestions from code review

Co-Authored-By: LaVeyanFiend <[email protected]>

Co-authored-by: Jianxiang Wang (王健翔) <[email protected]>
Co-authored-by: LaVeyanFiend <[email protected]>
  • Loading branch information
3 people authored and KorGgenT committed Jan 6, 2020
1 parent 57b6f2f commit 8ad1db2
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 1 deletion.
23 changes: 23 additions & 0 deletions data/mods/Magiclysm/Spells/technomancer.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,29 @@
"max_duration": 6000,
"duration_increment": 200
},
{
"id": "holographic_transposition",
"type": "SPELL",
"name": "Holographic Transposition",
"description": "Allows you to swap places with a previously existing holographic image of yourself. If the universe itself can't tell you apart, who could?",
"valid_targets": [ "hostile", "ally" ],
"targeted_monster_ids": [ "mon_mirror_image", "mon_hologram" ],
"flags": [ "NO_LEGS", "LOUD", "SOMATIC", "SWAP_POS" ],
"effect": "target_attack",
"spell_class": "TECHNOMANCER",
"energy_source": "MANA",
"difficulty": 3,
"max_level": 20,
"base_casting_time": 100,
"casting_time_increment": -1,
"final_casting_time": 80,
"base_energy_cost": 150,
"energy_increment": -2,
"final_energy_cost": 100,
"min_range": 20,
"max_range": 30,
"range_increment": 1
},
{
"type": "SPELL",
"name": "X-ray Vision",
Expand Down
1 change: 1 addition & 0 deletions data/mods/Magiclysm/itemgroups/spellbooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
[ "spell_scroll_storm_hammer", 35 ],
[ "spell_scroll_animated_blade", 35 ],
[ "spell_scroll_mirror_image", 15 ],
[ "spell_scroll_holographic_transposition", 15 ],
[ "spell_scroll_dark_sight", 30 ]
]
},
Expand Down
8 changes: 8 additions & 0 deletions data/mods/Magiclysm/items/spell_scrolls.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
"description": "A magical aura distorts light around your body, making it easier to dodge enemy attacks.",
"use_action": { "type": "learn_spell", "spells": [ "obfuscated_body" ] }
},
{
"type": "GENERIC",
"copy-from": "spell_scroll",
"id": "spell_scroll_holographic_transposition",
"name": { "str": "Scroll of Holographic Transposition", "str_pl": "Scrolls of Holographic Transposition" },
"description": "Allows you to swap places with a previously existing holographic image of yourself. If the universe itself can't tell you apart, who could?",
"use_action": { "type": "learn_spell", "spells": [ "holographic_transposition" ] }
},
{
"type": "GENERIC",
"copy-from": "spell_scroll",
Expand Down
10 changes: 9 additions & 1 deletion data/mods/Magiclysm/items/spellbooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@
"color": "light_gray",
"use_action": {
"type": "learn_spell",
"spells": [ "dark_sight", "blinding_flash", "obfuscated_body", "create_atomic_light", "mirror_image", "invisibility" ]
"spells": [
"dark_sight",
"blinding_flash",
"obfuscated_body",
"create_atomic_light",
"mirror_image",
"invisibility",
"holographic_transposition"
]
}
},
{
Expand Down
20 changes: 20 additions & 0 deletions src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ std::string enum_to_string<spell_flag>( spell_flag data )
case spell_flag::NO_HANDS: return "NO_HANDS";
case spell_flag::NO_LEGS: return "NO_LEGS";
case spell_flag::UNSAFE_TELEPORT: return "UNSAFE_TELEPORT";
case spell_flag::SWAP_POS: return "SWAP_POS";
case spell_flag::CONCENTRATE: return "CONCENTRATE";
case spell_flag::RANDOM_AOE: return "RANDOM_AOE";
case spell_flag::RANDOM_DAMAGE: return "RANDOM_DAMAGE";
Expand Down Expand Up @@ -248,6 +249,10 @@ void spell_type::load( const JsonObject &jo, const std::string & )
const auto effect_targets_reader = enum_flags_reader<valid_target> { "effect_targets" };
optional( jo, was_loaded, "effect_filter", effect_targets, effect_targets_reader );

const auto targeted_monster_ids_reader = auto_flags_reader<mtype_id> {};
optional( jo, was_loaded, "targeted_monster_ids", targeted_monster_ids,
targeted_monster_ids_reader );

const auto trigger_reader = enum_flags_reader<valid_target> { "valid_targets" };
mandatory( jo, was_loaded, "valid_targets", valid_targets, trigger_reader );

Expand Down Expand Up @@ -895,6 +900,7 @@ bool spell::is_valid_target( const Creature &caster, const tripoint &p ) const
valid = valid || ( cr_att == Creature::A_FRIENDLY && is_valid_target( target_ally ) &&
p != caster.pos() );
valid = valid || ( is_valid_target( target_self ) && p == caster.pos() );
valid = valid && target_by_monster_id( p );
} else {
valid = is_valid_target( target_ground );
}
Expand All @@ -906,6 +912,20 @@ bool spell::is_valid_effect_target( valid_target t ) const
return type->effect_targets[t];
}

bool spell::target_by_monster_id( const tripoint &p ) const
{
if( type->targeted_monster_ids.empty() ) {
return true;
}
bool valid = false;
if( monster *const target = g->critter_at<monster>( p ) ) {
if( type->targeted_monster_ids.find( target->type->id ) != type->targeted_monster_ids.end() ) {
valid = true;
}
}
return valid;
}

std::string spell::description() const
{
return type->description.translated();
Expand Down
4 changes: 4 additions & 0 deletions src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ template <typename E> struct enum_traits;
enum spell_flag {
PERMANENT, // items or creatures spawned with this spell do not disappear and die as normal
IGNORE_WALLS, // spell's aoe goes through walls
SWAP_POS, // a projectile spell swaps the positions of the caster and target
HOSTILE_SUMMON, // summon spell always spawns a hostile monster
HOSTILE_50, // summoned monster spawns friendly 50% of the time
SILENT, // spell makes no noise at target
Expand Down Expand Up @@ -245,6 +246,8 @@ class spell_type
// list of valid targets enum
enum_bitset<valid_target> valid_targets;

std::set<mtype_id> targeted_monster_ids;

// lits of bodyparts this spell applies its effect to
enum_bitset<body_part> affected_bps;

Expand Down Expand Up @@ -400,6 +403,7 @@ class spell
bool is_valid_target( const Creature &caster, const tripoint &p ) const;
bool is_valid_target( valid_target t ) const;
bool is_valid_effect_target( valid_target t ) const;
bool target_by_monster_id( const tripoint &p ) const;

// picks a random valid tripoint from @area
cata::optional<tripoint> random_valid_target( const Creature &caster,
Expand Down
12 changes: 12 additions & 0 deletions src/magic_spell_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ void spell_effect::teleport_random( const spell &sp, Creature &caster, const tri
teleport::teleport( caster, min_distance, max_distance, safe, false );
}

static void swap_pos( Creature &caster, const tripoint &target )
{
Creature *const critter = g->critter_at<Creature>( target );
critter->setpos( caster.pos() );
caster.setpos( target );
//update map in case a monster swapped positions with the player
g->update_map( g->u );
}

void spell_effect::pain_split( const spell &sp, Creature &caster, const tripoint & )
{
player *p = caster.as_player();
Expand Down Expand Up @@ -447,6 +456,9 @@ void spell_effect::target_attack( const spell &sp, Creature &caster,
{
damage_targets( sp, caster, spell_effect_area( sp, epicenter, spell_effect_blast, caster,
sp.has_flag( spell_flag::IGNORE_WALLS ) ) );
if( sp.has_flag( spell_flag::SWAP_POS ) ) {
swap_pos( caster, epicenter );
}
}

void spell_effect::cone_attack( const spell &sp, Creature &caster,
Expand Down

0 comments on commit 8ad1db2

Please sign in to comment.