Ejemplo n.º 1
0
        /// <summary>
        /// Drops this item from the inventory.
        /// </summary>
        public ItemPickup Drop()
        {
            if (!IsEmpty())
            {
                IInventoryItem item = GetItemRef();
                if (item == null)
                {
                    return(null);
                }

                CharacterItemDropPrefabTrait trait = new Character().GetTrait <CharacterItemDropPrefabTrait>();

                ItemPickup dropped  = null;
                Vector3    position = internalInv.transform.localPosition;
                // Try making the positions random, instead of letting the objects stuck into together.
                position.x = position.x + UnityEngine.Random.Range(0f, 0.85f);
                position.y = position.y + UnityEngine.Random.Range(0.75f, 1f);
                position.z = position.z + UnityEngine.Random.Range(0f, 0.85f);

                Vector3    arg      = new Vector3(UnityEngine.Random.Range(0.75f, 1.3f), UnityEngine.Random.Range(0.75f, 1.3f), UnityEngine.Random.Range(0.75f, 1.3f));
                Quaternion rotation = new Quaternion(0f, 0f, 0f, 1f);
                GameObject go       = NetCull.InstantiateDynamicWithArgs <Vector3>(trait.prefab, position, rotation, arg);
                dropped = go.GetComponent <ItemPickup>();
                if (!dropped.SetPickupItem(item))
                {
                    //Debug.LogError($"Could not make item pickup for {item}", inventory);
                    NetCull.Destroy(go);
                    //internalInv.RemoveItem(item);
                    //internalInv.MarkSlotDirty(Slot);
                    return(null);
                }

                internalInv.RemoveItem(item);
                //internalInv.MarkSlotDirty(Slot);
                return(dropped);
                //DropHelper.DropItem(this.internalInv, this.Slot);
            }

            return(null);
        }