From fcff06841e2940d584f8ce3092d47983538941ae Mon Sep 17 00:00:00 2001 From: Tyler Nutsathitya Date: Sat, 13 Jan 2024 11:20:55 -0800 Subject: [PATCH] Issue-26: Update test_health.gd to use the cards, fix a bug with Damage All card by adding EffectDamageAll.gd (#41) * Issue-26: Update test_health.gd to use the cards, fix a big with Damage All card by adding EffectDamageAll.gd * Issue-26: Update test_health.gd with array of enemies and comments * Issue-26: Resolve Default Cards in Test Scene * Issue-26: Update comment on test_health.gd --- #Scenes/TestingScene.tscn | 35 +------------- Cards/Effects/EffectDamageAll.gd | 9 ++++ Cards/Resource/Card_DamageAll.tres | 14 +++++- Tests/test_health.gd | 74 ++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 35 deletions(-) create mode 100644 Cards/Effects/EffectDamageAll.gd diff --git a/#Scenes/TestingScene.tscn b/#Scenes/TestingScene.tscn index 914f050e..ba679f4e 100644 --- a/#Scenes/TestingScene.tscn +++ b/#Scenes/TestingScene.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=22 format=3 uid="uid://b60uabg68ra1l"] +[gd_scene load_steps=19 format=3 uid="uid://b60uabg68ra1l"] [ext_resource type="PackedScene" uid="uid://clmg3l3n28x38" path="res://Entity/Player/Player.tscn" id="3_4psp7"] [ext_resource type="PackedScene" uid="uid://dpjfy4pv0vxst" path="res://Cards/CardContainer.tscn" id="3_e7sws"] @@ -11,7 +11,6 @@ [ext_resource type="Resource" uid="uid://ctx8jsvac84so" path="res://Cards/Resource/Card_Poison.tres" id="8_x6t2k"] [ext_resource type="Resource" uid="uid://d12g33rc6c3u5" path="res://Cards/Resource/Card_Heal.tres" id="9_ojxic"] [ext_resource type="Script" path="res://UI/DiscardPileUISetter.gd" id="10_pqly7"] -[ext_resource type="Script" path="res://Cards/Card_DamageHealth.gd" id="10_qowiy"] [ext_resource type="Resource" uid="uid://3s4aet1ciesh" path="res://Cards/Resource/Card_damage_and_poison.tres" id="10_w0xgm"] [ext_resource type="Resource" uid="uid://bsrdu33ukb1ym" path="res://Cards/Resource/Card_EnemyAttack.tres" id="11_3k5t2"] [ext_resource type="Texture2D" uid="uid://caemucaya30wh" path="res://Cards/draw_pile.png" id="11_pw70x"] @@ -20,36 +19,6 @@ [ext_resource type="Texture2D" uid="uid://hqkt8t1v2f5h" path="res://Cards/deck_pile.png" id="18_b54hn"] [ext_resource type="Script" path="res://UI/DeckPileUISetter.gd" id="19_ucc6f"] -[sub_resource type="Resource" id="Resource_82ci8"] -script = ExtResource("10_qowiy") -damage_to_apply_to_target = 0.0 -damage_to_apply_to_caster = 0.0 -status_to_apply_to_target = Array[Resource("res://Status/StatusBase.gd")]([]) -status_to_apply_to_caster = Array[Resource("res://Status/StatusBase.gd")]([]) -affect_all_targets = false -affect_all_casters = false -amount_of_cards_to_draw = 0 -amount_of_cards_to_discard = 0 -application_type = 1 -card_title = "NULL" -card_description = "NULL" -card_effects_data = Array[Resource("res://Cards/Effects/EffectData.gd")]([]) - -[sub_resource type="Resource" id="Resource_bjuo7"] -script = ExtResource("10_qowiy") -damage_to_apply_to_target = 0.0 -damage_to_apply_to_caster = 0.0 -status_to_apply_to_target = Array[Resource("res://Status/StatusBase.gd")]([]) -status_to_apply_to_caster = Array[Resource("res://Status/StatusBase.gd")]([]) -affect_all_targets = false -affect_all_casters = false -amount_of_cards_to_draw = 0 -amount_of_cards_to_discard = 0 -application_type = 1 -card_title = "NULL" -card_description = "NULL" -card_effects_data = Array[Resource("res://Cards/Effects/EffectData.gd")]([]) - [node name="TestingScene" type="Node2D"] metadata/_edit_vertical_guides_ = [1216.0] @@ -78,7 +47,7 @@ anchor_right = 0.5 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 0 -default_deck = Array[Resource("res://Cards/CardBase.gd")]([ExtResource("4_wvn3v"), ExtResource("5_j1lqt"), ExtResource("6_4124l"), ExtResource("7_smkw8"), ExtResource("9_ojxic"), ExtResource("8_x6t2k"), ExtResource("10_w0xgm"), ExtResource("11_3k5t2"), ExtResource("4_wvn3v"), ExtResource("4_wvn3v"), ExtResource("4_wvn3v"), ExtResource("10_w0xgm"), SubResource("Resource_82ci8"), SubResource("Resource_bjuo7")]) +default_deck = Array[Resource("res://Cards/CardBase.gd")]([ExtResource("4_wvn3v"), ExtResource("5_j1lqt"), ExtResource("6_4124l"), ExtResource("7_smkw8"), ExtResource("9_ojxic"), ExtResource("8_x6t2k"), ExtResource("10_w0xgm"), ExtResource("11_3k5t2")]) starting_hand_size = 10 max_hand_width = 900.0 min_card_separation = 90.0 diff --git a/Cards/Effects/EffectDamageAll.gd b/Cards/Effects/EffectDamageAll.gd new file mode 100644 index 00000000..549330df --- /dev/null +++ b/Cards/Effects/EffectDamageAll.gd @@ -0,0 +1,9 @@ +class_name EffectDamageAll extends EffectBase + +func apply_effect(caster: Entity, target: Entity, value: int) -> void: + var target_damage_data: DealDamageData = DealDamageData.new() + var party = target.get_party_component().party + target_damage_data.damage = value + target_damage_data.caster = caster + for party_target in party: + party_target.get_health_component().deal_damage(target_damage_data) diff --git a/Cards/Resource/Card_DamageAll.tres b/Cards/Resource/Card_DamageAll.tres index 5aeab2fc..62bdb679 100644 --- a/Cards/Resource/Card_DamageAll.tres +++ b/Cards/Resource/Card_DamageAll.tres @@ -1,10 +1,20 @@ -[gd_resource type="Resource" script_class="CardBase" load_steps=2 format=3 uid="uid://0x385c3nuq8f"] +[gd_resource type="Resource" script_class="CardBase" load_steps=6 format=3 uid="uid://0x385c3nuq8f"] +[ext_resource type="Script" path="res://Cards/Effects/EffectDamageAll.gd" id="1_5m74j"] [ext_resource type="Script" path="res://Cards/CardBase.gd" id="1_j02oq"] +[ext_resource type="Script" path="res://Cards/Effects/EffectData.gd" id="2_kr6on"] + +[sub_resource type="Resource" id="Resource_1loka"] +script = ExtResource("1_5m74j") + +[sub_resource type="Resource" id="Resource_s752v"] +script = ExtResource("2_kr6on") +effect = SubResource("Resource_1loka") +value = 2 [resource] script = ExtResource("1_j02oq") application_type = null card_title = "Damage All" card_description = "Deal 2 damage to all enemies" -card_effects_data = null +card_effects_data = Array[ExtResource("2_kr6on")]([SubResource("Resource_s752v")]) diff --git a/Tests/test_health.gd b/Tests/test_health.gd index e72e85eb..6bb7e817 100644 --- a/Tests/test_health.gd +++ b/Tests/test_health.gd @@ -7,18 +7,24 @@ var _enemy_scene: PackedScene = load("res://Entity/Enemy/Enemy.tscn") var _battler_scene: PackedScene = load("res://Core/Battler.tscn") var _player: Entity = null var _enemy: Entity = null +var _enemy_2: Entity = null var _battler: Battler = null var _player_health_component: HealthComponent = null var _enemy_health_component: HealthComponent = null +var _enemy_list: Array[Entity] func before_each(): _player = _player_scene.instantiate() _enemy = _enemy_scene.instantiate() + _enemy_2 = _enemy_scene.instantiate() _battler = _battler_scene.instantiate() + _enemy_list = [_enemy, _enemy_2] + get_tree().root.add_child(_player) get_tree().root.add_child(_enemy) + get_tree().root.add_child(_enemy_2) get_tree().root.add_child(_battler) _player_health_component = _player.get_health_component() @@ -28,6 +34,7 @@ func before_each(): func after_each(): _player.queue_free() _enemy.queue_free() + _enemy_2.queue_free() _battler.queue_free() @@ -149,3 +156,70 @@ func test_poison_status(): poison_status.on_turn_start() assert_eq(_enemy_health_component.current_health, 99.0) + +# Test Card to Deal 2 damage to all enemies +func test_card_damage_all(): + _enemy.get_party_component().set_party(_enemy_list) + var card_damage_all: CardBase = load("res://Cards/Resource/Card_DamageAll.tres") + + card_damage_all.on_card_play(_player, _enemy) + assert_eq(_enemy_health_component.current_health, 98.0) + assert_eq(_enemy_2.get_health_component().current_health, 98.0) + +# Test Card to Deal 3 damage to an enemy +func test_card_damage(): + var card_damage: CardBase = load("res://Cards/Resource/Card_Damage.tres") + card_damage.on_card_play(_player, _enemy) + + assert_eq(_enemy_health_component.current_health, 97.0) + +# Test Card to deal damage to enemy based on amount of player health lost +func test_card_damage_health(): + _player.get_health_component()._set_health(90.0) + var card_damage_health: CardBase = load("res://Cards/Resource/Card_DamageHealth.tres") + card_damage_health.on_card_play(_player, _enemy) + + assert_eq(_enemy_health_component.current_health, 90.0) + +# Test Card that applies 3 poison to enemy and does poison damage on enemy turn +func test_card_poison(): + var card_poison: CardBase = load("res://Cards/Resource/Card_Poison.tres") + + assert_eq(_enemy.get_status_component().current_status.size(), 0) + card_poison.on_card_play(_player, _enemy) + assert_eq(_enemy.get_status_component().current_status.size(), 1) + + var status = _enemy.get_status_component().current_status[0] + assert_is(status, Debuff_Poison) + assert_eq(status.status_turn_duration, 3) + + _enemy.get_status_component().apply_turn_start_status() + # May need to update once we have a better direction of what to do for poison, currently + # it deals only 1 damage per turn + assert_eq(_enemy_health_component.current_health, 99.0) + +# Test Card that deals 1 damage and applies 2 poison to enemy and does poison damage on enemy turn +func test_card_damage_and_poison(): + var card_damage_and_poison: CardBase = load("res://Cards/Resource/Card_damage_and_poison.tres") + + assert_eq(_enemy.get_status_component().current_status.size(), 0) + card_damage_and_poison.on_card_play(_player, _enemy) + assert_eq(_enemy.get_status_component().current_status.size(), 1) + assert_eq(_enemy_health_component.current_health, 99.0) + + var status = _enemy.get_status_component().current_status[0] + assert_is(status, Debuff_Poison) + assert_eq(status.status_turn_duration, 2) + + _enemy.get_status_component().apply_turn_start_status() + # May need to update once we have a better direction of what to do for poison, currently + # it deals only 1 damage per turn + assert_eq(_enemy_health_component.current_health, 98.0) + +# Test Card that heals one HP to player +func test_card_heal(): + var card_heal: CardBase = load("res://Cards/Resource/Card_Heal.tres") + _player_health_component._set_health(95.0) + card_heal.on_card_play(_player, _player) + + assert_eq(_player_health_component.current_health, 96.0)