diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-10-24 18:31:08 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-10-24 18:31:08 +0200 |
commit | a495681453c97578cc4a408d6919c6879524a603 (patch) | |
tree | 649c813cf26370a6ae762038b46c8e5fb075ea64 /Towers/Tower.gd | |
parent | 6db6465d1b938ec494cd66c9984bff5cc14bde11 (diff) |
next commit
Diffstat (limited to 'Towers/Tower.gd')
-rw-r--r-- | Towers/Tower.gd | 104 |
1 files changed, 98 insertions, 6 deletions
diff --git a/Towers/Tower.gd b/Towers/Tower.gd index 7eb8bf6..2de8216 100644 --- a/Towers/Tower.gd +++ b/Towers/Tower.gd @@ -36,24 +36,43 @@ var mobs_in_range: Array = [] #var selection_area: Area2D +signal selection_group_id_changed(previous_id: String) +@onready var selection_group_id := get_group_id(): + set(value): + var previous_id = selection_group_id + selection_group_id = value + selection_group_id_changed.emit(previous_id) + # rpc owner id @export var owner_id = 1 +signal attack_value_changed(value: int) @export var attack_range: int = 32 @export var attack_power: int = 1 + @export var attack_speed: int = 1 +var speed_base: float = 2.0 -@export var components: Array[TowerComponent] = [] +signal components_changed +@export var components: Array[TowerComponent] = []#: + #set(value): + #components = value + #components_changed.emit() func _ready(): $Range/CollisionShape2D.shape.radius = attack_range - $ShootCooldown.wait_time = attack_speed + $ShootCooldown.wait_time = speed_base / attack_speed %Data.text = "Range: %s - Power: %s - Speed: %s" % [ attack_range, attack_power, attack_speed ] - + + %HUD.visible = false + + components_changed.connect(func(): + selection_group_id = get_group_id() + ) #for component in [ #preload("res://Towers/Components/FrostComponent.gd").new(), @@ -138,6 +157,7 @@ func add_component(component: TowerComponent): var sprite = component.sprite $ComponentsAnchor.add_child(sprite) redraw_components() + components_changed.emit() func remove_component(component_name: String): for component in components: @@ -146,6 +166,7 @@ func remove_component(component_name: String): $ComponentsAnchor.remove_child($ComponentsAnchor.get_node(NodePath(component.name))) break redraw_components() + components_changed.emit() func redraw_components(): for idx in range(components.size()): @@ -176,7 +197,10 @@ func shoot(): func get_hud(): - return %HUD.get_child(0).duplicate() + var data = %HUD.get_child(0).duplicate() + data.name = name + + return data func get_region(): @@ -189,6 +213,19 @@ func get_region(): ) +func get_group_id() -> String: + var string := "" + + string += str(attack_range) + string += str(attack_power) + string += str(attack_speed) + + for component in components: + string += component.name + + return str(components.size()) + string.md5_text() + + func _on_tree_exiting() -> void: is_selected = false @@ -197,7 +234,9 @@ func _on_h_box_container_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): get_viewport().set_input_as_handled() - for tower in selected_towers: + var hud: HUD = Client.current_stage.get_node("HUD") + var towers = hud.selection_groups[hud.selected_group].duplicate() + for tower in towers: var found = false for idx in range(tower.components.size()): var component = tower.components[idx] @@ -216,7 +255,9 @@ func _on_h_box_container_2_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): get_viewport().set_input_as_handled() - for tower in selected_towers: + var hud: HUD = Client.current_stage.get_node("HUD") + var towers = hud.selection_groups[hud.selected_group].duplicate() + for tower in towers: var found = false for idx in range(tower.components.size()): var component = tower.components[idx] @@ -231,6 +272,57 @@ func _on_h_box_container_2_gui_input(event: InputEvent) -> void: Client.update_tower(tower.get_path(), tower.to_network_data()) +func _on_button_1_pressed() -> void: + if Client.player.money < (attack_range / 8.0) + 10: + return + + var hud: HUD = Client.current_stage.get_node("HUD") + var towers = hud.selection_groups[hud.selected_group].duplicate() + for tower: Tower in towers: + tower.attack_range += 8 + tower.attack_value_changed.emit((attack_range / 8.0) - 1) + tower.get_node("%Data").text = "Range: %s - Power: %s - Speed: %s" % [ + tower.attack_range, tower.attack_power, tower.attack_speed + ] + tower.get_node("%Range/CollisionShape2D").shape.radius = attack_range + tower.selection_group_id = tower.get_group_id() + Client.update_tower(tower.get_path(), tower.to_network_data()) + + +func _on_button_2_pressed() -> void: + if Client.player.money < attack_power * 10: + return + + var hud: HUD = Client.current_stage.get_node("HUD") + var towers = hud.selection_groups[hud.selected_group].duplicate() + for tower: Tower in towers: + tower.attack_power += 1 + tower.attack_value_changed.emit(attack_power - 1) + tower.get_node("%Data").text = "Range: %s - Power: %s - Speed: %s" % [ + tower.attack_range, tower.attack_power, tower.attack_speed + ] + tower.selection_group_id = tower.get_group_id() + Client.update_tower(tower.get_path(), tower.to_network_data()) + + +func _on_button_3_pressed() -> void: + if Client.player.money < attack_speed * 10: + return + + var hud: HUD = Client.current_stage.get_node("HUD") + var towers = hud.selection_groups[hud.selected_group].duplicate() + for tower: Tower in towers: + tower.attack_speed += 1 + tower.attack_value_changed.emit(attack_speed - 1) + tower.get_node("%Data").text = "Range: %s - Power: %s - Speed: %s" % [ + tower.attack_range, tower.attack_power, tower.attack_speed + ] + tower.get_node("%ShootCooldown").wait_time = (speed_base / attack_speed) + tower.selection_group_id = tower.get_group_id() + Client.update_tower(tower.get_path(), tower.to_network_data()) + + + class NetworkData extends Resource: var name: String var owner_id: int |