Example #1
0
        private void BuyButton_Click(object sender, RoutedEventArgs e)
        {
            if (GameEnvironment.Player.House == null)
            {
                GameMessageBox.Show("Покупка", "Вам негде это хранить, для начала обзаведитесь жильем.", GameMessageBox.MessageBoxType.Information); return;
            }
            Button button = sender as Button;

            if (button.Tag is BaseItem)
            {
                double price = (button.Tag as BaseItem).Price * GameEnvironment.Money.PlayerCurrency[0].Course;
                price += price / 100 * StorePercentage;

                if (price <= GameEnvironment.Money.PlayerCurrency[0].Count)
                {
                    GameEnvironment.Money.PlayerCurrency[0].Withdraw("Оплата покупки: " + (button.Tag as BaseItem).Name, Properties.Resources.ComponentStoreFullName, GameEnvironment.GameEvents.GameTimer.DateAndTime, price);
                    CoinCount.Content = GameEnvironment.Money.PlayerCurrency[0].Count.ToString("N3") + " " + GameEnvironment.Money.PlayerCurrency[0].Abbreviation;

                    if (button.Tag is Case)
                    {
                        Case @case = (button.Tag as Case);
                        GameEnvironment.Items.Cases.Add(new Case(@case.Uid, @case.Name, @case.GetTypeValue(), @case.Price, @case.ManufacturingDate, @case.Properties));
                    }
                    else if (button.Tag is Motherboard)
                    {
                        Motherboard motherboard = (button.Tag as Motherboard);
                        GameEnvironment.Items.Motherboards.Add(new Motherboard(motherboard.Uid, motherboard.Name, motherboard.GetTypeValue(), motherboard.Price, motherboard.ManufacturingDate, motherboard.Properties));
                    }
                    else if (button.Tag is PowerSupplyUnit)
                    {
                        PowerSupplyUnit psu = (button.Tag as PowerSupplyUnit);
                        GameEnvironment.Items.PowerSupplyUnits.Add(new PowerSupplyUnit(psu.Uid, psu.Name, psu.GetTypeValue(), psu.Price, psu.ManufacturingDate, psu.Properties));
                    }
                    else if (button.Tag is CPU)
                    {
                        CPU cpu = (button.Tag as CPU);
                        GameEnvironment.Items.CPUs.Add(new CPU(cpu.Uid, cpu.Name, cpu.GetTypeValue(), cpu.Price, cpu.ManufacturingDate, cpu.Properties));
                    }
                    else if (button.Tag is RAM)
                    {
                        RAM ram = (button.Tag as RAM);
                        GameEnvironment.Items.RAMs.Add(new RAM(ram.Uid, ram.Name, ram.GetTypeValue(), ram.Price, ram.ManufacturingDate, ram.Properties));
                    }
                    else if (button.Tag is CPUCooler)
                    {
                        CPUCooler cpuCooler = button.Tag as CPUCooler;
                        GameEnvironment.Items.CPUCoolers.Add(new CPUCooler(cpuCooler.Uid, cpuCooler.Name, cpuCooler.GetTypeValue(), cpuCooler.Price, cpuCooler.ManufacturingDate, cpuCooler.Properties));
                    }
                    else if (button.Tag is HDD)
                    {
                        HDD hdd = button.Tag as HDD;
                        GameEnvironment.Items.HDDs.Add(new HDD(hdd.Uid, hdd.Name, hdd.GetTypeValue(), hdd.Price, hdd.ManufacturingDate, hdd.Properties));
                    }
                    else if (button.Tag is Monitor)
                    {
                        Monitor monitor = button.Tag as Monitor;
                        GameEnvironment.Items.Monitors.Add(new Monitor(monitor.Uid, monitor.Name, monitor.GetTypeValue(), monitor.Price, monitor.ManufacturingDate, monitor.Properties));
                    }
                    else if (button.Tag is VideoCard)
                    {
                        VideoCard videoCard = button.Tag as VideoCard;
                        GameEnvironment.Items.VideoCards.Add(new VideoCard(videoCard.Uid, videoCard.Name, videoCard.GetTypeValue(), videoCard.Price, videoCard.ManufacturingDate, videoCard.Properties));
                    }
                    else if (button.Tag is OpticalDrive)
                    {
                        OpticalDrive opticalDrive = button.Tag as OpticalDrive;
                        GameEnvironment.Items.OpticalDrives.Add(new OpticalDrive(opticalDrive.Uid, opticalDrive.Name, opticalDrive.GetTypeValue(), opticalDrive.Price, opticalDrive.ManufacturingDate, opticalDrive.Properties));
                    }
                    else if (button.Tag is Keyboard)
                    {
                        Keyboard keyboard = button.Tag as Keyboard;
                        GameEnvironment.Items.Keyboards.Add(new Keyboard(keyboard.Uid, keyboard.Name, keyboard.GetTypeValue(), keyboard.Price, keyboard.ManufacturingDate, keyboard.Properties));
                    }

                    SellerText.Text = "Спасибо за покупку " + (button.Tag as BaseItem).Name + ", хороший выбор!";
                }
                else
                {
                    SellerText.Text = "Извини дружище, нет денег нет товара.";
                }
            }
            else if (button.Tag is Mouse)
            {
                Mouse mouse = button.Tag as Mouse;
                GameEnvironment.Items.Mice.Add(new Mouse(mouse.Uid, mouse.Name, mouse.GetTypeValue(), mouse.Price, mouse.ManufacturingDate, mouse.Properties));
            }
        }