private void SubCollectTreeLootConfig(LootTreeNodeBase child, ref GroupAndItemConfig gconfig)
        {
            var ltnrg = child as LootTreeNodeRollGroup;

            if (ltnrg != null)
            {
                var gc = new GroupAndItemConfig()
                {
                    GUID    = ltnrg.Guid,
                    Note    = ltnrg.Note,
                    RollAll = ltnrg.RollAll,
                    RollWithoutReplacement = ltnrg.RollWithoutReplacement,
                    RollCount = ltnrg.RollCount
                };
                foreach (var ch in ltnrg.Children)
                {
                    SubCollectTreeLootConfig(ch, ref gc);
                }
                if (gconfig.List == null)
                {
                    gconfig.List = new List <GroupAndItemConfig>();
                }
                gconfig.List.Add(gc);
                return;
            }

            var ltnst = child as LootTreeNodeSubtree;

            if (ltnst != null)
            {
                var gc = new GroupAndItemConfig()
                {
                    GUID               = ltnst.Guid,
                    ProbabilityCache   = ltnst.ProbabilityCache,
                    SiblingProbability = ltnst.SiblingProbability,
                    FailsPerSuccess    = ltnst.FailsPerSuccess
                };
                SubCollectTreeLootConfig(ltnst.LootTree.Root, ref gc);
                if (gconfig.List == null)
                {
                    gconfig.List = new List <GroupAndItemConfig>();
                }
                gconfig.List.Add(gc);
                return;
            }

            var ltnitemgenerator = child as LootTreeNodeItemGeneratorContainer;

            if (ltnitemgenerator != null)
            {
                var gc = new GroupAndItemConfig()
                {
                    GUID               = ltnitemgenerator.Guid,
                    ProbabilityCache   = ltnitemgenerator.ProbabilityCache,
                    SiblingProbability = ltnitemgenerator.SiblingProbability,
                    FailsPerSuccess    = ltnitemgenerator.FailsPerSuccess,
                };
                SubCollectTreeLootConfig(ltnitemgenerator.ChildTree, ref gc);
                if (gconfig.List == null)
                {
                    gconfig.List = new List <GroupAndItemConfig>();
                }
                gconfig.List.Add(gc);
                return;
            }

            var ltsfn = child as LootTreeSourceFilterNode;

            if (ltsfn != null)
            {
                if (ltsfn.LootTree != null)
                {
                    var gc = new GroupAndItemConfig()
                    {
                        GUID               = ltsfn.Guid,
                        ProbabilityCache   = ltsfn.ProbabilityCache,
                        SiblingProbability = ltsfn.SiblingProbability,
                        FailsPerSuccess    = ltsfn.FailsPerSuccess,
                        LevelMin           = ltsfn.LevelMin,
                        LevelMax           = ltsfn.LevelMax,
                    };
                    SubCollectTreeLootConfig(ltsfn.LootTree, ref gc);
                    if (gconfig.List == null)
                    {
                        gconfig.List = new List <GroupAndItemConfig>();
                    }
                    gconfig.List.Add(gc);
                }
                return;
            }

            var ltniga = child as LootTreeNodeItemGeneratorAdvanced;

            if (ltniga != null)
            {
                var p = ltniga.StackSize as MutatorGeneratorFloatFromReferenceCurve;
                if (p != null)
                {
                    if (gconfig.List == null)
                    {
                        gconfig.List = new List <GroupAndItemConfig>();
                    }
                    gconfig.List.Add(new GroupAndItemConfig()
                    {
                        GUID       = ltniga.Guid,
                        Name       = ltniga.LootResult?.name,
                        Mutliplier = p.Mutliplier
                    });
                }
                return;
            }

            var itemgenerator = child as LootTreeNodeItemGenerator;

            if (itemgenerator != null)
            {
                if (gconfig.List == null)
                {
                    gconfig.List = new List <GroupAndItemConfig>();
                }
                gconfig.List.Add(new GroupAndItemConfig()
                {
                    GUID    = itemgenerator.Guid,
                    Name    = itemgenerator.LootResult?.name,
                    MinDrop = itemgenerator.MinStack,
                    MaxDrop = itemgenerator.MaxStack
                });
                return;
            }
        }
        private bool SubSetLootTreeConfig(GroupAndItemConfig config, LootTreeNodeBase root)
        {
            var ltnrg = root as LootTreeNodeRollGroup;

            if (ltnrg != null)
            {
                if (config.GUID != ltnrg.Guid)
                {
                    return(false);
                }

                ltnrg.RollAll = config.RollAll;
                ltnrg.RollWithoutReplacement = config.RollWithoutReplacement;
                ltnrg.RollCount = config.RollCount;

                bool modified = false;
                if (config.List == null)
                {
                    return(modified);
                }
                foreach (var ch in config.List)
                {
                    foreach (var child in ltnrg.Children)
                    {
                        depth++;
                        bool m = SubSetLootTreeConfig(ch, child);
                        depth--;
                        modified |= m;
                        if (m)
                        {
                            break;
                        }
                    }
                }
                return(modified);
            }


            var ltnst = root as LootTreeNodeSubtree;

            if (ltnst != null)
            {
                if (config.GUID != ltnst.Guid)
                {
                    return(false);
                }

                ltnst.ProbabilityCache   = config.ProbabilityCache;
                ltnst.SiblingProbability = config.SiblingProbability;
                ltnst.FailsPerSuccess    = config.FailsPerSuccess;

                bool modified = false;
                if (config.List == null)
                {
                    return(modified);
                }
                foreach (var ch in config.List)
                {
                    depth++;
                    bool m = SubSetLootTreeConfig(ch, ltnst.LootTree.Root);
                    depth--;
                    modified |= m;
                    if (m)
                    {
                        break;
                    }
                }

                return(modified);
            }

            var ltniga = root as LootTreeNodeItemGeneratorAdvanced;

            if (ltniga != null)
            {
                if (config.GUID != ltniga.Guid)
                {
                    return(false);
                }
                var p = ltniga.StackSize as MutatorGeneratorFloatFromReferenceCurve;
                if (p != null)
                {
                    var value = config.Mutliplier * (config.Force ? 1 : _config.GlobalStackSizeMultiplier);
                    p.Mutliplier = value;
                }
                return(true);
            }

            var itemgenerator = root as LootTreeNodeItemGenerator;

            if (itemgenerator != null)
            {
                if (config.GUID != itemgenerator.Guid)
                {
                    return(false);
                }
                var value1 = Mathf.CeilToInt((float)config.MinDrop * (config.Force ? 1 : _config.GlobalStackSizeMultiplier));
                var value2 = Mathf.CeilToInt((float)config.MaxDrop * (config.Force ? 1 : _config.GlobalStackSizeMultiplier));
                itemgenerator.MinStack = value1;
                itemgenerator.MaxStack = value2;
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        private bool SubSetLootTreeConfig(GroupAndItemConfig config, LootTreeNodeBase root)
        {
            var rollGroup = root as LootTreeNodeRollGroup;

            if (rollGroup != null)
            {
                if (config.GUID != rollGroup.Guid)
                {
                    return(false);
                }

                rollGroup.RollAll = config.RollAll;
                rollGroup.RollWithoutReplacement = config.RollWithoutReplacement;
                rollGroup.RollCount = config.RollCount;

                bool modified = false;
                if (config.Children == null)
                {
                    return(modified);
                }
                foreach (var ch in config.Children)
                {
                    foreach (var child in rollGroup.Children)
                    {
                        depth++;
                        bool m = SubSetLootTreeConfig(ch, child);
                        depth--;
                    }
                }
                return(modified);
            }


            var subtree = root as LootTreeNodeSubtree;

            if (subtree != null)
            {
                if (config.GUID != subtree.Guid)
                {
                    return(false);
                }

                subtree.ProbabilityCache   = config.ProbabilityCache;
                subtree.SiblingProbability = config.SiblingProbability;
                subtree.FailsPerSuccess    = config.FailsPerSuccess;

                bool modified = false;
                if (config.Children == null)
                {
                    return(modified);
                }
                foreach (var ch in config.Children)
                {
                    depth++;
                    bool m = SubSetLootTreeConfig(ch, subtree.LootTree.Root);
                    depth--;
                }

                return(modified);
            }

            var itemGeneratorAdvanced = root as LootTreeNodeItemGeneratorAdvanced;

            if (itemGeneratorAdvanced != null)
            {
                if (config.GUID != itemGeneratorAdvanced.Guid)
                {
                    return(false);
                }
                var p = itemGeneratorAdvanced.StackSize as MutatorGeneratorFloatFromReferenceCurve;
                if (p != null)
                {
                    var value = config.Mutliplier * (config.Force ? 1 : _pluginConfig.GlobalStackSizeMultiplier);
                    p.Mutliplier = value;
                }
                return(true);
            }

            var itemGenerator = root as LootTreeNodeItemGenerator;

            if (itemGenerator != null)
            {
                if (config.GUID != itemGenerator.Guid)
                {
                    return(false);
                }
                var value1 = Mathf.CeilToInt((float)config.MinDrop * (config.Force ? 1 : _pluginConfig.GlobalStackSizeMultiplier));
                var value2 = Mathf.CeilToInt((float)config.MaxDrop * (config.Force ? 1 : _pluginConfig.GlobalStackSizeMultiplier));
                itemGenerator.MinStack           = value1;
                itemGenerator.MaxStack           = value2;
                itemGenerator.FailsPerSuccess    = config.FailsPerSuccess;
                itemGenerator.SiblingProbability = config.SiblingProbability;
                itemGenerator.ProbabilityCache   = config.ProbabilityCache;
                itemGenerator.SiblingProbability = config.SiblingProbability;
                if (GlobalItemManager.Instance.ItemGenerators.ContainsKey(config.ItemID))
                {
                    itemGenerator.LootResult = GlobalItemManager.Instance.ItemGenerators[config.ItemID];
                    config.Name = itemGenerator.LootResult?.ToString();
                }

                else if (config.ItemID != 0)
                {
                    Puts($"itemID \"{config.ItemID}\" doesn't exist for {config.Name} with GUID {config.GUID}.");
                }

                return(true);
            }
            return(false);
        }