public static void AddSelection(this BlueprintFeatureSelection feat, LevelUpState state, UnitDescriptor unit, int level) { // TODO: we may want to add the selection feat to the unit. // (But I don't think Respec mod will be able to clear it out if we do that.) // unit.AddFact(feat); state.AddSelection(null, feat, feat, level); }
internal static void HandleUpdateCasterLevel(UnitDescriptor unit, LevelUpState state, Spellbook spellbook) { var casterLevel = spellbook.CasterLevel; if (CanReplaceSpellThisLevel(spellbook)) { Dictionary <int, BlueprintFeatureSelection> levelEntries; if (!casterProgressions.TryGetValue(spellbook.Blueprint, out levelEntries)) { Log.Write($"Error: could not find spellbook {spellbook.Blueprint.name}" + $", keys are: {String.Join(", ", casterProgressions.Keys.Select(k => k.name))}"); return; } BlueprintFeatureSelection feat; if (levelEntries.TryGetValue(casterLevel, out feat)) { state.AddSelection(null, feat, feat, casterLevel); } } }
public static bool Prefix([NotNull] LevelUpState state, [NotNull] UnitDescriptor unit, [NotNull] IList <BlueprintFeatureBase> features, [CanBeNull] FeatureSource source, int level) { if (!Main.IsInGame) { return(false); } #if true //Logger.Log($"feature count = {features.ToArray().Count()} "); var description = source.Blueprint.GetDescription() ?? "nil"; //Logger.Log($"source: {source.Blueprint.name} - {description}"); foreach (BlueprintFeature blueprintFeature in features.OfType <BlueprintFeature>()) { if (blueprintFeature.MeetsPrerequisites((FeatureSelectionState)null, unit, state, true)) { //Logger.Log($" name: {blueprintFeature.Name} : {blueprintFeature.GetType()}"); if (blueprintFeature is IFeatureSelection selection) { // Bug Fix - due to issues in the implementation of FeatureSelectionState.CanSelectAnything we can get level up blocked so this is an attempt to work around for that var numToAdd = settings.featsMultiplier; if (selection is BlueprintFeatureSelection bpFS) { var bpFeatures = bpFS; var items = bpFS.ExtractSelectionItems(unit, null); //Logger.Log($" items: {items.Count()}"); var availableCount = 0; foreach (var item in items) { #if false if (bpFS.is BlueprintParametrizedFeature bppF) { Logger.Log($"checking parameterized feature {bppF.Name}"); if (selection.CanSelect(unit, state, null, item)) { Logger.Log($" {item.Feature.name} is avaiable"); availableCount++; } } else #endif if (!unit.Progression.Features.HasFact(item.Feature)) { availableCount++; // Logger.Log($" {item.Feature.name} is avaiable"); } #if false if (selection.CanSelect(unit, state, null, item)) { Logger.Log($" {item.Feature.name} is avaiable"); availableCount++; } else { Logger.Log($" {item.Feature.name} is NOT avaiable"); } if (!unit.Progression.Features.HasFact(item.Feature)) { if (item.Feature.MeetsPrerequisites(null, unit, state, true)) { Logger.Log($" {item.Feature.name} is avaiable"); availableCount++; } } else { Logger.Log($" has Fact {item.Feature.Name}"); } #endif } if (numToAdd > availableCount) { Logger.Log($"reduced numToAdd: {numToAdd} -> {availableCount}"); numToAdd = availableCount; } } //Logger.Log($" IFeatureSelection: {selection} adding: {numToAdd}"); for (int i = 0; i < numToAdd; ++i) { state.AddSelection((FeatureSelectionState)null, source, selection, level); } } Kingmaker.UnitLogic.Feature feature = (Kingmaker.UnitLogic.Feature)unit.AddFact((BlueprintUnitFact)blueprintFeature); BlueprintProgression progression = blueprintFeature as BlueprintProgression; if ((UnityEngine.Object)progression != (UnityEngine.Object)null) { //Logger.Log($" BlueprintProgression: {progression}"); LevelUpHelper.UpdateProgression(state, unit, progression); } FeatureSource source1 = source; int level1 = level; feature.SetSource(source1, level1); }