public static Optional <ItemsContainer> GetBasedOnOwnersType(GameObject owner)
        {
            SeamothStorageContainer seamothStorageContainer = owner.GetComponent <SeamothStorageContainer>();

            if (seamothStorageContainer != null)
            {
                return(Optional.Of(seamothStorageContainer.container));
            }
            StorageContainer storageContainer = owner.GetComponentInChildren <StorageContainer>();

            if (storageContainer != null)
            {
                return(Optional.Of(storageContainer.container));
            }
            BaseBioReactor baseBioReactor = owner.GetComponentInChildren <BaseBioReactor>();

            if (baseBioReactor != null)
            {
                ItemsContainer container = (ItemsContainer)baseBioReactor.ReflectionGetProperty("container");
                return(Optional.Of(container));
            }
            if (owner.name == "Player")
            {
                return(Optional.Of(Inventory.Get().container));
            }

            Log.Debug("Couldn't resolve container from gameObject: " + owner.name);

            return(Optional.Empty);
        }
Esempio n. 2
0
        public void OnPickup()
        {
            SeamothArmManager control      = ThisSeamoth.GetComponent <SeamothArmManager>();
            GameObject        activeTarget = control.GetActiveTarget();

            if (activeTarget)
            {
                Pickupable pickupable = activeTarget.GetComponent <Pickupable>();
                PickPrefab component  = activeTarget.GetComponent <PickPrefab>();

                ItemsContainer container = control.GetRoomForItem(pickupable);

                if (pickupable != null && pickupable.isPickupable && container != null)
                {
                    pickupable = pickupable.Initialize();
                    InventoryItem item = new InventoryItem(pickupable);
                    container.UnsafeAdd(item);
                    Utils.PlayFMODAsset(pickupSound, front, 5f);
                }
                else if (component != null && component.AddToContainer(container))
                {
                    component.SetPickedUp();
                }
            }
        }
        internal static bool PreAlterMaxSpeed(UnderwaterMotor __instance, float __result, ref float inMaxSpeed)
        {
            // AlterMaxSpeed is a complete mess and damn-near impossible to expand without transpiling a whole lot of it.
            // So I said "f**k it" and replace the entire thing.

            //Log.LogDebug($"UnderwaterMotorPatches.PreAlterMaxSpeed: inMaxSpeed = {inMaxSpeed}");
            Inventory      main           = Inventory.main;
            Equipment      equipment      = main.equipment;
            ItemsContainer container      = main.container;
            TechType       techTypeInSlot = equipment.GetTechTypeInSlot("Tank");

            inMaxSpeed += GetSpeedModifier(techTypeInSlot);

//			int count = container.GetCount(TechType.HighCapacityTank);
//			inMaxSpeed = Mathf.Max(inMaxSpeed - (float)count * 1.275f, 2f);

            TechType techTypeInSlot2 = equipment.GetTechTypeInSlot("Body");

            inMaxSpeed += GetSpeedModifier(techTypeInSlot2);

#if SUBNAUTICA_STABLE
//			float num2 = 1f;
//			global::Utils.AdjustSpeedScalarFromWeakness(ref num2);
//			inMaxSpeed *= num2;
#endif
            TechType techTypeInSlot3 = equipment.GetTechTypeInSlot("Foots");
            inMaxSpeed += GetSpeedModifier(techTypeInSlot3);

            //Log.LogDebug($"UnderwaterMotor.PreAlterMaxSpeed: got out inMaxSpeed {inMaxSpeed}");
            return(true);
        }
        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       = SerializationHelper.GetGameObject(itemdata.SerializedData);
                    Pickupable pickupable = item.RequireComponent <Pickupable>();
                    goals.Remove(pickupable.GetTechType());  // Remove Notification Goal Event On Item Player Already have On Any Container

                    if (itemdata.ContainerGuid == playerGuid)
                    {
                        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);
                    }
                }
            }
        }
Esempio n. 5
0
        private IEnumerator GetItemsContainer(string slotName)
        {
            SNLogger.Log($"[SeamothArms] GetItemsContainer coroutine started for this Seamoth: {ThisSeamoth.GetInstanceID()}");

            while (container == null)
            {
                container = ThisSeamoth.GetStorageInSlot(ThisSeamoth.GetSlotIndex(slotName), SeamothTorpedoArmPrefab.TechTypeID);

                SNLogger.Log($"[SeamothArms] ItemsContainer is not ready for this Seamoth: {ThisSeamoth.GetInstanceID()}");
                yield return(null);
            }

            SNLogger.Log($"[SeamothArms] ItemsContainer is ready for this Seamoth: {ThisSeamoth.GetInstanceID()}");
            SNLogger.Log($"[SeamothArms] GetItemsContainer coroutine stopped for this Seamoth: {ThisSeamoth.GetInstanceID()}");

            if (container != null)
            {
                container.SetAllowedTechTypes(GetTorpedoTypes());
                container.onAddItem    += OnAddItem;
                container.onRemoveItem += OnRemoveItem;
                UpdateVisuals();
            }

            yield break;
        }
Esempio n. 6
0
        private static void HasRoomFor_Postfix(ItemsContainer __instance, bool __result, Vector2int __state)
        {
            // We should only enter this method if the Prefix didn't have a cached value to use
            // Catch the result and map it to the size provided by the Prefix

            ItemStorageHelper.Singleton.CacheNewHasRoomData(__instance, __state, __result);
        }
Esempio n. 7
0
        public void AddItem(ItemData itemData)
        {
            Optional <GameObject> owner = GuidHelper.GetObjectFrom(itemData.ContainerGuid);

            if (owner.IsEmpty())
            {
                Log.Info("Unable to find inventory container with id: " + itemData.ContainerGuid);
                return;
            }

            Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner.Get());

            if (opContainer.IsPresent())
            {
                ItemsContainer container  = opContainer.Get();
                GameObject     item       = SerializationHelper.GetGameObject(itemData.SerializedData);
                Pickupable     pickupable = item.RequireComponent <Pickupable>();

                using (packetSender.Suppress <ItemContainerAdd>())
                {
                    container.UnsafeAdd(new InventoryItem(pickupable));
                }
            }
            else
            {
                Log.Error("Could not find container field on object " + owner.Get().name);
            }
        }
Esempio n. 8
0
        public void AddItem(GameObject item, NitroxId containerId)
        {
            Optional <GameObject> owner = NitroxEntity.GetObjectFrom(containerId);

            if (!owner.HasValue)
            {
                Log.Info("Unable to find inventory container with id: " + containerId);
                return;
            }
            Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner.Value);

            if (!opContainer.HasValue)
            {
                Log.Error("Could not find container field on object " + owner.Value.name);
                return;
            }

            ItemsContainer container  = opContainer.Value;
            Pickupable     pickupable = item.RequireComponent <Pickupable>();

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                container.UnsafeAdd(new InventoryItem(pickupable));
            }
        }
Esempio n. 9
0
        private IEnumerator CookAll(ItemsContainer container)
        {
            var list = new List <TechType>();

            _isCooking  = true;
            _targetTime = QPatch.Configuration.Config.CookTime * container.count;
            OnCookingStart?.Invoke(_rawTechType, GetCookedFood(_rawTechType));

            while (!_continue)
            {
                yield return(null);
            }

            QuickLogger.Debug("Transferring Cooked Items", true);

            foreach (InventoryItem item in container)
            {
                _rawTechType = item.item.GetTechType();
                list.Add(GetCookedFood(_rawTechType));
                QuickLogger.Debug($"Cooked food {_rawTechType}", true);
            }

            Reset();

            OnFoodCookedAll?.Invoke(_rawTechType, list);
        }
        protected override void ShowMore()
        {
            base.ShowMore();

            var req = new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++ *ItemsPerPage);

            req.Success += beatmaps =>
            {
                ShowMoreButton.FadeTo(beatmaps.Count == ItemsPerPage ? 1 : 0);
                ShowMoreLoading.Hide();

                if (!beatmaps.Any() && VisiblePages == 1)
                {
                    MissingText.Show();
                    return;
                }

                MissingText.Hide();

                foreach (var beatmap in beatmaps)
                {
                    ItemsContainer.Add(new DrawableMostPlayedRow(beatmap.GetBeatmapInfo(Rulesets), beatmap.PlayCount));
                }
            };

            Api.Queue(req);
        }
        internal bool SendItems(ItemsContainer items, AlterraShippingTarget target)
        {
            QuickLogger.Debug($"Starting Transfer to {target.GetInstanceID()}", true);
            QuickLogger.Debug($"Target Found: {target.Name}", true);
            QuickLogger.Debug($"Target IsReceivingTransfer: {target.IsReceivingTransfer}", true);

            if (_mono == null)
            {
                _mono = gameObject.GetComponent <AlterraShippingTarget>();
            }

            if (!target.IsReceivingTransfer)
            {
                QuickLogger.Debug($"Starting Transfer to {target.Name}", true);
                _target = target;
                _items  = items;
                _done   = false;
                _target.IsReceivingTransfer = true;
                _currentTime = GetTime(_target);
                _target.OnReceivingTransfer?.Invoke();
            }
            else
            {
                QuickLogger.Message(string.Format(AlterraShippingBuildable.TargetIsShipping(), _target.Name), true);
            }

            return(true);
        }
        private void InitializeRodsContainer()
        {
            if (_rodsRoot == null)
            {
                QuickLogger.Debug("Initializing StorageRoot");
                var storageRoot = new GameObject("StorageRoot");
                storageRoot.transform.SetParent(this.transform, false);
                _rodsRoot = storageRoot.AddComponent <ChildObjectIdentifier>();
            }

            if (RodsContainer == null)
            {
                QuickLogger.Debug("Initializing RodsContainer");
                RodsContainer = new ItemsContainer(ContainerWidth, ContainerHeight, _rodsRoot.transform, CyNukReactorBuildable.StorageLabel(), null);
                RodsContainer.SetAllowedTechTypes(new[] { TechType.ReactorRod, TechType.DepletedReactorRod });

                RodsContainer.isAllowedToAdd    += IsAllowedToAdd;
                RodsContainer.isAllowedToRemove += IsAllowedToRemove;

                RodsContainer.onAddItem    += OnAddItem;
                RodsContainer.onRemoveItem += OnRemoveItem;

                RodsContainer.onChangeItemPosition += RodsContainer_onChangeItemPosition;
            }
        }
        public static ItemsContainer GetOpenContainer()
        {
            int storageCount = Inventory.main.usedStorage.Count;

            if (Inventory.main.usedStorage.Count > 0)
            {
                IItemsContainer itemsContainer = Inventory.main.usedStorage[storageCount - 1];

                if (itemsContainer is ItemsContainer)
                {
                    ItemsContainer container = itemsContainer as ItemsContainer;
                    GameObject     parent    = container.tr.parent.gameObject;
                    //AddDebug(" parent " + parent.name);
                    //Main.Log(" parent " + parent.name);
                    //if (parent.GetComponentInChildren<Aquarium>())
                    if (parent.name == "Aquarium(Clone)")
                    {
                        //AddDebug(container.tr.name + " Aquarium ");
                        return(null);
                    }
                    return(container);
                }
            }
            return(null);
        }
        internal void Setup(FCSDeepDrillerController mono)
        {
            _mono = mono;

            _isConstructed = () => mono.IsConstructed;

            if (_containerRoot == null)
            {
                QuickLogger.Debug("Initializing Deep Driller StorageRoot");
                var storageRoot = new GameObject("DeepDrillerStorageRoot");
                storageRoot.transform.SetParent(mono.transform, false);
                _containerRoot = storageRoot.AddComponent <ChildObjectIdentifier>();
            }

            if (_container == null)
            {
                QuickLogger.Debug("Initializing Deep Driller Container");

                _container = new ItemsContainer(_containerWidth, _containerHeight, _containerRoot.transform,
                                                FCSDeepDrillerBuildable.StorageContainerLabel(), null);
                _container.Resize(_containerWidth, _containerHeight);
                _container.isAllowedToAdd += IsAllowedToAdd;
                _container.onRemoveItem   += OnRemoveItemEvent;
            }

            DayNightCycle main = DayNightCycle.main;

            //if (_timeSpawnMedKit < 0.0 && main)
            //{
            //    this._timeSpawnMedKit = (float)(main.timePassed + (!this.startWithMedKit ? (double)MedKitSpawnInterval : 0.0));
            //}
        }
 public static void Postfix(ItemsContainer __instance, InventoryItem item)
 {
     if (item != null && sessionManager.CurrentState.GetType() != typeof(Disconnected))
     {
         NitroxServiceLocator.LocateService <ItemContainers>().BroadcastItemRemoval(item.item, __instance.tr);
     }
 }
Esempio n. 16
0
        private void OpenPDA()
        {
            bool isStorageTypeExists = TechTypeHandler.TryGetModdedTechType(storageModuleString, out TechType techType);

            if (!isStorageTypeExists)
            {
                return;
            }

            ItemsContainer storageInSlot = helper.GetSeamothStorageInSlot(slotID, techType);

            if (storageInSlot != null)
            {
                PDA pda = Player.main.GetPDA();

                Inventory.main.SetUsedStorage(storageInSlot, false);

                if (!pda.Open(PDATab.Inventory, tr, new PDA.OnClose(OnClosePDA)))
                {
                    OnClosePDA(pda);
                }
            }
            else
            {
                OnClosePDA(null);
            }
        }
 public static void Postfix(ItemsContainer __instance, InventoryItem item)
 {
     if (item != null && __instance.tr.parent.name != "EscapePod" && __instance.tr.parent.name != "Player")
     {
         NitroxServiceLocator.LocateService <ItemContainers>().AddItem(item.item, __instance.tr.parent.gameObject);
     }
 }
Esempio n. 18
0
 protected override Validation <string, Menu> CreateService(Godot.Control node, ILoggerFactory loggerFactory)
 {
     return
         (from rootItems in Optional(RootItems).Filter(Enumerable.Any)
          .ToValidation("Menu must have at least one root item.")
          from menuHandlers in Optional(MenuHandlers).Filter(Enumerable.Any)
          .ToValidation("Menu must have at least menu handler.")
          from itemsContainer in ItemsContainer
          .ToValidation("Failed to find the items container.")
          from itemScene in Optional(ItemScene)
          .ToValidation("Item scene is missing.")
          select new Menu(
              rootItems,
              menuHandlers,
              Optional(StructureProviders).Flatten(),
              Optional(Renderers).Flatten(),
              BackAction.TrimToOption(),
              node,
              itemsContainer,
              CloseLabel,
              UpLabel,
              EmptyLabel,
              Breadcrumb,
              itemScene,
              loggerFactory));
 }
    public TechWorldRenderer(ItemsContainer itemsContainer)
    {
        blockMeshInfos = new Dictionary <Vector3Int, InstancedMeshInfo>();
        itemMeshInfos  = new Dictionary <Vector3Int, InstancedMeshInfo>();
        int length = itemsContainer.items.Length;

        blockMeshes    = new Mesh[length];
        blockMaterials = new Material[length];
        itemMeshes     = new Mesh[length];
        itemMaterials  = new Material[length];

        for (int i = 0; i < itemsContainer.items.Length; i++)
        {
            if (itemsContainer.items[i] != null && i != 0)
            {
                Model blockModel = itemsContainer.GetBlockModel(i);
                if (blockModel != null)
                {
                    blockMeshes[i]    = blockModel.mesh;
                    blockMaterials[i] = blockModel.material;
                }

                Model itemModel = itemsContainer.GetItemModel(i);
                if (itemModel != null)
                {
                    itemMeshes[i]    = itemModel.mesh;
                    itemMaterials[i] = itemModel.material;
                }
            }
        }
    }
 public static void Postfix(ItemsContainer __instance, InventoryItem item)
 {
     if (item != null && __instance.tr.parent.name != "EscapePod" && __instance.tr.parent.name != "Player")
     {
         Multiplayer.Logic.ItemContainers.AddItem(item.item, __instance.tr.parent.gameObject);
     }
 }
Esempio n. 21
0
        public void AddItem(GameObject item, NitroxId containerId)
        {
            Optional <GameObject> owner = NitroxEntity.GetObjectFrom(containerId);

            if (!owner.HasValue)
            {
                Log.Error($"Unable to find inventory container with id {containerId} for {item.name}");
                return;
            }
            Optional <ItemsContainer> opContainer = InventoryContainerHelper.TryGetContainerByOwner(owner.Value);

            if (!opContainer.HasValue)
            {
                Log.Error($"Could not find container field on GameObject {owner.Value.GetHierarchyPath()}");
                return;
            }

            ItemsContainer container  = opContainer.Value;
            Pickupable     pickupable = item.RequireComponent <Pickupable>();

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                container.UnsafeAdd(new InventoryItem(pickupable));
                Log.Debug($"Received: Added item {pickupable.GetTechType()} to container {owner.Value.GetHierarchyPath()}");
            }
        }
Esempio n. 22
0
        public static void SetCustomInteractText(StorageContainer _storage)
        {
            if (_storage != null)
            {
                string         customInfoText = string.Empty;
                ItemsContainer container      = _storage.container;

                if (container != null)
                {
                    if (container.count <= 0) // replace with container.IsEmpty()
                    {
                        customInfoText = "ContainerEmpty".Translate();
                    }

                    else if (container.count == 1)
                    {
                        customInfoText = "ContainerOneItem".Translate();
                    }

                    else if (!container.HasRoomFor(1, 1)) // replace with container.IsFull()
                    {
                        customInfoText = "ContainerFull".Translate();
                    }

                    else
                    {
                        customInfoText = "ContainerNonempty".FormatSingle(container.count.ToString());
                    }
                }

                HandReticle.main.SetInteractText(_storage.hoverText, customInfoText, true, false, HandReticle.Hand.Left); // From HandReticle.SetInteractText(string, string)
            }
        }
Esempio n. 23
0
        protected override void ShowMore()
        {
            base.ShowMore();

            request          = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ *ItemsPerPage);
            request.Success += activities => Schedule(() =>
            {
                ShowMoreButton.FadeTo(activities.Count == ItemsPerPage ? 1 : 0);
                ShowMoreLoading.Hide();

                if (!activities.Any() && VisiblePages == 1)
                {
                    MissingText.Show();
                    return;
                }

                MissingText.Hide();

                foreach (APIRecentActivity activity in activities)
                {
                    ItemsContainer.Add(new DrawableRecentActivity(activity));
                }
            });

            Api.Queue(request);
        }
    private MyItem[] GetItems()
    {
        string         json      = GetJsonTextSomehow();
        ItemsContainer container = JsonUtility.FromJson <ItemsContainer>(json);

        return(container.items);
    }
Esempio n. 25
0
 public static void Postfix(ItemsContainer __instance, InventoryItem item)
 {
     if (item != null)
     {
         NitroxServiceLocator.LocateService <ItemContainers>().BroadcastItemAdd(item.item, __instance.tr);
     }
 }
Esempio n. 26
0
        private static IEnumerator AddToVehicle(TechType techType, ItemsContainer itemsContainer)
        {
            CoroutineTask <GameObject> coroutineTask = CraftData.GetPrefabForTechTypeAsync(techType, false);

            yield return(coroutineTask);

            GameObject prefab = coroutineTask.GetResult();

            if (prefab is null)
            {
                prefab = Utils.CreateGenericLoot(techType);
            }

            GameObject gameObject = GameObject.Instantiate(prefab, null);
            Pickupable pickupable = gameObject.EnsureComponent <Pickupable>();

#if SUBNAUTICA_EXP
            TaskResult <Pickupable> result1 = new TaskResult <Pickupable>();
            yield return(pickupable.InitializeAsync(result1));

            pickupable = result1.Get();
#else
            pickupable.Initialize();
#endif
            var item = new InventoryItem(pickupable);
            itemsContainer.UnsafeAdd(item);
            string name = Language.main.GetOrFallback(techType.AsString(), techType.AsString());
            ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));
            uGUI_IconNotifier.main.Play(techType, uGUI_IconNotifier.AnimationType.From, null);
            pickupable.PlayPickupSound();

            yield break;
        }
Esempio n. 27
0
        protected override void ShowMore()
        {
            base.ShowMore();

            request          = new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++ *ItemsPerPage);
            request.Success += sets => Schedule(() =>
            {
                ShowMoreButton.FadeTo(sets.Count == ItemsPerPage ? 1 : 0);
                ShowMoreLoading.Hide();

                if (!sets.Any() && VisiblePages == 1)
                {
                    MissingText.Show();
                    return;
                }

                foreach (var s in sets)
                {
                    if (!s.OnlineBeatmapSetID.HasValue)
                    {
                        continue;
                    }

                    var panel = new DirectGridPanel(s.ToBeatmapSet(Rulesets));
                    ItemsContainer.Add(panel);
                }
            });

            Api.Queue(request);
        }
Esempio n. 28
0
 public static void Postfix(uGUI_ItemsContainer __instance, ItemsContainer container)
 {
     if (container == Inventory.main.container)
     {
         InventoryOpener.InventoryUGUI = __instance;
     }
 }
        protected override void ShowMore()
        {
            request          = new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
            request.Success += sets => Schedule(() =>
            {
                MoreButton.FadeTo(sets.Count == ItemsPerPage ? 1 : 0);
                MoreButton.IsLoading = false;

                if (!sets.Any() && VisiblePages == 1)
                {
                    MissingText.Show();
                    return;
                }

                foreach (var s in sets)
                {
                    if (!s.OnlineBeatmapSetID.HasValue)
                    {
                        continue;
                    }

                    ItemsContainer.Add(new DirectGridPanel(s.ToBeatmapSet(Rulesets))
                    {
                        Anchor = Anchor.TopCentre,
                        Origin = Anchor.TopCentre,
                    });
                }
            });

            Api.Queue(request);
        }
 public VisionResult()
 {
     FreeTiles    = new ItemsContainer <Tile>();
     Allies       = new ItemsContainer <Entity>();
     Enemies      = new ItemsContainer <Entity>();
     AlliesToHeal = new ItemsContainer <Entity>();
 }