From 5fe8458826c00b18720c12781f85baedd1a6ff78 Mon Sep 17 00:00:00 2001 From: RobbieNeko <30732426+RobbieNeko@users.noreply.github.com> Date: Sun, 12 Jan 2025 12:11:25 -0500 Subject: [PATCH] feat: Spell damage types case-insensitive, begin migration from `none` 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> --- .../Aftershock/spells/hologram_spells.json | 4 +-- data/mods/Magical_Nights/Spells/animist.json | 2 +- .../mods/Magical_Nights/Spells/classless.json | 2 +- data/mods/Magical_Nights/Spells/magus.json | 8 ++--- .../Magical_Nights/Spells/monsterspells.json | 2 +- data/mods/TEST_DATA/magic.json | 2 +- .../en/mod/json/reference/creatures/magic.md | 6 ++-- src/magic.cpp | 34 +++++++++++-------- tests/magic_spell_effect_test.cpp | 2 +- 9 files changed, 35 insertions(+), 27 deletions(-) diff --git a/data/mods/Aftershock/spells/hologram_spells.json b/data/mods/Aftershock/spells/hologram_spells.json index 7113d210b3b9..b2a3e57987b6 100644 --- a/data/mods/Aftershock/spells/hologram_spells.json +++ b/data/mods/Aftershock/spells/hologram_spells.json @@ -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", @@ -72,7 +72,7 @@ "spell_class": "NONE", "flags": [ "SILENT" ], "base_casting_time": 0, - "damage_type": "none", + "damage_type": "true", "difficulty": 1 }, { diff --git a/data/mods/Magical_Nights/Spells/animist.json b/data/mods/Magical_Nights/Spells/animist.json index bf1b35d0f069..81f4c7c44455 100644 --- a/data/mods/Magical_Nights/Spells/animist.json +++ b/data/mods/Magical_Nights/Spells/animist.json @@ -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, diff --git a/data/mods/Magical_Nights/Spells/classless.json b/data/mods/Magical_Nights/Spells/classless.json index eaaf57b6a79f..e03d4a84c468 100644 --- a/data/mods/Magical_Nights/Spells/classless.json +++ b/data/mods/Magical_Nights/Spells/classless.json @@ -127,7 +127,7 @@ "base_energy_cost": 150, "energy_source": "MANA", "difficulty": 3, - "damage_type": "none" + "damage_type": "true" }, { "id": "ethereal_grasp", diff --git a/data/mods/Magical_Nights/Spells/magus.json b/data/mods/Magical_Nights/Spells/magus.json index 98ece8225988..99b6b972c9e5 100644 --- a/data/mods/Magical_Nights/Spells/magus.json +++ b/data/mods/Magical_Nights/Spells/magus.json @@ -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, @@ -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, @@ -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 @@ -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, diff --git a/data/mods/Magical_Nights/Spells/monsterspells.json b/data/mods/Magical_Nights/Spells/monsterspells.json index d263bff7fb3c..8252897aee02 100644 --- a/data/mods/Magical_Nights/Spells/monsterspells.json +++ b/data/mods/Magical_Nights/Spells/monsterspells.json @@ -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, diff --git a/data/mods/TEST_DATA/magic.json b/data/mods/TEST_DATA/magic.json index c0f307f88b4f..f062049eafd9 100644 --- a/data/mods/TEST_DATA/magic.json +++ b/data/mods/TEST_DATA/magic.json @@ -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, diff --git a/doc/src/content/docs/en/mod/json/reference/creatures/magic.md b/doc/src/content/docs/en/mod/json/reference/creatures/magic.md index 659ffc2191fa..7dd30d728edf 100644 --- a/doc/src/content/docs/en/mod/json/reference/creatures/magic.md +++ b/doc/src/content/docs/en/mod/json/reference/creatures/magic.md @@ -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 diff --git a/src/magic.cpp b/src/magic.cpp index 9be46ac7fdf4..054354542152 100644 --- a/src/magic.cpp +++ b/src/magic.cpp @@ -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; } } @@ -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 ); diff --git a/tests/magic_spell_effect_test.cpp b/tests/magic_spell_effect_test.cpp index 43f528c6a51c..fa2f84653e62 100644 --- a/tests/magic_spell_effect_test.cpp +++ b/tests/magic_spell_effect_test.cpp @@ -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"