public static List <ItemDrop> GetExtraItems(ItemDrop item) { List <ItemDrop> list = new List <ItemDrop>(); if (extraDic.ContainsKey(item.cat) && extraDic[item.cat].ContainsKey(item.id)) { CatPriority cp = extraDic[item.cat][item.id]; int[] cats = cp.GetCats(1); for (int i = 0; i < cats.Length; i++) { if (catDic.ContainsKey(cp.cats[cats[i]])) { int index = cats[i]; ItemPriority itemPriority = catDic[cp.cats[index]]; int count = cp.counts[index]; for (int j = 0; j < count; j++) { foreach (ItemDrop drop in itemPriority.GetItems(1)) { list.Add(drop); } } } } } return(list); }
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); }
public static void Initial(int mapId) { if (dropDic == null || dropDic.Count <= 0) { 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> >(); int loaded = 0; foreach (var item in DropAreaConfig.current.Items) { Logger.InfoFormat("drop_area.xml MapId {0}, server MapId {1}", item.MapId, mapId); if (item.MapId == mapId) { rangeDic[item.AwardId] = new DropRange(item.Range, item.Count); dropDic[item.AwardId] = new CatPriority(item.Drop); loaded++; } } Logger.InfoFormat("drop_area data loaded, {0}", loaded); loaded = 0; if (dropDic.Count <= 0) { Logger.InfoFormat("无配置掉落点位,跳过道具表的读取。"); return; } MyDictionary <string, List <DropPool> > catMap = new MyDictionary <string, List <DropPool> >(); foreach (var item in DropPoolConfig.current.Items) { string cat = item.Cat; if (!catMap.ContainsKey(cat)) { catMap[cat] = new List <DropPool>(); } catMap[cat].Add(item); loaded++; } Logger.InfoFormat("drop_pool data loaded, {0}", loaded); loaded = 0; foreach (string key in catMap.Keys) { List <DropPool> 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].ItemType); ids[i] = int.Parse(list[i].ItemId); ps[i] = int.Parse(list[i].Proiority); cs[i] = int.Parse(list[i].DropCount); } catDic[key] = new ItemPriority(cats, ids, ps, cs); } foreach (var item in DropItemConfig.current.Items) { int index = int.Parse(item.Item); int cat = int.Parse(item.ItemType); string drop = item.ExtraDrop; if (!extraDic.ContainsKey(cat)) { extraDic.Add(cat, new MyDictionary <int, CatPriority>()); } extraDic[cat][index] = new CatPriority(drop); loaded++; } Logger.InfoFormat("drop_item data loaded, {0}", loaded); InitialPoints(mapId); } }
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(); } }