private IEnumerable <RecordSphereLevel> GetRecordSphereLevels(RecordSphereRow row) { IList <RecordSphereLevel> recordSphereLevels = new List <RecordSphereLevel>(); //can be up to 5 levels //level 1 if (!String.IsNullOrWhiteSpace(row.BenefitLevel1?.Replace(DashCharacter, String.Empty))) { RecordSphereLevel rsl = new RecordSphereLevel() { Level = 1, Benefit = row.BenefitLevel1, RequiredMotes = new List <ItemWithCountAndStarLevel>() }; //mote 1 if (!String.IsNullOrWhiteSpace(row.Mote1Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote1Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote1AmountLevel1), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rsl.RequiredMotes.Add(iwcasl); } } //mote 2 if (!String.IsNullOrWhiteSpace(row.Mote2Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote2Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote2AmountLevel1), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rsl.RequiredMotes.Add(iwcasl); } } //mote 3 if (!String.IsNullOrWhiteSpace(row.Mote3Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote3Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote3AmountLevel1), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rsl.RequiredMotes.Add(iwcasl); } } //mote 4 if (!String.IsNullOrWhiteSpace(row.Mote4Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote4Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote4AmountLevel1), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rsl.RequiredMotes.Add(iwcasl); } } recordSphereLevels.Add(rsl); } //level 2 if (!String.IsNullOrWhiteSpace(row.BenefitLevel2?.Replace(DashCharacter, String.Empty))) { RecordSphereLevel rs2 = new RecordSphereLevel() { Level = 2, Benefit = row.BenefitLevel2, RequiredMotes = new List <ItemWithCountAndStarLevel>() }; //mote 1 if (!String.IsNullOrWhiteSpace(row.Mote1Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote1Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote1AmountLevel2), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs2.RequiredMotes.Add(iwcasl); } } //mote 2 if (!String.IsNullOrWhiteSpace(row.Mote2Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote2Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote2AmountLevel2), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs2.RequiredMotes.Add(iwcasl); } } //mote 3 if (!String.IsNullOrWhiteSpace(row.Mote3Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote3Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote3AmountLevel2), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs2.RequiredMotes.Add(iwcasl); } } //mote 4 if (!String.IsNullOrWhiteSpace(row.Mote4Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote4Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote4AmountLevel2), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs2.RequiredMotes.Add(iwcasl); } } recordSphereLevels.Add(rs2); } //level 3 if (!String.IsNullOrWhiteSpace(row.BenefitLevel3?.Replace(DashCharacter, String.Empty))) { RecordSphereLevel rs3 = new RecordSphereLevel() { Level = 3, Benefit = row.BenefitLevel3, RequiredMotes = new List <ItemWithCountAndStarLevel>() }; //mote 1 if (!String.IsNullOrWhiteSpace(row.Mote1Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote1Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote1AmountLevel3), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs3.RequiredMotes.Add(iwcasl); } } //mote 2 if (!String.IsNullOrWhiteSpace(row.Mote2Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote2Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote2AmountLevel3), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs3.RequiredMotes.Add(iwcasl); } } //mote 3 if (!String.IsNullOrWhiteSpace(row.Mote3Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote3Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote3AmountLevel3), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs3.RequiredMotes.Add(iwcasl); } } //mote 4 if (!String.IsNullOrWhiteSpace(row.Mote4Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote4Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote4AmountLevel3), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs3.RequiredMotes.Add(iwcasl); } } recordSphereLevels.Add(rs3); } //level 4 if (!String.IsNullOrWhiteSpace(row.BenefitLevel4?.Replace(DashCharacter, String.Empty))) { RecordSphereLevel rs4 = new RecordSphereLevel() { Level = 4, Benefit = row.BenefitLevel4, RequiredMotes = new List <ItemWithCountAndStarLevel>() }; //mote 1 if (!String.IsNullOrWhiteSpace(row.Mote1Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote1Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote1AmountLevel4), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs4.RequiredMotes.Add(iwcasl); } } //mote 2 if (!String.IsNullOrWhiteSpace(row.Mote2Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote2Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote2AmountLevel4), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs4.RequiredMotes.Add(iwcasl); } } //mote 3 if (!String.IsNullOrWhiteSpace(row.Mote3Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote3Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote3AmountLevel4), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs4.RequiredMotes.Add(iwcasl); } } //mote 4 if (!String.IsNullOrWhiteSpace(row.Mote4Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote4Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote4AmountLevel4), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs4.RequiredMotes.Add(iwcasl); } } recordSphereLevels.Add(rs4); } //level 5 if (!String.IsNullOrWhiteSpace(row.BenefitLevel5?.Replace(DashCharacter, String.Empty))) { RecordSphereLevel rs5 = new RecordSphereLevel() { Level = 5, Benefit = row.BenefitLevel5, RequiredMotes = new List <ItemWithCountAndStarLevel>() }; //mote 1 if (!String.IsNullOrWhiteSpace(row.Mote1Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote1Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote1AmountLevel5), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs5.RequiredMotes.Add(iwcasl); } } //mote 2 if (!String.IsNullOrWhiteSpace(row.Mote2Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote2Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote2AmountLevel5), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs5.RequiredMotes.Add(iwcasl); } } //mote 3 if (!String.IsNullOrWhiteSpace(row.Mote3Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote3Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote3AmountLevel5), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs5.RequiredMotes.Add(iwcasl); } } //mote 4 if (!String.IsNullOrWhiteSpace(row.Mote4Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote4Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote4AmountLevel5), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { rs5.RequiredMotes.Add(iwcasl); } } recordSphereLevels.Add(rs5); } return(recordSphereLevels); }
protected IEnumerable <ItemWithCountAndStarLevel> ExtractItemWithCountAndStarLevel(string input) { List <ItemWithCountAndStarLevel> iwcaslList = new List <ItemWithCountAndStarLevel>(); try { //see if we need to jump out to the more complex multi item, single count reward parsing if (input.Contains(RewardAndToken)) { int andIndex = input.IndexOf(RewardAndToken); string lastPhrase = input.Substring(andIndex + 5); string[] lastPhraseParts = lastPhrase.Split(Space.ToCharArray()); string firstWordOfLastPhrase = lastPhraseParts[0]; string rewardPartOfLastPhrase = lastPhrase.Replace(firstWordOfLastPhrase, String.Empty).Trim(); string inputAndReplaced = input.Replace(RewardAndToken, CommaWithSpace); string inputRewardRemoved = inputAndReplaced.Replace(rewardPartOfLastPhrase, String.Empty).Trim(); string[] rewardTypes = inputRewardRemoved.Split(Comma.ToCharArray()); string[] rewardTypesAndCounts = rewardTypes.Select(r => $"{r} {rewardPartOfLastPhrase}").ToArray(); string convertedInput = String.Join(CommaWithSpace, rewardTypesAndCounts); input = convertedInput; } //turn reward string into a list, if needed IList <string> rewardStrings = ConvertCommaSeparatedStringToList(input); //for each reward, turn it into an item name and a count IList <ItemWithItemCount> rewardItemsWithItemCounts = new List <ItemWithItemCount>(); foreach (var rewardString in rewardStrings) { ItemWithItemCount itemWithItemCount = ExtractItemWithItemCount(rewardString); rewardItemsWithItemCounts.Add(itemWithItemCount); } //now for each reward item, extract the star level if applicable foreach (ItemWithItemCount iwc in rewardItemsWithItemCounts) { ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel(); ItemWithStarLevel iwsl = ExtractItemWithStarLevel(iwc.ItemName); iwcasl.ItemName = iwsl.ItemName; iwcasl.ItemCount = iwc.ItemCount > 0 ? iwc.ItemCount : !String.IsNullOrWhiteSpace(iwsl.ItemName) ? 1 : 0; iwcasl.ItemStarLevel = iwsl.ItemStarLevel; iwcaslList.Add(iwcasl); } } catch (Exception ex) { _logger.LogWarning("ItemWithCountAndStarLevel String {iwcaslString} could not be parsed; {Message}", input, ex.Message); } return(iwcaslList); }
private IEnumerable <LegendSphereInfo> GetLegendSphereInfo(LegendSphereRow row) { IList <LegendSphereInfo> legendSphereInfos = new List <LegendSphereInfo>(); //can be up to 4 indexes (spots from left to right) //index 1 if (!String.IsNullOrWhiteSpace(row.BenefitColumn1?.Replace(DashCharacter, String.Empty))) { LegendSphereInfo lsi1 = new LegendSphereInfo() { Index = 1, Benefit = row.BenefitColumn1, RequiredMotes = new List <ItemWithCountAndStarLevel>() }; //mote 1 if (!String.IsNullOrWhiteSpace(row.Mote1Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote1Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote1AmountColumn1), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { lsi1.RequiredMotes.Add(iwcasl); } } //mote 2 if (!String.IsNullOrWhiteSpace(row.Mote2Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote2Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote2AmountColumn1), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { lsi1.RequiredMotes.Add(iwcasl); } } legendSphereInfos.Add(lsi1); } //index 2 if (!String.IsNullOrWhiteSpace(row.BenefitColumn2?.Replace(DashCharacter, String.Empty))) { LegendSphereInfo lsi2 = new LegendSphereInfo() { Index = 2, Benefit = row.BenefitColumn2, RequiredMotes = new List <ItemWithCountAndStarLevel>() }; //mote 1 if (!String.IsNullOrWhiteSpace(row.Mote1Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote1Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote1AmountColumn2), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { lsi2.RequiredMotes.Add(iwcasl); } } //mote 2 if (!String.IsNullOrWhiteSpace(row.Mote2Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote2Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote2AmountColumn2), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { lsi2.RequiredMotes.Add(iwcasl); } } legendSphereInfos.Add(lsi2); } //index 3 if (!String.IsNullOrWhiteSpace(row.BenefitColumn3?.Replace(DashCharacter, String.Empty))) { LegendSphereInfo lsi3 = new LegendSphereInfo() { Index = 3, Benefit = row.BenefitColumn3, RequiredMotes = new List <ItemWithCountAndStarLevel>() }; //mote 1 if (!String.IsNullOrWhiteSpace(row.Mote1Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote1Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote1AmountColumn3), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { lsi3.RequiredMotes.Add(iwcasl); } } //mote 2 if (!String.IsNullOrWhiteSpace(row.Mote2Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote2Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote2AmountColumn3), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { lsi3.RequiredMotes.Add(iwcasl); } } legendSphereInfos.Add(lsi3); } //index 4 if (!String.IsNullOrWhiteSpace(row.BenefitColumn4?.Replace(DashCharacter, String.Empty))) { LegendSphereInfo lsi4 = new LegendSphereInfo() { Index = 4, Benefit = row.BenefitColumn4, RequiredMotes = new List <ItemWithCountAndStarLevel>() }; //mote 1 if (!String.IsNullOrWhiteSpace(row.Mote1Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote1Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote1AmountColumn4), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { lsi4.RequiredMotes.Add(iwcasl); } } //mote 2 if (!String.IsNullOrWhiteSpace(row.Mote2Type)) //we use this type of mote { ItemWithStarLevel iwsl = ExtractItemWithStarLevel(row.Mote2Type); ItemWithCountAndStarLevel iwcasl = new ItemWithCountAndStarLevel() { ItemCount = _intConverter.ConvertFromStringToInt(row.Mote2AmountColumn4), ItemName = iwsl.ItemName, ItemStarLevel = iwsl.ItemStarLevel }; if (iwcasl.ItemCount > 0) { lsi4.RequiredMotes.Add(iwcasl); } } legendSphereInfos.Add(lsi4); } return(legendSphereInfos); }