Example #1
0
        public static List <ItemDrop> GetDropItems(int id, int mapId)
        {
            Initial(mapId);

            if (dropCache.ContainsKey(id))
            {
                return(dropCache[id]);
            }

            List <ItemDrop> items = new List <ItemDrop>();

            if (dropDic.ContainsKey(id) && null != MapConfigPoints.current)
            {
                CatPriority catPriority = dropDic[id];
                DropRange   r           = rangeDic[id];

                MapConfigPoints.ID_Point idPoint = null;

                List <MapConfigPoints.ID_Point> ps = MapConfigPoints.current.IDPints;
                for (int i = 0; i < ps.Count; i++)
                {
                    if (ps[i].ID == id)
                    {
                        idPoint = ps[i];
                        break;
                    }
                }

                if (idPoint != null)
                {
                    int   itemCount = RandomUtil.Random(r.posFromCount, r.posToCount);
                    int[] pIndex    = RandomUtil.Random(0, idPoint.points.Count - 1, itemCount);
                    for (int p = 0; p < pIndex.Length; p++)
                    {
                        Vector3 pos = idPoint.points[pIndex[p]].pos;

                        int[] cats = catPriority.GetCats(RandomUtil.Random(r.dropFromCount, r.dropToCount));

                        for (int i = 0; i < cats.Length; i++)
                        {
                            if (catDic.ContainsKey(catPriority.cats[cats[i]]))
                            {
                                ItemPriority itemPriority = catDic[catPriority.cats[cats[i]]];
                                ItemDrop     item         = itemPriority.GetItems(1)[0];
                                item.pos = pos;

                                items.Add(item);
                            }
                        }
                    }
                }
            }

            return(items);
        }
Example #2
0
        public static void Initial()
        {
            if (dropDic == null)
            {
                dropDic   = new MyDictionary <int, CatPriority>();
                catDic    = new MyDictionary <string, ItemPriority>();
                extraDic  = new MyDictionary <int, MyDictionary <int, CatPriority> >();
                rangeDic  = new MyDictionary <int, DropRange>();
                dropCache = new Dictionary <int, List <ItemDrop> >();

                List <DataRecord> dropList = MysqlUtil.SelectRecords("select * from new_item_drop", FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in dropList)
                {
                    int    id    = int.Parse(dr.GetValue("id"));
                    string range = dr.GetValue("range");
                    string drop  = dr.GetValue("drop");
                    string count = dr.GetValue("count");

                    rangeDic[id] = new DropRange(range, count);
                    dropDic[id]  = new CatPriority(drop);
                }

                List <DataRecord> catList = MysqlUtil.SelectRecords("select * from new_drop_cat", FreeRuleConfig.MysqlConnection);
                MyDictionary <string, List <DataRecord> > catMap = new MyDictionary <string, List <DataRecord> >();
                foreach (DataRecord dr in catList)
                {
                    string cat = dr.GetValue("cat");
                    if (!catMap.ContainsKey(cat))
                    {
                        catMap[cat] = new List <DataRecord>();
                    }

                    catMap[cat].Add(dr);
                }
                foreach (string key in catMap.Keys)
                {
                    List <DataRecord> list = catMap[key];

                    int[] cats = new int[list.Count];
                    int[] ids  = new int[list.Count];
                    int[] ps   = new int[list.Count];
                    int[] cs   = new int[list.Count];

                    for (int i = 0; i < list.Count; i++)
                    {
                        cats[i] = int.Parse(list[i].GetValue("itemCat"));
                        ids[i]  = int.Parse(list[i].GetValue("itemId"));
                        ps[i]   = int.Parse(list[i].GetValue("priority"));
                        cs[i]   = int.Parse(list[i].GetValue("count"));
                    }

                    catDic[key] = new ItemPriority(cats, ids, ps, cs);
                }

                List <DataRecord> extraList = MysqlUtil.SelectRecords("select * from new_item_extra", FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in extraList)
                {
                    int    item = int.Parse(dr.GetValue("item"));
                    int    cat  = int.Parse(dr.GetValue("cat"));
                    string drop = dr.GetValue("extraDrop");
                    if (!extraDic.ContainsKey(cat))
                    {
                        extraDic.Add(cat, new MyDictionary <int, CatPriority>());
                    }
                    extraDic[cat][item] = new CatPriority(drop);
                }

                List <DataRecord> itemList = MysqlUtil.SelectRecords("select * from new_item", FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in itemList)
                {
                    string item = dr.GetValue("item");
                    int    id   = int.Parse(dr.GetValue("id"));
                }

                InitialPoints();
            }
        }