diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index 3d2be998e8213..2f75554ca47f1 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -4661,8 +4661,8 @@ void activity_handlers::study_spell_finish( player_activity *act, player *p ) if( act->get_str_value( 1 ) == "study" ) { p->add_msg_if_player( m_good, _( "You gained %i experience from your study session." ), total_exp_gained ); - p->practice( skill_id( "spellcraft" ), total_exp_gained, - p->magic.get_spell( spell_id( act->name ) ).get_difficulty() ); + const spell &sp = p->magic.get_spell( spell_id( act->name ) ); + p->practice( sp.skill(), total_exp_gained, sp.get_difficulty() ); } else if( act->get_str_value( 1 ) == "learn" && act->values[2] == 0 ) { p->magic.learn_spell( act->name, *p ); } diff --git a/src/magic.cpp b/src/magic.cpp index 3edd6db825919..cb89ab44c848c 100644 --- a/src/magic.cpp +++ b/src/magic.cpp @@ -24,6 +24,7 @@ #include "mutation.h" #include "output.h" #include "player.h" +#include "skill.h" #include "sounds.h" #include "translations.h" #include "ui.h" @@ -231,6 +232,7 @@ void spell_type::load( const JsonObject &jo, const std::string & ) mandatory( jo, was_loaded, "id", id ); mandatory( jo, was_loaded, "name", name ); mandatory( jo, was_loaded, "description", description ); + optional( jo, was_loaded, "skill", skill, skill_id( "spellcraft" ) ); optional( jo, was_loaded, "message", message, to_translation( "You cast %s!" ) ); optional( jo, was_loaded, "sound_description", sound_description, to_translation( "an explosion" ) ); @@ -445,6 +447,11 @@ trait_id spell::spell_class() const return type->spell_class; } +skill_id spell::skill() const +{ + return type->skill; +} + int spell::field_intensity() const { return std::min( type->max_field_intensity, @@ -706,7 +713,7 @@ float spell::spell_fail( const player &p ) const // effective skill of 8 (8 int, 0 spellcraft, 0 spell level, spell difficulty 0) is ~50% failure // effective skill of 30 is 0% failure const float effective_skill = 2 * ( get_level() - get_difficulty() ) + p.get_int() + - p.get_skill_level( skill_id( "spellcraft" ) ); + p.get_skill_level( skill() ); // add an if statement in here because sufficiently large numbers will definitely overflow because of exponents if( effective_skill > 30.0f ) { return 0.0f; @@ -1022,7 +1029,7 @@ float spell::exp_modifier( const player &p ) const { const float int_modifier = ( p.get_int() - 8.0f ) / 8.0f; const float difficulty_modifier = get_difficulty() / 20.0f; - const float spellcraft_modifier = p.get_skill_level( skill_id( "spellcraft" ) ) / 10.0f; + const float spellcraft_modifier = p.get_skill_level( skill() ) / 10.0f; return ( int_modifier + difficulty_modifier + spellcraft_modifier ) / 5.0f + 1.0f; } @@ -1431,8 +1438,8 @@ int known_magic::time_to_learn_spell( const player &p, const std::string &str ) int known_magic::time_to_learn_spell( const player &p, const spell_id &sp ) const { const int base_time = to_moves( 30_minutes ); - return base_time * ( 1.0 + sp.obj().difficulty / ( 1.0 + ( p.get_int() - 8.0 ) / 8.0 ) + - ( p.get_skill_level( skill_id( "spellcraft" ) ) / 10.0 ) ); + return base_time * ( 1.0 + sp->difficulty / ( 1.0 + ( p.get_int() - 8.0 ) / 8.0 ) + + ( p.get_skill_level( sp->skill ) / 10.0 ) ); } int known_magic::get_spellname_max_width() diff --git a/src/magic.h b/src/magic.h index ff81b13e3fbe8..94bcf20c335e9 100644 --- a/src/magic.h +++ b/src/magic.h @@ -133,6 +133,7 @@ class spell_type translation message; // spell sound effect translation sound_description; + skill_id skill; sounds::sound_t sound_type = sounds::sound_t::_LAST; bool sound_ambient = false; std::string sound_id; @@ -355,6 +356,8 @@ class spell spell_id id() const; // get spell class (from type) trait_id spell_class() const; + // get skill id + skill_id skill() const; // get spell effect string (from type) std::string effect() const; // get spell effect_str data