private void PrintLootNode(LootTreeNode lootNode, double parentChance, StringBuilder sb, int depth = 0) { var children = (List <KeyValuePair <double, LootTreeNode> >)childrenField.GetValue(lootNode); if (children != null && children.Count > 0) { sb.Append('\t', depth); sb.AppendLine($"{parentChance:P1}"); depth++; var sum = children.Sum(l => l.Key); var cur = 0d; foreach (var entry in children) { cur += entry.Key; PrintLootNode(entry.Value, parentChance * (cur / sum), sb, depth); } return; } var itemGeneratorStatic = lootNode.LootResult as ItemGeneratorStatic; if (itemGeneratorStatic != null) { sb.Append('\t', depth); sb.AppendLine($"{parentChance:P1} {itemGeneratorStatic.StackSize}x {itemGeneratorStatic.ItemId} ({itemGeneratorStatic.RandomVariance})"); } }
private void PrintLootNode(LootTreeNode lootNode, double parentChance, StringBuilder sb, int depth = 0, bool once = false) { var itemGeneratorStatic = lootNode.LootResult as ItemGeneratorStatic; if (itemGeneratorStatic != null) { sb.Append('\t', depth); sb.Append($"{parentChance:P1} {itemGeneratorStatic.StackSize}x {itemGeneratorStatic.ItemId}"); if (itemGeneratorStatic.RandomVariance > 0) { sb.Append($" (Rnd {itemGeneratorStatic.RandomVariance})"); } sb.AppendLine(once ? " (Once)" : string.Empty); return; } var children = (List <KeyValuePair <double, LootTreeNode> >)childrenField.GetValue(lootNode); if (children != null && children.Count > 0) { sb.Append('\t', depth++); sb.Append($"{parentChance:P1}"); sb.AppendLine(once ? " (Once)" : string.Empty); var rollCount = lootNode.RollCount; if (lootNode.RollWithoutReplacement && rollCount > children.Count) { rollCount = children.Count; } if (rollCount != children.Count || !lootNode.RollWithoutReplacement) { var sum = children.Sum(l => l.Key); var cur = 0d; foreach (var entry in children) { cur += entry.Key; PrintLootNode(entry.Value, parentChance * (cur / sum), sb, depth, once || lootNode.RollWithoutReplacement); } } else { foreach (var entry in children) { PrintLootNode(entry.Value, parentChance, sb, depth); } } } }
private LootTreeNode GetLootTreeNode(LootTreeNodeData lootTreeNodeData) { var lootTreeNode = new LootTreeNode { RollCount = lootTreeNodeData.RollCount, RollWithoutReplacement = lootTreeNodeData.RollWithoutReplacement }; if (lootTreeNodeData.LootResult != null) { var itemGenerator = new ItemGeneratorStatic { ItemId = lootTreeNodeData.LootResult.ItemId, RandomVariance = lootTreeNodeData.LootResult.RandomVariance, StackSize = (int)Math.Ceiling(lootTreeNodeData.LootResult.StackSize * _config.GlobalStackSizeMultiplier) }; lootTreeNode.LootResult = itemGenerator; } foreach (var child in lootTreeNodeData.Children) { lootTreeNode.AddChild(child.Key, GetLootTreeNode(child.Value)); } return(lootTreeNode); }