예제 #1
0
        private static void GetShopLot(RequestHolder request)                     // [1]name
        {
            ShopLot result = DataForWrappers.Shop.GetShopLot(request.Command[1]); // loading shoplot

            if (result == null)
            {
                Server.Send(request.Client, new byte[] { 0 });
                return;
            }

            Server.Send(request.Client, result.Save());
        }
예제 #2
0
        private static void Buy(RequestHolder request)                         // [1]item [2]password [3]my_account_name
        {
            ShopLot lot = DataForWrappers.Shop.GetShopLot(request.Command[1]); // loading shoplot

            if (lot == null)
            {
                Server.Send(request.Client, new byte[] { 0 });
                return;
            }

            Account account = DataForWrappers.Shop.GetAccount(request.Command[3]); // loading account

            if (account == null)
            {
                Server.Send(request.Client, new byte[] { 0 });
                return;
            }

            try
            {
                account.Withdraw(lot.Price, request.Command[2]);
                DataForWrappers.Shop.UpdateAccount(account); // applying changes
                Console.WriteLine($"{request.Command[3]} have bought {lot.Name} for {lot.Price}");
                Server.Send(request.Client, new byte[] { 1 });
            }
            catch (ArgumentOutOfRangeException e) // problem with withdraw
            {
                Server.Send(request.Client, new byte[] { 0 });
            }
            catch (ArgumentException e) // problem with applying
            {
                Server.Send(request.Client, new byte[] { 0 });
            }
            catch (MemberAccessException e) // problem with withdraw
            {
                Server.Send(request.Client, new byte[] { 0 });
            }
            catch // other problem
            {
                Server.Send(request.Client, new byte[] { 0 });
            }
        }
예제 #3
0
        private void RandomiseShopItems()
        {
            List <ShopLot> cachedShopItems    = MainWindow.GameWorld.GetAllShopItems();
            List <ItemLot> cachedTreasureLots = MainWindow.GameWorld.GetAllTreasureLots();

            foreach (var shopLot in cachedShopItems)
            {
                //We do not want to potentially reinsert key items that have been swapped into the shop back into the world at forbidden id's
                if (!IDBanks.keyItems.Contains(shopLot.ShopLotItem.EquipID))
                {
                    //Decide if swapping with vendor or with world items
                    bool swapWithWorldItem = true;

                    //swapWithWorldItem = rng.Next(0, 2) > 0;

                    if (swapWithWorldItem)
                    {
                        //Pick a random treasure to swap with, make sure its not a NORMAL soul drop
                        ItemLot treasureItemToSwapWith = cachedTreasureLots[rng.Next(cachedTreasureLots.Count)];
                        while (shopLot.ownerShopKeeper.HasShopLotItem(treasureItemToSwapWith) || Convert.ToInt64(treasureItemToSwapWith.ItemLotItems[0].ItemCategory) == -1 || IDBanks.soulsIds.Contains(treasureItemToSwapWith.ItemLotItems[0].ID))
                        {
                            treasureItemToSwapWith = cachedTreasureLots[rng.Next(cachedTreasureLots.Count)];
                        }

                        shopLot.SwapItemLotValues(treasureItemToSwapWith.ItemLotItems[0]);
                    }

                    if (!swapWithWorldItem)
                    {
                        //Don't swap an item with itself
                        ShopLot shopItemToSwapWith = cachedShopItems[rng.Next(cachedShopItems.Count)];
                        while (shopItemToSwapWith.ID == shopLot.ID || shopLot.ownerShopKeeper.HasShopLotItem(shopItemToSwapWith.ShopLotItem))
                        {
                            shopItemToSwapWith = cachedShopItems[rng.Next(cachedShopItems.Count)];
                        }

                        shopLot.SwapItemLotValues(shopItemToSwapWith.ShopLotItem);
                    }
                }
            }
        }
예제 #4
0
        private static void Add()
        {
            switch (TerminalCommand[1])
            {
            case "account":
            {
                string password;     // getting password
                while (true)
                {
                    Console.WriteLine("print new password");
                    password = Console.ReadLine();
                    Console.WriteLine("confirm password");
                    if (Console.ReadLine() == password)
                    {
                        break;
                    }
                    Console.WriteLine("passwords isn't similar");
                }

                Account account = new Account(TerminalCommand[2], password); // creating account

                try                                                          // adding account
                {
                    DataForWrappers.Shop.AddAccount(account);
                }
                catch (Exception e)     // all mistakes throwing to user console
                {
                    Console.WriteLine(e.Message);
                    return;
                }
                break;
            }

            case "goods":
            {
                string picturePath;     // getting picture
                while (true)
                {
                    Console.WriteLine("print path to the picture");
                    picturePath = Console.ReadLine();
                    if (File.Exists(picturePath))
                    {
                        break;
                    }

                    Console.WriteLine("wrong path");
                }

                Console.WriteLine("print goods description");     // getting description
                string about = Console.ReadLine();

                long price;     // getting price
                while (true)
                {
                    try
                    {
                        Console.WriteLine("print price");
                        price = Convert.ToInt64(Console.ReadLine());
                        break;
                    }
                    catch
                    {
                        Console.WriteLine("not a number");
                    }
                }

                /*string[] tags; // getting price
                 * while (true)
                 * {
                 *  try
                 *  {
                 *      Console.WriteLine(
                 *          "add tags" + Environment.NewLine +
                 *          "you can add no tags" + Environment.NewLine +
                 *          "tags must be spited by spaces"
                 *      );
                 *      tags = Console.ReadLine().Split();
                 *      break;
                 *  }
                 *  catch
                 *  {
                 *      Console.WriteLine("wrong input");
                 *  }
                 * }*/

                ShopLot shopLot = new ShopLot(TerminalCommand[2], picturePath, about, price);

                try     // adding shop lot
                {
                    DataForWrappers.Shop.AddShopLot(shopLot);
                }
                catch (Exception e)     // all mistakes throwing to user console
                {
                    Console.WriteLine(e.Message);
                    return;
                }
                break;
            }

            default:
            {
                Console.WriteLine("wrong argument");
                return;
            }
            }

            Console.WriteLine("Item added");
        }