Skip to content

Commit

Permalink
condition: "spell_count" condition + documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dseguin committed Aug 30, 2023
1 parent c8c37e6 commit 02013ef
Show file tree
Hide file tree
Showing 5 changed files with 24 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 @@ -1289,6 +1289,7 @@ Example | Description
`"u_val": "spell_level"` | Level of a given spell. -1 means the spell is not known when read and that the spell should be forgotten if written. Optional params: `school` gives the highest level of spells known of that school (read only), `spell` reads or writes the level of the spell with matching spell id. If no parameter is provided, you will get the highest spell level of the spells you know (read only).
`"u_val": "spell_exp"` | Experience for a given spell. -1 means the spell is not known when read and that the spell should be forgotten if written. Required param: `spell` is the id of the spell in question.
`"u_val": "spell_level_adjustment"` | 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 reccomended to adjust the values here with `+=` or `-=` instead of setting it to an absolute value. When an NPC consider what spell to cast they will be considered the primary talker, so their values are manipulated with `u_val` the same way the player's values are. Optional params: `school` makes it only apply to a given school. `spell` makes it only apply to a given spell.
`"u_val": "spell_count"` | Number of spells that this character knows. Optional params: `school` returns only the number of spells of the specified spell class that the character knows. Read-only.
`"u_val": "proficiency"` | Deals with a proficiency. Required params: `proficiency_id` is the id of the proficiency dealt with. `format` determines how the proficiency will be interacted with. `"format": <int>` will read or write how much you have trained a proficiency out of <int>. So for exaple, if you write a 5 to a proficiency using `"format": 10`, you will set the proficiency to be trained to 50%. `"format": "percent"` reads or writes how many percen done the learning is. `"format": "permille"` does likewise for permille. `"format": "total_time_required"` gives you total time required to train a given proficiency (read only). `"format": "time_spent"` deals with total time spent. `"format": "time_left"` sets the remaining time instead. For most formats possible, If the resulting time is set to equal or more than the time required to learn the proficiency, you learn it. If you read it and it gives back the total time required, it means it is learnt. Setting the total time practiced to a negative value completely removes the proficiency from your known and practiced proficiencies. If you try to read time spent on a proficiency that is not in your proficiency list, you will get back 0 seconds.
`"distance": []` | Distance between two targets. Valid targets are: "u","npc" and an object with a variable name.<br/><br/>Example:<pre>"condition": { "compare_num": [<br/> { "distance": [ "u",{ "u_val": "stuck", "type": "ps", "context": "teleport" } ] },<br/> ">", { "const": 5 }<br/>] }</pre>
`"hour"` | Hours since midnight.
Expand Down
8 changes: 8 additions & 0 deletions src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,14 @@ std::function<double( dialogue & )> conditional_t::get_get_dbl( J const &jo )
return [is_npc, this_spell_id]( dialogue & d ) {
return d.actor( is_npc )->get_spell_exp( this_spell_id );
};
} else if( checked_value == "spell_count" ) {
trait_id school = trait_id::NULL_ID();
if( jo.has_member( "school" ) ) {
school = trait_id( jo.get_string( "school" ) );
}
return [is_npc, school]( dialogue & d ) {
return d.actor( is_npc )->get_spell_count( school );
};
} else if( checked_value == "proficiency" ) {
const std::string proficiency_name = jo.get_string( "proficiency_id" );
const proficiency_id the_proficiency_id( proficiency_name );
Expand Down
3 changes: 3 additions & 0 deletions src/talker.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ class talker
virtual int get_highest_spell_level() const {
return 0;
}
virtual int get_spell_count( const trait_id & ) 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
11 changes: 11 additions & 0 deletions src/talker_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@ int talker_character_const::get_spell_exp( const spell_id &spell_name ) const
return me_chr_const->magic->get_spell( spell_name ).xp();
}

int talker_character_const::get_spell_count( const trait_id &school ) const
{
int count = 0;
for( const spell *sp : me_chr_const->magic->get_spells() ) {
if( school.is_null() || sp->spell_class() == school ) {
count++;
}
}
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 @@ -82,6 +82,7 @@ class talker_character_const: public talker_cloner<talker_character_const>
int get_spell_level( const spell_id & ) const override;
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;
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 02013ef

Please sign in to comment.