summaryrefslogtreecommitdiff
path: root/Towers/Tower.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Towers/Tower.gd')
-rw-r--r--Towers/Tower.gd70
1 files changed, 36 insertions, 34 deletions
diff --git a/Towers/Tower.gd b/Towers/Tower.gd
index f3b6667..54687fd 100644
--- a/Towers/Tower.gd
+++ b/Towers/Tower.gd
@@ -27,14 +27,11 @@ var is_hovered = false :
var mobs_in_range: Array = []
-var selection_area: Area2D
+#var selection_area: Area2D
# rpc owner id
var owner_id = 1
-# unique shared id on the network on all clients
-var network_id
-
@export var attack_range: int = 32
@export var attack_power: int = 1
@export var attack_speed: int = 1
@@ -74,12 +71,12 @@ func _process(_delta: float) -> void:
shoot()
$ShootCooldown.start()
- if selection_area and is_instance_valid(selection_area):
- var bodies = selection_area.get_overlapping_bodies()
- if bodies.size() > 0:
- selection_area.queue_free()
- for body in bodies:
- Client.select_tower(body)
+ #if selection_area and is_instance_valid(selection_area):
+ #var bodies = selection_area.get_overlapping_bodies()
+ #if bodies.size() > 0:
+ #selection_area.queue_free()
+ #for body in bodies:
+ #Client.select_tower(body)
func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int):
@@ -87,25 +84,7 @@ func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int):
if owner_id != multiplayer.get_unique_id():
return
- if Client.state is StateDefault:
- if event.is_action_pressed("builder_tower_select"):
- Client.select_tower(self)
-
- if event is InputEventMouseButton:
- if event.is_double_click():
- selection_area = Area2D.new()
- selection_area.position = (
- Client.stage.get_node("Camera").get_rect().position +
- Client.stage.get_node("Camera").get_rect().size / 2
- )
- selection_area.set_collision_mask_value(3, true)
- var collision_shape = CollisionShape2D.new()
- var shape = RectangleShape2D.new()
- shape.size = Client.stage.get_node("Camera").get_rect().size
- collision_shape.shape = shape
- selection_area.add_child(collision_shape)
- get_tree().current_scene.add_child(selection_area)
-
+ if Client.state is StateBuild:
if event.is_action_pressed("builder_cancel"):
Client.remove_tower(self)
@@ -114,22 +93,45 @@ func _on_range_body_entered(body: Node2D) -> void:
mobs_in_range.append(body)
func _on_range_body_exited(body: Node2D) -> void:
- mobs_in_range.remove_at(mobs_in_range.find(body))
+ mobs_in_range.erase(body)
-func _on_mouse_entered() -> void:
+func _on_selectable_area_hover_enter() -> void:
is_hovered = true
-func _on_mouse_exited() -> void:
+func _on_selectable_area_hover_exit() -> void:
is_hovered = false
+func _on_selectable_area_select(event: InputEvent) -> void:
+ # disable remote select for now
+ if owner_id != multiplayer.get_unique_id():
+ return
+
+ if Client.state is StateDefault:
+ Client.select_tower(self)
+
+ if event.is_double_click():
+ var selection_area = preload("res://Game/Selection/MultiSelectArea.tscn").instantiate()
+ selection_area.set_collision_mask_value(3, true)
+ selection_area.select.connect(func(nodes):
+ for node in nodes:
+ Client.select_tower(node)
+ )
+ get_tree().current_scene.add_child(selection_area)
+
+
+
func is_melee_range():
return attack_range <= (Client.stage.map.tile_set.tile_size.x * 2)
func shoot():
- var target = mobs_in_range.pick_random() as Unit
+ if get_multiplayer_authority() != multiplayer.get_unique_id():
+ # TODO: do shoot animation, but don't subtract hp
+ return
+
+ var target = mobs_in_range[0] as Unit
if is_melee_range():
target.set_hp(target.hp - 1)
@@ -158,7 +160,7 @@ func _on_tree_exiting() -> void:
func get_rpc_properties() -> Dictionary:
return {
+ "name": null,
"global_position": null,
"owner_id": null,
- "network_id": null,
}