Exemplo n.º 1
0
        public async Task <bool> EquipItemAsync(Item item, bool ignoreAllChecks = false)
        {
            var itemType = (ItemType)(item.ItemComponent.ItemType ?? (int)ItemType.Invalid);

            if (!ignoreAllChecks)
            {
                if (GameObject is Player player)
                {
                    if (!player.GetComponent <ModularBuilderComponent>().IsBuilding)
                    {
                        if (itemType == ItemType.Model || itemType == ItemType.LootModel ||
                            itemType == ItemType.Vehicle || item.Lot == 6086)
                        {
                            return(false);
                        }
                    }
                }
            }

            await OnEquipped.InvokeAsync(item);

            await MountItemAsync(item.Id);

            GameObject.Serialize(GameObject);

            return(true);
        }
Exemplo n.º 2
0
        public async Task EquipItemAsync(Item item, bool ignoreAllChecks = false)
        {
            if (item?.InventoryItem == null)
            {
                Logger.Error($"{item} is not a valid item");

                return;
            }

            var itemType = (ItemType)(item.ItemComponent.ItemType ?? (int)ItemType.Invalid);

            if (!ignoreAllChecks)
            {
                if (!As <Player>().GetComponent <ModularBuilderComponent>().IsBuilding)
                {
                    if (itemType == ItemType.Model || itemType == ItemType.LootModel || itemType == ItemType.Vehicle || item.Lot == 6086)
                    {
                        return;
                    }
                }
            }

            /*
             * Equip proxies
             */

            var proxies = await GenerateProxyItemsAsync(item);

            if (proxies?.Length > 0)
            {
                ProxyItems[item.ObjectId] = proxies;
            }

            Logger.Debug($"Equipping {item}");

            item.Equipped = true;

            var items = Items.Select(i => (i.Key, i.Value)).ToArray();

            foreach (var(equipLocation, value) in items)
            {
                if (!equipLocation.Equals(item.ItemComponent.EquipLocation))
                {
                    continue;
                }

                var manager = GameObject.GetComponent <InventoryManagerComponent>();

                if (manager != default)
                {
                    var oldItem = manager.FindItem(value.InventoryItemId);

                    await UnEquipItemAsync(oldItem);
                }
                else
                {
                    await UnEquipItemAsync(value.InventoryItemId);
                }
            }

            await OnEquipped.InvokeAsync(item);

            Items[item.ItemComponent.EquipLocation] = item.InventoryItem;

            await ChangeEquippedSateOnPlayerAsync(item.ObjectId, true);

            GameObject.Serialize(GameObject);
        }