private static bool LoadFusion(Dictionary <string, FusionInfo> fusion) { using (ProduceBussiness db = new ProduceBussiness()) { FusionInfo[] infos = db.GetAllFusion(); FusionInfo[] array = infos; for (int j = 0; j < array.Length; j++) { FusionInfo info = array[j]; List <int> list = new List <int>(); list.Add(info.Item1); list.Add(info.Item2); list.Add(info.Item3); list.Add(info.Item4); list.Add(info.Formula); list.Sort(); StringBuilder items = new StringBuilder(); foreach (int i in list) { if (i != 0) { items.Append(i); } } string key = items.ToString(); if (!fusion.ContainsKey(key)) { fusion.Add(key, info); } } } return(true); }
private static bool LoadFusion(Dictionary <string, FusionInfo> fusion) { using (ProduceBussiness produceBussiness = new ProduceBussiness()) { FusionInfo[] allFusion = produceBussiness.GetAllFusion(); FusionInfo[] array = allFusion; for (int i = 0; i < array.Length; i++) { FusionInfo fusionInfo = array[i]; List <int> list = new List <int>(); list.Add(fusionInfo.Item1); list.Add(fusionInfo.Item2); list.Add(fusionInfo.Item3); list.Add(fusionInfo.Item4); list.Sort(); StringBuilder stringBuilder = new StringBuilder(); foreach (int current in list) { if (current != 0) { stringBuilder.Append(current); } } string key = stringBuilder.ToString(); if (!fusion.ContainsKey(key)) { fusion.Add(key, fusionInfo); } } } return(true); }
public FusionInfo[] GetAllFusion() { List <FusionInfo> infos = new List <FusionInfo>(); SqlDataReader reader = null; try { db.GetReader(ref reader, "SP_Fusion_All"); while (reader.Read()) { FusionInfo info = new FusionInfo(); info.FusionID = (int)reader["FusionID"]; info.Item1 = (int)reader["Item1"]; info.Item2 = (int)reader["Item2"]; info.Item3 = (int)reader["Item3"]; info.Item4 = (int)reader["Item4"]; info.Formula = (int)reader["Formula"]; info.Reward = (int)reader["Reward"]; infos.Add(info); } } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("GetAllFusion", e); } } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } } return(infos.ToArray()); }
public static Dictionary <int, double> FusionPreview(List <ItemInfo> Items, List <ItemInfo> AppendItems, ItemInfo Formul, ref bool isBind) { List <int> list = new List <int>(); int MaxLevel = 0; int TotalRate = 0; Dictionary <int, double> Item_Rate = new Dictionary <int, double>(); Item_Rate.Clear(); foreach (ItemInfo p in Items) { list.Add(p.Template.FusionType); if (p.Template.Level > MaxLevel) { MaxLevel = p.Template.Level; } TotalRate += p.Template.FusionRate; if (p.IsBinds) { isBind = true; } } if (Formul.IsBinds) { isBind = true; } list.Add(Formul.TemplateID); foreach (ItemInfo p in AppendItems) { TotalRate += p.Template.FusionRate / 2; if (p.IsBinds) { isBind = true; } } list.Sort(); StringBuilder itemString = new StringBuilder(); foreach (int i in list) { itemString.Append(i); } string key = itemString.ToString(); FusionMgr.m_lock.AcquireReaderLock(-1); Dictionary <int, double> result; try { if (FusionMgr._fusions.ContainsKey(key)) { FusionInfo info = FusionMgr._fusions[key]; ItemTemplateInfo temp_0 = ItemMgr.GetGoodsbyFusionTypeandLevel(info.Reward, MaxLevel); ItemTemplateInfo temp_ = ItemMgr.GetGoodsbyFusionTypeandLevel(info.Reward, MaxLevel + 1); ItemTemplateInfo temp_2 = ItemMgr.GetGoodsbyFusionTypeandLevel(info.Reward, MaxLevel + 2); List <ItemTemplateInfo> temps = new List <ItemTemplateInfo>(); if (temp_2 != null) { temps.Add(temp_2); } if (temp_ != null) { temps.Add(temp_); } if (temp_0 != null) { temps.Add(temp_0); } ItemTemplateInfo tempMax = ( from s in temps where (double)TotalRate / (double)s.FusionNeedRate <= 1.1 orderby(double) TotalRate / (double)s.FusionNeedRate descending select s).FirstOrDefault <ItemTemplateInfo>(); ItemTemplateInfo tempMin = ( from s in temps where (double)TotalRate / (double)s.FusionNeedRate > 1.1 orderby(double) TotalRate / (double)s.FusionNeedRate select s).FirstOrDefault <ItemTemplateInfo>(); if (tempMax != null && tempMin == null) { Item_Rate.Add(tempMax.TemplateID, (double)(100 * TotalRate) / (double)tempMax.FusionNeedRate); } if (tempMax != null && tempMin != null) { double rateMax; double rateMin; if (tempMax.Level - tempMin.Level == 2) { rateMax = (double)(100 * TotalRate) * 0.6 / (double)tempMax.FusionNeedRate; rateMin = 100.0 - rateMax; } else { rateMax = (double)(100 * TotalRate) / (double)tempMax.FusionNeedRate; rateMin = 100.0 - rateMax; } Item_Rate.Add(tempMax.TemplateID, rateMax); if (rateMin > 0.0) { Item_Rate.Add(tempMin.TemplateID, rateMin); } } if (tempMax == null && tempMin != null) { Item_Rate.Add(tempMin.TemplateID, 100.0); } int[] templist = Item_Rate.Keys.ToArray <int>(); int[] array = templist; for (int j = 0; j < array.Length; j++) { int ID = array[j]; foreach (ItemInfo p in Items) { if (ID == p.Template.TemplateID) { if (Item_Rate.ContainsKey(ID)) { Item_Rate.Remove(ID); } } } } result = Item_Rate; return(result); } result = Item_Rate; return(result); } catch { } finally { FusionMgr.m_lock.ReleaseReaderLock(); } result = null; return(result); }
public static ItemTemplateInfo Fusion(List <ItemInfo> Items, List <ItemInfo> AppendItems, ItemInfo Formul, ref bool isBind, ref bool result) { List <int> list = new List <int>(); int MaxLevel = 0; int TotalRate = 0; ItemTemplateInfo returnItem = null; foreach (ItemInfo p in Items) { list.Add(p.Template.FusionType); if (p.Template.Level > MaxLevel) { MaxLevel = p.Template.Level; } TotalRate += p.Template.FusionRate; if (p.IsBinds) { isBind = true; } } if (Formul.IsBinds) { isBind = true; } foreach (ItemInfo p in AppendItems) { TotalRate += p.Template.FusionRate / 2; if (p.IsBinds) { isBind = true; } } list.Add(Formul.TemplateID); list.Sort(); StringBuilder itemString = new StringBuilder(); foreach (int i in list) { itemString.Append(i); } string key = itemString.ToString(); FusionMgr.m_lock.AcquireReaderLock(-1); ItemTemplateInfo result2; try { if (FusionMgr._fusions.ContainsKey(key)) { FusionInfo info = FusionMgr._fusions[key]; ItemTemplateInfo temp_0 = ItemMgr.GetGoodsbyFusionTypeandLevel(info.Reward, MaxLevel); ItemTemplateInfo temp_ = ItemMgr.GetGoodsbyFusionTypeandLevel(info.Reward, MaxLevel + 1); ItemTemplateInfo temp_2 = ItemMgr.GetGoodsbyFusionTypeandLevel(info.Reward, MaxLevel + 2); List <ItemTemplateInfo> temps = new List <ItemTemplateInfo>(); if (temp_2 != null) { temps.Add(temp_2); } if (temp_ != null) { temps.Add(temp_); } if (temp_0 != null) { temps.Add(temp_0); } ItemTemplateInfo tempMax = ( from s in temps where (double)TotalRate / (double)s.FusionNeedRate <= 1.1 orderby(double) TotalRate / (double)s.FusionNeedRate descending select s).FirstOrDefault <ItemTemplateInfo>(); ItemTemplateInfo tempMin = ( from s in temps where (double)TotalRate / (double)s.FusionNeedRate > 1.1 orderby(double) TotalRate / (double)s.FusionNeedRate select s).FirstOrDefault <ItemTemplateInfo>(); if (tempMax != null && tempMin == null) { returnItem = tempMax; if ((double)(100 * TotalRate) / (double)tempMax.FusionNeedRate > (double)FusionMgr.random.Next(100)) { result = true; } } if (tempMax != null && tempMin != null) { if (tempMax.Level - tempMin.Level == 2) { double rateMax = (double)(100 * TotalRate) * 0.6 / (double)tempMax.FusionNeedRate; double rateMin = 100.0 - rateMax; } else { double rateMax = (double)(100 * TotalRate) / (double)tempMax.FusionNeedRate; double rateMin = 100.0 - rateMax; } if ((double)(100 * TotalRate) / (double)tempMax.FusionNeedRate > (double)FusionMgr.random.Next(100)) { returnItem = tempMax; result = true; } else { returnItem = tempMin; result = true; } } if (tempMax == null && tempMin != null) { returnItem = tempMin; result = true; } if (result) { foreach (ItemInfo p in Items) { if (p.Template.TemplateID == returnItem.TemplateID) { result = false; break; } } } result2 = returnItem; return(result2); } } catch { } finally { FusionMgr.m_lock.ReleaseReaderLock(); } result2 = null; return(result2); }
public static Dictionary <int, double> FusionPreview(List <ItemInfo> Items, List <ItemInfo> AppendItems, ItemInfo Formul, ref bool isBind) { List <int> list = new List <int>(); int MaxLevel = 0; int TotalRate = 0; Dictionary <int, double> Item_Rate = new Dictionary <int, double>(); Item_Rate.Clear(); foreach (ItemInfo p in Items) { list.Add(p.Template.FusionType); if (p.Template.Level > MaxLevel) { MaxLevel = p.Template.Level; } TotalRate += p.Template.FusionRate; if (p.IsBinds) { isBind = true; } } if (Formul.IsBinds) { isBind = true; } foreach (ItemInfo p in AppendItems) { TotalRate += p.Template.FusionRate / 2; if (p.IsBinds) { isBind = true; } } list.Sort(); StringBuilder itemString = new StringBuilder(); foreach (int i in list) { itemString.Append(i); } itemString.Append(Formul.TemplateID); string key = itemString.ToString(); m_lock.AcquireReaderLock(Timeout.Infinite); try { if (_fusions.ContainsKey(key)) { FusionInfo info = _fusions[key]; double rateMax = 0; double rateMin = 0; ItemTemplateInfo temp_0 = Bussiness.Managers.ItemMgr.GetGoodsbyFusionTypeandLevel(info.Reward, MaxLevel); ItemTemplateInfo temp_1 = Bussiness.Managers.ItemMgr.GetGoodsbyFusionTypeandLevel(info.Reward, MaxLevel + 1); ItemTemplateInfo temp_2 = Bussiness.Managers.ItemMgr.GetGoodsbyFusionTypeandLevel(info.Reward, MaxLevel + 2); List <ItemTemplateInfo> temps = new List <ItemTemplateInfo>(); if (temp_2 != null) { temps.Add(temp_2); } if (temp_1 != null) { temps.Add(temp_1); } if (temp_0 != null) { temps.Add(temp_0); } ItemTemplateInfo tempMax = temps.Where(s => (TotalRate / (double)s.FusionNeedRate) <= 1.1).OrderByDescending(s => (TotalRate / (double)s.FusionNeedRate)).FirstOrDefault(); ItemTemplateInfo tempMin = temps.Where(s => (TotalRate / (double)s.FusionNeedRate) > 1.1).OrderBy(s => (TotalRate / (double)s.FusionNeedRate)).FirstOrDefault(); if ((tempMax != null) && (tempMin == null)) { Item_Rate.Add(tempMax.TemplateID, 100); } if ((tempMax != null) && (tempMin != null)) { if (tempMax.Level - tempMin.Level == 2) { rateMax = 100 * TotalRate * 0.6 / (double)tempMax.FusionNeedRate; rateMin = 100 - rateMax; } else { rateMax = 100 * TotalRate / (double)tempMax.FusionNeedRate; rateMin = 100 - rateMax; } Item_Rate.Add(tempMax.TemplateID, rateMax); Item_Rate.Add(tempMin.TemplateID, rateMin); } if ((tempMax == null) && (tempMin != null)) { Item_Rate.Add(tempMin.TemplateID, 100); } int[] templist = Item_Rate.Keys.ToArray(); foreach (int ID in templist) { foreach (ItemInfo p in Items) { if (ID == p.Template.TemplateID) { if (Item_Rate.ContainsKey(ID)) { Item_Rate.Remove(ID); } } } } return(Item_Rate); } else { return(Item_Rate); } } catch { } finally { m_lock.ReleaseReaderLock(); } return(null); }
public static Dictionary <int, double> FusionPreview(List <ItemInfo> Items, List <ItemInfo> AppendItems, ref bool isBind) { List <int> list = new List <int>(); int num = 0; int TotalRate = 0; Dictionary <int, double> dictionary = new Dictionary <int, double>(); dictionary.Clear(); foreach (ItemInfo current in Items) { list.Add(current.Template.FusionType); if (current.Template.Level > num) { num = current.Template.Level; } TotalRate += current.Template.FusionRate; if (current.IsBinds) { isBind = true; } } foreach (ItemInfo current2 in AppendItems) { TotalRate += current2.Template.FusionRate / 2; if (current2.IsBinds) { isBind = true; } } list.Sort(); StringBuilder stringBuilder = new StringBuilder(); foreach (int current3 in list) { stringBuilder.Append(current3); } string key = stringBuilder.ToString(); FusionMgr.m_lock.AcquireReaderLock(15000); try { Dictionary <int, double> result; if (FusionMgr._fusions.ContainsKey(key)) { FusionInfo fusionInfo = FusionMgr._fusions[key]; ItemTemplateInfo goodsbyFusionTypeandLevel = ItemMgr.GetGoodsbyFusionTypeandLevel(fusionInfo.Reward, num); ItemTemplateInfo goodsbyFusionTypeandLevel2 = ItemMgr.GetGoodsbyFusionTypeandLevel(fusionInfo.Reward, num + 1); ItemTemplateInfo goodsbyFusionTypeandLevel3 = ItemMgr.GetGoodsbyFusionTypeandLevel(fusionInfo.Reward, num + 2); List <ItemTemplateInfo> list2 = new List <ItemTemplateInfo>(); if (goodsbyFusionTypeandLevel3 != null) { list2.Add(goodsbyFusionTypeandLevel3); } if (goodsbyFusionTypeandLevel2 != null) { list2.Add(goodsbyFusionTypeandLevel2); } if (goodsbyFusionTypeandLevel != null) { list2.Add(goodsbyFusionTypeandLevel); } ItemTemplateInfo itemTemplateInfo = ( from s in list2 where (double)TotalRate / (double)s.FusionNeedRate <= 1.1 orderby(double) TotalRate / (double)s.FusionNeedRate descending select s).FirstOrDefault <ItemTemplateInfo>(); ItemTemplateInfo itemTemplateInfo2 = ( from s in list2 where (double)TotalRate / (double)s.FusionNeedRate > 1.1 orderby(double) TotalRate / (double)s.FusionNeedRate select s).FirstOrDefault <ItemTemplateInfo>(); if (itemTemplateInfo != null && itemTemplateInfo2 == null) { dictionary.Add(itemTemplateInfo.TemplateID, (double)(100 * TotalRate) / (double)itemTemplateInfo.FusionNeedRate); } if (itemTemplateInfo != null && itemTemplateInfo2 != null) { double num2; double value; if (itemTemplateInfo.Level - itemTemplateInfo2.Level == 2) { num2 = (double)(100 * TotalRate) * 0.6 / (double)itemTemplateInfo.FusionNeedRate; value = 100.0 - num2; } else { num2 = (double)(100 * TotalRate) / (double)itemTemplateInfo.FusionNeedRate; value = 100.0 - num2; } dictionary.Add(itemTemplateInfo.TemplateID, num2); dictionary.Add(itemTemplateInfo2.TemplateID, value); } if (itemTemplateInfo == null && itemTemplateInfo2 != null) { dictionary.Add(itemTemplateInfo2.TemplateID, 100.0); } int[] array = dictionary.Keys.ToArray <int>(); int[] array2 = array; for (int i = 0; i < array2.Length; i++) { int num3 = array2[i]; foreach (ItemInfo current4 in Items) { if (num3 == current4.Template.TemplateID && dictionary.ContainsKey(num3)) { dictionary.Remove(num3); } } } result = dictionary; return(result); } result = dictionary; return(result); } catch { } finally { FusionMgr.m_lock.ReleaseReaderLock(); } return(null); }
public static ItemTemplateInfo Fusion(List <ItemInfo> Items, List <ItemInfo> AppendItems, ref bool isBind, ref bool result) { List <int> list = new List <int>(); int num = 0; int TotalRate = 0; ItemTemplateInfo itemTemplateInfo = null; foreach (ItemInfo current in Items) { list.Add(current.Template.FusionType); if (current.Template.Level > num) { num = current.Template.Level; } TotalRate += current.Template.FusionRate; if (current.IsBinds) { isBind = true; } } foreach (ItemInfo current2 in AppendItems) { TotalRate += current2.Template.FusionRate / 2; if (current2.IsBinds) { isBind = true; } } list.Sort(); StringBuilder stringBuilder = new StringBuilder(); foreach (int current3 in list) { stringBuilder.Append(current3); } string key = stringBuilder.ToString(); FusionMgr.m_lock.AcquireReaderLock(15000); try { if (FusionMgr._fusions.ContainsKey(key)) { FusionInfo fusionInfo = FusionMgr._fusions[key]; ItemTemplateInfo goodsbyFusionTypeandLevel = ItemMgr.GetGoodsbyFusionTypeandLevel(fusionInfo.Reward, num); ItemTemplateInfo goodsbyFusionTypeandLevel2 = ItemMgr.GetGoodsbyFusionTypeandLevel(fusionInfo.Reward, num + 1); ItemTemplateInfo goodsbyFusionTypeandLevel3 = ItemMgr.GetGoodsbyFusionTypeandLevel(fusionInfo.Reward, num + 2); List <ItemTemplateInfo> list2 = new List <ItemTemplateInfo>(); if (goodsbyFusionTypeandLevel3 != null) { list2.Add(goodsbyFusionTypeandLevel3); } if (goodsbyFusionTypeandLevel2 != null) { list2.Add(goodsbyFusionTypeandLevel2); } if (goodsbyFusionTypeandLevel != null) { list2.Add(goodsbyFusionTypeandLevel); } ItemTemplateInfo itemTemplateInfo2 = ( from s in list2 where (double)TotalRate / (double)s.FusionNeedRate <= 1.1 orderby(double) TotalRate / (double)s.FusionNeedRate descending select s).FirstOrDefault <ItemTemplateInfo>(); ItemTemplateInfo itemTemplateInfo3 = ( from s in list2 where (double)TotalRate / (double)s.FusionNeedRate > 1.1 orderby(double) TotalRate / (double)s.FusionNeedRate select s).FirstOrDefault <ItemTemplateInfo>(); if (itemTemplateInfo2 != null && itemTemplateInfo3 == null) { itemTemplateInfo = itemTemplateInfo2; if ((double)(100 * TotalRate) / (double)itemTemplateInfo2.FusionNeedRate > (double)FusionMgr.rand.Next(100)) { result = true; } } if (itemTemplateInfo2 != null && itemTemplateInfo3 != null) { if (itemTemplateInfo2.Level - itemTemplateInfo3.Level == 2) { double num2 = (double)(100 * TotalRate) * 0.6 / (double)itemTemplateInfo2.FusionNeedRate; } else { double num2 = (double)(100 * TotalRate) / (double)itemTemplateInfo2.FusionNeedRate; } if ((double)(100 * TotalRate) / (double)itemTemplateInfo2.FusionNeedRate > (double)FusionMgr.rand.Next(100)) { itemTemplateInfo = itemTemplateInfo2; result = true; } else { itemTemplateInfo = itemTemplateInfo3; result = true; } } if (itemTemplateInfo2 == null && itemTemplateInfo3 != null) { itemTemplateInfo = itemTemplateInfo3; result = true; } if (result) { foreach (ItemInfo current4 in Items) { if (current4.Template.TemplateID == itemTemplateInfo.TemplateID) { result = false; break; } } } return(itemTemplateInfo); } } catch { } finally { FusionMgr.m_lock.ReleaseReaderLock(); } return(null); }