extends Control #signal range_applied(previous_value: int, current_value: int, number_of_towers: int) #signal power_applied(previous_value: int, current_value: int, number_of_towers: int) #signal speed_applied(previous_value: int, current_value: int, number_of_towers: int) var current_tower: Tower: set = set_current_tower func set_current_tower(tower: Tower): if current_tower and is_instance_valid(current_tower): current_tower.components_changed.disconnect(redraw_components) current_tower = tower redraw_components() current_tower.components_changed.connect(redraw_components) %Data.text = "Range: %s - Power: %s - Speed: %s" % [ current_tower.components.get(TowerComponent.ComponentType.Range).range, current_tower.components.get(TowerComponent.ComponentType.Attack).power, current_tower.components.get(TowerComponent.ComponentType.Attack).speed, ] func redraw_components(): for node in %Components.get_children(): node.modulate = Color(1.0, 1.0, 1.0, 0.5) node.get_node("Level").text = str(0) for component: TowerComponent in current_tower.components.values(): %Components.get_node(component.id).modulate = Color(1.0, 1.0, 1.0, 1.0) %Components.get_node(component.id).get_node("Level").text = ": %s" % [component.level] func get_selected_towers() -> Array: var hud: HUD = Client.current_stage.get_node("%HUD") # TODO: key not found error sometimes? return hud.selection_groups[hud.selected_group].duplicate() #func get_component(tower: Tower, component_name: String): #var component: TowerComponent #for idx in range(tower.components.size()): #if tower.components[idx].name == component_name: #component = tower.components[idx] #break # #return component #func _on_range_plus_pressed() -> void: #var towers = get_selected_towers() # #var cost = Client.current_stage.price_map.tower.attack_range.call(current_tower.attack_range, towers.size()) #if Client.player.money < cost: #Client.current_stage.add_status_message("Not enough money to upgrade") #return # #for tower: Tower in towers: #tower.attack_range += 8 #tower.selection_group_id = tower.get_group_id() #Client.update_tower(tower.get_path(), tower.to_network_data()) # #Network.update_player.rpc(Client.player.id, { #"money": -cost, #}) # ##%Data.text = "Range: %s - Power: %s - Speed: %s" % [ ##current_tower.attack_range, current_tower.attack_power, current_tower.attack_speed ##] # # #func _on_power_plus_pressed() -> void: #var towers = get_selected_towers() # #var cost = Client.current_stage.price_map.tower.attack_power.call(current_tower.attack_power, towers.size()) #if Client.player.money < cost: #Client.current_stage.add_status_message("Not enough money to upgrade") #return # #for tower: Tower in towers: #tower.attack_power += 1 #tower.selection_group_id = tower.get_group_id() #Client.update_tower(tower.get_path(), tower.to_network_data()) # #Network.update_player.rpc(Client.player.id, { #"money": -cost, #}) # ##%Data.text = "Range: %s - Power: %s - Speed: %s" % [ ##current_tower.attack_range, current_tower.attack_power, current_tower.attack_speed ##] # # #func _on_speed_plus_pressed() -> void: #var towers = get_selected_towers() # #var cost = Client.current_stage.price_map.tower.attack_speed.call(current_tower.attack_speed, towers.size()) #if Client.player.money < cost: #Client.current_stage.add_status_message("Not enough money to upgrade") #return # #for tower: Tower in towers: #tower.attack_speed += 1 #tower.selection_group_id = tower.get_group_id() #Client.update_tower(tower.get_path(), tower.to_network_data()) # #Network.update_player.rpc(Client.player.id, { #"money": -cost, #}) # ##%Data.text = "Range: %s - Power: %s - Speed: %s" % [ ##current_tower.attack_range, current_tower.attack_power, current_tower.attack_speed ##] func _on_range_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): get_viewport().set_input_as_handled() if current_tower.components.has(TowerComponent.ComponentType.Range): Client.current_stage.add_status_message("Component already added") return var towers = get_selected_towers() var cost = 100 * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to add component") return for tower: Tower in towers: tower.add_component(preload("res://Towers/Components/RangeComponent.tscn").instantiate()) Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) func _on_attack_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): get_viewport().set_input_as_handled() if current_tower.components.has(TowerComponent.ComponentType.Attack): Client.current_stage.add_status_message("Component already added") return var towers = get_selected_towers() var cost = 100 * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to add component") return for tower: Tower in towers: tower.add_component(preload("res://Towers/Components/AttackComponent.tscn").instantiate()) Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) func _on_frost_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): get_viewport().set_input_as_handled() if current_tower.components.has(TowerComponent.ComponentType.Frost): Client.current_stage.add_status_message("Component already added") return var towers = get_selected_towers() var cost = 100 * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to add component") return for tower: Tower in towers: tower.add_component(preload("res://Towers/Components/FrostComponent.tscn").instantiate()) Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) func _on_burn_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): get_viewport().set_input_as_handled() if current_tower.components.has(TowerComponent.ComponentType.Burn): Client.current_stage.add_status_message("Component already added") return var towers = get_selected_towers() var cost = 100 * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to add component") return for tower: Tower in towers: tower.add_component(preload("res://Towers/Components/BurnComponent.tscn").instantiate()) Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) func _on_poison_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): get_viewport().set_input_as_handled() if current_tower.components.has(TowerComponent.ComponentType.Poison): Client.current_stage.add_status_message("Component already added") return var towers = get_selected_towers() var cost = 100 * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to add component") return for tower: Tower in towers: tower.add_component(preload("res://Towers/Components/PoisonComponent.tscn").instantiate()) Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) func _on_range_level_up_pressed() -> void: var towers = get_selected_towers() var component: TowerComponent = current_tower.components.get(TowerComponent.ComponentType.Range) if not component: return var cost = pow(5, component.level) * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to level up") return for tower: Tower in towers: var tower_component: TowerComponent = tower.components.get(TowerComponent.ComponentType.Range) tower_component.level += 1 tower.components_changed.emit() Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) %Data.text = "Range: %s - Power: %s - Speed: %s" % [ current_tower.components.get(TowerComponent.ComponentType.Range).range, current_tower.components.get(TowerComponent.ComponentType.Attack).power, current_tower.components.get(TowerComponent.ComponentType.Attack).speed, ] func _on_attack_level_up_pressed() -> void: var towers = get_selected_towers() var component: TowerComponent = current_tower.components.get(TowerComponent.ComponentType.Attack) if not component: return var cost = 10 * component.level * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to level up") return for tower: Tower in towers: var tower_component: TowerComponent = tower.components.get(TowerComponent.ComponentType.Attack) tower_component.level += 1 tower.components_changed.emit() Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) %Data.text = "Range: %s - Power: %s - Speed: %s" % [ current_tower.components.get(TowerComponent.ComponentType.Range).range, current_tower.components.get(TowerComponent.ComponentType.Attack).power, current_tower.components.get(TowerComponent.ComponentType.Attack).speed, ] func _on_frost_level_up_pressed() -> void: var towers = get_selected_towers() var component: TowerComponent = current_tower.components.get(TowerComponent.ComponentType.Frost) if not component: return var cost = 10 * component.level * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to level up") return for tower: Tower in towers: var tower_component: TowerComponent = tower.components.get(TowerComponent.ComponentType.Frost) tower_component.level += 1 tower.components_changed.emit() Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) func _on_burn_level_up_pressed() -> void: var towers = get_selected_towers() var component: TowerComponent = current_tower.components.get(TowerComponent.ComponentType.Burn) if not component: return var cost = 10 * component.level * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to level up") return for tower: Tower in towers: var tower_component: TowerComponent = tower.components.get(TowerComponent.ComponentType.Burn) tower_component.level += 1 tower.components_changed.emit() Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) func _on_poison_level_up_pressed() -> void: var towers = get_selected_towers() var component: TowerComponent = current_tower.components.get(TowerComponent.ComponentType.Poison) if not component: return var cost = 10 * component.level * towers.size() if Client.player.money < cost: Client.current_stage.add_status_message("Not enough money to level up") return for tower: Tower in towers: var tower_component: TowerComponent = tower.components.get(TowerComponent.ComponentType.Poison) tower_component.level += 1 tower.components_changed.emit() Client.update_tower(tower.get_path(), tower.to_network_data()) Network.update_player.rpc(Client.player.id, { "money": -cost, }) #func _on_range_plus_mouse_entered() -> void: #var towers = get_selected_towers() #var cost = Client.current_stage.price_map.tower.attack_range.call(current_tower.attack_range, towers.size()) #%RangePlus.tooltip_text = "Cost: " + str(cost) # #func _on_power_plus_mouse_entered() -> void: #var towers = get_selected_towers() #var cost = Client.current_stage.price_map.tower.attack_power.call(current_tower.attack_power, towers.size()) #%PowerPlus.tooltip_text = "Cost: " + str(cost) # #func _on_speed_plus_mouse_entered() -> void: #var towers = get_selected_towers() #var cost = Client.current_stage.price_map.tower.attack_speed.call(current_tower.attack_speed, towers.size()) #%SpeedPlus.tooltip_text = "Cost: " + str(cost) func _on_range_mouse_entered() -> void: if current_tower.components.has(TowerComponent.ComponentType.Range): $Components/Range.tooltip_text = "" return var towers = get_selected_towers() var cost = 100 * towers.size() $Components/Range.tooltip_text = "Cost: " + str(cost) func _on_range_level_up_mouse_entered() -> void: var component = current_tower.components.get(TowerComponent.ComponentType.Range) if not component: $Components/Range/RangeLevelUp.tooltip_text = "" return var towers = get_selected_towers() var cost = pow(5, component.level) * towers.size() $Components/Range/RangeLevelUp.tooltip_text = "Cost: " + str(cost) func _on_attack_mouse_entered() -> void: if current_tower.components.has(TowerComponent.ComponentType.Attack): $Components/Attack.tooltip_text = "" return var towers = get_selected_towers() var cost = 100 * towers.size() $Components/Attack.tooltip_text = "Cost: " + str(cost) func _on_attack_level_up_mouse_entered() -> void: var component = current_tower.components.get(TowerComponent.ComponentType.Attack) if not component: $Components/Attack/AttackLevelUp.tooltip_text = "" return var towers = get_selected_towers() var cost = 10 * component.level * towers.size() $Components/Attack/AttackLevelUp.tooltip_text = "Cost: " + str(cost) func _on_frost_mouse_entered() -> void: if current_tower.components.has(TowerComponent.ComponentType.Frost): $Components/Frost.tooltip_text = "" return var towers = get_selected_towers() var cost = 100 * towers.size() $Components/Frost.tooltip_text = "Cost: " + str(cost) func _on_frost_level_up_mouse_entered() -> void: var component = current_tower.components.get(TowerComponent.ComponentType.Frost) if not component: $Components/Frost/FrostLevelUp.tooltip_text = "" return var towers = get_selected_towers() var cost = 10 * component.level * towers.size() $Components/Frost/FrostLevelUp.tooltip_text = "Cost: " + str(cost) func _on_burn_mouse_entered() -> void: if current_tower.components.has(TowerComponent.ComponentType.Burn): $Components/Range.tooltip_text = "" return var towers = get_selected_towers() var cost = 100 * towers.size() $Components/Burn.tooltip_text = "Cost: " + str(cost) func _on_burn_level_up_mouse_entered() -> void: var component = current_tower.components.get(TowerComponent.ComponentType.Burn) if not component: $Components/Burn/BurnLevelUp.tooltip_text = "" return var towers = get_selected_towers() var cost = 10 * component.level * towers.size() $Components/Burn/BurnLevelUp.tooltip_text = "Cost: " + str(cost) func _on_poison_mouse_entered() -> void: if current_tower.components.has(TowerComponent.ComponentType.Poison): $Components/Poison.tooltip_text = "" return var towers = get_selected_towers() var cost = 100 * towers.size() $Components/Poison.tooltip_text = "Cost: " + str(cost) func _on_poison_level_up_mouse_entered() -> void: var component = current_tower.components.get(TowerComponent.ComponentType.Poison) if not component: $Components/Poison/PoisonLevelUp.tooltip_text = "" return var towers = get_selected_towers() var cost = 10 * component.level * towers.size() $Components/Poison/PoisonLevelUp.tooltip_text = "Cost: " + str(cost)