Skip to content

Commit

Permalink
Merge pull request #38585 from KorGgenT/fix-fake-spell-again
Browse files Browse the repository at this point in the history
rewrite how monster attacks read spells
  • Loading branch information
ZhilkinSerg authored Mar 8, 2020
2 parents 4b40129 + eada76e commit 49d6ded
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 38 deletions.
6 changes: 3 additions & 3 deletions data/json/monsters/mi-go.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"special_attacks": [
[ "PARROT", 0 ],
{ "id": "scratch", "damage_max_instance": [ { "damage_type": "cut", "amount": 23, "armor_multiplier": 0.8 } ] },
{ "type": "spell", "spell_id": "mi-go_slaver_beam", "spell_level": 3, "cooldown": 100 }
{ "type": "spell", "spell_data": { "id": "mi-go_slaver_beam", "min_level": 3 }, "cooldown": 100 }
],
"death_function": [ "NORMAL" ],
"flags": [
Expand Down Expand Up @@ -179,7 +179,7 @@
[ "SHRIEK_STUN", 4 ],
[ "TAZER", 5 ],
{ "id": "scratch", "damage_max_instance": [ { "damage_type": "cut", "amount": 35, "armor_multiplier": 0.7 } ] },
{ "type": "spell", "spell_id": "mi-go_slaver_beam", "spell_level": 1, "cooldown": 100 }
{ "type": "spell", "spell_data": { "id": "mi-go_slaver_beam", "min_level": 1 }, "cooldown": 100 }
],
"death_function": [ "NORMAL" ],
"flags": [
Expand Down Expand Up @@ -230,7 +230,7 @@
[ "LONGSWIPE", 12 ],
[ "STRETCH_ATTACK", 20 ],
{ "id": "scratch", "damage_max_instance": [ { "damage_type": "cut", "amount": 30, "armor_multiplier": 0.7 } ] },
{ "type": "spell", "spell_id": "mi-go_slaver_beam", "spell_level": 2, "cooldown": 100 }
{ "type": "spell", "spell_data": { "id": "mi-go_slaver_beam", "min_level": 2 }, "cooldown": 100 }
],
"death_function": [ "NORMAL" ],
"flags": [
Expand Down
4 changes: 2 additions & 2 deletions data/mods/Magiclysm/monsters/demon_spider.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"vision_day": 6,
"vision_night": 12,
"harvest": "demon_spider",
"special_attacks": [ { "type": "spell", "spell_id": "burning_hands", "spell_level": 4, "cooldown": 20 } ],
"special_attacks": [ { "type": "spell", "spell_data": { "id": "burning_hands", "min_level": 4 }, "cooldown": 20 } ],
"anger_triggers": [ "FRIEND_ATTACKED", "FRIEND_DIED", "HURT", "STALK", "PLAYER_WEAK", "PLAYER_CLOSE" ],
"death_function": [ "NORMAL" ],
"flags": [ "SEES", "SMELLS", "HEARS", "VENOM", "WEBWALK", "CLIMBS", "HARDTOSHOOT", "PUSH_MON" ]
Expand All @@ -110,6 +110,6 @@
"vision_night": 18,
"harvest": "demon_spider_queen",
"flags": [ "SEES", "SMELLS", "HEARS", "VENOM", "WEBWALK", "CLIMBS", "HARDTOSHOOT", "PUSH_MON", "STUN_IMMUNE" ],
"special_attacks": [ { "type": "spell", "spell_id": "mon_summon_demon_spiderlings", "cooldown": 14 } ]
"special_attacks": [ { "type": "spell", "spell_data": { "id": "mon_summon_demon_spiderlings" }, "cooldown": 14 } ]
}
]
6 changes: 3 additions & 3 deletions data/mods/Magiclysm/monsters/dragon.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"special_attacks": [
{ "type": "bite", "cooldown": 10 },
[ "scratch", 7 ],
{ "type": "spell", "spell_id": "dragon_breath_black", "spell_level": 4, "cooldown": 20 }
{ "type": "spell", "spell_data": { "id": "dragon_breath_black", "min_level": 4 }, "cooldown": 20 }
],
"flags": [
"SEES",
Expand Down Expand Up @@ -134,7 +134,7 @@
"special_attacks": [
{ "type": "bite", "cooldown": 10 },
[ "scratch", 3 ],
{ "type": "spell", "spell_id": "dragon_breath_black", "spell_level": 12, "cooldown": 20 }
{ "type": "spell", "spell_data": { "id": "dragon_breath_black", "min_level": 12 }, "cooldown": 20 }
]
},
{
Expand All @@ -159,7 +159,7 @@
"special_attacks": [
{ "type": "bite", "cooldown": 10 },
[ "scratch", 3 ],
{ "type": "spell", "spell_id": "dragon_breath_black", "spell_level": 22, "cooldown": 30 }
{ "type": "spell", "spell_data": { "id": "dragon_breath_black", "min_level": 22 }, "cooldown": 30 }
]
}
]
4 changes: 2 additions & 2 deletions data/mods/Magiclysm/monsters/golems.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"dodge": 0,
"vision_day": 40,
"vision_night": 40,
"special_attacks": [ { "type": "spell", "spell_id": "rocket_punch", "spell_level": 5, "cooldown": 10 } ],
"special_attacks": [ { "type": "spell", "spell_data": { "id": "rocket_punch", "min_level": 5 }, "cooldown": 10 } ],
"anger_triggers": [ "PLAYER_CLOSE", "HURT" ],
"death_function": [ "BROKEN" ],
"flags": [ "SEES", "NO_BREATHE", "ACIDPROOF", "LOUDMOVES" ]
Expand Down Expand Up @@ -117,7 +117,7 @@
"dodge": 0,
"vision_day": 40,
"vision_night": 40,
"special_attacks": [ { "type": "spell", "spell_id": "gas_attack", "spell_level": 5, "cooldown": 60 } ],
"special_attacks": [ { "type": "spell", "spell_data": { "id": "gas_attack", "min_level": 5 }, "cooldown": 60 } ],
"anger_triggers": [ "PLAYER_CLOSE", "HURT" ],
"death_function": [ "BROKEN" ],
"flags": [ "SEES", "NO_BREATHE", "ACIDPROOF", "LOUDMOVES" ]
Expand Down
2 changes: 1 addition & 1 deletion data/mods/Magiclysm/monsters/lizardfolk.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"melee_skill": 3,
"melee_dice": 2,
"melee_dice_sides": 6,
"special_attacks": [ { "type": "spell", "spell_id": "spell_shaman_base", "cooldown": 5 }, [ "scratch", 5 ] ],
"special_attacks": [ { "type": "spell", "spell_data": { "id": "spell_shaman_base" }, "cooldown": 5 }, [ "scratch", 5 ] ],
"death_drops": {
"subtype": "distribution",
"items": [
Expand Down
14 changes: 9 additions & 5 deletions data/mods/Magiclysm/monsters/monsters.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@
"special_attacks": [
{
"type": "spell",
"spell_id": "bio_acidicspray",
"spell_data": { "id": "bio_acidicspray" },
"cooldown": 20,
"monster_message": "The black pudding burns you with acid!",
"spell_level": 0
"monster_message": "The black pudding burns %3$s with acid!"
}
],
"flags": [ "HEARS", "GOODHEARING", "NOHEAD", "POISON", "NO_BREATHE", "ACIDPROOF" ]
Expand Down Expand Up @@ -105,7 +104,12 @@
"cooldown": 1,
"damage_max_instance": [ { "damage_type": "cut", "amount": 25, "armor_multiplier": 1.2 } ]
},
{ "type": "spell", "spell_id": "necrotic_gaze", "cooldown": 5, "monster_message": "The krabgek gazes at %3$s!" }
{
"type": "spell",
"spell_data": { "id": "necrotic_gaze" },
"cooldown": 5,
"monster_message": "The krabgek gazes at %3$s!"
}
]
},
{
Expand Down Expand Up @@ -268,7 +272,7 @@
"vision_day": 20,
"vision_night": 20,
"harvest": "stirge",
"special_attacks": [ { "type": "spell", "spell_id": "blood_suck", "spell_level": 3, "cooldown": 3 } ],
"special_attacks": [ { "type": "spell", "spell_data": { "id": "blood_suck", "min_level": 3 }, "cooldown": 3 } ],
"anger_triggers": [ "PLAYER_CLOSE" ],
"death_function": [ "NORMAL" ],
"flags": [ "SEES", "SMELLS", "HEARS", "FLIES", "HIT_AND_RUN", "PATH_AVOID_FIRE", "SWARMS" ]
Expand Down
30 changes: 18 additions & 12 deletions src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,10 @@ spell::spell( spell_id sp, int xp ) :
experience( xp )
{}

spell::spell( spell_id sp, const translation &alt_msg ) :
type( sp ),
alt_message( alt_msg )
{}
void spell::set_message( const translation &msg )
{
alt_message = msg;
}

spell_id spell::id() const
{
Expand Down Expand Up @@ -1972,19 +1972,25 @@ void fake_spell::deserialize( JsonIn &jsin )
load( data );
}

spell fake_spell::get_spell( int input_level ) const
spell fake_spell::get_spell( int min_level_override ) const
{
spell sp( id );
int lvl = std::min( input_level, sp.get_max_level() );
if( max_level ) {
lvl = std::min( lvl, *max_level );
}
if( level > lvl ) {
// the max level this spell will be. can be optionally limited
int spell_limiter = max_level ? std::min( *max_level, sp.get_max_level() ) : sp.get_max_level();
// level is the minimum level the fake_spell will output
min_level_override = std::max( min_level_override, level );
if( min_level_override > spell_limiter ) {
// this override is for min level, and does not override max level
min_level_override = spell_limiter;
}
// the "level" of the fake spell is the goal, but needs to be clamped to min and max
int level_of_spell = clamp( level, min_level_override, std::min( sp.get_max_level(),
spell_limiter ) );
if( level > spell_limiter ) {
debugmsg( "ERROR: fake spell %s has higher min_level than max_level", id.c_str() );
return sp;
}
lvl = clamp( std::max( lvl, level ), level, lvl );
while( sp.get_level() < lvl ) {
while( sp.get_level() < level_of_spell ) {
sp.gain_level();
}
return sp;
Expand Down
7 changes: 5 additions & 2 deletions src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ struct fake_spell {
const cata::optional<int> &max_level = cata::nullopt ) : id( sp_id ),
max_level( max_level ), self( hit_self ) {}

spell get_spell( int input_level ) const;
// gets the spell with an additional override for minimum level (default 0)
spell get_spell( int min_level_override = 0 ) const;

void load( const JsonObject &jo );
void serialize( JsonOut &json ) const;
Expand Down Expand Up @@ -289,7 +290,9 @@ class spell
public:
spell() = default;
spell( spell_id sp, int xp = 0 );
spell( spell_id sp, const translation &alt_msg );

// sets the message to be different than the spell_type specifies
void set_message( const translation &msg );

// how much exp you need for the spell to gain a level
int exp_to_next_level() const;
Expand Down
13 changes: 5 additions & 8 deletions src/mattack_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,15 @@ std::unique_ptr<mattack_actor> mon_spellcasting_actor::clone() const
void mon_spellcasting_actor::load_internal( const JsonObject &obj, const std::string & )
{
std::string sp_id;
int spell_level = 0;
mandatory( obj, was_loaded, "spell_id", sp_id );
optional( obj, was_loaded, "self", self, false );
optional( obj, was_loaded, "spell_level", spell_level, 0 );
fake_spell intermediate;
mandatory( obj, was_loaded, "spell_data", intermediate );
self = intermediate.self;
translation monster_message;
optional( obj, was_loaded, "monster_message", monster_message,
//~ "<Monster Display name> cast <Spell Name> on <Target name>!"
to_translation( "%1$s casts %2$s at %3$s!" ) );
spell_data = spell( spell_id( sp_id ), monster_message );
for( int i = 0; i <= spell_level; i++ ) {
spell_data.gain_level();
}
spell_data = intermediate.get_spell();
spell_data.set_message( monster_message );
avatar fake_player;
move_cost = spell_data.casting_time( fake_player );
}
Expand Down

0 comments on commit 49d6ded

Please sign in to comment.