public override void UpdateSpellcasting() { List <SpellcastingFeature> spellcasts = new List <SpellcastingFeature>(from f in Context.Player.GetFeatures() where f is SpellcastingFeature && ((SpellcastingFeature)f).SpellcastingID != "MULTICLASS" orderby Context.Player.GetClassLevel(((SpellcastingFeature)f).SpellcastingID) descending, ((SpellcastingFeature)f).DisplayName, ((SpellcastingFeature)f).SpellcastingID select f as SpellcastingFeature); //if (spellcasts.Count == 0) Spellcasting.ReplaceRange(new List<SpellbookViewModel>() { new SpellbookViewModel(this, null) }); List <SpellbookViewModel> views = new List <SpellbookViewModel>(); List <SpellbookViewModel> oldviews = new List <SpellbookViewModel>(Spellcasting); foreach (SpellcastingFeature sf in spellcasts) { List <SpellChoiceFeature> spellfeatures = new List <SpellChoiceFeature>(from f in Context.Player.GetFeatures() where f is SpellChoiceFeature select f as SpellChoiceFeature); foreach (var f in spellfeatures) { if (f.SpellcastingID == sf.SpellcastingID) { if (Spellcasting.FirstOrDefault(view => view is SpellChoiceViewModel scv && view.SpellcastingID == sf.SpellcastingID && scv.UniqueID == f.UniqueID) is SpellChoiceViewModel v) { v.Refresh(sf, f); views.Add(v); } else { views.Add(new SpellChoiceViewModel(this, sf, f)); } } } List <ModifiedSpell> bonusprepared = null; if (sf.Preparation != PreparationMode.LearnSpells) { SpellbookViewModel v2 = Spellcasting.FirstOrDefault(view => view is SpellPrepareViewModel && view.SpellcastingID == sf.SpellcastingID); if (v2 != null) { v2.Refresh(sf); if (v2 is SpellPrepareViewModel spvm && spvm.Able > 0) { views.Add(spvm); } } else { v2 = new SpellPrepareViewModel(this, sf); if (v2 is SpellPrepareViewModel spvm && spvm.Able > 0) { views.Add(spvm); } } } else { bonusprepared = Context.Player.GetSpellcasting(sf.SpellcastingID).GetPrepared(Context.Player, Context).ToList(); if (bonusprepared.Count > 0 && Spellcasting.FirstOrDefault(view => view is SpellChoiceViewModel scv && view.SpellcastingID == sf.SpellcastingID && scv.Choice == null) is SpellChoiceViewModel v) { v.Refresh(sf, null); v.SetSpells(bonusprepared); views.Add(v); }
public override void UpdateSpellcasting() { List <SpellcastingFeature> spellcasts = new List <SpellcastingFeature>(from f in Context.Player.GetFeatures() where f is SpellcastingFeature && ((SpellcastingFeature)f).SpellcastingID != "MULTICLASS" orderby Context.Player.GetClassLevel(((SpellcastingFeature)f).SpellcastingID) descending, ((SpellcastingFeature)f).DisplayName, ((SpellcastingFeature)f).SpellcastingID select f as SpellcastingFeature); //if (spellcasts.Count == 0) Spellcasting.ReplaceRange(new List<SpellbookViewModel>() { new SpellbookViewModel(this, null) }); List <SpellbookViewModel> views = new List <SpellbookViewModel>(); List <SpellbookViewModel> oldviews = new List <SpellbookViewModel>(Spellcasting); foreach (SpellcastingFeature sf in spellcasts) { SpellbookViewModel v = Spellcasting.FirstOrDefault(view => view is SpellbookSpellsViewModel && view.SpellcastingID == sf.SpellcastingID); if (v != null) { v.Refresh(sf); views.Add(v); } else { views.Add(new SpellbookSpellsViewModel(this, sf)); } if (sf.Preparation != PreparationMode.LearnSpells) { SpellbookViewModel v2 = Spellcasting.FirstOrDefault(view => view is SpellPrepareViewModel && view.SpellcastingID == sf.SpellcastingID); if (v2 != null) { v2.Refresh(sf); if (v2 is SpellPrepareViewModel spvm && spvm.Able > 0) { views.Add(spvm); } } else { v2 = new SpellPrepareViewModel(this, sf); if (v2 is SpellPrepareViewModel spvm && spvm.Able > 0) { views.Add(spvm); } } } } if (!views.SequenceEqual(Spellcasting)) { Spellcasting.ReplaceRange(views); UpdatePages(); } if (views.Count == 0) { UpdatePages(); } }