Skip to content

Commit c4fac82

Browse files
committed
Add math function that return the enchantment value
1 parent 1f9af69 commit c4fac82

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

doc/JSON/NPCs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,7 @@ _some functions support array arguments or kwargs, denoted with square brackets
14041404
| calories() ||| u, n | Return amount of calories character has. If used on item, return amount of calories this item gives when consumed (not affected by enchantments or mutations). Optional kwargs:<br/>`format`: `s`/`v` - return the value in specific format. Can be `percent` (return percent to the healthy amount of calories, `100` being the target, bmi 25, or 110000 kcal) or `raw`. If now used, `raw` is used by default.<br/>`dont_affect_weariness`: `true`/`false` (default false) When assigning value, whether the gained/spent calories should be tracked by weariness.<br/><br/>Example:<br/>`"condition": { "math": [ "u_calories() < 0" ] }`<br/>`"condition": { "math": [ "u_calories('format': 'percent') > 0" ] }`<br/>`"condition": { "math": [ "u_calories() = 110000" ] }`|
14051405
| get_calories_daily() ||| g | Return amount of calories character consumed before, up to 30 days, in kcal. Calorie diary is something only character has, so it can't be used with NPCs. Optional kwargs:<br/>`day`: `d/v` - picks the date the value would be pulled from, from 0 to 30. Default 0, meaning amount of calories you consumed today.<br/>`type`: `s/v` - picks the data that would be pulled. Possible values are: `spent` - how much calories character spent in different activities throughout the day; `gained` - how much calories character ate that day; `ingested` - how much calories character processed that day; `total` - `gained` minus `spent`. Default is `total`;<br/><br/>Example:<br/>`"condition": { "math": [ "get_calories_daily() > 1000" ] }`<br/> `{ "math": [ "foo = get_calories_daily('type':'gained', 'day':'1')" ] }`|
14061406
| quality( `s` / `v` ) | ✅ | ❌ | u, n | Return the level of a specified item tool quality. Only usable on item talkers.<br/>Argument is the quality ID. Returns the lowest integer value if the item lacks the specified quality.<br/>Optional kwargs:<br/>`strict`: `true` / `false` (default false) When true the item must be empty to have the boiling quality.<br/><br/>Example<br/>`"condition: { "math": [ " u_quality('HACK') > 0 " ] }`<br/>`{ "math": [ "_cut_quality = u_quality('CUT') " ] }`<br/>`condition: { "math": [ " u_quality('BOIL', 'strict': true ) > 0" ] }`
1407+
| enchantment(`s`/`v`) ||| u, n | Return the result of the enchantment that you have, both `add` and `multiply` fields.<br/>Argument is enchantment id.<br/><br/>Example:<br/>`{ "math": [ "_x = u_enchantment('ARTIFACT_RESONANCE')" ] }`|
14071408

14081409
#### List of Character and item aspects
14091410
These can be read or written to with `val()`.

src/math_parser_diag.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,13 @@ double proficiency_eval( const_dialogue const &d, char scope, std::vector<diag_v
12871287
}
12881288
}
12891289

1290+
double enchantment_eval( const_dialogue const &d, char scope, std::vector<diag_value> const &params,
1291+
diag_kwargs const &/* kwargs */ )
1292+
{
1293+
const enchant_vals::mod mod_val = io::string_to_enum<enchant_vals::mod>( params[0].str( d ) );
1294+
return d.const_actor( is_beta( scope ) )->enchantment_value( mod_val );
1295+
}
1296+
12901297
void proficiency_ass( double val, dialogue &d, char scope, std::vector<diag_value> const &params,
12911298
diag_kwargs const &kwargs )
12921299
{
@@ -1698,6 +1705,7 @@ std::map<std::string_view, dialogue_func> const dialogue_funcs{
16981705
{ "moon_phase", { "g", 0, moon_phase_eval } },
16991706
{ "num_input", { "g", 2, num_input_eval } },
17001707
{ "pain", { "un", 0, pain_eval, pain_ass, { "type" } } },
1708+
{ "enchantment", { "un", 1, enchantment_eval } },
17011709
{ "school_level", { "un", 1, school_level_eval } },
17021710
{ "school_level_adjustment", { "un", 1, school_level_adjustment_eval, school_level_adjustment_ass } },
17031711
{ "spellcasting_adjustment", { "u", 1, {}, spellcasting_adjustment_ass, { "mod", "school", "spell", "flag_whitelist", "flag_blacklist" } } },

src/talker.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ class const_talker
261261
virtual bool knows_spell( const spell_id & ) const {
262262
return false;
263263
}
264+
virtual double enchantment_value( const enchant_vals::mod mod ) const {
265+
return 0.0;
266+
}
264267
virtual bool knows_proficiency( const proficiency_id & ) const {
265268
return false;
266269
}

src/talker_character.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ bool talker_character_const::has_max_power() const
394394
return me_chr_const->has_max_power();
395395
}
396396

397+
double talker_character_const::enchantment_value( const enchant_vals::mod mod ) const
398+
{
399+
double value;
400+
value = me_chr_const->enchantment_cache->get_value_add( mod );
401+
value *= 1.0 + me_chr_const->enchantment_cache->get_value_multiply( mod );
402+
return value;
403+
}
404+
397405
void talker_character::set_power_cur( units::energy value )
398406
{
399407
me_chr->set_power_level( value );

src/talker_character.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class talker_character_const: virtual public const_talker
8989
bool crossed_threshold() const override;
9090
int num_bionics() const override;
9191
bool has_max_power() const override;
92+
double enchantment_value( const enchant_vals::mod mod ) const override;
9293
bool has_bionic( const bionic_id &bionics_id ) const override;
9394
bool knows_spell( const spell_id &sp ) const override;
9495
int get_skill_level( const skill_id & ) const override;

0 commit comments

Comments
 (0)