From bfe7480b50adf853ad6e91a37660b8fac5c33363 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Sat, 21 Sep 2019 22:20:22 -0400 Subject: [PATCH] fix mutations overriding spell level --- src/magic.cpp | 15 ++++++++++++++- src/magic.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/magic.cpp b/src/magic.cpp index 9bbf563437d4d..c7c41552837b7 100644 --- a/src/magic.cpp +++ b/src/magic.cpp @@ -730,6 +730,11 @@ void spell::gain_exp( int nxp ) experience += nxp; } +void spell::set_exp( int nxp ) +{ + experience = nxp; +} + std::string spell::energy_string() const { switch( type->energy_source ) { @@ -1117,7 +1122,11 @@ void known_magic::deserialize( JsonIn &jsin ) std::string id = jo.get_string( "id" ); spell_id sp = spell_id( id ); int xp = jo.get_int( "xp" ); - spellbook.emplace( sp, spell( sp, xp ) ); + if( knows_spell( sp ) ) { + spellbook[sp].set_exp( xp ); + } else { + spellbook.emplace( sp, spell( sp, xp ) ); + } } } @@ -1152,6 +1161,10 @@ void known_magic::learn_spell( const spell_type *sp, player &p, bool force ) debugmsg( "Tried to learn invalid spell" ); return; } + if( p.magic.knows_spell( sp->id ) ) { + // you already know the spell + return; + } spell temp_spell( sp->id ); if( !temp_spell.is_valid() ) { debugmsg( "Tried to learn invalid spell" ); diff --git a/src/magic.h b/src/magic.h index 5bbdc80ba51d7..e7acc80e94b8a 100644 --- a/src/magic.h +++ b/src/magic.h @@ -284,6 +284,7 @@ class spell int xp() const; // gain some exp void gain_exp( int nxp ); + void set_exp( int nxp ); // how much xp you get if you successfully cast the spell int casting_exp( const player &p ) const; // modifier for gaining exp