Exemplo n.º 1
0
            public void AddItemsToInventories(object sender, EventArgs eventArgs)
            {
                ThrottledBuilder.main.QueueDrained -= AddItemsToInventories;

                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 inventoryItems)
                    {
                        GameObject item;

                        try
                        {
                            item = SerializationHelper.GetGameObject(itemdata.SerializedData);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Error deserializing item data " + itemdata.Guid + " " + ex.Message);
                            continue;
                        }

                        // Mark this entity as spawned by the server
                        item.AddComponent <NitroxEntity>();

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

                        if (pickupable != null && itemdata.ContainerGuid == playerGuid)
                        {
                            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.ContainerGuid);
                        }
                    }
                }
            }
Exemplo n.º 2
0
        public override void Process(InitialPlayerSync packet)
        {
            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)
                {
                    GameObject item;

                    try
                    {
                        item = SerializationHelper.GetGameObject(itemdata.SerializedData);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error deserializing item data " + itemdata.ItemId + " " + ex.Message);
                        continue;
                    }

                    Log.Info("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);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void SpawnItemContainer(string playerGuid, List <ItemData> inventoryItems)
        {
            Log.Info("Received initial sync packet with " + inventoryItems.Count + " ItemContainer");

            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 inventoryItems)
                {
                    GameObject item;

                    try
                    {
                        item = SerializationHelper.GetGameObject(itemdata.SerializedData);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error deserializing item data " + itemdata.Guid + " " + ex.Message);
                        continue;
                    }

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

                    if (pickupable != null && itemdata.ContainerGuid == playerGuid)
                    {
                        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(itemdata);
                    }
                }
            }
        }
        private void SpawnInventoryItemsPlayer(string playerGuid, List <ItemData> inventoryItems)
        {
            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 inventoryItems)
            {
                if (itemdata.ContainerGuid == playerGuid)
                {
                    GameObject     item          = SerializationHelper.GetGameObject(itemdata.SerializedData);
                    Pickupable     pickupable    = item.RequireComponent <Pickupable>();
                    ItemsContainer container     = Inventory.Get().container;
                    InventoryItem  inventoryItem = new InventoryItem(pickupable);
                    inventoryItem.container = container;
                    inventoryItem.item.Reparent(container.tr);
                    goals.Remove(pickupable.GetTechType());  // Remove Notification Goal Event On Item You Already have On Inventory
                    container.UnsafeAdd(inventoryItem);
                }
            }
        }
Exemplo n.º 5
0
        public override void Process(RocketStageUpdate packet)
        {
            GameObject gameObjectConstructor = NitroxEntity.RequireObjectFrom(packet.ConstructorId);
            GameObject gameObjectRocket      = NitroxEntity.RequireObjectFrom(packet.Id);

            Rocket rocket = gameObjectRocket.RequireComponent <Rocket>();

            rocket.StartRocketConstruction();

            ItemGoalTracker.OnConstruct(packet.CurrentStageTech);

            RocketConstructor rocketConstructor = gameObjectConstructor.GetComponentInChildren <RocketConstructor>(true);

            if (rocketConstructor)
            {
                GameObject gameObjectTobuild = SerializationHelper.GetGameObject(packet.SerializedGameObject);
                rocketConstructor.ReflectionCall("SendBuildBots", false, false, gameObjectTobuild);
            }
            else
            {
                Log.Error($"{nameof(RocketStageUpdateProcessor)}: Can't find attached rocketconstructor with id {packet.ConstructorId} for rocket with id {packet.Id}");
            }
        }
        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");
        }
Exemplo n.º 7
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");
        }