class_name UnitManager extends Node @export var stage: Stage @export var units_container: Node2D @export var money_manager: MoneyManager @export var path_manager: PathManager @export var notification_manager: NotificationManager func spawn_unit(unit: Unit, spawn: Spawn, overwrite_target: PathNode = null): if not can_spawn_unit(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 if overwrite_target: unit.target = overwrite_target spawn_unit_in_stage.rpc(inst_to_dict(unit.to_network_data())) @rpc("any_peer", "call_local") func spawn_unit_in_stage(remote_data: Dictionary): var data: Unit.NetworkData = dict_to_inst(remote_data) var unit := Unit.from_network_data(data) var player = Network.get_player(unit.owner_id) player.units.append(unit) player.money -= unit.unit_resource.cost player.income += unit.unit_resource.income Network.players_changed.emit() #if multiplayer.is_server(): # TODO: TeamManager #unit.reached_goal.connect(func(): #var team = get_team(player) #if team == teams.top: #update_lives.rpc("bottom", -1) #elif team == teams.bottom: #update_lives.rpc("top", -1) #) unit.sprite.modulate = player.get_color() units_container.add_child(unit, true) func can_spawn_unit(unit: Unit): if Client.player.money < unit.unit_resource.cost: notification_manager.add_status_message("Not enough money to spawn unit") return false return true