Skip to content

Commit

Permalink
Jsonize spell skills (#37368)
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT authored and ZhilkinSerg committed Mar 17, 2020
1 parent 1ce78cd commit b9d831f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
15 changes: 11 additions & 4 deletions src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<int>( 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()
Expand Down
3 changes: 3 additions & 0 deletions src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b9d831f

Please sign in to comment.