public static void LoadData() { SqliteDataReader reader = LocalDatabase.Instance.ReadFullTable("randomitemtype"); while (reader.Read()) { RandomItemTypeInfo typeInfo = new RandomItemTypeInfo(); typeInfo.itemNo = Convert.ToInt32(reader.GetString(reader.GetOrdinal("itemno"))); typeInfo.prototypeItem_id = Convert.ToInt32(reader.GetString(reader.GetOrdinal("prototypeItem_id"))); typeInfo.itemAmount = Convert.ToInt32(reader.GetString(reader.GetOrdinal("itemAmount"))); typeInfo.itemWeight = Convert.ToInt32(reader.GetString(reader.GetOrdinal("itemWeight"))); typeInfo.itemFloating = Convert.ToSingle(reader.GetString(reader.GetOrdinal("itemFloating"))); typeInfo.itemLevel = Convert.ToInt32(reader.GetString(reader.GetOrdinal("itemtypeLevel"))); typeInfo.itemType = Convert.ToInt32(reader.GetString(reader.GetOrdinal("itemtype"))); if (ItemAsset.ItemProto.Mgr.Instance.Get(typeInfo.prototypeItem_id) == null) { Debug.LogError("database Error:table-randomitemtype, itemno-" + typeInfo.itemNo + ", prototypeItem_id-" + typeInfo.prototypeItem_id); continue; } if (!mDataDic.ContainsKey(typeInfo.itemType)) { mDataDic[typeInfo.itemType] = new Dictionary <int, List <RandomItemTypeInfo> >(); } if (!mDataDic[typeInfo.itemType].ContainsKey(typeInfo.itemLevel)) { mDataDic[typeInfo.itemType][typeInfo.itemLevel] = new List <RandomItemTypeInfo> (); } mDataDic[typeInfo.itemType][typeInfo.itemLevel].Add(typeInfo); } }
public List <ItemIdCount> RandomItemDict(int count, System.Random rand = null) { List <ItemIdCount> items = new List <ItemIdCount>(); if (rand == null) { rand = new System.Random((int)System.DateTime.UtcNow.Ticks); } // if(count ==0) // Debug.LogError(string.Format("RandomItemDict count 0!")); for (int i = 0; i < count; i++) { int type; int level = RandomTypeLevel(out type, rand); List <RandomItemTypeInfo> riti = RandomItemTypeInfo.RandomItemTypeInfoByLevel(level, type); if (riti != null && riti.Count > 0) { RandomItemTypeInfo ritiPicked = new RandomItemTypeInfo(); ritiPicked = riti[rand.Next(riti.Count)]; int itemProtoId = ritiPicked.prototypeItem_id; double countDouble = ritiPicked.itemAmount * (1 + ritiPicked.itemFloating * rand.NextDouble()); int itemCount = Mathf.RoundToInt((float)countDouble); if (itemCount > 0) { ItemIdCount mi = new ItemIdCount(itemProtoId, itemCount); items.Add(mi); // }else{ // // Debug.LogError(string.Format("RandomItemDict itemCount 0:{0},{1}",ritiPicked.prototypeItem_id,ritiPicked.itemAmount)); } } } return(items); }