Skip to content

Commit

Permalink
add damage spellcast adjustment (#76064)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuardianDll authored Sep 1, 2024
1 parent f8b921d commit 64437b7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ _some functions support array arguments or kwargs, denoted with square brackets
| 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" ] }`|
| 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/>`damage` - Multiplier - alters the damage of the given spell(s). Negative damage result in healing.<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" ] }`|
| value_or(`v`,`d`/`v`) ||| g | Return value of variable if defined, otherwise the provided value<br/><br/> Example:<br/>`"condition": { "math": [ "u_blorg", "=", "value_or( fancy_var, 15 )" ] }`|
| time(`s`/`v`) ||| N/A<br/>(global) | Return a numeric value (in turns) for a time period string (see [Units](JSON_INFO.md#units)).<br/><br/>Special Values:<br/>`now` - returns duration since turn zero<br/>`cataclysm` - returns duration between cataclysm and turn zero<br/><br/>`time('now')` can serve as an assignment target to change current turn.<br/><br/>Optional kwargs:<br/> `unit`: specify return unit. Assumes `turns` if unspecified or empty.<br/><br/>Example:<br/>`{ "math": [ "time('now') - u_timer_caravan_RandEnc", ">", "time('1 h')" ] }`|
| time_since(`v`)<br/>time_since('cataclysm')<br/>time_since('midnight') ||| N/A<br/>(global) | Convenience function that returns a numeric value (in turns) for the time period since time point stored in variable.<br/><br/>Special values:<br/>`cataclysm` - return time since start of cataclysm<br/>`midnight` - return time since midnight<br/>`noon` - when the ingame clock reads 12:00<br/><br/>Optional kwargs:<br/> `unit`: specify return unit. Assumes `turns` if unspecified or empty.<br/><br/>Returns -1 if the argument is an undefined variable<br/><br/>Example:<br/>`{ "math": [ "time_since(u_timer_caravan_RandEnc)", ">", "time('1 h')" ] }`<br/>`{ "math": [ "time_since('cataclysm', 'unit':'years') > 1" ] }`|
Expand Down
11 changes: 8 additions & 3 deletions src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,15 @@ int spell::damage( const Creature &caster ) const
if( has_flag( spell_flag::RANDOM_DAMAGE ) ) {
return rng( std::min( leveled_damage, static_cast<int>( type->max_damage.evaluate( d ) ) ),
std::max( leveled_damage,
static_cast<int>( type->max_damage.evaluate( d ) ) ) );
static_cast<int>( type->max_damage.evaluate( d ) ) ) ) * temp_damage_multiplyer;
} else {
if( type->min_damage.evaluate( d ) >= 0 ||
type->max_damage.evaluate( d ) >= type->min_damage.evaluate( d ) ) {
return std::min( leveled_damage, static_cast<int>( type->max_damage.evaluate( d ) ) );
return std::min( leveled_damage,
static_cast<int>( type->max_damage.evaluate( d ) ) ) * temp_damage_multiplyer;
} else { // if it's negative, min and max work differently
return std::max( leveled_damage, static_cast<int>( type->max_damage.evaluate( d ) ) );
return std::max( leveled_damage,
static_cast<int>( type->max_damage.evaluate( d ) ) ) * temp_damage_multiplyer;
}
}
}
Expand Down Expand Up @@ -1641,6 +1643,8 @@ void spell::set_temp_adjustment( const std::string &target_property, float adjus
temp_level_adjustment += adjustment;
} else if( target_property == "casting_time" ) {
temp_cast_time_multiplyer += adjustment;
} else if( target_property == "damage" ) {
temp_damage_multiplyer += adjustment;
} else if( target_property == "cost" ) {
temp_spell_cost_multiplyer += adjustment;
} else if( target_property == "aoe" ) {
Expand All @@ -1664,6 +1668,7 @@ void spell::set_temp_adjustment( const std::string &target_property, float adjus
void spell::clear_temp_adjustments()
{
temp_level_adjustment = 0;
temp_damage_multiplyer = 1;
temp_cast_time_multiplyer = 1;
temp_spell_cost_multiplyer = 1;
temp_aoe_multiplyer = 1;
Expand Down
1 change: 1 addition & 0 deletions src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ class spell

// Temporary adjustments caused by EoC's
int temp_level_adjustment = 0; // NOLINT(cata-serialize)
float temp_damage_multiplyer = 1; // NOLINT(cata-serialize)
float temp_cast_time_multiplyer = 1; // NOLINT(cata-serialize)
float temp_spell_cost_multiplyer = 1; // NOLINT(cata-serialize)
float temp_aoe_multiplyer = 1; // NOLINT(cata-serialize)
Expand Down

0 comments on commit 64437b7

Please sign in to comment.