Skip to content

Commit

Permalink
math effect to sum all spells in school (#73394)
Browse files Browse the repository at this point in the history
* math effect to sum all spells in school

* add virtual int

* Update src/talker.h

* more clang fixes

* more clang fixes
  • Loading branch information
GuardianDll authored May 2, 2024
1 parent f28460d commit 58e3513
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,7 @@ _some functions support array arguments or kwargs, denoted with square brackets
| spell_exp(`s`/`v`) ||| u, n | Return or set spell xp<br/> Example:<br/>`"condition": { "math": [ "u_spell_exp('SPELL_ID')", ">=", "5"] }`|
| spell_exp_for_level(`d`/`v`) ||| g | Return the amount of XP necessary for a spell level. <br/> Example:<br/>`"math": [ "spell_exp_for_level(u_spell_level('SPELL_ID')) * 5"] }`|
| spell_count() ||| u, n | Return number of spells the character knows.<br/><br/> Optional kwargs:<br/>`school`: `s/v` - return number of spells known of that school.<br/><br/> Example:<br/>`"condition": { "math": [ "u_spell_count('school': 'MAGUS')", ">=", "10"] }`|
| spell_level_sum() ||| u, n | Return sum of all spell levels character has; having one spell of class A with level 5, and another with lvl 10 would return 15. <br/><br/> Optional kwargs:<br/>`school`: `s/v` - return number of spells known of that school. Omitting return sum of all spells character has, no matter of the class.<br/>`level`: `d/v` - count only spells that are higher or equal this field. Default 0.<br/><br/> Example:<br/>`{ "math": [ "test_var1", "=", "u_spell_level_sum()" ] }`<br/>`{ "math": [ "test_var2", "=", "u_spell_level_sum('school': 'MAGUS')" ] }`<br/>`{ "math": [ "test_var3", "=", "u_spell_level_sum('school': 'MAGUS', 'level': '10')" ] }`|
| spell_level(`s`/`v`) ||| u, n | Return or set level of a given spell. -1 means the spell is not known when read and that the spell should be forgotten if written.<br/>Argument is spell ID. If `"null"` is given, return the highest level of spells the character knows (read only).<br/> Example:<br/>`"condition": { "math": [ "u_spell_level('SPELL_ID')", "==", "-1"] }`|
| spell_level_adjustment(`s`/`v`) ||| u, n | Return or set temporary caster level adjustment. Only useable by EoCs that trigger on the event `opens_spellbook`. Old values will be reset to 0 before the event triggers. To avoid overwriting values from other EoCs, it is recommended to adjust the values here with `+=` or `-=` instead of setting it to an absolute value.<br/>Argument is spell ID. If `"null"` is given, adjust all spell level.<br/><br/>Example:<br/>`{ "math": [ "u_spell_level_adjustment('SPELL_ID')", "+=", "3"] }`|
| spellcasting_adjustment(`s`/`v`) | ❌ | ✅ | u | Temporary alters a property of spellcasting. Only useable by EoCs that trigger on the event `opens_spellbook`. Old values will be reset to default values before the event triggers. Multipliers have a default value of 1, while adjustments have a default value of 0. Assignment functions as an adjustment to the default value by the value assigned. So a `=` functions as you would expect a `+=` to function. Reading these values are not possible, and therefore using `+=` is not possible. <br/><br/>Possible argument values: <br/>`caster_level` - Adjustment - alters the caster level of the given spell(s). Works much like spell_level_adjustment, but will not be readable by `math` functions.<br/>`casting_time` - Multiplier - alters the casting time of the given spell(s).<br/>`cost` - Multiplier - alters the cost of the given spells. Note that this does not change what items may be consumed by the spell(s).<br/>`aoe` - Multiplier - alters the area of effect of the spell(s).<br/>`range` - Multiplier - alters the range of the spell(s).<br/>`duration` - Multiplier - alters the duration of the spell(s).<br/>`difficulty` - Adjustment - alters the difficulty of the spell(s), thus altering the probability of failing spellcasting.<br/>`somatic_difficulty` - Multiplier - alters how much encumbrance affects spellcasting time and difficulty. If set to 0, it will also remove the need to have your hands free while casting. Note that as a multiplier, it starts of at 1, and setting the value actually adjusts it. So setting the valute to -1 will result in a final value of 0. Alternatively, setting it to -0,5 twice would also do the trick.<br/>`sound` - Multiplier - alters the loudness and how much mouth encumbrance affects the spell(s).<br/>`concentration` - Multiplier - alters how much focus alters the difficulty of the spell(s).<br/><br/> Optional kwargs:<br/>`flag_blacklist`: `s/v` and<br/>`flag_whitelist`: `s/v` - Only applies the modifier to spells that matches the blacklist and/or whitelist<br/>`mod`: `s/v`, `school`: `s/v`, `spell`: `s/v` - Only one of these can be applied. Limits what spells will be affected. If none are specified, the modification will apply to all spells (whitelist and blacklist still applies separately).<br/><br/>Example:<br/>`{ "math": [ "u_spellcasting_adjustment('casting_time', 'mod': 'magiclysm', 'flag_blacklist': 'CONSUMES_RUNES' )", "=", "-0.95" ] }`|
Expand Down
23 changes: 23 additions & 0 deletions src/math_parser_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,28 @@ std::function<double( dialogue & )> spell_count_eval( char scope,
};
}

std::function<double( dialogue & )> spell_sum_eval( char scope,
std::vector<diag_value> const &/* params */, diag_kwargs const &kwargs )
{
diag_value school_value( std::string{} );
diag_value min_level( 0.0 );

if( kwargs.count( "school" ) != 0 ) {
school_value = *kwargs.at( "school" );
}

if( kwargs.count( "level" ) != 0 ) {
min_level = *kwargs.at( "level" );
}

return[beta = is_beta( scope ), school_value, min_level]( dialogue const & d ) {
std::string school_str = school_value.str( d );
int const min_spell_level = min_level.dbl( d );
const trait_id scid = school_str.empty() ? trait_id::NULL_ID() : trait_id( school_str );
return d.actor( beta )->get_spell_sum( scid, min_spell_level );
};
}

std::function<double( dialogue & )> spell_exp_eval( char scope,
std::vector<diag_value> const &params, diag_kwargs const &/* kwargs */ )
{
Expand Down Expand Up @@ -1529,6 +1551,7 @@ std::map<std::string_view, dialogue_func_eval> const dialogue_eval_f{
{ "skill", { "un", 1, skill_eval } },
{ "skill_exp", { "un", 1, skill_exp_eval } },
{ "spell_count", { "un", 0, spell_count_eval}},
{ "spell_level_sum", { "un", 0, spell_sum_eval}},
{ "spell_exp", { "un", 1, spell_exp_eval}},
{ "spell_exp_for_level", { "g", 1, spell_exp_for_level_eval}},
{ "spell_level", { "un", 1, spell_level_eval}},
Expand Down
3 changes: 3 additions & 0 deletions src/talker.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ class talker
virtual int get_spell_count( const trait_id & ) const {
return 0;
}
virtual int get_spell_sum( const trait_id &, int ) const {
return 0;
}
virtual void set_spell_level( const spell_id &, int ) {}
virtual void set_spell_exp( const spell_id &, int ) {}
virtual void set_skill_level( const skill_id &, int ) {}
Expand Down
13 changes: 13 additions & 0 deletions src/talker_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,19 @@ int talker_character_const::get_spell_count( const trait_id &school ) const
return count;
}

int talker_character_const::get_spell_sum( const trait_id &school, int min_level ) const
{
int count = 0;

for( const spell *sp : me_chr_const->magic->get_spells() ) {
if( school.is_null() || ( sp->spell_class() == school &&
sp->get_effective_level() >= min_level ) ) {
count = count + sp->get_effective_level() ;
}
}
return count;
}

void talker_character::set_spell_level( const spell_id &sp, int new_level )
{
me_chr->magic->set_spell_level( sp, new_level, me_chr );
Expand Down
1 change: 1 addition & 0 deletions src/talker_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class talker_character_const: public talker_cloner<talker_character_const>
int get_spell_exp( const spell_id & ) const override;
int get_highest_spell_level() const override;
int get_spell_count( const trait_id & ) const override;
int get_spell_sum( const trait_id &school, int min_level ) const override;
bool knows_proficiency( const proficiency_id &proficiency ) const override;
time_duration proficiency_practiced_time( const proficiency_id & ) const override;

Expand Down

0 comments on commit 58e3513

Please sign in to comment.