Beispiel #1
0
        public ItemShopScreen(int id) : base()
        {
            _shop = Data._itemShops.Find(s => s.id == id);
            Clear(ClearType.Both);
            DrawScreenTitle(_shop.name);

            if (_shop.greeting.Length > 0)
            {
                TypeWrite(_shop.greeting, ConsoleColor.DarkYellow, false, false, false);
            }

            if (_shop.sellItemIDs.Count() == 0)
            {
                _shopTab = ShopTab.Buy;
            }
            else
            {
                _shopTab = ShopTab.Sell;
            }

            while (_selectIndex != -1)
            {
                SetUpItemShop();
                GetSelection(true, _selectIndex);

                if (_selectIndex != -1)
                {
                    if (_shopTab == ShopTab.Sell)
                    {
                        if (Data._itemInfo.items.Find(item => item.id == _shop.sellItemIDs [_selectIndex]).unlimited)
                        {
                            if (!GameFile._items.Exists(item => item.itemId == _shop.sellItemIDs [_selectIndex]))
                            {
                                Buy(_shop.sellItemIDs [_selectIndex]);
                            }
                            else
                            {
                                TypeWrite(BuildText(_shop.alreadyHaveItemText, Data._itemInfo.items.Find(item => item.id == _shop.sellItemIDs [_selectIndex]), ""), ConsoleColor.DarkYellow, false, false, true);
                            }
                        }
                        else
                        {
                            Buy(_shop.sellItemIDs [_selectIndex]);
                        }
                    }
                    else
                    {
                        Sell(_shop.buyItemIDs [_selectIndex]);
                    }
                }
            }
        }
Beispiel #2
0
        private void GetItemShops()
        {
            XmlNodeList shops = _xml ["data"]["itemShops"].ChildNodes;

            foreach (XmlNode shopN in shops)
            {
                ItemShop shop = new ItemShop();
                shop.id                  = Convert.ToInt32(shopN.Attributes ["id"].Value);
                shop.name                = shopN.Attributes ["name"].Value;
                shop.greeting            = shopN.Attributes ["greeting"].Value;
                shop.sellTabText         = shopN.Attributes ["sellTabText"].Value;
                shop.buyTabText          = shopN.Attributes ["buyTabText"].Value;
                shop.boughtText          = shopN.Attributes ["boughtText"].Value;
                shop.cannotAffordText    = shopN.Attributes ["cannotAffordText"].Value;
                shop.alreadyHaveItemText = shopN.Attributes ["alreadyHaveItemText"].Value;
                shop.sellItemIDs         = new List <int> {
                };
                shop.sellPrices          = new List <int> {
                };
                shop.sortMode            = (ItemShop.SortMode)Enum.Parse(typeof(ItemShop.SortMode), shopN.Attributes ["sortMode"].Value);
                string [] itemsAndPrices = shopN.Attributes ["sellItems"].Value.Split(new char [] { ',' });

                if (itemsAndPrices [0].Length > 0)
                {
                    foreach (string s in itemsAndPrices)
                    {
                        shop.sellItemIDs.Add(Convert.ToInt32(s.Substring(0, s.IndexOf("-"))));
                        shop.sellPrices.Add(Convert.ToInt32(s.Substring(s.IndexOf("-") + 1)));
                    }

                    if (shop.sortMode == ItemShop.SortMode.ByName)
                    {
                        List <string> sortedItemNames = new List <string> {
                        };

                        for (int i = 0; i < shop.sellItemIDs.Count(); i++)
                        {
                            sortedItemNames.Add(Data._itemInfo.items.Find(theItem => theItem.id == shop.sellItemIDs [i]).name);
                        }

                        List <string> unsortedItemNames = new List <string> (sortedItemNames);
                        sortedItemNames = new AlphNumBST(sortedItemNames).GetStrings();
                        SortArraysByName(unsortedItemNames, sortedItemNames, new List <List <int> > {
                            shop.sellItemIDs, shop.sellPrices
                        });
                    }
                    else if (shop.sortMode == ItemShop.SortMode.ByPrice)
                    {
                        List <int> unsortedItemPrices = shop.sellPrices;
                        List <int> sortedItemPrices   = new NumBST(unsortedItemPrices).GetNums();
                        SortArraysByNumber(unsortedItemPrices, sortedItemPrices, shop.sellItemIDs, shop.sellPrices);
                    }
                }

                shop.soldText      = shopN.Attributes ["soldText"].Value;
                shop.notEnoughText = shopN.Attributes ["notEnoughText"].Value;
                shop.buyItemIDs    = new List <int> {
                };
                shop.buyPrices     = new List <int> {
                };
                itemsAndPrices     = shopN.Attributes ["buyItems"].Value.Split(new char [] { ',' });

                if (itemsAndPrices [0].Length > 0)
                {
                    foreach (string s in itemsAndPrices)
                    {
                        shop.buyItemIDs.Add(Convert.ToInt32(s.Substring(0, s.IndexOf("-"))));
                        shop.buyPrices.Add(Convert.ToInt32(s.Substring(s.IndexOf("-") + 1)));
                    }

                    if (shop.sortMode == ItemShop.SortMode.ByName)
                    {
                        List <string> sortedItemNames = new List <string> {
                        };

                        for (int i = 0; i < shop.buyItemIDs.Count(); i++)
                        {
                            sortedItemNames.Add(Data._itemInfo.items.Find(theItem => theItem.id == shop.buyItemIDs [i]).name);
                        }

                        List <string> unsortedItemNames = new List <string> (sortedItemNames);
                        sortedItemNames = new AlphNumBST(sortedItemNames).GetStrings();
                        SortArraysByName(unsortedItemNames, sortedItemNames, new List <List <int> > {
                            shop.buyItemIDs, shop.buyPrices
                        });
                    }
                    else if (shop.sortMode == ItemShop.SortMode.ByPrice)
                    {
                        List <int> unsortedItemPrices = shop.buyPrices;
                        List <int> sortedItemPrices   = new NumBST(unsortedItemPrices).GetNums();
                        SortArraysByNumber(unsortedItemPrices, sortedItemPrices, shop.buyItemIDs, shop.buyPrices);
                    }
                }

                _itemShops.Add(shop);
            }
        }