Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block #114

Merged
merged 24 commits into from
Aug 7, 2024
Merged

Block #114

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions Entity/Components/HealthComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ signal on_block_changed(new_block: int)
## Between 0 and max_health
var current_health: int = 100 # ? change this to max health, or just unset since it's init by the ready


var current_block: int = 0

## might need to find a better way to get which team the enitiy is on
var team: GlobalEnums.Team

## Initialize the health component, putting health to max health
## This only happens at game start for the player, the value is then tracked inside the [PlayerManager] singleton [br]
## 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)
PhaseManager.on_phase_changed.connect(reset_block_on_round_start)
PhaseManager.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]
func take_damage_block_and_health(amount : int, caster: Entity) -> void:
if amount <= 0.0:
if amount <= 0:
return

assert(owner != null, "No owner was set. Please call init on the Entity.")
Expand All @@ -46,7 +48,7 @@ func take_damage_block_and_health(amount : int, caster: Entity) -> void:
## removes health without considering block [br]
## primarily a helper function, but could be used in future for block ignoring attacks[br]
func _health_damage(damage : int) -> void:
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
if damage <= 0.0:
if damage <= 0:
return

var new_health : int = clamp(current_health - damage, 0, max_health)
Expand All @@ -55,7 +57,7 @@ func _health_damage(damage : int) -> void:

## adds health to the unit[br]
func heal(amount : int, _caster : Entity) -> void:
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
if amount <= 0.0:
if amount <= 0:
return

var new_health : int = clamp(current_health + amount, 0, max_health)
Expand All @@ -70,7 +72,7 @@ func _set_health(new_health: int) -> void:

## Removes block from the entity[br]
func block_damage(damage: int) -> int:
if damage <= 0.0:
if damage <= 0:
return 0

var leftover_damage : int = max(damage - current_block, 0)
Expand All @@ -82,7 +84,7 @@ func block_damage(damage: int) -> int:

## Adds block to the entity[br]
func add_block(amount : int, _caster : Entity) -> void:
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
if amount <= 0.0:
if amount <= 0:
return

var new_block : int = current_block + amount
Expand All @@ -99,8 +101,12 @@ func _set_block(new_block: int) -> void:
on_block_changed.emit(current_block)

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

## Sets block to 0 [br]
func reset_block() -> void:
Expand Down
2 changes: 2 additions & 0 deletions Entity/Entity.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ func _ready() -> void:
get_health_component().init_entity_component(self)
get_party_component().init_entity_component(self)
get_stat_component().init_entity_component(self)

get_health_component().team = get_party_component().team


func get_status_component() -> StatusComponent:
Expand Down
5 changes: 5 additions & 0 deletions Managers/PhaseManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ signal on_event_win
## When the player is dead (reduced to 0 health)
signal on_defeat

## This is a signal to fix a bug with blocking regarding order of turn start effects, might be removed later
signal before_phase_changed(new_phase: GlobalEnums.Phase, old_phase: GlobalEnums.Phase)
Tomzkk marked this conversation as resolved.
Show resolved Hide resolved

var current_phase: GlobalEnums.Phase = GlobalEnums.Phase.NONE

Expand Down Expand Up @@ -41,5 +43,8 @@ func set_phase(phase: GlobalEnums.Phase) -> void:
return

var old_phase: GlobalEnums.Phase = current_phase

before_phase_changed.emit(phase, old_phase)

current_phase = phase
on_phase_changed.emit(current_phase, old_phase)
Loading