Ejemplo n.º 1
0
 public PlayerNotesViewModel(PlayerModel parent) : base(parent, "Notes")
 {
     Image = ImageSource.FromResource("CB_5e.images.notes.png");
     UpdateNotes();
     NewNote = new Command(() =>
     {
         if (Note != null)
         {
             MakeHistory();
             Context.Player.Journal.Add(Note);
             RefreshNotes.Execute(null);
             Save();
         }
     }, () => Note != null && Note != "");
     SaveNote = new Command(() =>
     {
         if (selectedNote >= 0)
         {
             MakeHistory();
             if (Note != null && Note != "")
             {
                 Context.Player.Journal[selectedNote] = Note;
             }
             else
             {
                 Context.Player.Journal.RemoveAt(selectedNote);
             }
             RefreshNotes.Execute(null);
             Save();
         }
     }, () => selectedNote >= 0);
     RefreshNotes = new Command(() =>
     {
         NotesBusy = true;
         UpdateNotes();
         NotesBusy = false;
     });
     parent.PlayerChanged += Parent_PlayerChanged;
 }
Ejemplo n.º 2
0
        public PlayerViewModel(BuilderContext context) : base(context)
        {
            Scores         = new ScoresModelViewModel(Context);
            PlayerChanged += PlayerViewModel_PlayerChanged;
            ResetHitDie    = new Command(() => {
                HDBusy = true;
                MakeHistory();
                Context.Player.UsedHitDice = new List <int>();
                HitDice.ReplaceRange(from h in Context.Player.GetHitDie() orderby h select new HitDieViewModel(this, h));
                Save();
                HDBusy = false;
            });
            ResetHD = new Command(() => {
                MakeHistory();
                Context.Player.FailedDeathSaves  = 0;
                Context.Player.SuccessDeathSaves = 0;
                OnPropertyChanged("DeathSaveFail");
                OnPropertyChanged("DeathSaveSuccess");
                Save();
            });
            DeselectSkill = new Command(async() =>
            {
                SkillBusy     = true;
                SkillSearch   = null;
                SelectedSkill = null;
                await Task.Delay(500); //Stupid Refereshindicator
                SkillBusy = false;
            });
            Context.HistoryButtonChange += Player_HistoryButtonChange;
            Undo = new Command(() =>
            {
                Context.Undo();
                FirePlayerChanged();
                Save();
            }, () =>
            {
                return(Context.CanUndo());
            });
            Redo = new Command(() =>
            {
                Context.Redo();
                FirePlayerChanged();
                Save();
            }, () =>
            {
                return(Context.CanRedo());
            });
            ShowImage = new Command(async(par) =>
            {
                await Navigation.PushAsync(new ImageViewer(par as ImageSource, Context.Player?.Portrait, Context.Player?.Name));
            });
            ShowClasses = new Command(async() =>
            {
                List <IOGLElement> classes = new List <IOGLElement>();
                foreach (PlayerClass pc in Context.Player.Classes)
                {
                    classes.Add(pc.GetClass(Context));
                    classes.Add(pc.GetSubClass(Context));
                }
                await Navigation.PushAsync(InfoSelectPage.Show(classes));
            }, () =>
                                      Context.Player?.Classes?.Count > 0);
            ShowRace = new Command(async() => {
                await Navigation.PushAsync(InfoSelectPage.Show(Context.Player.Race, Context.Player.SubRace));
            }, () => Context.Player?.RaceName != null && Context.Player?.RaceName != "");
            ShowBackground = new Command(async() => {
                await Navigation.PushAsync(InfoSelectPage.Show(Context.Player.Background));
            }, () => Context.Player?.BackgroundName != null && Context.Player?.BackgroundName != "");
            skills = Context.Player.GetSkills();
            Skills.ReplaceRange(skills);
            skillSearch = null;
            HitDice.ReplaceRange(from h in Context.Player.GetHitDie() orderby h select new HitDieViewModel(this, h));
            UpdateAllConditions();
            UpdateCondtions();

            resources = new List <ResourceViewModel>();
            resources.AddRange(from r in Context.Player.GetResourceInfo(true).Values select new ResourceViewModel(r, this));
            resources.AddRange(from r in Context.Player.GetBonusSpells(false) select new ResourceViewModel(r, this));
            UpdateResources();

            features = (from f in Context.Player.GetFeatures() where f.Name != "" && !f.Hidden select f).ToList();
            UpdateFeatures();

            proficiencies = new List <IXML>();
            proficiencies.AddRange(Context.Player.GetLanguages());
            proficiencies.AddRange(Context.Player.GetToolProficiencies());
            proficiencies.AddRange(from p in Context.Player.GetToolKWProficiencies() select new Feature(p, "Proficiency"));
            proficiencies.AddRange(from p in Context.Player.GetOtherProficiencies() select new Feature(p, "Proficiency"));
            UpdateProficiencies();

            UpdateSpellcasting();

            AddCustomCondition = new Command(() =>
            {
                if (CustomCondition != null && CustomCondition != "")
                {
                    MakeHistory();
                    Context.Player.Conditions.Add(CustomCondition);
                    UpdateCondtions();
                    Save();
                }
            }, () => CustomCondition != null && CustomCondition != "");
            AddCondition = new Command((par) =>
            {
                if (par is OGL.Condition p)
                {
                    MakeHistory();
                    Context.Player.Conditions.Add(p.Name + " " + ConfigManager.SourceSeperator + " " + p.Source);
                    UpdateCondtions();
                    Save();
                }
            });
            RemoveCondition = new Command((par) =>
            {
                if (par is OGL.Condition p)
                {
                    MakeHistory();
                    Context.Player.Conditions.RemoveAll(s => ConfigManager.SourceInvariantComparer.Equals(s, p.Name + " " + ConfigManager.SourceSeperator + " " + p.Source));
                    UpdateCondtions();
                    Save();
                }
            });
            ResetConditions = new Command((par) =>
            {
                ConditionsBusy = true;
                MakeHistory();
                Context.Player.Conditions.Clear();
                UpdateCondtions();
                Save();
                ConditionsBusy = false;
            });
            DeselectResource = new Command(async() =>
            {
                ResourceBusy     = true;
                SelectedResource = null;
                Resources.ReplaceRange(new List <ResourceViewModel>());
                resources.Clear();
                resources.AddRange(from r in Context.Player.GetResourceInfo(true).Values select new ResourceViewModel(r, this));
                resources.AddRange(from r in Context.Player.GetBonusSpells(false) select new ResourceViewModel(r, this));
                UpdateResources();
                await Task.Delay(500); //Stupid Refereshindicator
                ResourceBusy = false;
            });
            LongRest = new Command(() =>
            {
                MakeHistory("LongRest");
                foreach (ResourceInfo r in Context.Player.GetResourceInfo(true).Values)
                {
                    if (r.Recharge >= RechargeModifier.LongRest)
                    {
                        Context.Player.SetUsedResources(r.ResourceID, 0);
                    }
                }
                foreach (ModifiedSpell ms in Context.Player.GetBonusSpells())
                {
                    if (ms.RechargeModifier >= RechargeModifier.LongRest)
                    {
                        Context.Player.SetUsedResources(ms.getResourceID(), 0);
                    }
                }
                DeselectResource.Execute(null);
            });
            ShortRest = new Command(() =>
            {
                MakeHistory("ShortRest");
                foreach (ResourceInfo r in Context.Player.GetResourceInfo(true).Values)
                {
                    if (r.Recharge >= RechargeModifier.ShortRest)
                    {
                        Context.Player.SetUsedResources(r.ResourceID, 0);
                    }
                }
                foreach (ModifiedSpell ms in Context.Player.GetBonusSpells())
                {
                    if (ms.RechargeModifier >= RechargeModifier.ShortRest)
                    {
                        Context.Player.SetUsedResources(ms.getResourceID(), 0);
                    }
                }
                DeselectResource.Execute(null);
            });
            UpdateJournal();
            UpdateNotes();
            NewNote = new Command(() =>
            {
                if (Note != null)
                {
                    MakeHistory();
                    Context.Player.Journal.Add(Note);
                    RefreshNotes.Execute(null);
                    Save();
                }
            }, () => Note != null && Note != "");
            SaveNote = new Command(() =>
            {
                if (selectedNote >= 0)
                {
                    MakeHistory();
                    if (Note != null && Note != "")
                    {
                        Context.Player.Journal[selectedNote] = Note;
                    }
                    else
                    {
                        Context.Player.Journal.RemoveAt(selectedNote);
                    }
                    RefreshNotes.Execute(null);
                    Save();
                }
            }, () => selectedNote >= 0);
            RefreshNotes = new Command(() =>
            {
                NotesBusy = true;
                UpdateNotes();
                NotesBusy = false;
            });
            RefreshJournal = new Command(() =>
            {
                JournalBusy = true;
                UpdateJournal();
                JournalBusy = false;
            });
        }