/// <summary> /// Handle full world sync message. /// </summary> /// <param name="msg">The message to handle.</param> public void HandleFullWorldSync(Messages.FullWorldSyncMessage msg) { // Doors. foreach (Messages.DoorsInitMessage door in msg.doors) { Vector3 position = Utils.NetVec3ToGame(door.position); Game.Objects.GameDoor doors = Game.GameDoorsManager.Instance.FindGameDoors(position); Client.Assert(doors != null, $"Unable to find doors at: {position}."); if (doors.IsOpen != door.open) { doors.Open(door.open); } } // Vehicles. foreach (Messages.VehicleInitMessage vehicleMsg in msg.vehicles) { Vector3 pos = Utils.NetVec3ToGame(vehicleMsg.transform.position); Quaternion rot = Utils.NetQuatToGame(vehicleMsg.transform.rotation); NetVehicle vehicle = GetVehicle(vehicleMsg.id); Client.Assert(vehicle != null, $"Received info about non existing vehicle {vehicleMsg.id} in full world sync. (pos: {pos}, rot: {rot})"); vehicle.Teleport(pos, rot); } // Pickupables foreach (Messages.PickupableSpawnMessage pickupableMsg in msg.pickupables) { SpawnPickupable(pickupableMsg); } }
/// <summary> /// Handle full world sync message. /// </summary> /// <param name="msg">The message to handle.</param> public void HandleFullWorldSync(Messages.FullWorldSyncMessage msg) { // Read time Game.GameWorld gameWorld = Game.GameWorld.Instance; gameWorld.WorldTime = msg.dayTime; gameWorld.WorldDay = msg.day; // Read mailbox name gameWorld.PlayerLastName = msg.mailboxName; // Doors. foreach (Messages.DoorsInitMessage door in msg.doors) { Vector3 position = Utils.NetVec3ToGame(door.position); Game.Objects.GameDoor doors = Game.GameDoorsManager.Instance.FindGameDoors(position); Client.Assert(doors != null, $"Unable to find doors at: {position}."); if (doors.IsOpen != door.open) { doors.Open(door.open); } } // Lights. foreach (Messages.LightSwitchMessage light in msg.lights) { Vector3 position = Utils.NetVec3ToGame(light.pos); Game.Objects.LightSwitch lights = Game.LightSwitchManager.Instance.FindLightSwitch(position); Client.Assert(lights != null, $"Unable to find light switch at: {position}."); if (lights.SwitchStatus != light.toggle) { lights.TurnOn(light.toggle); } } // Weather. Game.GameWeatherManager.Instance.SetWeather(msg.currentWeather); // Vehicles. foreach (Messages.VehicleInitMessage vehicleMsg in msg.vehicles) { Vector3 pos = Utils.NetVec3ToGame(vehicleMsg.transform.position); Quaternion rot = Utils.NetQuatToGame(vehicleMsg.transform.rotation); NetVehicle vehicle = GetVehicle(vehicleMsg.id); Client.Assert(vehicle != null, $"Received info about non existing vehicle {vehicleMsg.id} in full world sync. (pos: {pos}, rot: {rot})"); vehicle.Teleport(pos, rot); } // Pickupables List <ushort> pickupablesIds = new List <ushort>(); foreach (var kv in netPickupables) { pickupablesIds.Add(kv.Key); } foreach (Messages.PickupableSpawnMessage pickupableMsg in msg.pickupables) { SpawnPickupable(pickupableMsg); pickupablesIds.Remove(pickupableMsg.id); } // Remove spawned (and active) pickupables that we did not get info about. foreach (ushort id in pickupablesIds) { GameObject gameObject = netPickupables[id].gameObject; if (gameObject && !gameObject.activeSelf) { continue; } DestroyPickupableLocal(id); } }