Beispiel #1
0
        /// <summary>
        /// Purchase effect handler
        /// </summary>
        private void PurchaseEffect(int userId, CatalogueItem catalogueItem, int amount)
        {
            List <EffectData> purchaseEffectsQueue = new List <EffectData>();
            var existingEffects = EffectDao.GetUserEffects(userId);

            for (int i = 0; i < amount; i++)
            {
                foreach (var cataloguePackage in catalogueItem.Packages)
                {
                    var dataList = GenerateEffectData(userId, cataloguePackage, existingEffects);

                    if (!dataList.Any())
                    {
                        continue;
                    }

                    purchaseEffectsQueue.AddRange(dataList);
                }
            }

            // Bulk create items
            EffectDao.SaveEffects(purchaseEffectsQueue);

            var player = PlayerManager.Instance.GetPlayerById(userId);

            if (player == null)
            {
                return;
            }

            player.Send(new PurchaseOKComposer(catalogueItem));
            purchaseEffectsQueue.ForEach(player.EffectManager.AddEffect);
        }
Beispiel #2
0
 public SubscriptionGift(SubscriptionGiftData giftData, CatalogueItem catalogueItem)
 {
     this.Data          = giftData;
     this.CatalogueItem = catalogueItem;
 }
Beispiel #3
0
 public CataloguePackage(CataloguePackageData data, CatalogueItem catalogueItem)
 {
     Data = data;
 }
Beispiel #4
0
        /// <summary>
        /// Handle item purchase
        /// </summary>
        public void Purchase(int userId, int itemId, int amount, string extraData, long datePurchase, bool isClubGift = false)
        {
            CatalogueItem catalogueItem = Items.FirstOrDefault(x => x.Data.Id == itemId);

            if (catalogueItem == null)
            {
                return;
            }

            if (catalogueItem.Definition != null && catalogueItem.Definition.HasBehaviour(ItemBehaviour.EFFECT))
            {
                PurchaseEffect(userId, catalogueItem, amount);
                return;
            }

            List <ItemData> purchaseQueue = new List <ItemData>();

            for (int i = 0; i < amount; i++)
            {
                foreach (var cataloguePackage in catalogueItem.Packages)
                {
                    var dataList = GenerateItemData(userId, cataloguePackage, extraData, datePurchase);

                    if (!dataList.Any())
                    {
                        continue;
                    }

                    purchaseQueue.AddRange(dataList);
                }
            }

            // Bulk create items - ignore teleporters because they were already created
            ItemDao.CreateItems(purchaseQueue);

            // Convert item data to item instance
            List <Item> items = purchaseQueue.Select(x => new Item(x)).ToList();

            var player = PlayerManager.Instance.GetPlayerById(userId);

            if (player == null)
            {
                return;
            }

            foreach (var item in items)
            {
                player.Inventory.AddItem(item);
            }

            if (isClubGift)
            {
                player.Send(new ClubGiftReceivedComposer(catalogueItem));
            }
            else
            {
                player.Send(new PurchaseOKComposer(catalogueItem));
            }

            player.Send(new FurniListNotificationComposer(items));
            player.Send(new FurniListUpdateComposer());
        }