コード例 #1
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");
        }
コード例 #2
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");
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            Vector3 position = packet.PlayerSpawnData.ToUnity();

            if (Math.Abs(position.x) < 0.0002 && Math.Abs(position.y) < 0.0002 && Math.Abs(position.z) < 0.0002)
            {
                position = Player.mainObject.transform.position;
            }
            Player.main.SetPosition(position);

            // Player position is relative to a subroot if in a subroot
            Optional <NitroxId> subRootId = packet.PlayerSubRootId;

            if (!subRootId.HasValue)
            {
                yield break;
            }
            Optional <GameObject> sub = NitroxEntity.GetObjectFrom(subRootId.Value);

            if (!sub.HasValue)
            {
                Log.Error("Could not spawn player into subroot with id: " + subRootId.Value);
                yield break;
            }
            SubRoot root = sub.Value.GetComponent <SubRoot>();

            if (root == null)
            {
                Log.Error("Could not find subroot for player for subroot with id: " + subRootId.Value);
                yield break;
            }

            // If player is not swimming
            Player.main.SetCurrentSub(root);
            if (root.isBase)
            {
                yield break;
            }
            Transform  rootTransform = root.transform;
            Quaternion vehicleAngle  = rootTransform.rotation;

            position = vehicleAngle * position;
            position = position + rootTransform.position;
            Player.main.SetPosition(position);
        }
コード例 #5
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            Vector3             position  = packet.PlayerSpawnData;
            Optional <NitroxId> subRootId = packet.PlayerSubRootId;

            if (position.x == 0 && position.y == 0 && position.z == 0)
            {
                position = Player.mainObject.transform.position;
            }
            Player.main.SetPosition(position);

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

                if (sub.IsPresent())
                {
                    SubRoot root = sub.Get().GetComponent <SubRoot>();
                    // Player position is relative to a subroot if in a subroot
                    if (root != null)
                    {
                        // If player is not swimming
                        Player.main.SetCurrentSub(root);

                        if (!root.isBase) // Additionally, if player is not in base (has to be a vehicle)
                        {
                            Quaternion vehicleAngle = root.transform.rotation;
                            position = vehicleAngle * position;
                            position = position + root.transform.position;
                            Player.main.SetPosition(position);
                        }
                    }
                    else
                    {
                        Log.Error("Could not find subroot for player for subroot with id: " + subRootId.Get());
                    }
                }
                else
                {
                    Log.Error("Could not spawn player into subroot with id: " + subRootId.Get());
                }
            }

            yield return(null);
        }
コード例 #6
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");
        }
コード例 #7
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            this.waitScreenItem      = waitScreenItem;
            vehicles.VehicleCreated += OnVehicleCreated;

            totalCyclopsToLoad = packet.Vehicles.Where(v => v.TechType.Enum() == TechType.Cyclops).Count();

            foreach (VehicleModel vehicle in packet.Vehicles)
            {
                if (vehicle.TechType.Enum() == TechType.Cyclops)
                {
                    Log.Debug($"Trying to spawn {vehicle}");
                    vehicles.CreateVehicle(vehicle);
                }
            }

            yield return(new WaitUntil(() => cyclopsLoaded == totalCyclopsToLoad));
        }
コード例 #8
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            completed = false;

            List <BasePiece> basePieces = packet.BasePieces;

            Log.Info("Received initial sync packet with " + basePieces.Count + " base pieces");

            if (basePieces.Count == 0)
            {
                completed = true;
            }
            else
            {
                QueueUpPieces(packet.BasePieces);
                ThrottledBuilder.main.QueueDrained += FinishedCompletedBuildings;
            }

            yield return(new WaitUntil(() => completed));
        }
コード例 #9
0
        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);
                }
            }
        }
コード例 #10
0
        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");
        }
コード例 #11
0
 public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
 {
     Log.Info("Received initial sync packet with " + packet.GlobalRootEntities.Count + " global root entities");
     entities.Spawn(packet.GlobalRootEntities);
     yield return(null);
 }
コード例 #12
0
 public abstract IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem);