extends Node signal stage_state_changed(state: State) @warning_ignore("unused_signal") signal placed_tower(tower: Tower) signal multi_select_finished(nodes) var state: State : set(value): state = value stage_state_changed.emit(value) var current_stage: Stage var selection: SelectionManager var player: Player: get(): return Network.get_player(multiplayer.get_unique_id()) func initialize_stage(stage: Stage): current_stage = stage func ready_stage(_stage: Stage): selection = preload("res://Game/Selection/SelectionManager.tscn").instantiate() add_child(selection) func place_tower(tower: Tower): if not current_stage.can_place_tower(): return var network_id = multiplayer.get_unique_id() tower.owner_id = network_id tower.name = "Tower@" + str(network_id) + "@" + str(Time.get_ticks_usec()) #tower.attack_range = [ #current_stage.map.tile_set.tile_size.x * 2, #current_stage.map.tile_set.tile_size.x * 3, #current_stage.map.tile_set.tile_size.x * 4, #].pick_random() #tower.attack_power = [1, 2, 3, 4].pick_random() #tower.attack_speed = [1, 2, 3, 4].pick_random() current_stage.place_tower.rpc(inst_to_dict(tower.to_network_data())) func remove_tower(tower: Tower): if tower.owner_id == multiplayer.get_unique_id(): destroy_tower(tower) func destroy_tower(tower: Tower): current_stage.destroy_tower(tower) Network.destroy_tower.rpc(inst_to_dict(tower.to_network_data())) player.towers.erase(tower.global_position) func select_tower(tower: Tower): if tower.owner_id == multiplayer.get_unique_id(): tower.is_selected = true func multi_select(layer: int): var selection_area = preload("res://Game/Selection/MultiSelectArea.tscn").instantiate() selection_area.set_collision_mask_value(layer, true) selection_area.select.connect(func(nodes): for node in nodes: Client.select_tower(node) multi_select_finished.emit(nodes) ) get_tree().current_scene.add_child(selection_area) func update_tower(path: NodePath, data: Tower.NetworkData): Network.update_tower.rpc(path, inst_to_dict(data)) func spawn_unit(unit: Unit, spawn: Spawn, overwrite_target: PathNode = null): if not current_stage.can_spawn_unit(): return var network_id = multiplayer.get_unique_id() unit.owner_id = network_id unit.name = "Unit@" + str(network_id) + "@" + str(Time.get_ticks_usec()) unit.global_position = spawn.spawn_position unit.target = spawn.next_node #unit.hp = randi_range(5, 10) #20000b #unit.base_speed = randi_range(50, 150) if overwrite_target: unit.target = overwrite_target #var data := UnitCreationData.fromUnit(unit) current_stage.spawn_unit.rpc(inst_to_dict(unit.to_network_data())) func update_unit(path: NodePath, data: Unit.NetworkData): Network.update_unit.rpc(path, inst_to_dict(data)) func change_scene_to_instance(scene: Node): (func(): get_tree().current_scene.queue_free() get_tree().root.add_child(scene) get_tree().current_scene = scene ).call_deferred() func array_intersect(first, second): var compare = {} for value in first: compare[value] = true for value in second: if compare.get(value, false): return true return false