Esempio n. 1
0
        public static void RemoveItemArea(this Inventory inventory, string name, int amount)
        {
            if (!Plugin.Settings.CraftingWithContainersEnabled.Value ||
                !ContainerTracker.PlayerByInventoryDict.TryGetValue(inventory.GetHashCode(), out var player))
            {
                inventory.RemoveItem(name, amount);
                return;
            }
            var containers = ContainerTracker.GetViableContainersInRangeForPlayer(player,
                                                                                  Plugin.Settings.ContainerLookupRange.Value);

            InventoryItemRemover.IterateAndRemoveItemsFromInventories(player, containers, name, amount, out var removalReport);

            if (Plugin.Settings.AddExtractionEffectWhenCrafting.Value)
            {
                foreach (var removal in removalReport.Removals
                         .Where(removal => removal.TrackedContainer.HasValue))
                {
                    // ReSharper disable once PossibleInvalidOperationException
                    SpawnEffect(player, removal.TrackedContainer.Value);
                }
            }

            Plugin.Log.LogDebug(removalReport.GetReportString());
            if (Plugin.Settings.LogItemRemovalsToConsole.Value)
            {
                Console.instance.Print($"{removalReport.GetReportString(true)}");
            }
        }
Esempio n. 2
0
        public static int CountItemsArea(this Inventory inventory, string itemName)
        {
            if (!Plugin.Settings.CraftingWithContainersEnabled.Value ||
                !ContainerTracker.PlayerByInventoryDict.TryGetValue(inventory.GetHashCode(), out var player))
            {
                return(inventory.CountItems(itemName));
            }
            // only run our handler if we are tracking the inventory, hence it's a
            // player inventory. otherwise - let the default execute as is
            var playerItemCount = inventory.CountItems(itemName);
            var containers      = ContainerTracker
                                  .GetViableContainersInRangeForPlayer(player, Plugin.Settings.ContainerLookupRange.Value);
            var containerItemCount = containers
                                     .Sum(container => container.Container.GetInventory().CountItems(itemName));

            return(playerItemCount + containerItemCount);
        }
Esempio n. 3
0
        public static bool HaveItemArea(this Inventory inventory, string itemName)
        {
            if (!Plugin.Settings.CraftingWithContainersEnabled.Value ||
                !ContainerTracker.PlayerByInventoryDict.TryGetValue(inventory.GetHashCode(), out var player))
            {
                return(inventory.HaveItem(itemName));
            }

            var playerHasAny = player.GetInventory().HaveItem(itemName);
            var containers   = ContainerTracker
                               .GetViableContainersInRangeForPlayer(player, Plugin.Settings.ContainerLookupRange.Value);
            var containersHaveAny = containers
                                    .Any(container => container.Container.GetInventory().HaveItem(itemName));

            Plugin.Log.LogDebug(
                $"Player ${player.GetPlayerID()} found {playerHasAny}+{containersHaveAny} of {itemName} via {containers.Count}");
            return(playerHasAny || containersHaveAny);
        }
Esempio n. 4
0
 private void OnGUI()
 {
     if (!Settings.DebugViableContainerIndicatorEnabled.Value || !Player.m_localPlayer)
     {
         return;
     }
     foreach (var containerEntry in ContainerTracker.GetViableContainersInRangeForPlayer(Player.m_localPlayer, Settings.ContainerLookupRange.Value))
     {
         var position = Camera.main.WorldToScreenPoint(containerEntry.Container.transform.position + Vector3.up * 0.5f);
         if (position.z <= 0.1)
         {
             continue;
         }
         GUI.color = Color.magenta;
         var textSize = GUI.skin.label.CalcSize(new GUIContent("+"));
         GUI.Label(new Rect(position.x, Screen.height - position.y, textSize.x, textSize.y), "+");
     }
 }
Esempio n. 5
0
        public void Update_AnyThread(double elapsedTime)
        {
            if (this.EventOccurred == null)
            {
                return;
            }

            // Compare current state to previous state for each item to be watched
            var hits = new List <Tuple <LifeEventType, double> >();
            Tuple <LifeEventType, double> result;

            #region standard containers

            foreach (ContainerTracker standard in _standardContainers)
            {
                result = standard.ExamineContainer();
                if (result != null)
                {
                    hits.Add(result);
                }
            }

            #endregion
            #region cargo bays

            if (_cargoBay != null)
            {
                Tuple <double, double> currentCargo = _cargoBay.CargoVolume;
                double prevCargo = Interlocked.Exchange(ref _prevCargo, currentCargo.Item1);

                double diffCargo = currentCargo.Item1 - prevCargo;

                result = ContainerTracker.ExamineValue(diffCargo, currentCargo.Item2, LifeEventType.AddedCargo, null);

                if (result != null)
                {
                    hits.Add(result);
                }
            }

            #endregion

            if (!_shouldRaiseEvents)
            {
                //NOTE: Waiting until now, because the prev values need to stay current
                return;
            }

            // Raise the events
            if (hits.Count > 0)
            {
                DateTime time = DateTime.UtcNow;

                // If the bot was just created, then don't raise events (giving it time to initialize)
                if ((time - _createTime).TotalSeconds < 1.5)
                {
                    return;
                }

                foreach (Tuple <LifeEventType, double> hit in hits)
                {
                    this.EventOccurred(this, new LifeEventArgs(time, hit.Item1, hit.Item2));
                }
            }
        }