Пример #1
0
 private void LevelUp(UnitDescriptor unit, int levels, bool fromFact)
 {
     using (new IgnorePrerequisites())
     {
         ClassLevelLimit component       = unit.Blueprint.GetComponent <ClassLevelLimit>();
         int             classLevelLimit = component == null ? int.MaxValue : component.LevelLimit;
         if (ElementsContext.GetData <DefaultBuildData>() != null)
         {
             classLevelLimit = 0;
         }
         Dictionary <SelectionEntry, HashSet <int> > selectionsHistory = new Dictionary <SelectionEntry, HashSet <int> >();
         HashSet <int> spellHistory = (instance.SelectSpells.Length <= 0) ? null : new HashSet <int>();
         for (int i = 0; i < levels; i++)
         {
             if (unit.Progression.CharacterLevel < classLevelLimit)
             {
                 Main.Log($"A: Adding level {i} unitlevel {unit.Progression.CharacterLevel}");
                 this.AddLevel(unit, selectionsHistory, spellHistory);
             }
             else
             {
                 Main.Log($"B: Adding level {i} unitlevel {unit.Progression.CharacterLevel}");
                 LevelUpPlanUnitHolder levelUpPlanUnitHolder = unit.Get <LevelUpPlanUnitHolder>();
                 if (levelUpPlanUnitHolder != null)
                 {
                     UnitDescriptor    unitDescriptor    = levelUpPlanUnitHolder.RequestPlan();
                     LevelUpController levelUpController = this.AddLevel(unitDescriptor, selectionsHistory, spellHistory);
                     unit.Progression.AddLevelPlan(levelUpController.GetPlan());
                 }
             }
         }
         this.PrepareSpellbook(unit);
         unit.Progression.ReapplyFeaturesOnLevelUp();
         UnitEntityView view = unit.Unit.View;
         if (view != null)
         {
             view.UpdateClassEquipment();
         }
         RestController.ApplyRest(unit);
     }
 }