Skip to content

Commit

Permalink
Issue-26: Update test_health.gd to use the cards, fix a big with Dama…
Browse files Browse the repository at this point in the history
…ge All card by adding EffectDamageAll.gd
  • Loading branch information
Tysterman74 committed Jan 9, 2024
1 parent e40671e commit c75d864
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
5 changes: 3 additions & 2 deletions #Scenes/TestingScene.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Cards/Effects/EffectDamageAll.gd
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 12 additions & 2 deletions Cards/Resource/Card_DamageAll.tres
Original file line number Diff line number Diff line change
@@ -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")])
65 changes: 65 additions & 0 deletions Tests/test_health.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -28,6 +31,7 @@ func before_each():
func after_each():
_player.queue_free()
_enemy.queue_free()
_enemy_2.queue_free()
_battler.queue_free()


Expand Down Expand Up @@ -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)

0 comments on commit c75d864

Please sign in to comment.