/// <summary> /// bonus can be in the form A:B,C,D (or A:B) /// </summary> /// <param name="bonus"></param> /// <param name="itemBonusList"></param> /// <returns></returns> public SetBonus CalculateSetBonus(string bonus, IEnumerable <ItemBonus> itemBonusList) { var setBonus = new SetBonus(); if (String.IsNullOrEmpty(bonus)) { return(null); } var bonusEntry = bonus.Split(':'); // If the form is A:B,C,D if (bonusEntry[1].Contains(',')) { var bonusTypeId = bonusEntry[1].Split(',')[0]; var bonusValue = bonusEntry[1].Split(',')[1]; setBonus.MinLevel = Convert.ToInt32(bonusEntry[0]); var bonusObject = itemBonusList.SingleOrDefault(x => x.Entry == Convert.ToInt32(bonusTypeId)); if (bonusObject != null) { setBonus.BonusId = itemBonusList.Single(x => x.Entry == Convert.ToInt32(bonusTypeId)).Entry; setBonus.Name = itemBonusList.Single(x => x.Entry == Convert.ToInt32(bonusTypeId)).BonusName; } else { Logger.Warn($"Could not locate item {bonusTypeId} in bonus list "); } setBonus.Value = Convert.ToInt32(bonusValue); } else { var bonusObject = itemBonusList.Single(x => x.Entry == Convert.ToInt32(bonusEntry[0])); // Form is A:B if (bonusObject != null) { setBonus.MinLevel = 0; setBonus.BonusId = bonusObject.Entry; setBonus.Name = bonusObject.BonusName; } else { Logger.Warn($"Could not locate item {Convert.ToInt32(bonusEntry[0])} in bonus list "); } setBonus.Value = Convert.ToInt32(bonusEntry[1]); } return(setBonus); }
/// <summary> /// From an Item Set object, return a "Set Bonus Json object" /// </summary> /// <param name="itemSetObject"></param> /// <returns></returns> private static List <SetBonus> GetSetBonus(ItemSet itemSetObject) { // List of strings in the form A:B,C,D (or A:B) var listBonus = itemSetObject.BonusString.Split('|'); var setBonusList = new List <SetBonus>(); var count = 1; foreach (var bonus in listBonus) { var setBonus = new SetBonus().CalculateSetBonus(bonus, ItemBonusList); if (setBonus != null) { setBonus.NumberPieces = ++count; setBonusList.Add(setBonus); } } return(setBonusList); }