Skip to content

Commit

Permalink
Fix block to use new phases (#125)
Browse files Browse the repository at this point in the history
* Add new phases to remove block, update battler

* Separate turn start effects into their own phase
  • Loading branch information
Turtyo authored Aug 30, 2024
1 parent ac66d38 commit b94b6a8
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 319 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Godot 4+ specific ignores
.godot/
.tmp
9 changes: 5 additions & 4 deletions Cards/CardSets/DefaultDeck.tres
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[gd_resource type="Resource" script_class="CardSetBase" load_steps=21 format=3 uid="uid://cda81lacxt2ai"]
[gd_resource type="Resource" script_class="CardSetBase" load_steps=22 format=3 uid="uid://cda81lacxt2ai"]

[ext_resource type="Script" path="res://Cards/CardSetBase.gd" id="1_pnxc0"]
[ext_resource type="Resource" uid="uid://dam752rc15nu5" path="res://Cards/Resource/Card_Buff_Poison_Duration.tres" id="1_to4gc"]
[ext_resource type="Resource" uid="uid://dxgoopi1roxu4" path="res://Cards/Resource/Card_Damage.tres" id="2_q7qqo"]
[ext_resource type="Resource" uid="uid://0x385c3nuq8f" path="res://Cards/Resource/Card_DamageAllEnemies.tres" id="3_4ka0y"]
[ext_resource type="Resource" uid="uid://cnxsrwpr52cig" path="res://Cards/Resource/Card_DamageAllEnemies.tres" id="3_4ka0y"]
[ext_resource type="Resource" uid="uid://boodcfdepyk5i" path="res://Cards/Resource/Card_DamageHealth.tres" id="4_es3ma"]
[ext_resource type="Resource" uid="uid://3s4aet1ciesh" path="res://Cards/Resource/Card_damage_and_poison.tres" id="5_giy28"]
[ext_resource type="Resource" uid="uid://uv2rili0xf3x" path="res://Cards/Resource/Card_Damage_EVERYTHING.tres" id="6_gr534"]
Expand All @@ -13,14 +13,15 @@
[ext_resource type="Resource" uid="uid://btj36bhn3n2tr" path="res://Cards/Resource/Card_Strength.tres" id="10_7m46u"]
[ext_resource type="Resource" uid="uid://b4kmg3lm0e45q" path="res://Cards/Resource/Card_Vulnerability.tres" id="11_0eivv"]
[ext_resource type="Resource" uid="uid://bobfsmcwcgsbb" path="res://Cards/Resource/Card_Weakness.tres" id="12_lo5f6"]
[ext_resource type="Resource" uid="uid://c4nm7mbdlsf6r" path="res://Cards/Resource/Card_Banana.tres" id="13_v3qs7"]
[ext_resource type="Resource" uid="uid://c8kpsky7tt3yq" path="res://Cards/Resource/Card_Banana.tres" id="13_v3qs7"]
[ext_resource type="Resource" uid="uid://vydmm1p103mg" path="res://Cards/Resource/Card_FaunaSweep.tres" id="14_ghttq"]
[ext_resource type="Resource" uid="uid://dans622owjixj" path="res://Cards/Resource/Card_Slap.tres" id="15_ie3pe"]
[ext_resource type="Resource" uid="uid://yc2ns5s0qask" path="res://Cards/Resource/Card_SuperSlap.tres" id="16_jluts"]
[ext_resource type="Resource" uid="uid://c787doijq7xg2" path="res://Cards/Resource/Card_Buff_healing.tres" id="17_0kgrg"]
[ext_resource type="Resource" uid="uid://bek3vbtsf3x2l" path="res://Cards/Resource/Card_Debuff_healing.tres" id="18_uj8io"]
[ext_resource type="Resource" uid="uid://wkffjp5doca1" path="res://Cards/Resource/Card_Stress_Damage.tres" id="19_s1aj2"]
[ext_resource type="Resource" uid="uid://b1u8retwosbc0" path="res://Cards/Resource/Card_Get_block.tres" id="20_nvohy"]

[resource]
script = ExtResource("1_pnxc0")
card_set = Array[Resource("res://Cards/CardBase.gd")]([ExtResource("1_to4gc"), ExtResource("2_q7qqo"), ExtResource("3_4ka0y"), ExtResource("4_es3ma"), ExtResource("5_giy28"), ExtResource("6_gr534"), ExtResource("7_y1gya"), ExtResource("8_haia1"), ExtResource("9_1tkbv"), ExtResource("10_7m46u"), ExtResource("11_0eivv"), ExtResource("12_lo5f6"), ExtResource("13_v3qs7"), ExtResource("14_ghttq"), ExtResource("15_ie3pe"), ExtResource("16_jluts"), ExtResource("17_0kgrg"), ExtResource("18_uj8io"), ExtResource("19_s1aj2")])
card_set = Array[Resource("res://Cards/CardBase.gd")]([ExtResource("1_to4gc"), ExtResource("2_q7qqo"), ExtResource("3_4ka0y"), ExtResource("4_es3ma"), ExtResource("5_giy28"), ExtResource("6_gr534"), ExtResource("7_y1gya"), ExtResource("8_haia1"), ExtResource("9_1tkbv"), ExtResource("10_7m46u"), ExtResource("11_0eivv"), ExtResource("12_lo5f6"), ExtResource("13_v3qs7"), ExtResource("14_ghttq"), ExtResource("15_ie3pe"), ExtResource("16_jluts"), ExtResource("17_0kgrg"), ExtResource("18_uj8io"), ExtResource("19_s1aj2"), ExtResource("20_nvohy")])
2 changes: 1 addition & 1 deletion Cards/Resource/Card_Banana.tres
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_resource type="Resource" script_class="CardBase" load_steps=13 format=3 uid="uid://c8kpsky7tt3yq"]

[ext_resource type="PackedScene" path="res://Cards/Animation/Scene/Anim_Banana.tscn" id="1_ggtdb"]
[ext_resource type="PackedScene" uid="uid://dicabrkoa6bvl" path="res://Cards/Animation/Scene/Anim_Banana.tscn" id="1_ggtdb"]
[ext_resource type="Script" path="res://Cards/Animation/CastPosition/CastPos_Caster.gd" id="2_ntgql"]
[ext_resource type="Script" path="res://Cards/Animation/CastAnimationData.gd" id="3_83qul"]
[ext_resource type="Script" path="res://Cards/Effects/EffectDamage.gd" id="4_xup0k"]
Expand Down
2 changes: 1 addition & 1 deletion Cards/Resource/Card_damage_and_poison.tres
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[ext_resource type="Script" path="res://Cards/Targeting/TargetingBase.gd" id="3_0biqs"]
[ext_resource type="Script" path="res://Cards/Effects/EffectApplyStatus.gd" id="3_l3hyf"]
[ext_resource type="Script" path="res://Status/Debuffs/Debuff_Poison.gd" id="4_84i11"]
[ext_resource type="PackedScene" path="res://Cards/Animation/Scene/Anim_Poison.tscn" id="4_vlagw"]
[ext_resource type="PackedScene" uid="uid://c13302ahcfpuy" path="res://Cards/Animation/Scene/Anim_Poison.tscn" id="4_vlagw"]
[ext_resource type="Script" path="res://Cards/EnergyData.gd" id="5_ajuey"]
[ext_resource type="Script" path="res://Cards/Animation/CastPosition/CastPos_AllTargets.gd" id="5_rlt1d"]
[ext_resource type="Script" path="res://Cards/Animation/CastAnimationData.gd" id="6_0uuxe"]
Expand Down
45 changes: 34 additions & 11 deletions Core/Battler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ func _on_player_initialized() -> void:


func _on_phase_changed(new_phase: GlobalEnums.CombatPhase, _old_phase: GlobalEnums.CombatPhase) -> void:
if new_phase == GlobalEnums.CombatPhase.PLAYER_ATTACKING:
_on_player_start_turn()

if new_phase == GlobalEnums.CombatPhase.ENEMY_ATTACKING:
_on_enemy_start_turn()
match new_phase:
GlobalEnums.CombatPhase.REMOVE_BLOCK_ALLY:
_remove_block_ally()
GlobalEnums.CombatPhase.PLAYER_TURN_START:
_on_player_turn_start()
GlobalEnums.CombatPhase.REMOVE_BLOCK_ENEMY:
_remove_block_all_enemies()
GlobalEnums.CombatPhase.ENEMY_TURN_START:
_on_enemy_turn_start()
GlobalEnums.CombatPhase.ENEMY_ATTACKING:
_enemy_turn()


func _on_card_container_initialized() -> void:
Expand All @@ -66,17 +72,29 @@ func _on_card_container_initialized() -> void:
func _on_player_hand_discarded() -> void:
PhaseManager.advance_to_next_combat_phase()

## Remove the block of all allies (currently just the player) [br]
## Note that later, if we add a status which allows to keep block between turns,
## it should probably be checked here (or maybe in the health component ?)
func _remove_block_ally() -> void:
PlayerManager.player.get_health_component().reset_block()
PhaseManager.advance_to_next_combat_phase()

## player start phase: apply status
func _on_player_start_turn() -> void:
func _on_player_turn_start() -> void:
PlayerManager.player.get_status_component().apply_turn_start_status()
PlayerManager.player.get_energy_component().on_turn_start()
PhaseManager.advance_to_next_combat_phase()


## Remove the block of all enemies
func _remove_block_all_enemies() -> void:
for enemy: Entity in _enemy_list:
enemy.get_health_component().reset_block()
PhaseManager.advance_to_next_combat_phase()


## enemy start phase: apply status and attack player. Afterwards, set phase to player phase
## NOTE: these are applied in two separate loops just encase an enemy affects another member of their
## party with a status during their attack
func _on_enemy_start_turn() -> void:
## enemy start phase: apply status and check death
func _on_enemy_turn_start() -> void:
# apply status
for enemy: Entity in _enemy_list:
enemy.get_stress_component().on_turn_start()
Expand All @@ -85,7 +103,12 @@ func _on_enemy_start_turn() -> void:
# if battle have ended, skip the rest of code
if _handle_deaths():
return

else:
PhaseManager.advance_to_next_combat_phase()


## The turn of the enemies, attack player then go the player phase
func _enemy_turn() -> void:
# generate list of enemy actions
for enemy: Enemy in _enemy_list:
var stress_comp: StressComponent = enemy.get_stress_component()
Expand Down
13 changes: 1 addition & 12 deletions Entity/Components/HealthComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ var team: GlobalEnums.Team
## For enemies, this is called when the scene is instantiated (or more accurately, when each enemy is instanciated) [br]
func _ready() -> void:
_set_health(max_health)

## This is a is a temporary solution to block removal while #118 and #120 are done
## should be removed with those issues
PhaseManager.temp_before_phase_changed.connect(reset_block_on_round_start)


## The intended way for entities to take damage.[br]
## Removes block first and then deals excess damage to the health[br]
Expand Down Expand Up @@ -103,14 +100,6 @@ func _set_block(new_block: int) -> void:
current_block = new_block
on_block_changed.emit(current_block)

func reset_block_on_round_start(new_phase: GlobalEnums.CombatPhase, _old_phase: GlobalEnums.CombatPhase) -> void:
if(team == GlobalEnums.Team.FRIENDLY):
if(new_phase == GlobalEnums.CombatPhase.PLAYER_ATTACKING):
reset_block()
if(team == GlobalEnums.Team.ENEMY):
if(new_phase == GlobalEnums.CombatPhase.ENEMY_ATTACKING):
reset_block()

## Sets block to 0 [br]
func reset_block() -> void:
_set_block(0)
4 changes: 4 additions & 0 deletions Global/Global_Enums.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ enum GlobalPhase {

## For phases that are combat specific
enum CombatPhase {
REMOVE_BLOCK_ALLY, ## Remove the block of all allied entity
PLAYER_TURN_START, ## Everything that happens to the player at the start of their turn except the block, like taking poison damage
PLAYER_ATTACKING, ## The player is attacking
PLAYER_FINISHING, ## The player finished its turn (card discard and other stuff starts here)
REMOVE_BLOCK_ENEMY, ## Remove the block of all the enemies
ENEMY_TURN_START, ## ## Everything that happens to enemies at the start of their turn except the block, like taking poison damage
ENEMY_ATTACKING, ## Enemy turn
}

Expand Down
8 changes: 1 addition & 7 deletions Managers/PhaseManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ signal on_event_win
## When the player is dead (reduced to 0 health)
signal on_defeat

## This is a signal is a temporary solution to block removal while #118 and #120 are done
## should be removed with those issues
signal temp_before_phase_changed(new_phase: GlobalEnums.CombatPhase, old_phase: GlobalEnums.CombatPhase)

var current_combat_phase: GlobalEnums.CombatPhase = GlobalEnums.CombatPhase.PLAYER_ATTACKING
var current_combat_phase_index: int = 0
var current_global_phase: GlobalEnums.GlobalPhase = GlobalEnums.GlobalPhase.NONE
Expand All @@ -38,7 +34,7 @@ func initialize_game() -> void:

## Start the game
func _start_game() -> void:
_set_combat_phase(GlobalEnums.CombatPhase.PLAYER_ATTACKING)
_set_combat_phase(GlobalEnums.CombatPhase.REMOVE_BLOCK_ALLY)
on_game_start.emit()


Expand All @@ -49,8 +45,6 @@ func _set_combat_phase(phase: GlobalEnums.CombatPhase) -> void:

var old_phase: GlobalEnums.CombatPhase = current_combat_phase

temp_before_phase_changed.emit(phase, old_phase)

current_combat_phase = phase
on_combat_phase_changed.emit(current_combat_phase, old_phase)

Expand Down
1 change: 1 addition & 0 deletions Tests/TestBase.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func before_each() -> void:
_player._should_save_persistent_data = false
_player_energy_component.ignore_cost = true
CardManager.disable_card_animations = true
PhaseManager.start_combat()

## Clear between tests
func after_each() -> void:
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_death_handling.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func after_each() -> void:

func test_player_death_during_enemy_turn() -> void:
_player.get_health_component()._set_health(1)
_battler._on_enemy_start_turn()
_battler._enemy_turn()
assert_eq(_player.get_health_component().current_health, 0)
assert_signal_emitted(PhaseManager, "on_defeat")

Expand Down Expand Up @@ -114,7 +114,7 @@ func test_enemy_death_to_poison() -> void:
card_poison.on_card_play(_player, _enemy)

assert_eq(_enemy_list.size(), 2)
_battler._on_enemy_start_turn()
_battler._on_enemy_turn_start()
assert_eq(_enemy_list.size(), 1)
assert_true(_enemy.is_queued_for_deletion())
await get_tree().process_frame
Expand All @@ -129,7 +129,7 @@ func test_enemy_death_to_expiring_poison() -> void:

assert_eq(_enemy_list.size(), 2)
assert_eq(_enemy.get_status_component().current_status.size(), 1)
_battler._on_enemy_start_turn()
_battler._on_enemy_turn_start()
assert_eq(_enemy.get_status_component().current_status.size(), 0)
assert_eq(_enemy_list.size(), 1)
assert_true(_enemy.is_queued_for_deletion())
Expand Down
4 changes: 3 additions & 1 deletion Tests/test_health.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func test_reset_block_on_round_start() -> void:
var caster: Entity = _player

_player_health_component.add_block(block_amount, caster)
PhaseManager.temp_before_phase_changed.emit(GlobalEnums.CombatPhase.PLAYER_ATTACKING, GlobalEnums.CombatPhase.ENEMY_ATTACKING)
PhaseManager._set_combat_phase(GlobalEnums.CombatPhase.REMOVE_BLOCK_ALLY)
PhaseManager.current_combat_phase_index = 0
#PhaseManager.on_combat_phase_changed.emit(GlobalEnums.CombatPhase.REMOVE_BLOCK_ALLY, GlobalEnums.CombatPhase.ENEMY_ATTACKING)
assert_eq(_player_health_component.current_block, 0)

func test_take_lots_of_damage() -> void:
Expand Down
18 changes: 0 additions & 18 deletions conBC3F.tmp

This file was deleted.

18 changes: 0 additions & 18 deletions conDD72.tmp

This file was deleted.

83 changes: 0 additions & 83 deletions inv9CAE.tmp

This file was deleted.

Loading

0 comments on commit b94b6a8

Please sign in to comment.