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

suggestion: inform units on receiving hit #98

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions source/match/MatchSignals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ signal unit_targeted(unit)
signal unit_selected(unit)
signal unit_deselected(unit)
signal unit_died(unit)

signal attacked_by(unit, attacker)
11 changes: 11 additions & 0 deletions source/match/units/Unit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var action = null:

var _action_locked = false

var _auxillary_target = null

@onready var _match = find_parent("Match")


Expand All @@ -47,6 +49,9 @@ func _ready():
await _match.ready
_setup_color()
_setup_default_properties_from_constants()

MatchSignals.attacked_by.connect(_on_friendly_attacked)

assert(_safety_checks())


Expand Down Expand Up @@ -167,3 +172,9 @@ func _setup_default_properties_from_constants():
func _on_action_node_tree_exited(action_node):
assert(action_node == action, "unexpected action released")
action = null


func _on_friendly_attacked(attacked, target):
if self.player == attacked.player:
if self.position.distance_to(attacked.position) <= self.sight_range:
_auxillary_target = target
9 changes: 8 additions & 1 deletion source/match/units/actions/WaitingForTargets.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func is_idle():

func _get_units_to_attack():
var self_position_yless = _unit.global_position * Vector3(1, 0, 1)
return get_tree().get_nodes_in_group("units").filter(

var units_to_attack = get_tree().get_nodes_in_group("units").filter(
func(unit): return (
unit.player != _unit.player
and unit.movement_domain in _unit.attack_domains
Expand All @@ -39,6 +40,12 @@ func _get_units_to_attack():
)
)

if units_to_attack.is_empty():
if _unit._auxillary_target != null:
units_to_attack.append(_unit._auxillary_target)

return units_to_attack


func _attack_unit(unit):
_timer.timeout.disconnect(_on_timer_timeout)
Expand Down
1 change: 1 addition & 0 deletions source/match/units/projectiles/CannonShell.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func _ready():
_unit_particles.visible = _unit.visible
_setup_unit_particles()
_setup_timer()
MatchSignals.attacked_by.emit(target_unit, _unit)
target_unit.hp -= _unit.attack_damage


Expand Down