Exemplo n.º 1
0
        private RustItem?CreateItem(string itemId, IItemState?state)
        {
            if (!int.TryParse(itemId, out var parsedItemId))
            {
                throw new ArgumentException($"Invalid Item ID: {itemId}", nameof(itemId));
            }

            var item = ItemManager.CreateByItemID(parsedItemId);

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

            var rustItem = new RustItem(item);

            if (state != null && !(state is NullItemState))
            {
                rustItem.SetItemAmountAsync(state.ItemAmount);
                rustItem.SetItemQualityAsync(state.ItemQuality);
                rustItem.Item.maxCondition = (float)state.ItemDurability;
            }

            return(rustItem);
        }
Exemplo n.º 2
0
        private async UniTask <RustItem?> CreateItem(string itemId, IItemState?state)
        {
            if (!int.TryParse(itemId, out var parsedItemId))
            {
                throw new ArgumentException($"Invalid Item ID: {itemId}", nameof(itemId));
            }

            await UniTask.SwitchToMainThread();

            var item = ItemManager.CreateByItemID(parsedItemId);

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

            var rustItem = new RustItem(item);

            if (state != null && !(state is NullItemState))
            {
                await rustItem.SetItemAmountAsync(state.ItemAmount);

                await rustItem.SetItemQualityAsync(state.ItemQuality);

                await rustItem.SetItemDurabilityAsync(state.ItemDurability);
            }

            return(rustItem);
        }