Skip to content

Commit

Permalink
feat: Spell damage types case-insensitive, begin migration from `none…
Browse files Browse the repository at this point in the history
…` to `true` (#5916)

* Better damage type handling

none gets hit with a debug message nagging you but still works FOR NOW

* Fix some things

* style(autofix.ci): automated formatting

* Fix the other mods too

* Fix this test

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
RobbieNeko and autofix-ci[bot] authored Jan 12, 2025
1 parent 710d95f commit 5fe8458
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 27 deletions.
4 changes: 2 additions & 2 deletions data/mods/Aftershock/spells/hologram_spells.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"max_range": 20,
"difficulty": 1,
"extra_effects": [ { "id": "afs_holo_flare_explosion" } ],
"damage_type": "none"
"damage_type": "true"
},
{
"id": "afs_holo_flare_explosion",
Expand All @@ -72,7 +72,7 @@
"spell_class": "NONE",
"flags": [ "SILENT" ],
"base_casting_time": 0,
"damage_type": "none",
"damage_type": "true",
"difficulty": 1
},
{
Expand Down
2 changes: 1 addition & 1 deletion data/mods/Magical_Nights/Spells/animist.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"effect": "target_attack",
"base_casting_time": 85,
"base_energy_cost": 250,
"damage_type": "none",
"damage_type": "true",
"spell_class": "ANIMIST",
"difficulty": 8,
"max_level": 22,
Expand Down
2 changes: 1 addition & 1 deletion data/mods/Magical_Nights/Spells/classless.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"base_energy_cost": 150,
"energy_source": "MANA",
"difficulty": 3,
"damage_type": "none"
"damage_type": "true"
},
{
"id": "ethereal_grasp",
Expand Down
8 changes: 4 additions & 4 deletions data/mods/Magical_Nights/Spells/magus.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"flags": [ "SOMATIC", "NO_LEGS", "SILENT" ],
"min_damage": 10,
"damage_increment": 1.5,
"damage_type": "none",
"damage_type": "true",
"max_damage": 39,
"min_range": 13,
"range_increment": 0.8,
Expand Down Expand Up @@ -84,7 +84,7 @@
"min_damage": 21,
"max_damage": 111,
"damage_increment": 3,
"damage_type": "none",
"damage_type": "true",
"min_aoe": 3,
"max_aoe": 7,
"aoe_increment": 0.25,
Expand All @@ -109,7 +109,7 @@
"min_damage": 57,
"max_damage": 217,
"damage_increment": 5,
"damage_type": "none",
"damage_type": "true",
"min_range": 17,
"max_range": 57,
"range_increment": 1.5
Expand Down Expand Up @@ -150,7 +150,7 @@
"min_damage": 18,
"max_damage": 108,
"damage_increment": 3,
"damage_type": "none",
"damage_type": "true",
"min_aoe": 1,
"max_aoe": 1,
"min_range": 12,
Expand Down
2 changes: 1 addition & 1 deletion data/mods/Magical_Nights/Spells/monsterspells.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
"flags": [ "SOMATIC", "NO_LEGS", "SILENT" ],
"min_damage": 10,
"damage_increment": 2,
"damage_type": "none",
"damage_type": "true",
"max_damage": 50,
"min_range": 5,
"base_energy_cost": 50,
Expand Down
2 changes: 1 addition & 1 deletion data/mods/TEST_DATA/magic.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Pew, Pew",
"description": "You aim your finger at your opponent and make 'Pew, pew' sounds.",
"effect": "target_attack",
"damage_type": "none",
"damage_type": "true",
"valid_targets": [ "hostile" ],
"flags": [ "VERBAL", "SOMATIC", "NO_LEGS" ],
"max_level": 10,
Expand Down
6 changes: 4 additions & 2 deletions doc/src/content/docs/en/mod/json/reference/creatures/magic.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,19 @@ experience you need to get to a level is below:
valid target within range instead of the caster choosing the target. This also affects
extra_effects.

##### For Spells that have an attack type, these are the available damage types:
##### For Spells that have an attack type, these are the available damage types (case-insensitive):

- `fire`
- `acid`
- `bash`
- `bullet`
- `bio` - internal damage such as poison
- `cold`
- `cut`
- `electric`
- `stab`
- `none` - this damage type goes through armor altogether. it is the default.
- `true` - this damage type goes through armor altogether, and thus is very powerful. It is the
default damage type when unspecified.

#### Spells that level up

Expand Down
34 changes: 20 additions & 14 deletions src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,37 @@ static energy_type energy_source_from_string( const std::string &str )
}
}

static damage_type damage_type_from_string( const std::string &str )
static damage_type damage_type_from_string( std::string &str )
{
if( str == "fire" ) {
// Uppercase the string so that case on the input doesn't matter
std::transform( str.begin(), str.end(), str.begin(), ::toupper );
if( str == "FIRE" ) {
return DT_HEAT;
} else if( str == "acid" ) {
} else if( str == "ACID" ) {
return DT_ACID;
} else if( str == "bash" ) {
} else if( str == "BASH" ) {
return DT_BASH;
} else if( str == "bio" ) {
} else if( str == "BIO" ) {
return DT_BIOLOGICAL;
} else if( str == "cold" ) {
} else if( str == "COLD" ) {
return DT_COLD;
} else if( str == "cut" ) {
} else if( str == "CUT" ) {
return DT_CUT;
} else if( str == "bullet" ) {
} else if( str == "BULLET" ) {
return DT_BULLET;
} else if( str == "electric" ) {
} else if( str == "ELECTRIC" ) {
return DT_ELECTRIC;
} else if( str == "stab" ) {
} else if( str == "STAB" ) {
return DT_STAB;
} else if( str == "none" || str == "NONE" ) {
} else if( str == "TRUE" ) {
return DT_TRUE;
} else {
debugmsg( _( "ERROR: Invalid damage type string. Defaulting to none" ) );
} else if( str == "NONE" ) {
debugmsg( _( "ERROR: 'None' damage is not not valid and obsoleted for spells! Please switch to 'True' instead" ) );
return DT_TRUE;
} else {
// Bash is much less problematic than defaulting to True damage, bypassing any and all armor, like it did previously
debugmsg( _( "ERROR: Invalid damage type string. Defaulting to bash" ) );
return DT_BASH;
}
}

Expand Down Expand Up @@ -317,7 +323,7 @@ void spell_type::load( const JsonObject &jo, const std::string & )
spell_class = trait_id( temp_string );
optional( jo, was_loaded, "energy_source", temp_string, "NONE" );
energy_source = energy_source_from_string( temp_string );
optional( jo, was_loaded, "damage_type", temp_string, "NONE" );
optional( jo, was_loaded, "damage_type", temp_string, "TRUE" );
dmg_type = damage_type_from_string( temp_string );
optional( jo, was_loaded, "difficulty", difficulty, 0 );
optional( jo, was_loaded, "max_level", max_level, 0 );
Expand Down
2 changes: 1 addition & 1 deletion tests/magic_spell_effect_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST_CASE( "line_attack", "[magic]" )
" \"name\": { \"str\": \"Test Line Spell\" },\n"
" \"description\": \"Spews a line of magic\",\n"
" \"valid_targets\": [ \"ground\" ],\n"
" \"damage_type\": \"none\",\n"
" \"damage_type\": \"true\",\n"
" \"min_range\": 5,\n"
" \"max_range\": 5,\n"
" \"effect\": \"line_attack\",\n"
Expand Down

0 comments on commit 5fe8458

Please sign in to comment.