From c75d864052872b7763132a32e5c042ddfcd1b87d Mon Sep 17 00:00:00 2001 From: tynutsathitya Date: Mon, 8 Jan 2024 20:29:49 -0800 Subject: [PATCH] Issue-26: Update test_health.gd to use the cards, fix a big with Damage All card by adding EffectDamageAll.gd --- #Scenes/TestingScene.tscn | 5 ++- Cards/Effects/EffectDamageAll.gd | 9 +++++ Cards/Resource/Card_DamageAll.tres | 14 ++++++- Tests/test_health.gd | 65 ++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 Cards/Effects/EffectDamageAll.gd diff --git a/#Scenes/TestingScene.tscn b/#Scenes/TestingScene.tscn index e9ad8979..c5baab90 100644 --- a/#Scenes/TestingScene.tscn +++ b/#Scenes/TestingScene.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=15 format=3 uid="uid://b60uabg68ra1l"] +[gd_scene load_steps=16 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"] [ext_resource type="Resource" uid="uid://dxgoopi1roxu4" path="res://Cards/Resource/Card_Damage.tres" id="4_wvn3v"] +[ext_resource type="Resource" uid="uid://0x385c3nuq8f" path="res://Cards/Resource/Card_DamageAll.tres" id="5_j1lqt"] [ext_resource type="Resource" uid="uid://5yn4t13kwwoo" path="res://Cards/Resource/Card_DamageHealth.tres" id="6_4124l"] [ext_resource type="Resource" uid="uid://d4lugn62mmlep" path="res://Cards/Resource/Card_DrawCards.tres" id="7_smkw8"] [ext_resource type="PackedScene" uid="uid://bcpmrmofcilbn" path="res://Core/Battler.tscn" id="8_qtw1k"] @@ -42,7 +43,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("6_4124l"), ExtResource("7_smkw8"), ExtResource("9_ojxic"), ExtResource("8_x6t2k"), ExtResource("10_w0xgm")]) +default_deck = Array[Resource("res://Cards/CardBase.gd")]([ExtResource("4_wvn3v"), ExtResource("6_4124l"), ExtResource("7_smkw8"), ExtResource("9_ojxic"), ExtResource("8_x6t2k"), ExtResource("10_w0xgm"), ExtResource("5_j1lqt")]) 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..7ccba219 100644 --- a/Tests/test_health.gd +++ b/Tests/test_health.gd @@ -7,6 +7,7 @@ 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 @@ -15,10 +16,12 @@ var _enemy_health_component: HealthComponent = null func before_each(): _player = _player_scene.instantiate() _enemy = _enemy_scene.instantiate() + _enemy_2 = _enemy_scene.instantiate() _battler = _battler_scene.instantiate() 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 +31,7 @@ func before_each(): func after_each(): _player.queue_free() _enemy.queue_free() + _enemy_2.queue_free() _battler.queue_free() @@ -149,3 +153,64 @@ func test_poison_status(): poison_status.on_turn_start() assert_eq(_enemy_health_component.current_health, 99.0) + +func test_card_damage_all(): + _enemy.get_party_component().set_party([_enemy, _enemy_2]) + 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) + +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) + +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) + +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) + +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) + +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)