Example #1
0
        public ShopItemCollection GetAllShopItems(int PageSize, int PageIndex, string SortField, bool DESC, out int retCnt)
        {
            ShopItemCollection retobjs = null;
            string             _DESC   = "DESC";

            if (DESC)
            {
                _DESC = "DESC";
            }
            else
            {
                _DESC = "ASC";
            }

            string sql = "select * from " + this.m_shopItemTablename
                         + " order by " + SortField + " " + _DESC;

            retobjs = this._getShopItems(sql, PageIndex, PageSize);
            //try
            //{
            sql    = sql.Replace("*", "count(*)");
            sql    = sql.Replace("order", "");
            sql    = sql.Replace("by", "");
            sql    = sql.Replace(_DESC, "");
            sql    = sql.Replace(SortField, "");
            retCnt = this.m_db.GetRecordCount(sql);
            //}
            //catch
            //{
            retCnt = 0;
            //}
            return(retobjs);
        }
Example #2
0
        private ShopItemCollection _getShopItems(string sql, int pPageIndex, int pPageSize)
        {
            ShopItemCollection retobjs = new ShopItemCollection();
            SqlDataReader      sdr     = null;
            ShopItem           obj     = null;

            m_db.RunSql(sql, out sdr);
            if (null == sdr)
            {
                return(null);
            }
            int _curRecPos = 0;
            //计算页记录///
            long _startpos = 0;
            long _endpos   = 0;

            if (pPageIndex > -1)
            {
                _startpos = pPageIndex * pPageSize;
                _endpos   = _startpos + pPageSize;
            }
            while (sdr.Read())
            {
                if (_curRecPos > _endpos)
                {
                    break;
                }
                if (_curRecPos >= _startpos && _curRecPos < _endpos)
                {
                    obj = this._buildShopItem(ref sdr);
                    if (null != obj)
                    {
                        retobjs.Add(obj);
                    }
                }
                _curRecPos++;
            }
            sdr.Close();
            if (retobjs.Count > 0)
            {
                return(retobjs);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        private ShopItemCollection _getShopItems(string sql)
        {
            ShopItemCollection retobjs = new ShopItemCollection();
            SqlDataReader      sdr     = null;

            m_db.RunSql(sql, out sdr);
            if (null == sdr)
            {
                return(null);
            }
            while (sdr.Read())
            {
                retobjs.Add(this._buildShopItem(ref sdr));
            }
            sdr.Close();
            return(retobjs);
        }
Example #4
0
        protected override void SetStringValue(string value)
        {
            var entries = value.Split(':');

            if (!this.Validate(entries, $"Malformed shop event \"{value}\".", e => e.Length >= 7 && e[0] == "shop"))
            {
                return;
            }

            var newShopStockIndex = this.ParseIntOrAddError(entries[1]);

            var newShopTypeNumber = this.ParseIntOrAddError(entries[2]);

            this.ParseEnumOrAddError <ShopTypeNumber>(entries[2]);

            var newClerkType = this.ParseIntOrAddError(entries[3]);

            this.ParseEnumOrAddError <ShopClerkTypeNumber>(entries[3]);

            var newFaceSheet = this.ParseIntOrAddError(entries[4]);
            var newFaceIndex = this.ParseIntOrAddError(entries[5]);
            var newFace      = new FaceId(newFaceSheet, (byte)newFaceIndex, false).ToFace();

            this.ParseEnumOrAddError <FACE>(((int)newFace).ToString());

            var newPriceTypeNumber = this.ParseIntOrAddError(entries[6]);

            this.ParseEnumOrAddError <ShopPriceTypeNumber>(entries[6]);

            var newShopItems = new ShopItemCollection {
                StringValue = string.Join(":", entries.Skip(7)), ShopType = newShopTypeNumber, PriceType = newPriceTypeNumber
            };

            this.ShopStockIndex      = newShopStockIndex;
            this.ShopTypeNumber      = newShopTypeNumber;
            this.ShopClerkTypeNumber = newClerkType;
            this.Face            = newFace;
            this.PriceTypeNumber = newPriceTypeNumber;
            this.ShopItems       = newShopItems;
        }
Example #5
0
        static public void Export(string filename, ref ShopItemCollection shopitems)
        {
            if (filename == "" && null == shopitems && shopitems.Count <= 0)
            {
                return;
            }
            string       str = string.Empty;
            StreamWriter sw  = new StreamWriter(filename, false, Encoding.ASCII);

            str = "TabType\tItemIndex\tRandSeed\tCountLimit\tReputeLevel\tPrice";
            sw.WriteLine(str);
            foreach (ShopItem item in shopitems)
            {
                str = item.TabType + "\t"
                      + item.ItemIndex + "\t"
                      + item.RandSeed + "\t"
                      + item.CountLimit + "\t"
                      + item.ReputeLevel + "\t"
                      + item.Price;
                sw.WriteLine(str);
            }
            sw.Flush();
            sw.Close();
        }
Example #6
0
        private static GameShop ReadPriceList(string path)
        {
            XDocument xdoc = null;

            try
            {
                xdoc = XDocument.Load(path);
            }
            catch (XmlException) { }

            if (xdoc == null || xdoc.Root == null) return null;

            var xNameCategories = XName.Get("categories", DefaultNamespace);
            var xNameCategory = XName.Get("category", DefaultNamespace);
            var xNameItem = XName.Get("item", DefaultNamespace);

            var result = new GameShop();
            var categoriesRoot = xdoc.Root.Element(xNameCategories);

            if (categoriesRoot == null)
                return null;

            foreach (var xcat in categoriesRoot.Elements(xNameCategory))
            {
                var catAttr = xcat.Attribute("name");
                if (catAttr == null || string.IsNullOrEmpty(catAttr.Value)) return null;

                var category = new ShopItemCollection(catAttr.Value.Trim());

                foreach (var xitem in xcat.Elements(xNameItem))
                {
                    var idAttr = xitem.Attribute("id");
                    var titleAttr = xitem.Attribute("title");
                    var qualityAttr = xitem.Attribute("quality");
                    var raceAttr = xitem.Attribute("race");
                    var iconAttr = xitem.Attribute("icon");
                    var countAttr = xitem.Attribute("count");
                    var priceAttr = xitem.Attribute("price");

                    if (idAttr == null || string.IsNullOrEmpty(idAttr.Value)) continue;
                    if (titleAttr == null || string.IsNullOrEmpty(titleAttr.Value)) continue;
                    if (priceAttr == null || string.IsNullOrEmpty(priceAttr.Value)) continue;

                    uint id;
                    uint price;
                    uint count;

                    var idTest = uint.TryParse(idAttr.Value, out id);
                    var priceTest = uint.TryParse(priceAttr.Value, out price);

                    if (!idTest || !priceTest) continue;

                    if (countAttr != null)
                    {
                        var countTest = uint.TryParse(countAttr.Value, out count);

                        if (!countTest)
                            count = 1;
                    }
                    else
                        count = 1;

                    var quality = ItemQuality.Common;

                    if (qualityAttr != null &&
                        !string.IsNullOrEmpty(qualityAttr.Value))
                    {
                        ItemQuality temp;

                        var qualityTest = Enum.TryParse(qualityAttr.Value, true, out temp);

                        if (qualityTest)
                            quality = temp;
                    }

                    var race = ItemRaceRestriction.Universal;

                    if (raceAttr != null &&
                        !string.IsNullOrEmpty(raceAttr.Value))
                    {
                        ItemRaceRestriction temp;

                        var raceTest = Enum.TryParse(raceAttr.Value, true, out temp);

                        if (raceTest)
                            race = temp;
                    }

                    string icon = null;

                    if (iconAttr != null &&
                        !string.IsNullOrEmpty(iconAttr.Value))
                        icon = iconAttr.Value.Trim();

                    category.Add(new ShopItem(id, titleAttr.Value.Trim(), quality, race, icon, count, price));
                }

                if (category.Count > 0)
                    result.Add(category);
            }

            return result.Count == 0 ? null : result;
        }
Example #7
0
        private static GameShop ReadPriceList(string path)
        {
            XDocument xdoc = null;

            try
            {
                xdoc = XDocument.Load(path);
            }
            catch (XmlException) { }

            if (xdoc == null || xdoc.Root == null)
            {
                return(null);
            }

            var xNameCategories = XName.Get("categories", DefaultNamespace);
            var xNameCategory   = XName.Get("category", DefaultNamespace);
            var xNameItem       = XName.Get("item", DefaultNamespace);

            var result         = new GameShop();
            var categoriesRoot = xdoc.Root.Element(xNameCategories);

            if (categoriesRoot == null)
            {
                return(null);
            }

            foreach (var xcat in categoriesRoot.Elements(xNameCategory))
            {
                var catAttr = xcat.Attribute("name");
                if (catAttr == null || string.IsNullOrEmpty(catAttr.Value))
                {
                    return(null);
                }

                var category = new ShopItemCollection(catAttr.Value.Trim());

                foreach (var xitem in xcat.Elements(xNameItem))
                {
                    var idAttr      = xitem.Attribute("id");
                    var titleAttr   = xitem.Attribute("title");
                    var qualityAttr = xitem.Attribute("quality");
                    var raceAttr    = xitem.Attribute("race");
                    var iconAttr    = xitem.Attribute("icon");
                    var countAttr   = xitem.Attribute("count");
                    var priceAttr   = xitem.Attribute("price");

                    if (idAttr == null || string.IsNullOrEmpty(idAttr.Value))
                    {
                        continue;
                    }
                    if (titleAttr == null || string.IsNullOrEmpty(titleAttr.Value))
                    {
                        continue;
                    }
                    if (priceAttr == null || string.IsNullOrEmpty(priceAttr.Value))
                    {
                        continue;
                    }

                    uint id;
                    uint price;
                    uint count;

                    var idTest    = uint.TryParse(idAttr.Value, out id);
                    var priceTest = uint.TryParse(priceAttr.Value, out price);

                    if (!idTest || !priceTest)
                    {
                        continue;
                    }

                    if (countAttr != null)
                    {
                        var countTest = uint.TryParse(countAttr.Value, out count);

                        if (!countTest)
                        {
                            count = 1;
                        }
                    }
                    else
                    {
                        count = 1;
                    }

                    var quality = ItemQuality.Common;

                    if (qualityAttr != null &&
                        !string.IsNullOrEmpty(qualityAttr.Value))
                    {
                        ItemQuality temp;

                        var qualityTest = Enum.TryParse(qualityAttr.Value, true, out temp);

                        if (qualityTest)
                        {
                            quality = temp;
                        }
                    }

                    var race = ItemRaceRestriction.Universal;

                    if (raceAttr != null &&
                        !string.IsNullOrEmpty(raceAttr.Value))
                    {
                        ItemRaceRestriction temp;

                        var raceTest = Enum.TryParse(raceAttr.Value, true, out temp);

                        if (raceTest)
                        {
                            race = temp;
                        }
                    }

                    string icon = null;

                    if (iconAttr != null &&
                        !string.IsNullOrEmpty(iconAttr.Value))
                    {
                        icon = iconAttr.Value.Trim();
                    }

                    category.Add(new ShopItem(id, titleAttr.Value.Trim(), quality, race, icon, count, price));
                }

                if (category.Count > 0)
                {
                    result.Add(category);
                }
            }

            return(result.Count == 0 ? null : result);
        }