From 6fd29f06273454f3ef1cca833c780cb9d94b457c Mon Sep 17 00:00:00 2001 From: newfrenchy83 Date: Tue, 31 Oct 2023 14:54:19 +0100 Subject: [PATCH] add tests the events-test_filter_attack_type test verify what [filter_attack]type= can check type of damage same if modified by [damage]replacement/alternative_type. The second verify [filter_weapon]type= called by a special(or leadership/resistance abilities) can ckeck type without modofication by [damage] for don't risk infinite recursion. --- .../events-test_filter_attack_type.cfg | 91 +++++++++++++++++++ .../AbilitiesWML/special_damage_type.cfg | 64 ++++++++++--- wml_test_schedule | 2 + 3 files changed, 142 insertions(+), 15 deletions(-) create mode 100644 data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filter_attack_type.cfg diff --git a/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filter_attack_type.cfg b/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filter_attack_type.cfg new file mode 100644 index 0000000000000..4da79222ef806 --- /dev/null +++ b/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filter_attack_type.cfg @@ -0,0 +1,91 @@ +# wmllint: no translatables + +##### +# API(s) being tested: [event][filter_attack]type= +## +# Actions: +# Give Alice an ability that adds a damage special with addition of arcnae type to all of his weapons. +# Define events that use filter_attack matching Alice's arcane type. +# Have Alice attack Bob. +## +# Expected end state: +# An event triggers when Alice attacks during side 1's turn because type=arcane detected. +##### +{GENERIC_UNIT_TEST event_test_filter_attack_type ( + [event] + name=start + [object] + silent=yes + [effect] + apply_to=new_ability + [abilities] + [damage] + id=test_arcane_damage + alternative_type=arcane + [/damage] + [/abilities] + [/effect] + [filter] + id=alice + [/filter] + [/object] + [modify_unit] + [filter] + [/filter] + # Make sure they don't die during the attacks + [status] + invulnerable=yes + [/status] + [/modify_unit] + {VARIABLE triggers 0} + [/event] + [event] + name=side 1 turn 1 + [do_command] + [move] + x=7,13 + y=3,4 + [/move] + [attack] + [source] + x,y=13,4 + [/source] + [destination] + x,y=13,3 + [/destination] + [/attack] + [/do_command] + [end_turn][/end_turn] + [/event] + + [event] + name=side 2 turn + [do_command] + [attack] + [source] + x,y=13,3 + [/source] + [destination] + x,y=13,4 + [/destination] + [/attack] + [/do_command] + [end_turn][/end_turn] + [/event] + + # Event when Alice attacks + [event] + name=attack + first_time_only=no + [filter_attack] + type=arcane + [/filter_attack] + {ASSERT ({VARIABLE_CONDITIONAL side_number equals 1})} + {ASSERT ({VARIABLE_CONDITIONAL triggers equals 0})} + {VARIABLE_OP triggers add 1} + [/event] + [event] + name=turn 2 + {RETURN ({VARIABLE_CONDITIONAL triggers equals 1})} + [/event] +)} diff --git a/data/test/scenarios/wml_tests/UnitsWML/AbilitiesWML/special_damage_type.cfg b/data/test/scenarios/wml_tests/UnitsWML/AbilitiesWML/special_damage_type.cfg index 1c5b2852446a1..a47382c021c3e 100644 --- a/data/test/scenarios/wml_tests/UnitsWML/AbilitiesWML/special_damage_type.cfg +++ b/data/test/scenarios/wml_tests/UnitsWML/AbilitiesWML/special_damage_type.cfg @@ -1,20 +1,15 @@ #textdomain wesnoth-test -##### -# API(s) being tested: [damage]replacement_type= -## -# Actions: -# Give both Alice and Bob 100% chance to hit. -# Give Bob one [damage] with replacement_type=fire and two [damage] with replacement_type=cold -# change resistance of Bob to arcane to 50% and fire to -100%. -# Give Alice one [damage] with replacement_type=cold, two [damage] with replacement_type=arcane and three with replacement_type=fire -# and change Alice resistance to cold to -100% and fire to 50%. -# Move Alice next to Bob, and have Alice attack Bob. -## -# Expected end state: -# Alice attack with fire and Bob use cold. -##### -{GENERIC_UNIT_TEST "damage_type_test" ( +# macro used for two tests below +#define FILTER_TYPE_BLADE + [filter_self] + [filter_weapon] + type=blade + [/filter_weapon] + [/filter_self] +#enddef + +#define DAMAGE_TYPE_TEST FILTER_WEAPON [event] name=start [modify_unit] @@ -46,12 +41,15 @@ [/damage] [damage] replacement_type=fire + {FILTER_WEAPON} [/damage] [damage] replacement_type=cold + {FILTER_WEAPON} [/damage] [damage] replacement_type=cold + {FILTER_WEAPON} [/damage] [chance_to_hit] value=100 @@ -166,6 +164,42 @@ {ASSERT ({VARIABLE_CONDITIONAL b.hitpoints equals 76})} {SUCCEED} [/event] +#enddef + +##### +# API(s) being tested: [damage]replacement_type= +## +# Actions: +# Give both Alice and Bob 100% chance to hit. +# Give Bob one [damage] with replacement_type=fire and two [damage] with replacement_type=cold +# change resistance of Bob to arcane to 50% and fire to -100%. +# Give Alice one [damage] with replacement_type=cold, two [damage] with replacement_type=arcane and three with replacement_type=fire +# and change Alice resistance to cold to -100% and fire to 50%. +# Move Alice next to Bob, and have Alice attack Bob. +## +# Expected end state: +# Alice attack with fire and Bob use cold. +##### +{GENERIC_UNIT_TEST "damage_type_test" ( + {DAMAGE_TYPE_TEST ()} +)} + +##### +# API(s) being tested: [damage]replacement_type=[filter_self][filter_weapon]type=blade +## +# Actions: +# Give both Alice and Bob 100% chance to hit. +# Give Bob one [damage] with replacement_type=fire and two [damage] with replacement_type=cold and filter by type=blade +# change resistance of Bob to arcane to 50% and fire to -100%. +# Give Alice one [damage] with replacement_type=cold, two [damage] with replacement_type=arcane and three with replacement_type=fire +# and change Alice resistance to cold to -100% and fire to 50%. +# Move Alice next to Bob, and have Alice attack Bob. +## +# Expected end state: +# Alice attack with fire; and Bob use cold because Bob [damage] filter must check type=blade and not the replacement type, that who cause infinite recursion. +##### +{GENERIC_UNIT_TEST "damage_type_with_filter_test" ( + {DAMAGE_TYPE_TEST {FILTER_TYPE_BLADE}} )} ##### diff --git a/wml_test_schedule b/wml_test_schedule index 4d6e3fdd9c623..02aeadc4dc3bf 100644 --- a/wml_test_schedule +++ b/wml_test_schedule @@ -155,6 +155,7 @@ 0 test_ability_id_not_active 0 event_test_filter_attack 0 event_test_filter_attack_no_defense +0 event_test_filter_attack_type 0 event_test_filter_attack_specials 0 event_test_filter_attack_on_moveto 0 event_test_filter_attack_opponent_weapon_condition @@ -335,6 +336,7 @@ 0 test_remove_ability_by_filter 0 test_overwrite_specials_filter 0 damage_type_test +0 damage_type_with_filter_test 0 damage_secondary_type_test 0 swarms_filter_student_by_type 0 swarms_effects_not_checkable