Skip to content

Commit

Permalink
fix: closes #34. Thank you @Hairic95
Browse files Browse the repository at this point in the history
OctoD authored Jun 28, 2023
1 parent 5aeb5ae commit 250e24b
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ func _get_cooldown_timer(ability: Ability) -> Timer:
## Handles the [signal Ability.activated] signal
## [br]It's called internally by the current [AbilityContainer], so you should not call it.
func _handle_ability_activated(ability: Ability, activation_event: ActivationEvent) -> void:
if not active:
if not _is_eligible_for_operation(activation_event):
return

_handle_lifecycle_tagging(LifeCycle.Activated, ability)
@@ -131,7 +131,7 @@ func _handle_ability_activated(ability: Ability, activation_event: ActivationEve
## Handles the [signal Ability.blocked] signal.
## [br]It's called internally by the current [AbilityContainer], so you should not call it.
func _handle_ability_blocked(ability: Ability, activation_event: ActivationEvent) -> void:
if not active:
if not _is_eligible_for_operation(activation_event):
return

ability_blocked.emit(ability, activation_event)
@@ -141,7 +141,7 @@ func _handle_ability_blocked(ability: Ability, activation_event: ActivationEvent
## Handles the [signal Ability.cancelled] signal
## [br]It's called internally by the current [AbilityContainer], so you should not call it.
func _handle_ability_cancelled(ability: Ability, activation_event: ActivationEvent) -> void:
if not active:
if not _is_eligible_for_operation(activation_event):
return

_handle_lifecycle_tagging(LifeCycle.Cancelled, ability)
@@ -152,7 +152,7 @@ func _handle_ability_cancelled(ability: Ability, activation_event: ActivationEve
## Handles the [signal Ability.ended] signal
## [br]It's called internally by the current [AbilityContainer], so you should not call it.
func _handle_ability_ended(ability: Ability, activation_event: ActivationEvent) -> void:
if not active:
if not _is_eligible_for_operation(activation_event):
return

_handle_lifecycle_tagging(LifeCycle.Ended, ability)
@@ -193,6 +193,11 @@ func _handle_lifecycle_tagging(lifecycle: LifeCycle, ability: Ability) -> void:
return


## Returns [code]true[/code] if the [AbilityContainer] can process and [ActivationEvent], [code]false[/code] otherwise.
func _is_eligible_for_operation(activation_event: ActivationEvent) -> bool:
return activation_event.ability_container == self and active


## The [method Node._ready] override
func _ready() -> void:
gameplay_attribute_map = get_node(gameplay_attribute_map_path)
Original file line number Diff line number Diff line change
@@ -222,3 +222,43 @@ func test_granting_issue_23() -> void:


# it should reach this point to avoid that possible bug about not granting abilities at all if one is not grantable


class _test_Enemy_hairic95 extends Node2D:
var ability_container: AbilityContainer

func _init(ability: Ability000) -> void:
ability_container = AbilityContainer.new()
add_child(ability_container)


func fire() -> void:
ability_container.activate_many()


func test_hairic95_issue() -> void:
var ability000 = Ability000.new("000")

ability000.tags_activation.append("started")

var enemy000 = _test_Enemy_hairic95.new(ability000)
var enemy001 = _test_Enemy_hairic95.new(ability000)
var enemy002 = _test_Enemy_hairic95.new(ability000)
var enemies = [enemy000, enemy001, enemy002]

add_child_autofree(enemy000)
add_child_autofree(enemy001)
add_child_autofree(enemy002)

enemy000.get("fire").call()

assert_eq(enemy000.ability_container.tags.has("started") == true, "Ability container should have the tag")
assert_eq(enemy001.ability_container.tags.has("started") == false, "Ability container should have the tag")
assert_eq(enemy002.ability_container.tags.has("started") == false, "Ability container should have the tag")

for e in enemies:
e.get("fire").call()

assert_eq(enemy000.ability_container.tags.has("started") == true, "Ability container should have the tag")
assert_eq(enemy001.ability_container.tags.has("started") == true, "Ability container should have the tag")
assert_eq(enemy002.ability_container.tags.has("started") == true, "Ability container should have the tag")

0 comments on commit 250e24b

Please sign in to comment.