Ejemplo n.º 1
0
        public static void UpdateSearchResults()
        {
            if (blueprints == null)
            {
                return;
            }
            selectedCollationIndex      = 0;
            selectedBlueprint           = null;
            selectedBlueprintIndex      = -1;
            selectedCollatedBPs         = null;
            BlueprintListUI.needsLayout = true;
            if (settings.searchText.Trim().Length == 0)
            {
                ResetSearch();
            }
            var terms = settings.searchText.Split(' ').Select(s => s.ToLower()).ToHashSet();

            selectedTypeFilter = blueprintTypeFilters[settings.selectedBPTypeFilter];
            var selectedType = selectedTypeFilter.type;
            IEnumerable <BlueprintScriptableObject> bps = null;

            if (selectedTypeFilter.blueprintSource != null)
            {
                bps = selectedTypeFilter.blueprintSource();
            }
            else
            {
                bps = BlueprintExensions.BlueprintsOfType(selectedType).Where((bp) => selectedTypeFilter.filter(bp));
            }
            var filtered = new List <BlueprintScriptableObject>();

            foreach (BlueprintScriptableObject blueprint in bps)
            {
                var name = blueprint.name.ToLower();
                if (terms.All(term => name.Contains(term)))
                {
                    filtered.Add(blueprint);
                }
            }
            filteredBPs = filtered.OrderBy(bp => bp.name);
            matchCount  = filtered.Count();
            if (selectedTypeFilter.collator != null)
            {
                collatedBPs = filtered.GroupBy(selectedTypeFilter.collator).OrderBy(bp => bp.Key);
                // I could do something like this but I will leave it up to the UI when a collation is selected.
                // GetItems().GroupBy(g => g.Type).Select(s => new { Type = s.Key, LastTen = s.Take(10).ToList() });
                collationKeys = new List <String>()
                {
                    "All"
                };
                collationKeys = collationKeys.Concat(collatedBPs.Select(cbp => cbp.Key)).ToList();
            }
            filteredBPs     = filteredBPs.Take(settings.searchLimit).ToArray();
            filteredBPNames = filteredBPs.Select(b => b.name).ToArray();
            firstSearch     = false;
        }
Ejemplo n.º 2
0
        public static void To(this BlueprintArea area)
        {
            var areaEnterPoints = BlueprintExensions.BlueprintsOfType <BlueprintAreaEnterPoint>();
            var blueprint       = areaEnterPoints.FirstOrDefault(bp => bp is BlueprintAreaEnterPoint ep && ep.Area == area);

            if (blueprint is BlueprintAreaEnterPoint enterPoint)
            {
                GameHelper.EnterToArea(enterPoint, AutoSaveMode.None);
            }
        }
Ejemplo n.º 3
0
 private static bool Unload(UnityModManager.ModEntry modEntry)
 {
     foreach (var obj in Objects)
     {
         UnityEngine.Object.DestroyImmediate(obj);
     }
     BlueprintExensions.ResetCollationCache();
     HarmonyInstance.UnpatchAll(modId);
     NeedsActionInit = true;
     return(true);
 }
Ejemplo n.º 4
0
 private static void ResetGUI(UnityModManager.ModEntry modEntry)
 {
     settings             = UnityModManager.ModSettings.Load <Settings>(modEntry);
     settings.searchText  = "";
     settings.searchLimit = 100;
     BagOfTricks.ResetGUI();
     LevelUp.ResetGUI();
     PartyEditor.ResetGUI();
     CrusadeEditor.ResetGUI();
     CharacterPicker.ResetGUI();
     BlueprintBrowser.ResetGUI();
     QuestEditor.ResetGUI();
     BlueprintExensions.ResetCollationCache();
     caughtException = null;
 }
Ejemplo n.º 5
0
        static public void OnGUI(UnitEntityData ch, List <Spellbook> spellbooks)
        {
            var blueprints = BlueprintBrowser.GetBlueprints();

            if (blueprints == null)
            {
                return;
            }
            OnGUI <Spellbook>("Spellbooks", ch, spellbooks,
                              (sb) => sb.Blueprint,
                              BlueprintExensions.GetBlueprints <BlueprintSpellbook>(),
                              (sb) => sb.Blueprint.GetDisplayName(),
                              (sb) => sb.Blueprint.GetDescription(),
                              null,
                              BlueprintAction.ActionsForType(typeof(BlueprintSpellbook))
                              );
        }
Ejemplo n.º 6
0
        static public void OnGUI(UnitEntityData ch, List <Ability> facts)
        {
            var blueprints = BlueprintBrowser.GetBlueprints();

            if (blueprints == null)
            {
                return;
            }
            OnGUI <Ability>("Abilities", ch, facts,
                            (fact) => fact.Blueprint,
                            BlueprintExensions.GetBlueprints <BlueprintAbility>().Where((bp) => !((BlueprintAbility)bp).IsSpell),
                            (fact) => fact.Name,
                            (fact) => fact.Description,
                            (fact) => fact.GetRank(),
                            BlueprintAction.ActionsForType(typeof(BlueprintAbility))
                            );
        }
Ejemplo n.º 7
0
        static public void OnGUI(UnitEntityData ch, List <Buff> facts)
        {
            var blueprints = BlueprintBrowser.GetBlueprints();

            if (blueprints == null)
            {
                return;
            }
            OnGUI <Buff>("Features", ch, facts,
                         (fact) => fact.Blueprint,
                         BlueprintExensions.GetBlueprints <BlueprintBuff>(),
                         (fact) => fact.Name,
                         (fact) => fact.Description,
                         (fact) => fact.GetRank(),
                         BlueprintAction.ActionsForType(typeof(BlueprintBuff))
                         );
        }
Ejemplo n.º 8
0
        public static void OnGUI()
        {
            var player        = Game.Instance.Player;
            var filterChoices = GetPartyFilterChoices();

            if (filterChoices == null)
            {
                return;
            }

            charToAdd    = null;
            charToRemove = null;
            var characterListFunc = UI.TypePicker <List <UnitEntityData> >(
                null,
                ref Main.settings.selectedPartyFilter,
                filterChoices
                );
            var characterList = characterListFunc.func();
            var mainChar      = GameHelper.GetPlayerCharacter();

            if (characterListFunc.name == "Nearby")
            {
                UI.Slider("Nearby Distance", ref nearbyRange, 1f, 200, 25, 0, " meters", UI.Width(250));
                characterList = characterList.OrderBy((ch) => ch.DistanceTo(mainChar)).ToList();
            }
            UI.Space(20);
            int chIndex = 0;

            respecableCount = 0;
            var  selectedCharacter = GetSelectedCharacter();
            bool isWide            = Main.IsWide;

            foreach (UnitEntityData ch in characterList)
            {
                var classData = ch.Progression.Classes;
                // TODO - understand the difference between ch.Progression and ch.Descriptor.Progression
                UnitProgressionData      progression = ch.Descriptor.Progression;
                BlueprintStatProgression xpTable     = BlueprintRoot.Instance.Progression.XPTable;
                int level       = progression.CharacterLevel;
                int mythicLevel = progression.MythicExperience;
                var spellbooks  = ch.Spellbooks;
                var spellCount  = spellbooks.Sum((sb) => sb.GetAllKnownSpells().Count());
                using (UI.HorizontalScope()) {
                    UI.Label(ch.CharacterName.orange().bold(), UI.Width(200));
                    UI.Space(25);
                    float distance = mainChar.DistanceTo(ch);;
                    UI.Label(distance < 1 ? "" : distance.ToString("0") + "m", UI.Width(75));
                    UI.Space(25);
                    UI.Label("lvl".green() + $": {level}", UI.Width(75));
                    // Level up code adapted from Bag of Tricks https://www.nexusmods.com/pathfinderkingmaker/mods/2
                    if (player.AllCharacters.Contains(ch))
                    {
                        if (progression.Experience < xpTable.GetBonus(level + 1) && level < 20)
                        {
                            UI.ActionButton("+1", () => {
                                progression.AdvanceExperienceTo(xpTable.GetBonus(level + 1), true);
                            }, UI.Width(70));
                        }
                        else if (progression.Experience >= xpTable.GetBonus(level + 1) && level < 20)
                        {
                            UI.Label("LvUp".cyan().italic(), UI.Width(70));
                        }
                        else
                        {
                            UI.Space(74);
                        }
                    }
                    else
                    {
                        UI.Space(74);
                    }
                    UI.Space(25);
                    UI.Label($"my".green() + $": {mythicLevel}", UI.Width(100));
                    if (player.AllCharacters.Contains(ch))
                    {
                        if (progression.MythicExperience < 10)
                        {
                            UI.ActionButton("+1", () => {
                                progression.AdvanceMythicExperience(progression.MythicExperience + 1, true);
                            }, UI.Width(70));
                        }
                        else
                        {
                            UI.Label("max".cyan(), UI.Width(70));
                        }
                    }
                    else
                    {
                        UI.Space(74);
                    }
                    UI.Space(35);
                    if (!isWide)
                    {
                        ActionsGUI(ch);
                    }
                    UI.Wrap(!Main.IsWide, 303, 0);
                    bool showClasses = ch == selectedCharacter && selectedToggle == ToggleChoice.Classes;
                    if (UI.DisclosureToggle($"{classData.Count} Classes", ref showClasses))
                    {
                        if (showClasses)
                        {
                            selectedCharacter = ch; selectedToggle = ToggleChoice.Classes; Logger.Log($"selected {ch.CharacterName}");
                        }
                        else
                        {
                            selectedToggle = ToggleChoice.None;
                        }
                    }
                    bool showStats = ch == selectedCharacter && selectedToggle == ToggleChoice.Stats;
                    if (UI.DisclosureToggle("Stats", ref showStats, true, isWide ? 150 : 200))
                    {
                        if (showStats)
                        {
                            selectedCharacter = ch; selectedToggle = ToggleChoice.Stats;
                        }
                        else
                        {
                            selectedToggle = ToggleChoice.None;
                        }
                    }
                    UI.Wrap(Main.IsNarrow, 279);
                    bool showFacts = ch == selectedCharacter && selectedToggle == ToggleChoice.Facts;
                    if (UI.DisclosureToggle("Facts", ref showFacts, true, isWide ? 150 : 200))
                    {
                        if (showFacts)
                        {
                            selectedCharacter = ch; selectedToggle = ToggleChoice.Facts;
                        }
                        else
                        {
                            selectedToggle = ToggleChoice.None;
                        }
                    }
                    bool showBuffs = ch == selectedCharacter && selectedToggle == ToggleChoice.Buffs;
                    if (UI.DisclosureToggle("Buffs", ref showBuffs, true, isWide ? 150 : 200))
                    {
                        if (showBuffs)
                        {
                            selectedCharacter = ch; selectedToggle = ToggleChoice.Buffs;
                        }
                        else
                        {
                            selectedToggle = ToggleChoice.None;
                        }
                    }
                    UI.Wrap(Main.IsNarrow, 304);
                    bool showAbilities = ch == selectedCharacter && selectedToggle == ToggleChoice.Abilities;
                    if (UI.DisclosureToggle("Abilities", ref showAbilities, true))
                    {
                        if (showAbilities)
                        {
                            selectedCharacter = ch; selectedToggle = ToggleChoice.Abilities;
                        }
                        else
                        {
                            selectedToggle = ToggleChoice.None;
                        }
                    }
                    UI.Space(25);
                    if (spellCount > 0)
                    {
                        bool showSpells = ch == selectedCharacter && selectedToggle == ToggleChoice.Spells;
                        if (UI.DisclosureToggle($"{spellCount} Spells", ref showSpells, true))
                        {
                            if (showSpells)
                            {
                                selectedCharacter = ch; selectedToggle = ToggleChoice.Spells;
                            }
                            else
                            {
                                selectedToggle = ToggleChoice.None;
                            }
                        }
                    }
                    else
                    {
                        UI.Space(180);
                    }
                    if (isWide)
                    {
                        ActionsGUI(ch);
                    }
                }
                if (!Main.IsWide)
                {
                    UI.Div(20, 20);
                }
                if (selectedCharacter != spellbookEditCharacter)
                {
                    editSpellbooks         = false;
                    spellbookEditCharacter = null;
                }
                if (selectedCharacter != multiclassEditCharacter)
                {
                    editMultiClass          = false;
                    multiclassEditCharacter = null;
                }
                if (ch == selectedCharacter && selectedToggle == ToggleChoice.Classes)
                {
#if DEBUG
                    UI.Div(100, 20);
                    using (UI.HorizontalScope()) {
                        UI.Space(100);
                        UI.Toggle("Multiple Classes On Level-Up", ref settings.toggleMulticlass, 0);
                        if (settings.toggleMulticlass)
                        {
                            UI.Space(39);
                            if (UI.DisclosureToggle("Config".orange().bold(), ref editMultiClass))
                            {
                                multiclassEditCharacter = selectedCharacter;
                            }
                            UI.Space(25);
                            UI.Label("Experimental Preview ".magenta() + "See 'Level Up + Multiclass' for more options".green());
                        }
                        else
                        {
                            UI.Space(50);  UI.Label("Experimental Preview ".magenta());
                        }
                    }
#endif
                    UI.Div(100, 20);
                    if (editMultiClass)
                    {
                        var multiclassSet = ch.GetMulticlassSet();
                        MulticlassPicker.OnGUI(multiclassSet);
                        ch.SetMulticlassSet(multiclassSet);
                    }
                    else
                    {
                        var prog = ch.Descriptor.Progression;
                        using (UI.HorizontalScope()) {
                            UI.Space(100);
                            UI.Label("Character Level".cyan(), UI.Width(250));
                            UI.ActionButton("<", () => prog.CharacterLevel = Math.Max(0, prog.CharacterLevel - 1), UI.AutoWidth());
                            UI.Space(25);
                            UI.Label("level".green() + $": {prog.CharacterLevel}", UI.Width(100f));
                            UI.ActionButton(">", () => prog.CharacterLevel = Math.Min(20, prog.CharacterLevel + 1), UI.AutoWidth());
                            UI.Space(25);
                            UI.ActionButton("Reset", () => ch.resetClassLevel(), UI.Width(125));
                            UI.Space(23);
                            UI.Label("This directly changes your character level but will not change exp or adjust any features associated with your character. To do a normal level up use +1 Lvl above".green());
                        }
                        UI.Div(0, 25);
                        using (UI.HorizontalScope()) {
                            UI.Space(100);
                            UI.Label("Mythic Level".cyan(), UI.Width(250));
                            UI.ActionButton("<", () => prog.MythicLevel = Math.Max(0, prog.MythicLevel - 1), UI.AutoWidth());
                            UI.Space(25);
                            UI.Label("my lvl".green() + $": {prog.MythicLevel}", UI.Width(100f));
                            UI.ActionButton(">", () => prog.MythicLevel = Math.Min(10, prog.MythicLevel + 1), UI.AutoWidth());
                            UI.Space(175);
                            UI.Label("This directly changes your mythic level but will not adjust any features associated with your character. To do a normal mythic level up use +1 my above".green());
                        }
                        foreach (var cd in classData)
                        {
                            UI.Div(100, 20);
                            using (UI.HorizontalScope()) {
                                UI.Space(100);
                                UI.Label(cd.CharacterClass.Name.orange(), UI.Width(250));
                                UI.ActionButton("<", () => cd.Level = Math.Max(0, cd.Level - 1), UI.AutoWidth());
                                UI.Space(25);
                                UI.Label("level".green() + $": {cd.Level}", UI.Width(100f));
                                var maxLevel = cd.CharacterClass.Progression.IsMythic ? 10 : 20;
                                UI.ActionButton(">", () => cd.Level = Math.Min(maxLevel, cd.Level + 1), UI.AutoWidth());
                                UI.Space(175);
                                UI.Label(cd.CharacterClass.Description.green(), UI.AutoWidth());
                            }
                        }
                    }
                }
                if (ch == selectedCharacter && selectedToggle == ToggleChoice.Stats)
                {
                    UI.Div(100, 20, 755);
                    var alignment = ch.Descriptor.Alignment.Value;
                    using (UI.HorizontalScope()) {
                        UI.Space(100);
                        UI.Label("Alignment", UI.Width(425));
                        UI.Label($"{alignment.Name()}".color(alignment.Color()).bold(), UI.Width(1250f));
                    }
                    using (UI.HorizontalScope()) {
                        UI.Space(528);
                        int alignmentIndex = Array.IndexOf(alignments, alignment);
                        var titles         = alignments.Select(
                            a => a.Acronym().color(a.Color()).bold()).ToArray();
                        if (UI.SelectionGrid(ref alignmentIndex, titles, 3, UI.Width(250f)))
                        {
                            ch.Descriptor.Alignment.Set(alignments[alignmentIndex]);
                        }
                    }
                    UI.Div(100, 20, 755);
                    using (UI.HorizontalScope()) {
                        UI.Space(100);
                        UI.Label("Size", UI.Width(425));
                        var size = ch.Descriptor.State.Size;
                        UI.Label($"{size}".orange().bold(), UI.Width(175));
                    }
                    using (UI.HorizontalScope()) {
                        UI.Space(528);
                        UI.EnumGrid(
                            () => ch.Descriptor.State.Size,
                            (s) => ch.Descriptor.State.Size = s,
                            3, UI.Width(600));
                    }
                    using (UI.HorizontalScope()) {
                        UI.Space(528);
                        UI.ActionButton("Reset", () => { ch.Descriptor.State.Size = ch.Descriptor.OriginalSize; }, UI.Width(197));
                    }
                    UI.Div(100, 20, 755);
                    foreach (StatType obj in Enum.GetValues(typeof(StatType)))
                    {
                        StatType        statType        = (StatType)obj;
                        ModifiableValue modifiableValue = ch.Stats.GetStat(statType);
                        if (modifiableValue != null)
                        {
                            String key         = $"{ch.CharacterName}-{statType.ToString()}";
                            var    storedValue = statEditorStorage.ContainsKey(key) ? statEditorStorage[key] : modifiableValue.BaseValue;
                            var    statName    = statType.ToString();
                            if (statName == "BaseAttackBonus" || statName == "SkillAthletics")
                            {
                                UI.Div(100, 20, 755);
                            }
                            using (UI.HorizontalScope()) {
                                UI.Space(100);
                                UI.Label(statName, UI.Width(400f));
                                UI.Space(25);
                                UI.ActionButton(" < ", () => {
                                    modifiableValue.BaseValue -= 1;
                                    storedValue = modifiableValue.BaseValue;
                                }, UI.AutoWidth());
                                UI.Space(20);
                                UI.Label($"{modifiableValue.BaseValue}".orange().bold(), UI.Width(50f));
                                UI.ActionButton(" > ", () => {
                                    modifiableValue.BaseValue += 1;
                                    storedValue = modifiableValue.BaseValue;
                                }, UI.AutoWidth());
                                UI.Space(25);
                                UI.ActionIntTextField(ref storedValue, statType.ToString(), (v) => {
                                    modifiableValue.BaseValue = v;
                                }, null, UI.Width(75));
                                statEditorStorage[key] = storedValue;
                            }
                        }
                    }
                }
                if (ch == selectedCharacter && selectedToggle == ToggleChoice.Facts)
                {
                    FactsEditor.OnGUI(ch, ch.Progression.Features.Enumerable.ToList());
                }
                if (ch == selectedCharacter && selectedToggle == ToggleChoice.Buffs)
                {
                    FactsEditor.OnGUI(ch, ch.Descriptor.Buffs.Enumerable.ToList());
                }
                if (ch == selectedCharacter && selectedToggle == ToggleChoice.Abilities)
                {
                    FactsEditor.OnGUI(ch, ch.Descriptor.Abilities.Enumerable.ToList());
                }
                if (ch == selectedCharacter && selectedToggle == ToggleChoice.Spells)
                {
                    UI.Space(20);
                    var names  = spellbooks.Select((sb) => sb.Blueprint.GetDisplayName()).ToArray();
                    var titles = names.Select((name, i) => $"{name} ({spellbooks.ElementAt(i).CasterLevel})").ToArray();
                    if (spellbooks.Any())
                    {
                        using (UI.HorizontalScope()) {
                            UI.SelectionGrid(ref selectedSpellbook, titles, 7, UI.Width(1581));
                            if (selectedSpellbook > names.Count())
                            {
                                selectedSpellbook = 0;
                            }
                            //                        UI.DisclosureToggle("Edit", ref editSpellbooks);
                        }
                        var spellbook = spellbooks.ElementAt(selectedSpellbook);
                        if (editSpellbooks)
                        {
                            spellbookEditCharacter = ch;
                            var blueprints = BlueprintExensions.GetBlueprints <BlueprintSpellbook>().OrderBy((bp) => bp.GetDisplayName());
                            BlueprintListUI.OnGUI(ch, blueprints, 100);
                        }
                        else
                        {
                            var maxLevel    = spellbook.Blueprint.MaxSpellLevel;
                            var casterLevel = spellbook.CasterLevel;
                            using (UI.HorizontalScope()) {
                                UI.EnumerablePicker <int>(
                                    "Spell Level".bold() + " (count)",
                                    ref selectedSpellbookLevel,
                                    Enumerable.Range(0, casterLevel + 1),
                                    0,
                                    (lvl) => {
                                    var levelText  = lvl <= casterLevel ? $"L{lvl}".bold() : $"L{lvl}".grey();
                                    var knownCount = spellbook.GetKnownSpells(lvl).Count();
                                    var countText  = knownCount > 0 ? $" ({knownCount})".white() : "";
                                    return(levelText + countText);
                                },
                                    UI.AutoWidth()
                                    );
                                if (casterLevel < maxLevel)
                                {
                                    UI.ActionButton("+1 Caster Level", () => spellbook.AddBaseLevel());
                                }
                            }
                            FactsEditor.OnGUI(ch, spellbook, selectedSpellbookLevel);
                        }
                    }
#if false
                    else
                    {
                        spellbookEditCharacter = ch;
                        editSpellbooks         = true;
                        var blueprints = BlueprintExensions.GetBlueprints <BlueprintSpellbook>().OrderBy((bp) => bp.GetDisplayName());
                        BlueprintListUI.OnGUI(ch, blueprints, 100);
                    }
#endif
                }
                if (selectedCharacter != GetSelectedCharacter())
                {
                    selectedCharacterIndex = characterList.IndexOf(selectedCharacter);
                }
                chIndex += 1;
            }
            UI.Space(25);
            if (respecableCount > 0)
            {
                UI.Label($"{respecableCount} characters".yellow().bold() + " can be respecced. Pressing Respec will close the mod window and take you to character level up".orange());
                UI.Label("WARNING".yellow().bold() + " this feature is ".orange() + "EXPERIMENTAL".yellow().bold() + " and uses unreleased and likely buggy code.".orange());
                UI.Label("BACK UP".yellow().bold() + " before playing with this feature.You will lose your mythic ranks but you can restore them in this Party Editor.".orange());
            }
            UI.Space(25);
            if (charToAdd != null)
            {
                UnitEntityDataUtils.AddCompanion(charToAdd);
            }
            if (charToRemove != null)
            {
                UnitEntityDataUtils.RemoveCompanion(charToRemove);
            }
        }
Ejemplo n.º 9
0
        public static void InitializeActions()
        {
            BlueprintAction.Register(
                new BlueprintAction <BlueprintItem>("Add",
                                                    (bp, ch, n) => Game.Instance.Player.Inventory.Add(bp, n, null),
                                                    null,
                                                    true
                                                    ),
                new BlueprintAction <BlueprintItem>("Remove",
                                                    (bp, ch, n) => Game.Instance.Player.Inventory.Remove(bp, n),
                                                    (bp, ch) => Game.Instance.Player.Inventory.Contains(bp),
                                                    true
                                                    ),
                new BlueprintAction <BlueprintUnit>("Spawn",
                                                    (bp, ch, n) => Actions.SpawnUnit(bp, n),
                                                    null,
                                                    true
                                                    ),
#if false
                new BlueprintAction("Kill", typeof(BlueprintUnit),
                                    (bp, ch) => { Actions.SpawnUnit((BlueprintUnit)bp); }
                                    ),
                new BlueprintAction("Remove", typeof(BlueprintUnit),
                                    (bp, ch) => { CheatsCombat.Kill((BlueprintUnit)bp); },
                                    (bp, ch) => { return(ch.Inventory.Contains((BlueprintUnit)bp)); }
                                    ),
#endif
                new BlueprintAction <BlueprintFeature>("Add",
                                                       (bp, ch, n) => ch.Descriptor.AddFact(bp),
                                                       (bp, ch) => !ch.Progression.Features.HasFact(bp)
                                                       ),
                new BlueprintAction <BlueprintFeature>("Remove",
                                                       (bp, ch, n) => ch.Progression.Features.RemoveFact(bp),
                                                       (bp, ch) => ch.Progression.Features.HasFact(bp)
                                                       ),
                new BlueprintAction <BlueprintFeature>("<",
                                                       (bp, ch, n) => { try { ch.Progression.Features.GetFact(bp).RemoveRank(); } catch (Exception e) { Logger.Log(e); } },
                                                       (bp, ch) => {
                var feature = ch.Progression.Features.GetFact(bp);
                return(feature != null && feature.GetRank() > 1);
            }),
                new BlueprintAction <BlueprintFeature>(">",
                                                       (bp, ch, n) => ch.Progression.Features.GetFact(bp).AddRank(),
                                                       (bp, ch) => {
                var feature = ch.Progression.Features.GetFact(bp);
                return(feature != null && feature.GetRank() < feature.Blueprint.Ranks);
            }),

                // Spellbooks
                new BlueprintAction <BlueprintSpellbook>("Add",
                                                         (bp, ch, n) => { ch.Descriptor.DemandSpellbook(bp.CharacterClass); },
                                                         (bp, ch) => !ch.Descriptor.Spellbooks.Any((sb) => sb.Blueprint == bp)
                                                         ),
                new BlueprintAction <BlueprintSpellbook>("Remove",
                                                         (bp, ch, n) => ch.Descriptor.DeleteSpellbook(bp),
                                                         (bp, ch) => ch.Descriptor.Spellbooks.Any((sb) => sb.Blueprint == bp)
                                                         ),
                new BlueprintAction <BlueprintSpellbook>(">",
                                                         (bp, ch, n) => {
                try {
                    var spellbook = ch.Descriptor.Spellbooks.First((sb) => sb.Blueprint == bp);
                    if (spellbook.IsMythic)
                    {
                        spellbook.AddMythicLevel();
                    }
                    else
                    {
                        spellbook.AddBaseLevel();
                    }
                }
                catch (Exception e) { Logger.Log(e); }
            },
                                                         (bp, ch) => ch.Descriptor.Spellbooks.Any((sb) => sb.Blueprint == bp && sb.CasterLevel < bp.MaxSpellLevel)
                                                         ),

                // Buffs
                new BlueprintAction <BlueprintBuff>("Add",
                                                    (bp, ch, n) => GameHelper.ApplyBuff(ch, bp),
                                                    (bp, ch) => !ch.Descriptor.Buffs.HasFact(bp)
                                                    ),
                new BlueprintAction <BlueprintBuff>("Remove",
                                                    (bp, ch, n) => ch.Descriptor.RemoveFact(bp),
                                                    (bp, ch) => ch.Descriptor.Buffs.HasFact(bp)
                                                    ),
                new BlueprintAction <BlueprintBuff>("<",
                                                    (bp, ch, n) => ch.Descriptor.Buffs.GetFact(bp).RemoveRank(),
                                                    (bp, ch) => {
                var buff = ch.Descriptor.Buffs.GetFact(bp);
                return(buff != null && buff.GetRank() > 1);
            }),
                new BlueprintAction <BlueprintBuff>(">",
                                                    (bp, ch, n) => ch.Descriptor.Buffs.GetFact(bp).AddRank(),
                                                    (bp, ch) => {
                var buff = ch.Descriptor.Buffs.GetFact(bp);
                return(buff != null && buff.GetRank() < buff.Blueprint.Ranks - 1);
            }),

                // Abilities
                new BlueprintAction <BlueprintAbility>("Add",
                                                       (bp, ch, n) => ch.AddAbility(bp),
                                                       (bp, ch) => ch.CanAddAbility(bp)
                                                       ),
                new BlueprintAction <BlueprintAbility>("At Will",
                                                       (bp, ch, n) => ch.AddSpellAsAbility(bp),
                                                       (bp, ch) => ch.CanAddSpellAsAbility(bp)
                                                       ),
                new BlueprintAction <BlueprintAbility>("Remove",
                                                       (bp, ch, n) => ch.RemoveAbility(bp),
                                                       (bp, ch) => ch.HasAbility(bp)
                                                       ),
                // BlueprintActivatableAbility
                new BlueprintAction <BlueprintActivatableAbility>("Add",
                                                                  (bp, ch, n) => ch.Descriptor.AddFact(bp),
                                                                  (bp, ch) => !ch.Descriptor.HasFact(bp)
                                                                  ),
                new BlueprintAction <BlueprintActivatableAbility>("Remove",
                                                                  (bp, ch, n) => ch.Descriptor.RemoveFact(bp),
                                                                  (bp, ch) => ch.Descriptor.HasFact(bp)
                                                                  ),
                // Etudes
                new BlueprintAction <BlueprintEtude>("Start",
                                                     (bp, ch, n) => Game.Instance.Player.EtudesSystem.StartEtude(bp),
                                                     (bp, ch) => Game.Instance.Player.EtudesSystem.EtudeIsNotStarted(bp)
                                                     ),
                new BlueprintAction <BlueprintEtude>("Complete",
                                                     (bp, ch, n) => Game.Instance.Player.EtudesSystem.MarkEtudeCompleted(bp),
                                                     (bp, ch) => !Game.Instance.Player.EtudesSystem.EtudeIsNotStarted(bp) && !Game.Instance.Player.EtudesSystem.EtudeIsCompleted(bp)
                                                     ),
                // Cut Scenes
                new BlueprintAction <Cutscene>("Play",
                                               (bp, ch, n) => {
                Actions.ToggleModWindow();
                CutscenePlayerData cutscenePlayerData = CutscenePlayerData.Queue.FirstOrDefault <CutscenePlayerData>((Func <CutscenePlayerData, bool>)(c => c.PlayActionId == bp.name));
                if (cutscenePlayerData != null)
                {
                    cutscenePlayerData.PreventDestruction = true;
                    cutscenePlayerData.Stop();
                    cutscenePlayerData.PreventDestruction = false;
                }
                var state = Kingmaker.ElementsSystem.ContextData <SpawnedUnitData> .Current?.State;
                CutscenePlayerView.Play(bp, null, true, state).PlayerData.PlayActionId = bp.name;
            }),
                // Teleport
                new BlueprintAction <BlueprintAreaEnterPoint>("Teleport",
                                                              (bp, ch, n) => GameHelper.EnterToArea(bp, AutoSaveMode.None)
                                                              ),
                new BlueprintAction <BlueprintGlobalMap>("Teleport",
                                                         (bp, ch, n) => GameHelper.EnterToArea(bp.GlobalMapEnterPoint, AutoSaveMode.None)
                                                         ),
                //new BlueprintAction<BlueprintAreaPart>("Teleport",
                //    (bp, ch, n) => GameHelper.EnterToArea(bp, AutoSaveMode.None)
                //    ),
                new BlueprintAction <BlueprintArea>("Teleport",
                                                    (area, ch, n) => {
                var areaEnterPoints = BlueprintExensions.BlueprintsOfType <BlueprintAreaEnterPoint>();
                var blueprint       = areaEnterPoints.Where(bp => (bp is BlueprintAreaEnterPoint ep) ? ep.Area == area : false).FirstOrDefault();
                if (blueprint is BlueprintAreaEnterPoint enterPoint)
                {
                    GameHelper.EnterToArea(enterPoint, AutoSaveMode.None);
                }
            }),
Ejemplo n.º 10
0
        public static void UpdateSearchResults()
        {
            if (blueprints == null)
            {
                return;
            }
            selectedCollationIndex      = 0;
            selectedCollatedBPs         = null;
            BlueprintListUI.needsLayout = true;
            if (settings.searchText.Trim().Length == 0)
            {
                ResetSearch();
            }
            var searchText = settings.searchText;
            var terms      = searchText.Split(' ').Select(s => s.ToLower()).ToHashSet();

            selectedTypeFilter = blueprintTypeFilters[settings.selectedBPTypeFilter];
            var selectedType = selectedTypeFilter.type;
            IEnumerable <SimpleBlueprint> bps = null;

            if (selectedTypeFilter.blueprintSource != null)
            {
                bps = selectedTypeFilter.blueprintSource();
            }
            else
            {
                bps = from bp in BlueprintExensions.BlueprintsOfType(selectedType)
                      where selectedTypeFilter.filter(bp)
                      select bp;
            }
            var filtered = new List <SimpleBlueprint>();

            foreach (var blueprint in bps)
            {
                if (blueprint.AssetGuid.ToString().Contains(searchText) ||
                    blueprint.GetType().ToString().Contains(searchText))
                {
                    filtered.Add(blueprint);
                }
                else
                {
                    var name        = blueprint.name;
                    var displayName = blueprint.GetDisplayName();
                    var description = blueprint.GetDescription() ?? "";
                    if (terms.All(term => name.Matches(term)) ||
                        terms.All(term => displayName.Matches(term)) ||
                        settings.searchesDescriptions &&
                        (terms.All(term => description.Matches(term)) ||
                         blueprint is BlueprintItem itemBP &&
                         terms.All(term => itemBP.FlavorText.Matches(term))
                        )
                        )
                    {
                        filtered.Add(blueprint);
                    }
                }
            }
            filteredBPs = filtered.OrderBy(bp => bp.name);
            matchCount  = filtered.Count();
            UpdatePageCount();
            for (var i = 0; i < BlueprintListUI.ParamSelected.Length; i++)
            {
                BlueprintListUI.ParamSelected[i] = 0;
            }
            uncolatedMatchCount = matchCount;
            if (selectedTypeFilter.collator != null)
            {
                collatedBPs = from bp in filtered
                              from key in selectedTypeFilter.collator(bp)
                              //where selectedTypeFilter.collator(bp).Contains(key) // this line causes a mutation error
                              group bp by key into g
                              orderby g.Key.LongSortKey(), g.Key
                select g;

                _ = collatedBPs.Count();
                var keys = collatedBPs.ToList().Select(cbp => cbp.Key).ToList();
                collationKeys = new List <string> {
                    "All"
                };
                collationKeys.AddRange(keys);
            }
            else
            {
                collationKeys = null;
            }

            unpagedBPs = filteredBPs;
            UpdatePaginatedResults();
            firstSearch = false;
            UpdateCollation();
        }
Ejemplo n.º 11
0
        public static void InitializeActions()
        {
#if false
            var flags = Game.Instance.Player.UnlockableFlags;
            BlueprintAction.Register <BlueprintItem>("Add",
                                                     (bp, ch, n, index) => Game.Instance.Player.Inventory.Add(bp, n), isRepeatable: true);

            BlueprintAction.Register <BlueprintItem>("Remove",
                                                     (bp, ch, n, index) => Game.Instance.Player.Inventory.Remove(bp, n),
                                                     (bp, ch, index) => Game.Instance.Player.Inventory.Contains(bp), true);

            BlueprintAction.Register <BlueprintUnit>("Spawn",
                                                     (bp, ch, n, index) => Actions.SpawnUnit(bp, n), isRepeatable: true);

            BlueprintAction.Register <BlueprintFeature>("Add",
                                                        (bp, ch, n, index) => ch.Descriptor.AddFact(bp),
                                                        (bp, ch, index) => !ch.Progression.Features.HasFact(bp));

            BlueprintAction.Register <BlueprintFeature>("Remove",
                                                        (bp, ch, n, index) => ch.Progression.Features.RemoveFact(bp),
                                                        (bp, ch, index) => ch.Progression.Features.HasFact(bp));

            BlueprintAction.Register <BlueprintParametrizedFeature>("Add",
                                                                    (bp, ch, n, index) => ch?.Descriptor?.AddFact <UnitFact>(bp, null, bp.Items.OrderBy(x => x.Name).ElementAt(BlueprintListUI.ParamSelected[index]).Param),
                                                                    (bp, ch, index) => ch?.Descriptor?.Unit?.Facts?.Get <Feature>(i => i.Blueprint == bp && i.Param == bp.Items.OrderBy(x => x.Name).ElementAt(BlueprintListUI.ParamSelected[index]).Param) == null);

            BlueprintAction.Register <BlueprintParametrizedFeature>("Remove", (bp, ch, n, index) => ch?.Progression?.Features?.RemoveFact(ch.Descriptor?.Unit?.Facts?.Get <Feature>(i => i.Blueprint == bp && i.Param == bp.Items.OrderBy(x => x.Name).ToArray()[BlueprintListUI.ParamSelected[index]].Param)),
                                                                    (bp, ch, index) => ch?.Descriptor?.Unit?.Facts?.Get <Feature>(i => i.Blueprint == bp && i.Param == bp.Items.OrderBy(x => x.Name).ToArray()[BlueprintListUI.ParamSelected[index]].Param) != null);

            BlueprintAction.Register <BlueprintFeature>("<",
                                                        (bp, ch, n, index) => ch.Progression.Features.GetFact(bp)?.RemoveRank(),
                                                        (bp, ch, index) => {
                var feature = ch.Progression.Features.GetFact(bp);
                return(feature?.GetRank() > 1);
            });

            BlueprintAction.Register <BlueprintFeature>(">",
                                                        (bp, ch, n, index) => ch.Progression.Features.GetFact(bp)?.AddRank(),
                                                        (bp, ch, index) => {
                var feature = ch.Progression.Features.GetFact(bp);
                return(feature != null && feature.GetRank() < feature.Blueprint.Ranks);
            });
            //BlueprintAction.Register<BlueprintArchetype>(
            //    "Add",
            //    (bp, ch, n, index) => ch.Progression.AddArchetype(ch.Progression.Classes.First().CharacterClass, bp),
            //    (bp, ch, index) => ch.Progression.CanAddArchetype(ch.Progression.Classes.First().CharacterClass, bp)
            //    );
            //BlueprintAction.Register<BlueprintArchetype>("Remove",
            //    (bp, ch, n, index) => ch.Progression.AddArchetype(ch.Progression.Classes.First().CharacterClass, bp),
            //    (bp, ch, index) => ch.Progression.Classes.First().Archetypes.Contains(bp)
            //    );

            // Spellbooks
            BlueprintAction.Register <BlueprintSpellbook>("Add",
                                                          (bp, ch, n, index) => ch.Descriptor.DemandSpellbook(bp.CharacterClass),
                                                          (bp, ch, index) => ch.Descriptor.Spellbooks.All(sb => sb.Blueprint != bp));

            BlueprintAction.Register <BlueprintSpellbook>("Remove",
                                                          (bp, ch, n, index) => ch.Descriptor.DeleteSpellbook(bp),
                                                          (bp, ch, index) => ch.Descriptor.Spellbooks.Any(sb => sb.Blueprint == bp));

            BlueprintAction.Register <BlueprintSpellbook>(">",
                                                          (bp, ch, n, index) => {
                try {
                    var spellbook = ch.Descriptor.Spellbooks.First(sb => sb.Blueprint == bp);

                    if (spellbook.IsMythic)
                    {
                        spellbook.AddMythicLevel();
                    }
                    else
                    {
                        spellbook.AddBaseLevel();
                    }
                }
                catch (Exception e) { Mod.Error(e); }
            },
                                                          (bp, ch, index) => ch.Descriptor.Spellbooks.Any(sb => sb.Blueprint == bp && sb.CasterLevel < bp.MaxSpellLevel));

            // Buffs
            BlueprintAction.Register <BlueprintBuff>("Add",
                                                     (bp, ch, n, index) => GameHelper.ApplyBuff(ch, bp),
                                                     (bp, ch, index) => !ch.Descriptor.Buffs.HasFact(bp));

            BlueprintAction.Register <BlueprintBuff>("Remove",
                                                     (bp, ch, n, index) => ch.Descriptor.RemoveFact(bp),
                                                     (bp, ch, index) => ch.Descriptor.Buffs.HasFact(bp));

            BlueprintAction.Register <BlueprintBuff>("<",
                                                     (bp, ch, n, index) => ch.Descriptor.Buffs.GetFact(bp)?.RemoveRank(),
                                                     (bp, ch, index) => {
                var buff = ch.Descriptor.Buffs.GetFact(bp);

                return(buff?.GetRank() > 1);
            });

            BlueprintAction.Register <BlueprintBuff>(">",
                                                     (bp, ch, n, index) => ch.Descriptor.Buffs.GetFact(bp)?.AddRank(),
                                                     (bp, ch, index) => {
                var buff = ch.Descriptor.Buffs.GetFact(bp);

                return(buff != null && buff.GetRank() < buff.Blueprint.Ranks - 1);
            });

            // Abilities
            BlueprintAction.Register <BlueprintAbility>("Add",
                                                        (bp, ch, n, index) => ch.AddAbility(bp),
                                                        (bp, ch, index) => ch.CanAddAbility(bp));

            BlueprintAction.Register <BlueprintAbility>("At Will",
                                                        (bp, ch, n, index) => ch.AddSpellAsAbility(bp),
                                                        (bp, ch, index) => ch.CanAddSpellAsAbility(bp));

            BlueprintAction.Register <BlueprintAbility>("Remove",
                                                        (bp, ch, n, index) => ch.RemoveAbility(bp),
                                                        (bp, ch, index) => ch.HasAbility(bp));
            // Ability Resources

            BlueprintAction.Register <BlueprintAbilityResource>("Add",
                                                                (bp, ch, n, index) => ch.Resources.Add(bp, true),
                                                                (bp, ch, index) => !ch.Resources.ContainsResource(bp));

            BlueprintAction.Register <BlueprintAbilityResource>("Remove",
                                                                (bp, ch, n, index) => ch.Resources.Remove(bp),
                                                                (bp, ch, index) => ch.Resources.ContainsResource(bp));

            // Spellbooks


            // BlueprintActivatableAbility
            BlueprintAction.Register <BlueprintActivatableAbility>("Add",
                                                                   (bp, ch, n, index) => ch.Descriptor.AddFact(bp),
                                                                   (bp, ch, index) => !ch.Descriptor.HasFact(bp));

            BlueprintAction.Register <BlueprintActivatableAbility>("Remove",
                                                                   (bp, ch, n, index) => ch.Descriptor.RemoveFact(bp),
                                                                   (bp, ch, index) => ch.Descriptor.HasFact(bp));

            // Quests
            BlueprintAction.Register <BlueprintQuest>("Start",
                                                      (bp, ch, n, index) => Game.Instance.Player.QuestBook.GiveObjective(bp.Objectives.First()),
                                                      (bp, ch, index) => Game.Instance.Player.QuestBook.GetQuest(bp) == null);

            BlueprintAction.Register <BlueprintQuest>("Complete",
                                                      (bp, ch, n, index) => {
                foreach (var objective in bp.Objectives)
                {
                    Game.Instance.Player.QuestBook.CompleteObjective(objective);
                }
            }, (bp, ch, index) => Game.Instance.Player.QuestBook.GetQuest(bp)?.State == QuestState.Started);

            // Quests Objectives
            BlueprintAction.Register <BlueprintQuestObjective>("Start",
                                                               (bp, ch, n, index) => Game.Instance.Player.QuestBook.GiveObjective(bp),
                                                               (bp, ch, index) => Game.Instance.Player.QuestBook.GetQuest(bp.Quest) == null);

            BlueprintAction.Register <BlueprintQuestObjective>("Complete",
                                                               (bp, ch, n, index) => Game.Instance.Player.QuestBook.CompleteObjective(bp),
                                                               (bp, ch, index) => Game.Instance.Player.QuestBook.GetQuest(bp.Quest)?.State == QuestState.Started);

            // Etudes
            BlueprintAction.Register <BlueprintEtude>("Start",
                                                      (bp, ch, n, index) => Game.Instance.Player.EtudesSystem.StartEtude(bp),
                                                      (bp, ch, index) => Game.Instance.Player.EtudesSystem.EtudeIsNotStarted(bp));
            BlueprintAction.Register <BlueprintEtude>("Unstart",
                                                      (bp, ch, n, index) => Game.Instance.Player.EtudesSystem.UnstartEtude(bp),
                                                      (bp, ch, index) => !Game.Instance.Player.EtudesSystem.EtudeIsNotStarted(bp));
            BlueprintAction.Register <BlueprintEtude>("Complete",
                                                      (bp, ch, n, index) => Game.Instance.Player.EtudesSystem.MarkEtudeCompleted(bp),
                                                      (bp, ch, index) => !Game.Instance.Player.EtudesSystem.EtudeIsNotStarted(bp) &&
                                                      !Game.Instance.Player.EtudesSystem.EtudeIsCompleted(bp));
            // Flags
            BlueprintAction.Register <BlueprintUnlockableFlag>("Unlock",
                                                               (bp, ch, n, index) => flags.Unlock(bp),
                                                               (bp, ch, index) => !flags.IsUnlocked(bp));

            BlueprintAction.Register <BlueprintUnlockableFlag>("Lock",
                                                               (bp, ch, n, index) => flags.Lock(bp),
                                                               (bp, ch, index) => flags.IsUnlocked(bp));

            BlueprintAction.Register <BlueprintUnlockableFlag>(">",
                                                               (bp, ch, n, index) => flags.SetFlagValue(bp, flags.GetFlagValue(bp) + n),
                                                               (bp, ch, index) => flags.IsUnlocked(bp));

            BlueprintAction.Register <BlueprintUnlockableFlag>("<",
                                                               (bp, ch, n, index) => flags.SetFlagValue(bp, flags.GetFlagValue(bp) - n),
                                                               (bp, ch, index) => flags.IsUnlocked(bp));

            // Cutscenes
            BlueprintAction.Register <Cutscene>("Play", (bp, ch, n, index) => {
                Actions.ToggleModWindow();
                var cutscenePlayerData = CutscenePlayerData.Queue.FirstOrDefault(c => c.PlayActionId == bp.name);

                if (cutscenePlayerData != null)
                {
                    cutscenePlayerData.PreventDestruction = true;
                    cutscenePlayerData.Stop();
                    cutscenePlayerData.PreventDestruction = false;
                }

                var state = ContextData <SpawnedUnitData> .Current?.State;
                CutscenePlayerView.Play(bp, null, true, state).PlayerData.PlayActionId = bp.name;
            });

            // Teleport
            BlueprintAction.Register <BlueprintAreaEnterPoint>("Teleport", (bp, ch, n, index) => GameHelper.EnterToArea(bp, AutoSaveMode.None));
            BlueprintAction.Register <BlueprintGlobalMap>("Teleport", (bp, ch, n, index) => GameHelper.EnterToArea(bp.GlobalMapEnterPoint, AutoSaveMode.None));

            BlueprintAction.Register <BlueprintArea>("Teleport", (area, ch, n, index) => {
                var areaEnterPoints = BlueprintExensions.BlueprintsOfType <BlueprintAreaEnterPoint>();
                var blueprint       = areaEnterPoints.FirstOrDefault(bp => bp is BlueprintAreaEnterPoint ep && ep.Area == area);

                if (blueprint is BlueprintAreaEnterPoint enterPoint)
                {
                    GameHelper.EnterToArea(enterPoint, AutoSaveMode.None);
                }
            });

            BlueprintAction.Register <BlueprintGlobalMapPoint>("Teleport", (globalMapPoint, ch, n, index) => {
                if (!Teleport.TeleportToGlobalMapPoint(globalMapPoint))
                {
                    Teleport.TeleportToGlobalMap(() => Teleport.TeleportToGlobalMapPoint(globalMapPoint));
                }
            });

            //Army
            BlueprintAction.Register <BlueprintArmyPreset>("Add", (bp, ch, n, l) => {
                Actions.CreateArmy(bp);
            });

            //ArmyGeneral
            BlueprintAction.Register <BlueprintLeaderSkill>("Add",
                                                            (bp, ch, n, l) => Actions.AddSkillToLeader(bp),
                                                            (bp, ch, index) => Actions.LeaderSelected(bp) && !Actions.LeaderHasSkill(bp));

            //ArmyGeneral
            BlueprintAction.Register <BlueprintLeaderSkill>("Remove",
                                                            (bp, ch, n, l) => Actions.RemoveSkillFromLeader(bp),
                                                            (bp, ch, index) => Actions.LeaderSelected(bp) && Actions.LeaderHasSkill(bp));
#endif
        }