Exemplo n.º 1
0
        // This method is only used by `SpellBookView.SetupHeader()` to find information such
        // as spellbook bloodlines, cleric deity, etc.
        //
        // Unfortunately, it doesn't understand how to find data from the archetype.
        // So this patch addresses it.
        static void Postfix(BlueprintProgression progression, UnitProgressionData progressionData, ref List <BlueprintFeatureBase> __result)
        {
            try
            {
                var @class = Helpers.classes.FirstOrDefault(c => c.Progression == progression);
                if (@class == null)
                {
                    return;
                }

                var list      = __result ?? new List <BlueprintFeatureBase>();
                var archetype = @class.Archetypes.FirstOrDefault(progressionData.IsArchetype);
                if (archetype == null)
                {
                    return;
                }

                foreach (var entry in archetype.RemoveFeatures)
                {
                    foreach (var feat in entry.Features.OfType <BlueprintFeatureSelection>().Where(f => !f.HideInUI))
                    {
                        var selections = progressionData.GetSelections(feat, entry.Level);
                        list.RemoveAll(f => f == feat || selections.Contains(f));
                    }
                }
                foreach (var entry in archetype.AddFeatures)
                {
                    foreach (var feat in entry.Features.OfType <BlueprintFeatureSelection>().Where(f => !f.HideInUI))
                    {
                        var selections = progressionData.GetSelections(feat, entry.Level);
                        foreach (var s in selections)
                        {
                            if (IsDeterminator(s) && !list.Contains(s))
                            {
                                list.Add(s);
                            }
                        }
                        if (selections.Count == 0 && IsDeterminator(feat))
                        {
                            list.Add(feat);
                        }
                    }
                }
                __result = list.Count == 0 ? null : list;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemplo n.º 2
0
            public FeaturesTree(UnitProgressionData progression)
            {
                Dictionary <BlueprintScriptableObject, FeatureNode> normalNodes = new Dictionary <BlueprintScriptableObject, FeatureNode>();
                List <FeatureNode> parametrizedNodes = new List <FeatureNode>();

                // get nodes (features / race)
                foreach (Feature feature in progression.Features.Enumerable)
                {
                    if (feature.Blueprint is BlueprintParametrizedFeature)
                    {
                        parametrizedNodes.Add(new FeatureNode(feature.Name, feature.Blueprint, feature.Source));
                    }
                    else
                    {
                        normalNodes.Add(feature.Blueprint, new FeatureNode(feature.Name, feature.Blueprint, feature.Source));
                    }
                }

                // get nodes (classes)
                foreach (BlueprintCharacterClass characterClass in progression.Classes.Select(item => item.CharacterClass))
                {
                    normalNodes.Add(characterClass, new FeatureNode(characterClass.Name, characterClass, null));
                }

                // set source selection
                List <FeatureNode> selectionNodes = normalNodes.Values
                                                    .Where(item => item.Blueprint is BlueprintFeatureSelection).ToList();

                for (int i = 0; i <= 20; i++)
                {
                    foreach (FeatureNode selection in selectionNodes)
                    {
                        foreach (BlueprintFeature feature in progression.GetSelections(selection.Blueprint as BlueprintFeatureSelection, i))
                        {
                            FeatureNode node = default;
                            if (feature is BlueprintParametrizedFeature)
                            {
                                node = parametrizedNodes
                                       .FirstOrDefault(item => item.Source != null && item.Source == selection.Source);
                            }

                            if (node != null || normalNodes.TryGetValue(feature, out node))
                            {
                                node.Source = selection.Blueprint;
                            }
                            else
                            {
                                // missing child
                                normalNodes.Add(feature,
                                                new FeatureNode(string.Empty, feature, selection.Blueprint)
                                {
                                    IsMissing = true
                                });
                            }
                        }
                    }
                }

                // build tree
                foreach (FeatureNode node in normalNodes.Values.Concat(parametrizedNodes).ToList())
                {
                    if (node.Source == null)
                    {
                        RootNodes.Add(node);
                    }
                    else if (normalNodes.TryGetValue(node.Source, out FeatureNode parent))
                    {
                        parent.ChildNodes.Add(node);
                    }
                    else
                    {
                        // missing parent
                        parent = new FeatureNode(string.Empty, node.Source, null)
                        {
                            IsMissing = true
                        };
                        parent.ChildNodes.Add(node);
                        normalNodes.Add(parent.Blueprint, parent);
                        RootNodes.Add(parent);
                    }
                }
            }
Exemplo n.º 3
0
            public FeaturesTree(UnitProgressionData progression)
            {
                Dictionary <BlueprintScriptableObject, FeatureNode> normalNodes = new();
                List <FeatureNode> parametrizedNodes = new();

                //Main.Log($"prog: {progression}");
                // get nodes (features / race)
                foreach (var feature in progression.Features.Enumerable)
                {
                    var name = feature.Name;
                    if (name == null || name.Length == 0)
                    {
                        name = feature.Blueprint.name;
                    }
                    //Main.Log($"feature: {name}");
                    var source = feature.m_Source;
                    //Main.Log($"source: {source}");
                    if (feature.Blueprint is BlueprintParametrizedFeature)
                    {
                        parametrizedNodes.Add(new FeatureNode(name, feature.SourceLevel, feature.Blueprint, source));
                    }
                    else
                    {
                        normalNodes.Add(feature.Blueprint, new FeatureNode(name, feature.SourceLevel, feature.Blueprint, source));
                    }
                }

                // get nodes (classes)
                foreach (var characterClass in progression.Classes.Select(item => item.CharacterClass))
                {
                    normalNodes.Add(characterClass, new FeatureNode(characterClass.Name, 0, characterClass, null));
                }

                // set source selection
                var selectionNodes = normalNodes.Values
                                     .Where(item => item.Blueprint is BlueprintFeatureSelection).ToList();

                for (var level = 0; level <= 100; level++)
                {
                    foreach (var selection in selectionNodes)
                    {
                        foreach (var feature in progression.GetSelections(selection.Blueprint as BlueprintFeatureSelection, level))
                        {
                            FeatureNode node = default;
                            if (feature is BlueprintParametrizedFeature)
                            {
                                node = parametrizedNodes
                                       .FirstOrDefault(item => item.Source != null && item.Source == selection.Source);
                            }

                            if (node != null || normalNodes.TryGetValue(feature, out node))
                            {
                                node.Source = selection.Blueprint;
                                node.Level  = level;
                            }
                            else
                            {
                                // missing child
                                normalNodes.Add(feature,
                                                new FeatureNode(string.Empty, level, feature, selection.Blueprint)
                                {
                                    IsMissing = true
                                });
                            }
                        }
                    }
                }

                // build tree
                foreach (var node in normalNodes.Values.Concat(parametrizedNodes).ToList())
                {
                    if (node.Source == null)
                    {
                        RootNodes.Add(node);
                    }
                    else if (normalNodes.TryGetValue(node.Source, out var parent))
                    {
                        parent.ChildNodes.Add(node);
                    }
                    else
                    {
                        // missing parent
                        parent = new FeatureNode(string.Empty, 0, node.Source, null)
                        {
                            IsMissing = true
                        };
                        parent.ChildNodes.Add(node);
                        normalNodes.Add(parent.Blueprint, parent);
                        RootNodes.Add(parent);
                    }
                }
            }