diff --git a/.Lib9c.Tests/Action/SynthesizeTest.cs b/.Lib9c.Tests/Action/SynthesizeTest.cs index cda7f63720..db8ae19d23 100644 --- a/.Lib9c.Tests/Action/SynthesizeTest.cs +++ b/.Lib9c.Tests/Action/SynthesizeTest.cs @@ -256,6 +256,14 @@ public void ExecuteMultiple(Grade grade, ItemSubType itemSubType) if (result.IsSuccess) { Assert.Equal((int)grade + 1, result.ItemBase.Grade); + + var weightSheet = TableSheets.SynthesizeWeightSheet; + var weightRow = weightSheet.Values.FirstOrDefault(r => r.ItemId == result.ItemBase.Id); + + if (weightRow != null) + { + Assert.True(weightRow.Weight != 0); + } } else { diff --git a/Lib9c/Helper/SynthesizeSimulator.cs b/Lib9c/Helper/SynthesizeSimulator.cs index 8bab8c5df9..e5d1493413 100644 --- a/Lib9c/Helper/SynthesizeSimulator.cs +++ b/Lib9c/Helper/SynthesizeSimulator.cs @@ -384,7 +384,7 @@ private static ItemBase GetRandomCostume(Grade grade, bool isSuccess, ItemSubTyp throw new InvalidOperationException($"No available items to synthesize for grade {grade} and subtype {itemSubType}"); } - var randomValue = GetRandomValueForItem(grade, synthesizeResultPool, weightSheet, random, out var itemWeights); + var randomValue = GetRandomValueForItem(synthesizeResultPool, weightSheet, random, out var itemWeights); var cumulativeWeight = 0; foreach (var (itemId, weight) in itemWeights) { @@ -440,7 +440,7 @@ private static ItemBase GetRandomEquipment( throw new InvalidOperationException($"No available items to synthesize for grade {grade} and subtype {itemSubType}"); } - var randomValue = GetRandomValueForItem(grade, synthesizeResultPool, weightSheet, random, out var itemWeights); + var randomValue = GetRandomValueForItem(synthesizeResultPool, weightSheet, random, out var itemWeights); var cumulativeWeight = 0; foreach (var (itemId, weight) in itemWeights) { @@ -506,14 +506,14 @@ private static ItemBase GetRandomEquipment( throw new InvalidOperationException("Failed to select a synthesized item."); } - private static int GetRandomValueForItem(Grade grade, HashSet synthesizeResultPool, SynthesizeWeightSheet synthesizeWeightSheet, + private static int GetRandomValueForItem(HashSet synthesizeResultPool, SynthesizeWeightSheet synthesizeWeightSheet, IRandom random, out List<(int ItemId, int Weight)> itemWeights) { var totalWeight = 0; itemWeights = new List<(int ItemId, int Weight)>(); foreach (var itemId in synthesizeResultPool) { - var weight = GetWeight(grade, itemId, synthesizeWeightSheet); + var weight = GetWeight(itemId, synthesizeWeightSheet); itemWeights.Add((itemId, weight)); totalWeight += weight; } @@ -631,11 +631,11 @@ public static Grade GetUpgradeGrade(Grade grade ,ItemSubType subType, EquipmentI /// item id of material item /// SynthesizeWeightSheet to use /// weight of the item that can be obtained by synthesizing the item - public static int GetWeight(Grade grade, int itemId, SynthesizeWeightSheet sheet) + public static int GetWeight(int itemId, SynthesizeWeightSheet sheet) { var defaultWeight = SynthesizeWeightSheet.DefaultWeight; - var gradeRow = sheet.Values.FirstOrDefault(r => r.GradeId == (int)grade); - return gradeRow == null ? defaultWeight : gradeRow.WeightDict.GetValueOrDefault(itemId, defaultWeight); + var gradeRow = sheet.Values.FirstOrDefault(r => r.Key == itemId); + return gradeRow?.Weight ?? defaultWeight; } // TODO: move to ItemExtensions diff --git a/Lib9c/TableCSV/Item/SynthesizeWeightSheet.csv b/Lib9c/TableCSV/Item/SynthesizeWeightSheet.csv index c808bb9e0b..afed6fd97f 100644 --- a/Lib9c/TableCSV/Item/SynthesizeWeightSheet.csv +++ b/Lib9c/TableCSV/Item/SynthesizeWeightSheet.csv @@ -1,7 +1,8 @@ -grade_id,item_id,weight +item_id,weight _default value for weight is 10000. -3,40100001,3000 -3,40100015,1000 -3,40100016,1000 -3,40100019,1000 -5,49900027,40000 \ No newline at end of file +40100001,3000 +40100015,1000 +40100016,1000 +40100017,0 +40100019,1000 +49900027,40000 \ No newline at end of file diff --git a/Lib9c/TableData/Item/SynthesizeWeightSheet.cs b/Lib9c/TableData/Item/SynthesizeWeightSheet.cs index 35b270b95a..f5e02e90aa 100644 --- a/Lib9c/TableData/Item/SynthesizeWeightSheet.cs +++ b/Lib9c/TableData/Item/SynthesizeWeightSheet.cs @@ -17,42 +17,20 @@ public class SynthesizeWeightSheet : Sheet [Serializable] public class Row : SheetRow { - public override int Key => GradeId; + public override int Key => ItemId; - public int GradeId { get; private set; } - - public Dictionary WeightDict { get; private set; } + public int ItemId { get; private set; } + public int Weight { get; private set; } public override void Set(IReadOnlyList fields) { - GradeId = ParseInt(fields[0]); - - WeightDict = new Dictionary(); - var itemId = ParseInt(fields[1]); - var weight = ParseInt(fields[2], DefaultWeight); - WeightDict.Add(itemId, weight); + ItemId = ParseInt(fields[0]); + Weight = TryParseInt(fields[1], out var weight) ? weight : DefaultWeight; } } public SynthesizeWeightSheet() : base(nameof(SynthesizeWeightSheet)) { } - - protected override void AddRow(int key, Row value) - { - if (!TryGetValue(key, out var row)) - { - Add(key, value); - - return; - } - - if (!value.WeightDict.Any()) - { - return; - } - - row.WeightDict.TryAdd(value.WeightDict.First().Key, value.WeightDict.First().Value); - } } }