public override void Refresh(SpellcastingFeature feature)
 {
     SpellcastingFeature = feature;
     Spellcasting        = Model.Context.Player.GetSpellcasting(SpellcastingID);
     AddSpells();
     OnPropertyChanged(null);
 }
Ejemplo n.º 2
0
 private void Awake()
 {
     player       = GameObject.Find("RightHand").GetComponent <Spellcasting>();
     mesh.enabled = true;
     rb           = GetComponent <Rigidbody>();
     audioManager = GetComponent <AudioSource>();
 }
Ejemplo n.º 3
0
 private void Start()
 {
     spellMana       = GameObject.Find("RightHand").GetComponent <Spellcasting>();
     enemyPooler     = GameObject.Find("Enemies").GetComponent <EnemyPooler>();
     explosionNoise  = explosionEffect.GetComponent <AudioSource>();
     rb              = this.gameObject.GetComponent <Rigidbody>();
     bridgePuzzleVar = GameObject.Find("BridgeAnchors").GetComponent <bridgePuzzle>();
     gatePuzzle      = GameObject.Find("Fortress Gate").GetComponent <KeyGatePuzzle>();
 }
        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);
                    }
 private string SpellcastingHeader(Spellcasting spellcasting, int line)
 {
     if (line == 0)
     {
         return("Cantrips (at will)");
     }
     if (!spellcasting.SpellListClass.Equals("warlock", StringComparison.InvariantCultureIgnoreCase))
     {
         return($"{ThIfy(line)} level ({spellcasting.Spellslots[line - 1]} slot{(spellcasting.Spellslots[line - 1] > 1 ? "s)" : ")")}");
     }
     return($"1st-{ThIfy(line)} level ({spellcasting.Spellslots[line - 1]} {ThIfy(line)}-level slots)");
 }
        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();
            }
        }
 private void RenderSpellcasting(Spellcasting spellcasting, StringBuilder stringBuilder)
 {
     stringBuilder.AppendLine($"> ***Spellcasting***. {spellcasting.TextBeforeTable}");
     for (var i = 0; i < spellcasting.Spells.GetLength(0); i++)
     {
         if (spellcasting.Spells[i] != null)
         {
             stringBuilder.AppendLine($"> {SpellcastingHeader(spellcasting, i)}: {SpellList(spellcasting, i)}");
             stringBuilder.AppendLine($">");
         }
     }
     if (!string.IsNullOrWhiteSpace(spellcasting.TextAfterTable))
     {
         stringBuilder.AppendLine($"> {spellcasting.TextAfterTable}");
     }
     stringBuilder.AppendLine($">");
 }
Ejemplo n.º 8
0
        public override void Refresh(SpellcastingFeature feature)
        {
            SpellcastingFeature = feature;
            Spellcasting        = Model.Context.Player.GetSpellcasting(SpellcastingID);
            UpdateSlots();
            spells.Clear();
            spells.AddRange(from s in Spellcasting.GetLearned(Model.Context.Player, Model.Context) select new SpellViewModel(s)
            {
                Highlight = OnHighlight,
                ShowInfo  = ShowInfo,
                AddAlwaysPreparedToName = false
            });
            spells.AddRange(from s in Spellcasting.GetPrepared(Model.Context.Player, Model.Context) select new SpellViewModel(s)
            {
                Highlight = OnHighlight,
                ShowInfo  = ShowInfo,
                AddAlwaysPreparedToName = false
            });
            spells.Sort();
            if (SpellcastingFeature.Preparation == OGL.Base.PreparationMode.ClassList)
            {
                spells.AddRange(from s in Spellcasting.GetCLassListRituals(SpellcastingFeature.PrepareableSpells ?? "false", Model.Context.Player, Model.Context) select new SpellViewModel(s)
                {
                    Highlight = OnHighlight,
                    ShowInfo  = ShowInfo,
                    AddAlwaysPreparedToName = false
                });
            }
            else if (SpellcastingFeature.Preparation == OGL.Base.PreparationMode.Spellbook)
            {
                spells.AddRange(from s in Spellcasting.GetSpellbookRituals(Model.Context.Player, Model.Context) select new SpellViewModel(s)
                {
                    Highlight = OnHighlight,
                    ShowInfo  = ShowInfo,
                    AddAlwaysPreparedToName = false
                });
            }

            UpdateSpells();
            OnPropertyChanged(null);
        }
Ejemplo n.º 9
0
    public void RecoverSpellSlots()
    {
        if (!UsedASlot)
        {
            return;
        }

        foreach (var spellcaster in Spellcasting)
        {
            foreach (Level _level in Enum.GetValues(typeof(Level)))
            {
                if (spellcaster.SpellsLeft[_level] < spellcaster.MaximumSpellSlots[_level])
                {
                    spellcaster.SpellsLeft[_level] = spellcaster.MaximumSpellSlots[_level];
                    break;  // only recover from one depleted level per rest cyle, starting at First
                }
            }
        }

        var used_levels = Spellcasting.Select(caster => caster.SpellsLeft.Where(sl => sl.Value < caster.MaximumSpellSlots[sl.Key])).ToList();

        UsedASlot &= used_levels.Count > 0;
    }
Ejemplo n.º 10
0
        public SpellbookSpellsViewModel(PlayerViewModel model, SpellcastingFeature spellcastingFeature) : base(model, spellcastingFeature)
        {
            Title = spellcastingFeature.DisplayName;
            if (Title == null || Title == "")
            {
                Title = SpellcastingID;
            }
            Spellcasting = Model.Context.Player.GetSpellcasting(SpellcastingID);
            OnHighlight  = new Command((par) =>
            {
                Model.MakeHistory("Highlight");
                Spellcasting.Highlight = (par as SpellViewModel)?.Name;
                foreach (SpellViewModel s in Spells)
                {
                    s.IsHightlighted = false;
                }
                if (par is SpellViewModel svm)
                {
                    svm.IsHightlighted = true;
                }
                OnPropertyChanged("Highlight");
                Model.Save();
            });
            RemoveHighlight = new Command(() =>
            {
                Model.MakeHistory("Highlight");
                Spellcasting.Highlight = null;
                foreach (SpellViewModel s in Spells)
                {
                    s.IsHightlighted = false;
                }
                OnPropertyChanged("Highlight");
                Model.Save();
            });
            OnReduce = new Command((par) =>
            {
                if (par is SpellSlotInfo s && s.Used < s.Slots)
                {
                    if (last == s.Level)
                    {
                        s.Used++;
                        Model.MakeHistory(s.SpellcastingID + "Slots" + s.Level);
                        Model.Context.Player.SetSpellSlot(s.SpellcastingID, s.Level, s.Used);
                        Model.Save();
                        (s as SpellSlotViewModel)?.UpdateUsed();
                        if (selected == s)
                        {
                            used = s.Used;
                            OnPropertyChanged("Used");
                        }
                        Model.UpdateSlots(this);
                    }
                    last = s.Level;
                }
            });
            OnReset = new Command((par) =>
            {
                if (par is SpellSlotInfo s)
                {
                    s.Used = 0;
                    Model.MakeHistory(s.SpellcastingID + "Slots" + s.Level);
                    Model.Context.Player.SetSpellSlot(s.SpellcastingID, s.Level, s.Used);
                    Model.Save();
                    (s as SpellSlotViewModel)?.UpdateUsed();
                    if (selected == s)
                    {
                        used = s.Used;
                        OnPropertyChanged("Used");
                    }
                    Model.UpdateSlots(this);
                }
            });
            ResetAll = new Command(() =>
            {
                IsBusy = true;
                Model.MakeHistory();
                Model.Context.Player.ResetSpellSlots(SpellcastingID);
                Model.Save();
                UpdateSlots();
                used = 0;
                OnPropertyChanged("Used");
                Model.UpdateSlots(this);
                IsBusy = false;
            });
            ShowInfo = new Command(async(par) =>
            {
                if (par is SpellViewModel svm)
                {
                    if (svm.Spell is ModifiedSpell ms)
                    {
                        ms.Info = Model.Context.Player.GetAttack(ms, ms.differentAbility == OGL.Base.Ability.None ? SpellcastingFeature.SpellcastingAbility : ms.differentAbility);
                        ms.Modifikations.AddRange(from f in Model.Context.Player.GetFeatures() where f is SpellModifyFeature && Utils.Matches(Model.Context, ms, ((SpellModifyFeature)f).Spells, null) select f);
                        ms.Modifikations = ms.Modifikations.Distinct().ToList();
                    }
                    await Navigation.PushAsync(InfoPage.Show(svm.Spell));
                }
            });
            spells = new List <SpellViewModel>();
            spells.AddRange(from s in Spellcasting.GetLearned(Model.Context.Player, Model.Context) select new SpellViewModel(s)
            {
                Highlight = OnHighlight,
                ShowInfo  = ShowInfo,
                AddAlwaysPreparedToName = false
            });
            spells.AddRange(from s in Spellcasting.GetPrepared(Model.Context.Player, Model.Context) select new SpellViewModel(s)
            {
                Highlight = OnHighlight,
                ShowInfo  = ShowInfo,
                AddAlwaysPreparedToName = false
            });
            spells.Sort();
            if (SpellcastingFeature.Preparation == OGL.Base.PreparationMode.ClassList)
            {
                spells.AddRange(from s in Spellcasting.GetCLassListRituals(SpellcastingFeature.PrepareableSpells ?? "false", Model.Context.Player, Model.Context) select new SpellViewModel(s)
                {
                    Highlight = OnHighlight,
                    ShowInfo  = ShowInfo,
                    AddAlwaysPreparedToName = false
                });
            }
            else if (SpellcastingFeature.Preparation == OGL.Base.PreparationMode.Spellbook)
            {
                spells.AddRange(from s in Spellcasting.GetSpellbookRituals(Model.Context.Player, Model.Context) select new SpellViewModel(s)
                {
                    Highlight = OnHighlight,
                    ShowInfo  = ShowInfo,
                    AddAlwaysPreparedToName = false
                });
            }

            UpdateSlots();
            UpdateSpells();
        }
        private void BuildAttacks()
        {
            List <Possession> equip = new List <Possession>();

            foreach (Possession pos in Program.Context.Player.GetItemsAndPossessions())
            {
                if (pos.Count > 0 && pos.BaseItem != null && pos.BaseItem != "")
                {
                    Item i = Program.Context.GetItem(pos.BaseItem, null);
                    if (pos.Equipped != EquipSlot.None || i is Weapon || i is Armor || i is Shield)
                    {
                        equip.Add(pos);
                    }
                }
            }
            equip.Sort(delegate(Possession t1, Possession t2)
            {
                if (t1.Hightlight && !t2.Hightlight)
                {
                    return(-1);
                }
                else if (t2.Hightlight && !t1.Hightlight)
                {
                    return(1);
                }
                else
                {
                    if (!string.Equals(t1.Equipped, EquipSlot.None, StringComparison.OrdinalIgnoreCase) && string.Equals(t2.Equipped, EquipSlot.None, StringComparison.OrdinalIgnoreCase))
                    {
                        return(-1);
                    }
                    else if (!string.Equals(t2.Equipped, EquipSlot.None, StringComparison.OrdinalIgnoreCase) && string.Equals(t1.Equipped, EquipSlot.None, StringComparison.OrdinalIgnoreCase))
                    {
                        return(1);
                    }
                    else
                    {
                        return(t1.ToString().CompareTo(t2.ToString()));
                    }
                }
            });

            List <KeyValuePair <string, AttackInfo> > attackinfos = new List <KeyValuePair <string, AttackInfo> >();
            List <SpellcastingFeature> spellcasts = new List <SpellcastingFeature>(from f in Program.Context.Player.GetFeatures() where f is SpellcastingFeature && ((SpellcastingFeature)f).SpellcastingID != "MULTICLASS" select(SpellcastingFeature) f);
            List <KeyValuePair <string, AttackInfo> > addattackinfos = new List <KeyValuePair <string, AttackInfo> >();

            foreach (SpellcastingFeature scf in spellcasts)
            {
                Spellcasting sc = Program.Context.Player.GetSpellcasting(scf.SpellcastingID);
                foreach (Spell s in sc.GetLearned(Program.Context.Player, Program.Context))
                {
                    if (sc.Highlight != null && sc.Highlight != "" && s.Name.ToLowerInvariant() == sc.Highlight.ToLowerInvariant())
                    {
                        AttackInfo ai = Program.Context.Player.GetAttack(s, scf.SpellcastingAbility);
                        if (ai != null && ai.Damage != null && ai.Damage != "")
                        {
                            attackinfos.Add(new KeyValuePair <string, AttackInfo>(s.Name, ai));
                        }
                    }
                    else
                    {
                        AttackInfo ai = Program.Context.Player.GetAttack(s, scf.SpellcastingAbility);
                        if (ai != null && ai.Damage != null && ai.Damage != "")
                        {
                            addattackinfos.Add(new KeyValuePair <string, AttackInfo>(s.Name, ai));
                        }
                    }
                }
                //No prepared Cantrips, so whatever
                //foreach (Spell s in sc.GetPrepared(Program.Context.Player, Program.Context))
                //{
                //    if (sc.Highlight != null && sc.Highlight != "" && s.Name.ToLowerInvariant() == sc.Highlight.ToLowerInvariant())
                //    {
                //        AttackInfo ai = Program.Context.Player.GetAttack(s, scf.SpellcastingAbility);
                //        if (ai != null && ai.Damage != null && ai.Damage != "") attackinfos.Add(new KeyValuePair<string, AttackInfo>(s.Name, ai));
                //    }
                //    else
                //    {
                //        AttackInfo ai = Program.Context.Player.GetAttack(s, scf.SpellcastingAbility);
                //        if (ai != null && ai.Damage != null && ai.Damage != "") addattackinfos.Add(new KeyValuePair<string, AttackInfo>(s.Name, ai));
                //    }
                //}
                //foreach (Spell s in sc.GetAdditionalClassSpells(Program.Context.Player, Program.Context))
                //{
                //    if (sc.Highlight != null && sc.Highlight != "" && s.Name.ToLowerInvariant() == sc.Highlight.ToLowerInvariant())
                //    {
                //        AttackInfo ai = Program.Context.Player.GetAttack(s, scf.SpellcastingAbility);
                //        if (ai != null && ai.Damage != null && ai.Damage != "") attackinfos.Add(new KeyValuePair<string, AttackInfo>(s.Name, ai));
                //    }
                //    else
                //    {
                //        AttackInfo ai = Program.Context.Player.GetAttack(s, scf.SpellcastingAbility);
                //        if (ai != null && ai.Damage != null && ai.Damage != "") addattackinfos.Add(new KeyValuePair<string, AttackInfo>(s.Name, ai));
                //    }
                //}
            }
            foreach (Possession pos in equip)
            {
                IEnumerable <AttackInfo> ais = Program.Context.Player.GetAttack(pos);
                if (ais != null)
                {
                    attackinfos.AddRange(ais.Select(ai => new KeyValuePair <string, AttackInfo>(pos.ToString() + (ai.AttackOptions.Count > 0 ? " (" + string.Join(", ", ai.AttackOptions) + " )" : ""), ai)));
                }
            }
            foreach (ModifiedSpell s in Program.Context.Player.GetBonusSpells(false))
            {
                if (Utils.Matches(Program.Context, s, "Attack or Save", null))
                {
                    AttackInfo ai = Program.Context.Player.GetAttack(s, s.differentAbility);
                    if (ai != null && ai.Damage != null && ai.Damage != "")
                    {
                        attackinfos.Add(new KeyValuePair <string, AttackInfo>(s.Name, ai));
                    }
                }
            }
            attackinfos.AddRange(addattackinfos);
            //attackinfos.OrderBy((a, b) =>
            //{
            //    int oa = Program.Context.Player.AttackOrder.FindIndex(s => StringComparer.OrdinalIgnoreCase.Equals(a.Key, s));
            //    int ob = Program.Context.Player.AttackOrder.FindIndex(s => StringComparer.OrdinalIgnoreCase.Equals(b.Key, s));
            //    if (oa < 0) oa = int.MaxValue;
            //    if (ob < 0) ob = int.MaxValue;
            //    return oa.CompareTo(ob);
            //});

            AttackOrder.Items.Clear();
            foreach (var a in attackinfos.OrderBy(a => { int i = Program.Context.Player.AttackOrder.FindIndex(s => StringComparer.OrdinalIgnoreCase.Equals(a.Key, s)); return(i < 0 ? int.MaxValue : i); }))
            {
                AttackOrder.Items.Add(a);
            }
        }
 private string SpellList(Spellcasting spellcasting, int line)
 {
     return(string.Join(", ", spellcasting.Spells[line].Select(s => $"*{s.Name}*{(s.Marked ? @"\*" : "")}").ToArray()).ToLower());
 }
 public SpellPrepareViewModel(PlayerModel model, SpellcastingFeature spellcasting) : base(model, spellcasting, "Prepare " + (spellcasting.DisplayName ?? spellcasting.SpellcastingID) + " Spells")
 {
     Image        = ImageSource.FromResource("CB_5e.images.prepare.png");
     Spellcasting = Model.Context.Player.GetSpellcasting(SpellcastingID);
     OnPrepare    = new Command((par) =>
     {
         if (par is SpellViewModel svm && SpellcastingFeature != null && !svm.AddAlwaysPreparedToName)
         {
             if (!svm.Prepared)
             {
                 if (Count < Able)
                 {
                     svm.Prepared = true;
                     Model.MakeHistory();
                     Spellcasting.GetPreparedList(Model.Context.Player, Model.Context).Add(svm.Name + " " + ConfigManager.SourceSeperator + " " + svm.Source);
                     Model.Save();
                 }
             }
             else
             {
                 svm.Prepared = false;
                 Model.MakeHistory();
                 string r = svm.Name + " " + ConfigManager.SourceSeperator + " " + svm.Source;
                 Spellcasting.GetPreparedList(Model.Context.Player, Model.Context).RemoveAll(s => ConfigManager.SourceInvariantComparer.Equals(s, r));
                 Model.Save();
                 if (svm.BadChoice)
                 {
                     Spells.Remove(svm);
                 }
                 if (svm.BadChoice)
                 {
                     spells.Remove(svm);
                 }
             }
             OnPropertyChanged("Count");
             OnPropertyChanged("Prepared");
             (model as PlayerViewModel)?.ChangedPreparedSpells(SpellcastingID);
         }
     }, (par) => par is SpellViewModel svm && !svm.AddAlwaysPreparedToName);
     ShowInfo = new Command(async(par) =>
     {
         if (par is SpellViewModel svm)
         {
             if (svm.Spell is ModifiedSpell ms)
             {
                 ms.Info = Model.Context.Player.GetAttack(ms, ms.differentAbility == Ability.None ? SpellcastingFeature.SpellcastingAbility : ms.differentAbility);
                 ms.Modifikations.AddRange(from f in Model.Context.Player.GetFeatures() where f is SpellModifyFeature && Utils.Matches(Model.Context, ms, ((SpellModifyFeature)f).Spells, null) select f);
                 ms.Modifikations = ms.Modifikations.Distinct().ToList();
             }
             await Navigation.PushAsync(InfoPage.Show(svm.Spell));
         }
     });
     ResetPrepared = new Command(() =>
     {
         IsBusy = true;
         Model.MakeHistory();
         Spellcasting.GetPreparedList(Model.Context.Player, Model.Context).Clear();
         Model.Save();
         foreach (SpellViewModel s in spells)
         {
             s.Prepared = s.AddAlwaysPreparedToName;
         }
         spells.RemoveAll(s => s.BadChoice);
         UpdateSpells();
         OnPropertyChanged("Count");
         OnPropertyChanged("Prepared");
         (model as PlayerViewModel)?.ChangedPreparedSpells(SpellcastingID);
         IsBusy = false;
     });
     AddSpells();
 }