Beispiel #1
0
        private bool TryAddItem(Item item, UnturnedPlayerInventory playerInventory, out ItemJar itemJar)
        {
            var inventory = playerInventory.Inventory;
            var player    = playerInventory.Player;

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

            ItemAsset itemAsset = (ItemAsset)Assets.find(EAssetType.ITEM, item.id);

            if (itemAsset == null || itemAsset.isPro)
            {
                return(false);
            }

            if (itemAsset.canPlayerEquip)
            {
                if (itemAsset.slot.canEquipAsSecondary() && TryAddItemEquip(playerInventory, item, 1 /* secondary slot */))
                {
                    itemJar = playerInventory.Inventory.items[1].getItem(index: 0);
                    return(true);
                }
                if (itemAsset.slot.canEquipAsPrimary() && TryAddItemEquip(playerInventory, item, 0 /* primary slot */))
                {
                    itemJar = playerInventory.Inventory.items[0].getItem(index: 0);
                    return(true);
                }
            }

            for (var page = PlayerInventory.SLOTS; page < PlayerInventory.PAGES - 2; page++)
            {
                if (!inventory.items[page].tryAddItem(item))
                {
                    continue;
                }

                itemJar = inventory.items[page].getItem((byte)(inventory.items[page].getItemCount() - 1));
                if (!player.equipment.isSelected && itemAsset.slot.canEquipInPage(page) && itemAsset.canPlayerEquip)
                {
                    player.equipment.tryEquip(page, itemJar.x, itemJar.y);
                }

                return(true);
            }

            return(false);
        }
Beispiel #2
0
        private bool TryAddItemEquip(UnturnedPlayerInventory playerInventory, Item item, byte page)
        {
            var inventory = playerInventory.Inventory;
            var player    = playerInventory.Player;

            if (!inventory.items[page].tryAddItem(item))
            {
                return(false);
            }

            player.equipment.sendSlot(page);
            if (!player.equipment.isSelected)
            {
                player.equipment.tryEquip(page, 0, 0);
            }
            return(true);
        }
Beispiel #3
0
        private bool TryAddItem(ItemAsset itemAsset, Item?item, UnturnedPlayerInventory playerInventory, out ItemJar?itemJar)
        {
            var inventory = playerInventory.Inventory;
            var player    = playerInventory.Player;

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

            if (itemAsset.isPro)
            {
                return(false);
            }

            if (itemAsset.canPlayerEquip)
            {
                if (itemAsset.slot.canEquipAsSecondary() && TryAddItemEquip(playerInventory, item, page: 1 /* secondary slot */))
                {
                    itemJar = playerInventory.Inventory.items[1].getItem(index: 0);
                    return(true);
                }
                if (itemAsset.slot.canEquipAsPrimary() && TryAddItemEquip(playerInventory, item, page: 0 /* primary slot */))
                {
                    itemJar = playerInventory.Inventory.items[0].getItem(index: 0);
                    return(true);
                }
            }

            // ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
            switch (itemAsset.type)
            {
            case EItemType.BACKPACK:
                if (player.clothing.backpack != 0)
                {
                    break;
                }

                player.clothing.askWearBackpack(item.id, item.quality, item.state, playEffect: true);
                return(true);

            case EItemType.GLASSES:
                if (player.clothing.glasses != 0)
                {
                    break;
                }

                player.clothing.askWearGlasses(item.id, item.quality, item.state, playEffect: true);
                return(true);

            case EItemType.HAT:
                if (player.clothing.hat != 0)
                {
                    break;
                }

                player.clothing.askWearHat(item.id, item.quality, item.state, playEffect: true);
                return(true);

            case EItemType.MASK:
                if (player.clothing.mask != 0)
                {
                    break;
                }

                player.clothing.askWearMask(item.id, item.quality, item.state, playEffect: true);
                return(true);

            case EItemType.PANTS:
                if (player.clothing.pants != 0)
                {
                    break;
                }

                player.clothing.askWearPants(item.id, item.quality, item.state, playEffect: true);
                return(true);

            case EItemType.SHIRT:
                if (player.clothing.shirt != 0)
                {
                    break;
                }

                player.clothing.askWearShirt(item.id, item.quality, item.state, playEffect: true);
                return(true);

            case EItemType.VEST:
                if (player.clothing.vest != 0)
                {
                    break;
                }

                player.clothing.askWearVest(item.id, item.quality, item.state, playEffect: true);
                return(true);
            }

            for (var page = PlayerInventory.SLOTS; page < PlayerInventory.PAGES - 2; page++)
            {
                if (!inventory.items[page].tryAddItem(item))
                {
                    continue;
                }

                itemJar = inventory.items[page].getItem((byte)(inventory.items[page].getItemCount() - 1));
                if (!player.equipment.isSelected && itemAsset.slot.canEquipInPage(page) && itemAsset.canPlayerEquip)
                {
                    player.equipment.tryEquip(page, itemJar.x, itemJar.y);
                }

                return(true);
            }

            return(false);
        }
Beispiel #4
0
 public UnturnedPlayerInventoryPage(UnturnedPlayerInventory inventory, byte pageIndex, SDG.Unturned.Items page)
 {
     Inventory = inventory;
     Page      = page;
     PageIndex = pageIndex;
 }
Beispiel #5
0
 public UnturnedInventoryItem(UnturnedPlayerInventory inventory, ItemJar itemJar, UnturnedItem item)
 {
     Inventory = inventory;
     ItemJar   = itemJar;
     Item      = item;
 }
Beispiel #6
0
 public UnturnedInventoryItem(UnturnedPlayerInventory inventory, ItemJar itemJar)
 {
     Inventory = inventory;
     ItemJar   = itemJar;
     Item      = new UnturnedItem(itemJar.item, DestroyAsync);
 }
Beispiel #7
0
        private bool TryAddItem(Item?item, UnturnedPlayerInventory playerInventory, out ItemJar?itemJar)
        {
            var inventory = playerInventory.Inventory;
            var player    = playerInventory.Player;

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

            var itemAsset = (ItemAsset?)Assets.find(EAssetType.ITEM, item.id);

            if (itemAsset == null || itemAsset.isPro)
            {
                return(false);
            }

            if (itemAsset.canPlayerEquip)
            {
                if (itemAsset.slot.canEquipAsSecondary() && TryAddItemEquip(playerInventory, item, 1 /* secondary slot */))
                {
                    itemJar = playerInventory.Inventory.items[1].getItem(index: 0);
                    return(true);
                }
                if (itemAsset.slot.canEquipAsPrimary() && TryAddItemEquip(playerInventory, item, 0 /* primary slot */))
                {
                    itemJar = playerInventory.Inventory.items[0].getItem(index: 0);
                    return(true);
                }
            }

            if (player.clothing.hat == 0 && itemAsset.type == EItemType.HAT)
            {
                player.clothing.askWearHat(item.id, item.quality, item.state, true);
                return(true);
            }
            if (player.clothing.shirt == 0 && itemAsset.type == EItemType.SHIRT)
            {
                player.clothing.askWearShirt(item.id, item.quality, item.state, true);
                return(true);
            }
            if (player.clothing.pants == 0 && itemAsset.type == EItemType.PANTS)
            {
                player.clothing.askWearPants(item.id, item.quality, item.state, true);
                return(true);
            }
            if (player.clothing.backpack == 0 && itemAsset.type == EItemType.BACKPACK)
            {
                player.clothing.askWearBackpack(item.id, item.quality, item.state, true);
                return(true);
            }
            if (player.clothing.vest == 0 && itemAsset.type == EItemType.VEST)
            {
                player.clothing.askWearVest(item.id, item.quality, item.state, true);
                return(true);
            }
            if (player.clothing.mask == 0 && itemAsset.type == EItemType.MASK)
            {
                player.clothing.askWearMask(item.id, item.quality, item.state, true);
                return(true);
            }
            if (player.clothing.glasses == 0 && itemAsset.type == EItemType.GLASSES)
            {
                player.clothing.askWearGlasses(item.id, item.quality, item.state, true);
                return(true);
            }

            for (var page = PlayerInventory.SLOTS; page < PlayerInventory.PAGES - 2; page++)
            {
                if (!inventory.items[page].tryAddItem(item))
                {
                    continue;
                }

                itemJar = inventory.items[page].getItem((byte)(inventory.items[page].getItemCount() - 1));
                if (!player.equipment.isSelected && itemAsset.slot.canEquipInPage(page) && itemAsset.canPlayerEquip)
                {
                    player.equipment.tryEquip(page, itemJar.x, itemJar.y);
                }

                return(true);
            }

            return(false);
        }