Example #1
0
 object CanLootEntity(BasePlayer player, DroppedItemContainer container)
 {
     if (container.playerName.Equals("_back"))
     {
         bool canPickup = false;
         foreach (var item in container.inventory.itemList.ToList())
         {
             canPickup = CheckForMultipleBackpacks(player.inventory.containerMain, item) == null;
             if (!canPickup)
             {
                 break;
             }
             item.MoveToContainer(player.inventory.containerMain);
         }
         if (canPickup)
         {
             container.Kill();
             GiveBackpackWorldmodel(player);
         }
         return(false);
     }
     else
     {
         return(null);
     }
 }
Example #2
0
        /// <param name="unloading">Specify true if the plugin is unloading.</param>
        public void Destroy(bool destroyOutputContainer, bool unloading = false)
        {
            resetDespawnTimer.DestroyToPool();

            foreach (var player in NearbyPlayers)
            {
                OnPlayerLeave(player);
            }

            if (!unloading)
            {
                // Drop queue items
                if (CraftingTasks.Count > 0)
                {
                    var container = new ItemContainer();
                    container.ServerInitialize(null, 36);

                    foreach (var task in CraftingTasks)
                    {
                        foreach (var ingredient in task.Blueprint.ingredients)
                        {
                            var item = ItemManager.CreateByItemID(ingredient.itemid, (int)ingredient.amount * task.Amount);

                            if (!item.MoveToContainer(container))
                            {
                                item.Drop(Position + Recycler.transform.up * 1.25f, Recycler.GetDropVelocity(), Recycler.ServerRotation);
                            }
                        }
                    }

                    var droppedContainer = container.Drop(Constants.ItemDropPrefab, Position + Recycler.transform.up * 1.25f, Recycler.ServerRotation);
                    droppedContainer.playerName = Lang.Translate(null, "queue-items");
                }
            }

            Recycler.Kill();
            CodeLock?.Kill();

            if (!outputContainer.IsDestroyed)
            {
                // Remove rock from output container that keeps it from despawning when emptied
                outputInventory.GetSlot(outputInventory.capacity - 1).Remove();

                // Force kill output bag if there's nothing in it.
                if (!destroyOutputContainer && OutputInventory.AnyItems())
                {
                    // Enable physics on output container
                    outputContainer.GetComponent <Rigidbody>().isKinematic = false;
                }
                else
                {
                    outputContainer.Kill();
                }
            }
        }
Example #3
0
 void OnEntitySpawned(BaseNetworkable entity)
 {
     // ignore loot box collision
     NextTick(() =>
     {
         if (entity == null)
         {
             return;
         }
         DroppedItemContainer droppedContainer = entity as DroppedItemContainer;
         if (droppedContainer != null)
         {
             timer.Once(300f, () =>
             {
                 if (droppedContainer != null && !droppedContainer.IsDestroyed)
                 {
                     droppedContainer.Kill();
                 }
             });
         }
         DroppedItem item = entity as DroppedItem;
         if (item != null)
         {
             if (item?.item?.info?.worldModelPrefab == null)
             {
                 return;
             }
             if (!item.item.info.worldModelPrefab.isValid)
             {
                 return;
             }
             try
             {
                 if (rotatingItems.Count < limit)
                 {
                     var component = item?.gameObject?.AddComponent <RotatePickupComponent>();
                     if (component == null || component.Error)
                     {
                         UnityEngine.Object.Destroy(component);
                         return;
                     }
                     rotatingItems.Add(entity, component);
                 }
             }
             catch (Exception ex)
             {
                 Puts(ex.Message + Environment.NewLine + ex.StackTrace);
                 throw;
             }
         }
     });
 }