Ejemplo n.º 1
0
        public override void LoadSave(object obj)
        {
            PlayerSave save = obj as PlayerSave;

            if (save != null)
            {
                Gender       = (Gender)save.gender;
                Level        = save.level;
                CurrentXP    = save.currentXP;
                XPLevelLimit = save.XPLevelLimit;

                PurchasedProducts.Clear();
                if (save.purchasedProducts == null)
                {
                    save.purchasedProducts = new List <int>();
                }
                foreach (int id in save.purchasedProducts)
                {
                    PurchasedProducts.Add(id);
                }
                StatusPoints             = save.statusPoints;
                LifetimeEarnings         = save.lifetimeEarnings;
                LifetimeEarningsInPlanet = save.lifetimeEarningsInPlanet;
                //MaxCompanyCash = save.maxCompanyCash;
                IsHasMicromanager = save.isHasMicromanager;
                IsLoaded          = true;
            }
            else
            {
                LoadDefaults();
            }
        }
Ejemplo n.º 2
0
        private void UpdateProducts()
        {
            var allProducts = _productsCatalog.GetProducts();

            foreach (var product in allProducts)
            {
                var language1 = _resourcesProvider.GetResource("Lang" + product.Language1);
                var language2 = _resourcesProvider.GetResource("Lang" + product.Language2);
                var any       = _resourcesProvider.GetResource("Any");
                if (((language1 == _CurrentLanguage1 || _CurrentLanguage1 == any) && ((language2 == _CurrentLanguage2 || _CurrentLanguage2 == any)) ||
                     ((language2 == _CurrentLanguage1 || _CurrentLanguage1 == any) && ((language1 == _CurrentLanguage2 || CurrentLanguage2 == any)))))
                {
                    if (!product.IsPurchased && !Products.Contains(product) && !product.RemovedFromSale)
                    {
                        Products.Add(product);
                    }
                    else if (product.IsPurchased && !PurchasedProducts.Contains(product))
                    {
                        PurchasedProducts.Add(product);
                    }
                }
                else
                {
                    if (!product.IsPurchased && Products.Contains(product))
                    {
                        Products.Remove(product);
                    }
                    else if (product.IsPurchased && PurchasedProducts.Contains(product))
                    {
                        PurchasedProducts.Remove(product);
                    }
                }
                if (!Products.Contains(_currentProduct) || !PurchasedProducts.Contains(_currentProduct))
                {
                    //Если ранее выбранный словарь не попал в отфильтрованный список то выставляем самый первый в списке в качестве выбранного
                    if (PurchasedProducts.Count != 0)
                    {
                        CurrentProduct = PurchasedProducts[0];
                    }
                    else if (Products.Count != 0)
                    {
                        CurrentProduct = Products[0];
                    }
                    else
                    {
                        //
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public IProductPurchase ConfirmPurchaseWith(string reservationId)
        {
            if (!ReservationIsValid(reservationId))
            {
                throw new Exception($"Cannot confirm the purchase with this Id: {reservationId}");
            }

            var reservation = GetReservationWith(reservationId);
            var purchase    = new ProductPurchase(reservationId, this, reservation.Quantity);

            reservation.HasBeenConfirmed = true;
            PurchasedProducts.Add(purchase);

            return(purchase);
        }
Ejemplo n.º 4
0
        private void AddPurchasedProduct(SelectedProductModel product)
        {
            var item = new SelectedProductModel
            {
                Quantity = 1,
                ID       = product.ID,
                Label    = product.Label,
                Price    = product.Price,
                Discount = product.Discount
            };

            item.ComputeSubTotal();

            PurchasedProducts.Add(item);

            CurrentPurchase.ComputeTotal();
        }
Ejemplo n.º 5
0
        private void FillProducts()
        {
            PurchasedProducts.Clear();
            Products.Clear();

            IReadOnlyCollection <Product> products = _productsCatalog.GetProducts();

            foreach (Product product in products)
            {
                if (product.IsPurchased)
                {
                    PurchasedProducts.Add(product);
                }
                else if (!product.RemovedFromSale)
                {
                    Products.Add(product);
                }
            }
        }
        public async Task GetPurchasedProducts(object sender, RoutedEventArgs e)
        {
            // 抓取已經購買的項目
            var purchased = await storeContext.GetUserCollectionAsync(GetProductKinds());

            if (purchased.ExtendedError != null)
            {
                Errored?.Invoke(this, purchased.ExtendedError);
                return;
            }

            if (purchased.Products == null || purchased.Products.Count == 0)
            {
                Message = "Not purchased any product";
                return;
            }

            PurchasedProducts.Clear();

            foreach (var item in purchased.Products)
            {
                PurchasedProducts.Add(new StoreProductDataWrapper(item.Key, item.Value));
            }
        }
Ejemplo n.º 7
0
 public TransactionState PurchaseProduct(ProductData data)
 {
     if (!IsProductPurchased(data.id))
     {
         var price = data.price;
         Bos.Data.Currency currency = Bos.Data.Currency.CreatePlayerCash(price);
         if (IsEnough(currency))
         {
             RemoveCurrency(currency);
             AddStatusPoints(data.status_points);
             PurchasedProducts.Add(data.id);
             GameEvents.OnProductPurchased(data);
             return(TransactionState.Success);
         }
         else
         {
             return(TransactionState.DontEnoughCurrency);
         }
     }
     else
     {
         return(TransactionState.AlreadyPurchased);
     }
 }