Exemple #1
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            SetCompletedStoryGoals(packet.StoryGoalData.CompletedGoals);
            waitScreenItem.SetProgress(0.33f);
            yield return(null);

            SetRadioQueue(packet.StoryGoalData.RadioQueue);
            waitScreenItem.SetProgress(0.66f);
            yield return(null);

            SetGoalUnlocks(packet.StoryGoalData.GoalUnlocks);
            waitScreenItem.SetProgress(1f);
            yield return(null);
        }
Exemple #2
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int remotePlayersSynced = 0;

            foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData)
            {
                waitScreenItem.SetProgress(remotePlayersSynced, packet.RemotePlayerData.Count);

                List <TechType> equippedTechTypes = playerData.EquippedTechTypes.Select(techType => techType.Enum()).ToList();
                RemotePlayer    player            = remotePlayerManager.Create(playerData.PlayerContext, equippedTechTypes);

                if (playerData.SubRootId.IsPresent())
                {
                    Optional <GameObject> sub = NitroxEntity.GetObjectFrom(playerData.SubRootId.Get());

                    if (sub.IsPresent())
                    {
                        player.SetSubRoot(sub.Get().GetComponent <SubRoot>());
                    }
                    else
                    {
                        Log.Error("Could not spawn remote player into subroot with id: " + playerData.SubRootId.Get());
                    }
                }

                remotePlayersSynced++;
                yield return(null);
            }
        }
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int storageSlotsSynced = 0;

            HashSet <NitroxId> onlinePlayers = new HashSet <NitroxId> {
                packet.PlayerGameObjectId
            };

            onlinePlayers.AddRange(packet.RemotePlayerData.Select(playerData => playerData.PlayerContext.PlayerNitroxId));

            // Removes any batteries which are in inventories from offline players
            List <ItemData> currentlyIgnoredItems = packet.InventoryItems.Where(item => !onlinePlayers.Any(player => player.Equals(item.ContainerId))).ToList();

            packet.StorageSlotItems.RemoveAll(storageItem => currentlyIgnoredItems.Any(ignoredItem => ignoredItem.ItemId.Equals(storageItem.ContainerId)));

            using (packetSender.Suppress <StorageSlotItemAdd>())
            {
                foreach (ItemData itemData in packet.StorageSlotItems)
                {
                    waitScreenItem.SetProgress(storageSlotsSynced, packet.StorageSlotItems.Count);

                    GameObject item = SerializationHelper.GetGameObject(itemData.SerializedData);

                    Log.Debug($"Initial StorageSlot item data for {item.name} giving to container {itemData.ContainerId}");

                    NitroxEntity.SetNewId(item, itemData.ItemId);
                    slots.AddItem(item, itemData.ContainerId, true);

                    storageSlotsSynced++;
                    yield return(null);
                }
            }
        }
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            SetPlayerGameObjectId(packet.PlayerGameObjectId);
            waitScreenItem.SetProgress(0.25f);
            yield return(null);

            AddStartingItemsToPlayer(packet.FirstTimeConnecting);
            waitScreenItem.SetProgress(0.5f);
            yield return(null);

            SetPlayerStats(packet.PlayerStatsData);
            waitScreenItem.SetProgress(0.75f);
            yield return(null);

            SetPlayerGameMode(packet.GameMode);
            waitScreenItem.SetProgress(1f);
            yield return(null);
        }
Exemple #5
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int totalItemDataSynced = 0;

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                ItemGoalTracker itemGoalTracker = (ItemGoalTracker)typeof(ItemGoalTracker).GetField("main", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
                Dictionary <TechType, List <ItemGoal> > goals = (Dictionary <TechType, List <ItemGoal> >)(typeof(ItemGoalTracker).GetField("goals", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(itemGoalTracker));

                foreach (ItemData itemdata in packet.InventoryItems)
                {
                    waitScreenItem.SetProgress(totalItemDataSynced, packet.InventoryItems.Count);

                    GameObject item;

                    try
                    {
                        item = SerializationHelper.GetGameObject(itemdata.SerializedData);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, $"Error deserializing item data. Id: {itemdata.ItemId}");
                        continue;
                    }

                    Log.Debug($"Initial item data for {item.name} giving to container {itemdata.ContainerId}");

                    Pickupable pickupable = item.GetComponent <Pickupable>();

                    if (pickupable != null && itemdata.ContainerId == packet.PlayerGameObjectId)
                    {
                        goals.Remove(pickupable.GetTechType());  // Remove Notification Goal Event On Item Player Already have On Any Container

                        ItemsContainer container     = Inventory.Get().container;
                        InventoryItem  inventoryItem = new InventoryItem(pickupable);
                        inventoryItem.container = container;
                        inventoryItem.item.Reparent(container.tr);

                        container.UnsafeAdd(inventoryItem);
                    }
                    else
                    {
                        itemContainers.AddItem(item, itemdata.ContainerId);

                        ContainerAddItemPostProcessor postProcessor = ContainerAddItemPostProcessor.From(item);
                        postProcessor.process(item, itemdata);
                    }

                    totalItemDataSynced++;
                    yield return(null);
                }
            }

            Log.Info($"Received initial sync with {totalItemDataSynced} inventory items");
        }
        private void OnVehicleCreated(GameObject gameObject)
        {
            waitScreenItem.SetProgress((totalCyclopsToLoad - cyclopsStillLoading), totalCyclopsToLoad);

            cyclopsStillLoading--;

            // After all cyclops are created
            if (cyclopsStillLoading == 0)
            {
                vehicles.VehicleCreated -= OnVehicleCreated;
            }
        }
Exemple #7
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int totalEquippedItemsDone = 0;

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                foreach (EquippedItemData equippedItem in packet.EquippedItems)
                {
                    waitScreenItem.SetProgress(totalEquippedItemsDone, packet.EquippedItems.Count);

                    GameObject gameObject = SerializationHelper.GetGameObject(equippedItem.SerializedData);
                    NitroxEntity.SetNewId(gameObject, equippedItem.ItemId);

                    Pickupable            pickupable   = gameObject.RequireComponent <Pickupable>();
                    Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(equippedItem.ContainerId);

                    if (opGameObject.HasValue)
                    {
                        GameObject owner = opGameObject.Value;

                        Optional <Equipment> opEquipment = EquipmentHelper.FindEquipmentComponent(owner);

                        if (opEquipment.HasValue)
                        {
                            Equipment     equipment     = opEquipment.Value;
                            InventoryItem inventoryItem = new(pickupable);
                            inventoryItem.container = equipment;
                            inventoryItem.item.Reparent(equipment.tr);

                            Dictionary <string, InventoryItem> itemsBySlot = equipment.equipment;
                            itemsBySlot[equippedItem.Slot] = inventoryItem;

                            equipment.UpdateCount(pickupable.GetTechType(), true);
                            Equipment.SendEquipmentEvent(pickupable, 0, owner, equippedItem.Slot);
                            equipment.NotifyEquip(equippedItem.Slot, inventoryItem);
                        }
                        else
                        {
                            Log.Info("Could not find equipment type for " + gameObject.name);
                        }
                    }
                    else
                    {
                        Log.Info("Could not find Container for " + gameObject.name);
                    }

                    totalEquippedItemsDone++;
                    yield return(null);
                }
            }

            Log.Info("Recieved initial sync with " + totalEquippedItemsDone + " pieces of equipped items");
        }
Exemple #8
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            SetEncyclopediaEntry(packet.PDAData.EncyclopediaEntries);
            waitScreenItem.SetProgress(0.17f);
            yield return(null);

            SetPDAEntryComplete(packet.PDAData.UnlockedTechTypes);
            waitScreenItem.SetProgress(0.33f);
            yield return(null);

            SetPDAEntryPartial(packet.PDAData.PartiallyUnlockedTechTypes);
            waitScreenItem.SetProgress(0.5f);
            yield return(null);

            SetKnownTech(packet.PDAData.KnownTechTypes, packet.PDAData.AnalyzedTechTypes);
            waitScreenItem.SetProgress(0.67f);
            yield return(null);

            SetPDALog(packet.PDAData.PDALogEntries);
            waitScreenItem.SetProgress(0.83f);
            yield return(null);

            SetCachedProgress(packet.PDAData.CachedProgress);
            waitScreenItem.SetProgress(1f);
            yield return(null);
        }
Exemple #9
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int idsSynced = 0;

            foreach (NitroxId entityId in packet.InitialSimulationOwnerships)
            {
                waitScreenItem.SetProgress(idsSynced++, packet.InitialSimulationOwnerships.Count);
                // Initial locks are transient
                simulationOwnership.SimulateEntity(entityId, SimulationLockType.TRANSIENT);
                Log.Debug($"Transient simulation ownership for {entityId} from initial sync");
            }
            yield return(null);
        }
        private void OnVehicleCreated(GameObject gameObject)
        {
            cyclopsLoaded++;
            waitScreenItem.SetProgress(cyclopsLoaded, totalCyclopsToLoad);

            // After all cyclops are created
            if (cyclopsLoaded == totalCyclopsToLoad)
            {
                vehicles.VehicleCreated -= OnVehicleCreated;
                Log.Debug($"Spawned cyclops {NitroxEntity.GetId(gameObject)}");
            }

            Log.Debug($"We still need to load {totalCyclopsToLoad - cyclopsLoaded} cyclops");
        }
Exemple #11
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int remotePlayersSynced = 0;

            foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData)
            {
                waitScreenItem.SetProgress(remotePlayersSynced, packet.RemotePlayerData.Count);

                List <TechType> equippedTechTypes = playerData.EquippedTechTypes.Select(techType => techType.ToUnity()).ToList();
                RemotePlayer    player            = remotePlayerManager.Create(playerData.PlayerContext, equippedTechTypes);

                if (playerData.SubRootId.HasValue)
                {
                    Optional <GameObject> sub = NitroxEntity.GetObjectFrom(playerData.SubRootId.Value);

                    if (sub.HasValue)
                    {
                        Log.Debug($"sub value set to {sub.Value}. Try to find subroot");
                        SubRoot subroot = null;
                        sub.Value.TryGetComponent <SubRoot>(out subroot);
                        if (subroot != null)
                        {
                            Log.Debug("Found subroot for player. Will add him and update animation.");
                            player.SetSubRoot(subroot);
                            // Set the animation for the remote player to standing instead of swimming if player is not in a flooded subroot
                            if (!subroot.IsUnderwater(player.Body.transform.position))
                            {
                                player.UpdateAnimation(AnimChangeType.UNDERWATER, AnimChangeState.OFF);
                            }
                        }
                        Log.Debug("Trying to find escape pod.");
                        EscapePod escapePod = null;
                        sub.Value.TryGetComponent <EscapePod>(out escapePod);
                        if (escapePod != null)
                        {
                            Log.Debug("Found escape pod for player. Will add him and update animation.");
                            player.UpdateAnimation(AnimChangeType.UNDERWATER, AnimChangeState.OFF);
                        }
                    }
                    else
                    {
                        Log.Error("Could not spawn remote player into subroot/escape pod with id: " + playerData.SubRootId.Value);
                    }
                }

                remotePlayersSynced++;
                yield return(null);
            }
        }
Exemple #12
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int totalSyncedVehicles    = 0;
            int nonCyclopsVehicleCount = packet.Vehicles.Where(v => v.TechType.ToUnity() != TechType.Cyclops).Count();

            foreach (VehicleModel vehicle in packet.Vehicles)
            {
                if (vehicle.TechType.ToUnity() != TechType.Cyclops)
                {
                    waitScreenItem.SetProgress(totalSyncedVehicles, nonCyclopsVehicleCount);
                    vehicles.CreateVehicle(vehicle);
                    totalSyncedVehicles++;
                    yield return(null);
                }
            }

            Log.Info("Recieved initial sync with " + totalSyncedVehicles + " non-cyclops vehicles");
        }
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int remotePlayersSynced = 0;

            foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData)
            {
                waitScreenItem.SetProgress(remotePlayersSynced, packet.RemotePlayerData.Count);

                List <TechType> equippedTechTypes = playerData.EquippedTechTypes.Select(techType => techType.ToUnity()).ToList();

                RemotePlayer player = remotePlayerManager.Create(playerData.PlayerContext, playerData.SubRootId, equippedTechTypes, new List <Pickupable>());

                if (!IsSwimming(playerData.Position.ToUnity(), playerData.SubRootId))
                {
                    player.UpdateAnimation(AnimChangeType.UNDERWATER, AnimChangeState.OFF);
                }
                remotePlayersSynced++;
                yield return(null);
            }
        }
        private IEnumerator RunPendingProcessors()
        {
            processorsRanLastCycle = 0;

            foreach (InitialSyncProcessor processor in processors)
            {
                if (IsWaitingToRun(processor.GetType()) && HasDependenciesSatisfied(processor))
                {
                    loadingMultiplayerWaitItem.SetProgress(cumulativeProcessorsRan, processors.Count);

                    Log.Info("Running " + processor.GetType());
                    alreadyRan.Add(processor.GetType());
                    processorsRanLastCycle++;
                    cumulativeProcessorsRan++;

                    subWaitScreenItem = WaitScreen.Add("Running " + processor.GetType().Name);
                    yield return(Multiplayer.Main.StartCoroutine(processor.Process(packet, subWaitScreenItem)));

                    WaitScreen.Remove(subWaitScreenItem);
                }
            }
        }
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int storageSlotsSynced = 0;

            using (packetSender.Suppress <StorageSlotItemAdd>())
            {
                foreach (ItemData itemData in packet.StorageSlots)
                {
                    waitScreenItem.SetProgress(storageSlotsSynced, packet.StorageSlots.Count);

                    GameObject item = SerializationHelper.GetGameObject(itemData.SerializedData);

                    Log.Debug($"Initial StorageSlot item data for {item.name} giving to container {itemData.ContainerId}");

                    NitroxEntity.SetNewId(item, itemData.ItemId);
                    slots.AddItem(item, itemData.ContainerId, true);

                    storageSlotsSynced++;
                    yield return(null);
                }
            }
        }
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int basePiecesWithMetadata = 0;
            int basePiecesChecked      = 0;

            foreach (BasePiece basePiece in packet.BasePieces)
            {
                waitScreenItem.SetProgress(basePiecesChecked, packet.BasePieces.Count);

                if (basePiece.Metadata.HasValue)
                {
                    BasePieceMetadata          metadata          = basePiece.Metadata.Value;
                    BasePieceMetadataProcessor metadataProcessor = BasePieceMetadataProcessor.FromMetaData(metadata);
                    metadataProcessor.UpdateMetadata(basePiece.Id, metadata);
                    basePiecesWithMetadata++;
                }

                basePiecesChecked++;
                yield return(null);
            }

            Log.Info("Received initial sync packet having " + basePiecesWithMetadata + " base pieces with meta data");
        }
        private static IEnumerator PreloadCustomMusic()
        {
            WaitScreen.ManualWaitItem waitItemCustomMusic = null;
            yield return(new WaitUntil(() => WaitScreen.main != null));

            waitItemCustomMusic = WaitScreen.Add("Preloading custom music ♫");

            foreach (var audioClipPath in CustomMusic.ToList())
            {
                if (audioClipPath.Value == null)
                {
                    var loadTrackTask = LoadTrack(audioClipPath.Key);
                    yield return(loadTrackTask);

                    yield return(new WaitWhile(() => loadTrackTask.GetResult() == null));

                    var audioClip = loadTrackTask.GetResult();

                    if (audioClip.AudioClip == null)
                    {
                        CustomMusic.Remove(audioClipPath.Key);
                        failedPaths.Add(audioClipPath.Key);
                    }
                    else
                    {
                        yield return(new WaitWhile(() => audioClip.AudioClip.loadState == AudioDataLoadState.Loading));

                        RegisterAudioClip(audioClipPath.Key, audioClip.AudioClip);
                    }

                    waitItemCustomMusic.SetProgress(CustomMusic.Count(x => x.Value != null), CustomMusic.Count());
                }
            }

            WaitScreen.Remove(waitItemCustomMusic);
            CustomMusicPreload = null;
        }
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int totalItemDataSynced = 0;

            HashSet <NitroxId> onlinePlayers = new HashSet <NitroxId> {
                packet.PlayerGameObjectId
            };

            onlinePlayers.AddRange(packet.RemotePlayerData.Select(playerData => playerData.PlayerContext.PlayerNitroxId));

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                ItemGoalTracker itemGoalTracker = (ItemGoalTracker)typeof(ItemGoalTracker).GetField("main", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
                Dictionary <TechType, List <ItemGoal> > goals = (Dictionary <TechType, List <ItemGoal> >)(typeof(ItemGoalTracker).GetField("goals", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(itemGoalTracker));

                foreach (ItemData itemData in packet.InventoryItems)
                {
                    waitScreenItem.SetProgress(totalItemDataSynced, packet.InventoryItems.Count);

                    GameObject item;

                    try
                    {
                        item = SerializationHelper.GetGameObject(itemData.SerializedData);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, $"Error deserializing item data. Id: {itemData.ItemId}");
                        continue;
                    }

                    Log.Debug($"Initial item data for {item.name} giving to container {itemData.ContainerId}");

                    Pickupable pickupable = item.GetComponent <Pickupable>();

                    if (pickupable && itemData.ContainerId == packet.PlayerGameObjectId)
                    {
                        goals.Remove(pickupable.GetTechType());  // Remove notification goal event from item player has in any container

                        ItemsContainer container     = Inventory.Get().container;
                        InventoryItem  inventoryItem = new InventoryItem(pickupable)
                        {
                            container = container
                        };
                        inventoryItem.item.Reparent(container.tr);

                        container.UnsafeAdd(inventoryItem);
                    }
                    else if (onlinePlayers.Any(playerId => playerId.Equals(itemData.ContainerId)))
                    {
                        itemContainers.AddItem(item, itemData.ContainerId);

                        ContainerAddItemPostProcessor postProcessor = ContainerAddItemPostProcessor.From(item);
                        postProcessor.process(item, itemData);
                    }

                    totalItemDataSynced++;
                    yield return(null);
                }

                foreach (NitroxTechType usedItem in packet.UsedItems)
                {
                    Player.main.AddUsedTool(usedItem.ToUnity());
                }

                string[] quickSlotsBinding = packet.QuickSlotsBinding.ToArray();
                Inventory.main.serializedQuickSlots = quickSlotsBinding;
                Inventory.main.quickSlots.RestoreBinding(quickSlotsBinding);
            }

            Log.Info($"Received initial sync with {totalItemDataSynced} inventory items");
        }
Exemple #19
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int totalItemDataSynced = 0;

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                ItemGoalTracker itemGoalTracker = (ItemGoalTracker)itemGoalTrackerMainField.GetValue(null);
                Dictionary <TechType, List <ItemGoal> > goals = (Dictionary <TechType, List <ItemGoal> >)itemGoalTrackerGoalsField.GetValue(itemGoalTracker);

                foreach (ItemData itemData in packet.InventoryItems)
                {
                    waitScreenItem.SetProgress(totalItemDataSynced, packet.InventoryItems.Count);

                    GameObject item;

                    try
                    {
                        item = SerializationHelper.GetGameObject(itemData.SerializedData);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, $"Error deserializing item data. Id: {itemData.ItemId}");
                        continue;
                    }

                    Log.Debug($"Initial item data for {item.name} giving to container {itemData.ContainerId}");

                    Pickupable pickupable = item.GetComponent <Pickupable>();
                    Validate.NotNull(pickupable);

                    if (itemData.ContainerId == packet.PlayerGameObjectId)
                    {
                        goals.Remove(pickupable.GetTechType());  // Remove notification goal event from item player has in any container

                        ItemsContainer container     = Inventory.Get().container;
                        InventoryItem  inventoryItem = new InventoryItem(pickupable)
                        {
                            container = container
                        };
                        inventoryItem.item.Reparent(container.tr);

                        container.UnsafeAdd(inventoryItem);
                    }
                    else if (NitroxEntity.TryGetObjectFrom(itemData.ContainerId, out GameObject containerOwner))
                    {
                        Optional <ItemsContainer> opContainer = InventoryContainerHelper.TryGetContainerByOwner(containerOwner);
                        Validate.IsPresent(opContainer);
                        opContainer.Value.UnsafeAdd(new InventoryItem(pickupable));

                        ContainerAddItemPostProcessor postProcessor = ContainerAddItemPostProcessor.From(item);
                        postProcessor.process(item, itemData);
                    }

                    totalItemDataSynced++;
                    yield return(null);
                }

                foreach (NitroxTechType usedItem in packet.UsedItems)
                {
                    Player.main.AddUsedTool(usedItem.ToUnity());
                }

                string[] quickSlotsBinding = packet.QuickSlotsBinding.ToArray();
                Inventory.main.serializedQuickSlots = quickSlotsBinding;
                Inventory.main.quickSlots.RestoreBinding(quickSlotsBinding);
            }

            Log.Info($"Received initial sync with {totalItemDataSynced} inventory items");
        }