Example #1
0
        private static async Task <Lot[]> ParseProxyItemsAsync(Lot item)
        {
            await using var ctx = new CdClientContext();

            var itemInfo = await ctx.ItemComponentTable.FirstOrDefaultAsync(
                i => i.Id == item.GetComponentId(ComponentId.ItemComponent)
                );

            if (itemInfo == default)
            {
                return(new Lot[0]);
            }

            if (string.IsNullOrWhiteSpace(itemInfo.SubItems))
            {
                return(new Lot[0]);
            }

            var proxies = itemInfo.SubItems
                          .Replace(" ", "")
                          .Split(',')
                          .Select(i => (Lot)int.Parse(i));

            return(proxies.ToArray());
        }
Example #2
0
        public async Task Buy(Lot lot, uint count, Player player)
        {
            await using var ctx = new CdClientContext();

            var itemComponent = await ctx.ItemComponentTable.FirstAsync(
                i => i.Id == lot.GetComponentId(ComponentId.ItemComponent)
                );

            if (count == default || itemComponent.BaseValue <= 0)
            {
                return;
            }

            var cost = (uint)((itemComponent.BaseValue ?? 0) * count);

            if (cost > player.Currency)
            {
                return;
            }

            player.Currency -= cost;

            await player.GetComponent <InventoryManagerComponent>().AddItemAsync(lot, count);

            player.Message(new VendorTransactionResultMessage
            {
                Associate = GameObject,
                Result    = TransactionResult.Success
            });

            await OnBuy.InvokeAsync(lot, count, player);
        }
Example #3
0
        public long EquipUnmanagedItem(Lot lot, uint count         = 1, int slot = -1,
                                       InventoryType inventoryType = InventoryType.None)
        {
            using var cdClient = new CdClientContext();
            var cdClientObject = cdClient.ObjectsTable.FirstOrDefault(
                o => o.Id == lot
                );

            var itemRegistryEntry = lot.GetComponentId(ComponentId.ItemComponent);

            if (cdClientObject == default || itemRegistryEntry == default)
            {
                Logger.Error($"{lot} is not a valid item");
                return(-1);
            }

            var itemComponent = cdClient.ItemComponentTable.First(
                i => i.Id == itemRegistryEntry
                );

            var id = IdUtilities.GenerateObjectId();

            Items[itemComponent.EquipLocation] = new InventoryItem
            {
                InventoryItemId = id,
                Count           = count,
                Slot            = slot,
                LOT             = lot,
                InventoryType   = (int)inventoryType
            };

            return(id);
        }
Example #4
0
        public async Task Buy(Lot lot, uint count, Player player)
        {
            var componentId   = lot.GetComponentId(ComponentId.ItemComponent);
            var itemComponent = await ClientCache.FindAsync <ItemComponent>(componentId);

            if (count == default || itemComponent.BaseValue <= 0)
            {
                return;
            }

            var character = player.GetComponent <CharacterComponent>();
            var cost      = (uint)((itemComponent.BaseValue ?? 0) * count);

            if (cost > character.Currency)
            {
                return;
            }

            // If we have to buy this with an alternative currency
            if (itemComponent.CurrencyLOT != null)
            {
                var alternativeCurrencyLot  = (Lot)itemComponent.CurrencyLOT;
                var alternativeCurrencyCost = itemComponent.AltCurrencyCost ?? 0;
                var inventory = player.GetComponent <InventoryManagerComponent>();

                if (alternativeCurrencyCost > inventory.FindItems(alternativeCurrencyLot)
                    .Select(i => (int)i.Count).Sum())
                {
                    return;
                }

                await inventory.RemoveLotAsync(alternativeCurrencyLot, (uint)alternativeCurrencyCost);
            }

            character.Currency -= cost;

            await player.GetComponent <InventoryManagerComponent>().AddLotAsync(lot, count, lootType: LootType.Vendor);

            player.Message(new VendorTransactionResultMessage
            {
                Associate = GameObject,
                Result    = TransactionResult.Success
            });

            await OnBuy.InvokeAsync(lot, count, player);
        }
Example #5
0
File: Item.cs Project: kulaj/Uchu
        protected Item()
        {
            OnConsumed = new Event();

            Listen(OnStart, () =>
            {
                IsPackage = Lot.GetComponentId(ComponentId.PackageComponent) != default;

                using var cdClient = new CdClientContext();

                var skills = cdClient.ObjectSkillsTable.Where(
                    s => s.ObjectTemplate == Lot
                    ).ToArray();

                IsConsumable = skills.Any(
                    s => s.CastOnType == (int)SkillCastType.OnConsumed
                    );
            });

            Listen(OnDestroyed, () => Inventory.UnManageItem(this));
        }