Skip to content

Add math function that return the enchantment value #81691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/JSON/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ _some functions support array arguments or kwargs, denoted with square brackets
| 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" ] }`|
| 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')" ] }`|
| 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" ] }`
| 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')" ] }`|

#### List of Character and item aspects
These can be read or written to with `val()`.
Expand Down
13 changes: 13 additions & 0 deletions src/math_parser_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,18 @@ double proficiency_eval( const_dialogue const &d, char scope, std::vector<diag_v
}
}

double enchantment_eval( const_dialogue const &d, char scope, std::vector<diag_value> const &params,
diag_kwargs const &/* kwargs */ )
{
const std::optional<enchant_vals::mod> mod_val = io::string_to_enum_optional<enchant_vals::mod>
( params[0].str( d ) );
if( mod_val.has_value() ) {
return d.const_actor( is_beta( scope ) )->enchantment_value( mod_val.value() );
} else {
throw math::runtime_error( "Incorrect enchantment value id" );
}
}

void proficiency_ass( double val, dialogue &d, char scope, std::vector<diag_value> const &params,
diag_kwargs const &kwargs )
{
Expand Down Expand Up @@ -1698,6 +1710,7 @@ std::map<std::string_view, dialogue_func> const dialogue_funcs{
{ "moon_phase", { "g", 0, moon_phase_eval } },
{ "num_input", { "g", 2, num_input_eval } },
{ "pain", { "un", 0, pain_eval, pain_ass, { "type" } } },
{ "enchantment", { "un", 1, enchantment_eval } },
{ "school_level", { "un", 1, school_level_eval } },
{ "school_level_adjustment", { "un", 1, school_level_adjustment_eval, school_level_adjustment_ass } },
{ "spellcasting_adjustment", { "u", 1, {}, spellcasting_adjustment_ass, { "mod", "school", "spell", "flag_whitelist", "flag_blacklist" } } },
Expand Down
3 changes: 3 additions & 0 deletions src/talker.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ class const_talker
virtual bool knows_spell( const spell_id & ) const {
return false;
}
virtual double enchantment_value( const enchant_vals::mod ) const {
return 0.0;
}
virtual bool knows_proficiency( const proficiency_id & ) const {
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions src/talker_character.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <algorithm>

Check failure on line 1 in src/talker_character.cpp

View workflow job for this annotation

GitHub Actions / iwyu

add '#include "magic_enchantment.h"' (for enchant_cache)
#include <bitset>
#include <cmath>
#include <cstddef>
Expand Down Expand Up @@ -394,6 +394,14 @@
return me_chr_const->has_max_power();
}

double talker_character_const::enchantment_value( const enchant_vals::mod mod ) const
{
double value;
value = me_chr_const->enchantment_cache->get_value_add( mod );
value *= 1.0 + me_chr_const->enchantment_cache->get_value_multiply( mod );
return value;
}

void talker_character::set_power_cur( units::energy value )
{
me_chr->set_power_level( value );
Expand Down
1 change: 1 addition & 0 deletions src/talker_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
bool crossed_threshold() const override;
int num_bionics() const override;
bool has_max_power() const override;
double enchantment_value( const enchant_vals::mod mod ) const override;

Check failure on line 92 in src/talker_character.h

View workflow job for this annotation

GitHub Actions / run-clang-tidy (indirectly-changed-src)

parameter 'mod' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]

Check failure on line 92 in src/talker_character.h

View workflow job for this annotation

GitHub Actions / run-clang-tidy (indirectly-changed-src)

parameter 'mod' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]

Check failure on line 92 in src/talker_character.h

View workflow job for this annotation

GitHub Actions / run-clang-tidy (indirectly-changed-src)

parameter 'mod' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]

Check failure on line 92 in src/talker_character.h

View workflow job for this annotation

GitHub Actions / run-clang-tidy (indirectly-changed-src)

parameter 'mod' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]

Check failure on line 92 in src/talker_character.h

View workflow job for this annotation

GitHub Actions / run-clang-tidy (indirectly-changed-src)

parameter 'mod' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]

Check failure on line 92 in src/talker_character.h

View workflow job for this annotation

GitHub Actions / run-clang-tidy (directly-changed)

parameter 'mod' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]
bool has_bionic( const bionic_id &bionics_id ) const override;
bool knows_spell( const spell_id &sp ) const override;
int get_skill_level( const skill_id & ) const override;
Expand Down
Loading