Пример #1
0
        public static Item CreateByPartialName(string shortname, uint amount = 1, ulong skinid = 0)
        {
            ItemInformation iteminfo = itemlist.Find(p => p.Shortname == shortname);

            if (iteminfo == null)
            {
                return(null);
            }

            return(Item.CreateItem(iteminfo, amount, skinid));
        }
Пример #2
0
        public static Item CreateByItemID(ItemID itemid, uint amount = 1, ulong skinid = 0)
        {
            ItemInformation info = FindInformation((int)itemid);

            if (info == null)
            {
                return(null);
            }

            return(Item.CreateItem(info, amount, skinid));
        }
Пример #3
0
        public static ItemInformation Load(Item item)
        {
            var iteminfo = new ItemInformation();

            iteminfo.ItemID       = item.info.itemid;
            iteminfo.Shortname    = item.info.shortname;
            iteminfo.MaxStack     = item.info.stackable;
            iteminfo.MaxCondition = item.info.condition.max;

            var heldent = item.GetHeldEntity();

            if (heldent != null)
            {
                iteminfo.HeldEntity = ItemHeldEntity.Load(heldent);

                var heldtype = heldent.GetType();
                if (heldtype == typeof(HeldEntity))
                {
                    iteminfo.HeldType = ItemHeldType.HeldEntity;
                }
                else if (heldtype == typeof(AttackEntity))
                {
                    iteminfo.HeldType = ItemHeldType.AttackEntity;
                }
                else if (heldtype == typeof(BaseProjectile))
                {
                    iteminfo.HeldType = ItemHeldType.BaseProjectile;
                }
                else if (heldtype == typeof(BaseMelee))
                {
                    iteminfo.HeldType = ItemHeldType.BaseMelee;
                }

                iteminfo.HeldEntity     = ItemHeldEntity.Load(heldent);
                iteminfo.BaseProjectile = ItemBaseProjectileInfo.Load(heldent);
                iteminfo.BaseMelee      = ItemBaseMelee.Load(heldent);
            }

            return(iteminfo);
        }
Пример #4
0
        private Item(ItemInformation _info, uint _amount, ulong _skinid)
        {
            this.UID = BaseNetworkable.TakeUID();
            ListItemsInWorld[this.UID] = this;

            this.Information = _info;

            this.SkinID    = _skinid;
            this.Condition = this.Information.MaxCondition;

            if (_amount <= 0)
            {
                this.Amount = 1;
            }
            else if (_amount > this.Information.MaxStack)
            {
                this.Amount = (uint)this.Information.MaxStack;
            }
            else
            {
                this.Amount = _amount;
            }

            if (this.Information.IsHoldable())
            {
                if (ItemInformation.GetHeldType(_info.HeldType, out Type type) == false)
                {
                    ConsoleSystem.LogError($"[{nameof(Item)}] Unrealized class for <{_info.Shortname}>");
                }
                this.HeldEntity = (BaseHeldEntity)Framework.Bootstraper.AddType(type);
                this.HeldEntity.Spawn(this.Information.HeldEntity.PrefabID);
                this.HeldEntity.SendNetworkUpdate();

                this.HeldEntity.ItemOwner = this;
                this.HeldEntity.Initialization();
            }
        }
Пример #5
0
 public static Item CreateItem(ItemInformation info, uint amount = 1, ulong skinid = 0) => new Item(info, amount, skinid);