/// <summary> /// 获得道具列表 /// </summary> /// <param name="characterId">角色id</param> /// <param name="type">0-3,表示要哪个级别的商品列表</param> /// <param name="profession">表示是哪个职业</param> /// <param name="cachedItems">Logic上缓存的商品id列表</param> /// <param name="itemList">返回商品列表</param> /// <param name="dirty">返回Logic上缓存的商品是否有变化</param> /// <returns>返回错误码</returns> public static ErrorCodes GetList(ulong characterId, int type, int profession, List <long> cachedItems, out GroupShopItemList itemList, out bool dirty) { return(mImpl.GetList(characterId, type, profession, cachedItems, out itemList, out dirty)); }
//重置内容 public ErrorCodes GetNewList(ulong characterId, int type, int profession, List <long> cachedItems, out GroupShopItemList itemList) { itemList = new GroupShopItemList(); var tbGSU = Table.GetGroupShopUpdate(type); if (tbGSU == null) { return(ErrorCodes.Error_DataOverflow); } var i = 0; foreach (var tableId in tbGSU.Goods) { if (tableId < 0) { break; } var count = tbGSU.Count[i]; if (count <= 0) { continue; } var id = GetGroupShopId(tableId, profession); List <GroupShopOne> tempList; if (GroupShop.StoreList.TryGetValue(id, out tempList)) { var selectList = tempList.RandRange(0, count); foreach (var one in selectList) { itemList.Items.Add(one.GetNetData(characterId)); } } ++i; } return(ErrorCodes.OK); }
public ErrorCodes GetList(ulong characterId, int type, int profession, List <long> cachedItems, out GroupShopItemList itemList, out bool dirty) { dirty = false; if (cachedItems.Count == 0) { dirty = true; var err = GetNewList(characterId, type, profession, cachedItems, out itemList); return(err); } itemList = new GroupShopItemList(); var tbGSU = Table.GetGroupShopUpdate(type); if (tbGSU == null) { return(ErrorCodes.Error_DataOverflow); } var items = new Dictionary <int, int>(); var sortedItems = new List <SortedGroupShopItemOne>(); var index = 0; foreach (var tableId in tbGSU.Goods) { if (tableId < 0) { break; } var id = GetGroupShopId(tableId, profession); var count = tbGSU.Count[index]; items.modifyValue(id, count); index++; } //检查已有的内容 foreach (var l in cachedItems) { var temp = GetItem(l); if (temp != null) { var id = temp.tbGroupShop.Id; items.modifyValue(id, -1); sortedItems.Add(new SortedGroupShopItemOne { Id = id, Item = temp.GetNetData(characterId) }); } } //补充新内容 foreach (var i in items) { if (i.Value <= 0) { continue; } List <GroupShopOne> tempList; if (GroupShop.StoreList.TryGetValue(i.Key, out tempList)) { for (var j = 0; j < i.Value; ++j) { var newList = new List <GroupShopOne>(); foreach (var one in tempList) { if (one.State != (int)eGroupShopItemState.OnSell) { continue; } if (sortedItems.All(item => one.Guid != item.Item.Guid)) { newList.Add(one); } } if (newList.Count <= 0) { Logger.Error("In GetList().newList.Count <= 0! id = {0}, j = {1}", i.Key, j); continue; } dirty = true; var select = newList.Range(); sortedItems.Add(new SortedGroupShopItemOne { Id = i.Key, Item = select.GetNetData(characterId) }); } } else { Logger.Error("In GetList(). GroupShop.StoreList.TryGetValue(i.Key, out tempList) return false!"); } } // sort sortedItems.Sort((l, r) => { if (l.Id < r.Id) { return(-1); } if (l.Id > r.Id) { return(1); } return(0); }); // 把 sortedItems 中的内容挪到 itemListItems 里 var itemListItems = itemList.Items; itemListItems.AddRange(sortedItems.Select(one => one.Item)); return(ErrorCodes.OK); }