private void ShowEditMonsterWindow(EncounterMonsterViewModel encounterMonsterViewModel)
        {
            EncounterMonsterModel editedMonsterModel = _dialogService.ShowEncounterMonsterDialog("Edit Monster", encounterMonsterViewModel.EncounterMonsterModel);

            if (editedMonsterModel != null)
            {
                EncounterCreatureModel originalMonster = _encounterModel.Creatures.FirstOrDefault(x => x.ID == encounterMonsterViewModel.EncounterMonsterModel.ID);
                if (originalMonster != null)
                {
                    _encounterModel.Creatures[_encounterModel.Creatures.IndexOf(originalMonster)] = editedMonsterModel;

                    CreateCreatureViewModels();
                    EstimateEncounterChallenge();

                    OnPropertyChanged(nameof(Monsters));
                    OnPropertyChanged(nameof(TotalMonsterXP));
                    OnPropertyChanged(nameof(AverageMonsterCR));
                    OnPropertyChanged(nameof(AverageMonsterMaxHP));
                    OnPropertyChanged(nameof(AverageMonsterAC));
                    OnPropertyChanged(nameof(AverageMonsterSaveDC));
                    OnPropertyChanged(nameof(AverageMonsterPassivePerception));
                    OnPropertyChanged(nameof(AverageMonsterDamageTurn));
                    OnPropertyChanged(nameof(OverallMonsterDamageVulnerabilities));
                    OnPropertyChanged(nameof(OverallMonsterDamageResistances));
                    OnPropertyChanged(nameof(OverallMonsterDamageImmunities));
                    OnPropertyChanged(nameof(OverallMonsterConditionImmunities));
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates an instance of <see cref="EncounterCreatureModel"/>
        /// </summary>
        public EncounterCreatureViewModel(EncounterCreatureModel encounterCreatureModel)
        {
            _encounterCreatureModel = encounterCreatureModel;

            _conditions.Clear();
            foreach (AppliedConditionModel appliedConditionModel in _encounterCreatureModel.Conditions)
            {
                _conditions.Add(new AppliedConditionViewModel(appliedConditionModel));
            }

            _showHPDialogCommand            = new RelayCommand(obj => true, obj => ShowHPDialog());
            _showAddConditionDialogCommand  = new RelayCommand(obj => true, obj => ShowAddConditionDialog());
            _showEditConditionDialogCommand = new RelayCommand(obj => true, obj => ShowEditConditionDialog(obj as AppliedConditionViewModel));
            _viewConditionCommand           = new RelayCommand(obj => true, obj => ViewConditon(obj as AppliedConditionViewModel));
            _removeConditionCommand         = new RelayCommand(obj => true, obj => RemoveCondition(obj as AppliedConditionViewModel));
        }
        private void ShowEditCharacterWindow(EncounterCharacterViewModel encounterCharacterModel)
        {
            EncounterCharacterModel editedCharacterModel = _dialogService.ShowEncounterCharacterDialog("Edit Character", encounterCharacterModel.EncounterCharacterModel);

            if (editedCharacterModel != null)
            {
                EncounterCreatureModel originalCharacter = _encounterModel.Creatures.FirstOrDefault(x => x.ID == encounterCharacterModel.EncounterCharacterModel.ID);
                if (originalCharacter != null)
                {
                    _encounterModel.Creatures[_encounterModel.Creatures.IndexOf(originalCharacter)] = editedCharacterModel;

                    CreateCreatureViewModels();
                    EstimateEncounterChallenge();

                    OnPropertyChanged(nameof(Characters));
                    OnPropertyChanged(nameof(AverageCharacterLevel));
                    OnPropertyChanged(nameof(AverageCharacterMaxHP));
                    OnPropertyChanged(nameof(AverageCharacterAC));
                    OnPropertyChanged(nameof(AverageCharacterSaveDC));
                    OnPropertyChanged(nameof(AverageCharacterPassivePerception));
                    OnPropertyChanged(nameof(AverageCharacterPassiveInvestigation));
                }
            }
        }
        /// <inheritdoc />
        public IEnumerable <EncounterModel> GetEncounters(byte[] encounterBytes, IEnumerable <CharacterModel> characters, IEnumerable <ConditionModel> conditions, IEnumerable <MonsterModel> monsters)
        {
            List <EncounterModel> encounters = new List <EncounterModel>();

            using (MemoryStream memoryStream = new MemoryStream(encounterBytes))
            {
                using (BinaryReader reader = new BinaryReader(memoryStream))
                {
                    int version = BitConverter.ToInt16(reader.ReadBytes(4), 0);
                    if (version == _version)
                    {
                        int encounterCount = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                        for (int i = 0; i < encounterCount; ++i)
                        {
                            EncounterModel encounter = new EncounterModel();

                            encounter.Id   = new Guid(reader.ReadBytes(16));
                            encounter.Name = ReadNextString(reader);

                            encounter.Creatures = new List <EncounterCreatureModel>();
                            int creatureCount = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            for (int j = 0; j < creatureCount; ++j)
                            {
                                bool isCharacter = BitConverter.ToBoolean(reader.ReadBytes(1), 0);

                                EncounterCreatureModel encounterCreature = isCharacter ? new EncounterCharacterModel() : new EncounterMonsterModel() as EncounterCreatureModel;
                                encounterCreature.ID                = new Guid(reader.ReadBytes(16));
                                encounterCreature.Name              = ReadNextString(reader);
                                encounterCreature.CurrentHP         = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.MaxHP             = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.AC                = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.SpellSaveDC       = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.PassivePerception = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.InitiativeBonus   = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                bool initiativeSet = BitConverter.ToBoolean(reader.ReadBytes(1), 0);
                                int? initiative    = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.Initiative = initiativeSet ? initiative : null;
                                encounterCreature.Selected   = BitConverter.ToBoolean(reader.ReadBytes(1), 0);

                                encounterCreature.Conditions = new List <AppliedConditionModel>();
                                int conditionCount = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                for (int k = 0; k < conditionCount; ++k)
                                {
                                    AppliedConditionModel appliedCondition = new AppliedConditionModel();
                                    appliedCondition.ID = new Guid(reader.ReadBytes(16));

                                    Guid           conditionID    = new Guid(reader.ReadBytes(16));
                                    string         conditionName  = ReadNextString(reader);
                                    ConditionModel conditionModel = conditions.FirstOrDefault(x => x.Id == conditionID);
                                    if (conditionModel == null)
                                    {
                                        conditionModel = conditions.FirstOrDefault(x => x.Name.Equals(conditionName, StringComparison.CurrentCultureIgnoreCase));
                                    }
                                    appliedCondition.ConditionModel = conditionModel;

                                    appliedCondition.Name = ReadNextString(reader);
                                    bool hasLevel = BitConverter.ToBoolean(reader.ReadBytes(1), 0);
                                    int? level    = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                    appliedCondition.Level = hasLevel ? level : null;
                                    appliedCondition.Notes = ReadNextString(reader);

                                    encounterCreature.Conditions.Add(appliedCondition);
                                }

                                if (isCharacter)
                                {
                                    Guid           characterID   = new Guid(reader.ReadBytes(16));
                                    string         characterName = ReadNextString(reader);
                                    CharacterModel character     = characters.FirstOrDefault(x => x.Id == characterID);
                                    if (character == null)
                                    {
                                        character = characters.FirstOrDefault(x => x.Name.Equals(characterName, StringComparison.CurrentCultureIgnoreCase));
                                    }
                                    ((EncounterCharacterModel)encounterCreature).CharacterModel       = character;
                                    ((EncounterCharacterModel)encounterCreature).Level                = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                    ((EncounterCharacterModel)encounterCreature).PassiveInvestigation = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                }
                                else
                                {
                                    Guid         monsterID   = new Guid(reader.ReadBytes(16));
                                    string       monsterName = ReadNextString(reader);
                                    MonsterModel monster     = monsters.FirstOrDefault(x => x.Id == monsterID);
                                    if (monster == null)
                                    {
                                        monster = monsters.FirstOrDefault(x => x.Name.Equals(monsterName, StringComparison.CurrentCultureIgnoreCase));
                                    }
                                    ((EncounterMonsterModel)encounterCreature).MonsterModel      = monster;
                                    ((EncounterMonsterModel)encounterCreature).Quantity          = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                    ((EncounterMonsterModel)encounterCreature).AverageDamageTurn = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                    ((EncounterMonsterModel)encounterCreature).CR = ReadNextString(reader);
                                    ((EncounterMonsterModel)encounterCreature).DamageVulnerabilities = ReadNextString(reader);
                                    ((EncounterMonsterModel)encounterCreature).DamageResistances     = ReadNextString(reader);
                                    ((EncounterMonsterModel)encounterCreature).DamageImmunities      = ReadNextString(reader);
                                    ((EncounterMonsterModel)encounterCreature).ConditionImmunities   = ReadNextString(reader);
                                }

                                encounter.Creatures.Add(encounterCreature);
                            }

                            encounter.Round = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.EncounterChallenge = (EncounterChallenge)BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.TotalCharacterHP   = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.TotalMonsterHP     = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.TimeElapsed        = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.CurrentTurn        = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.EncounterState     = (EncounterState)BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.Notes = ReadNextString(reader);

                            encounters.Add(encounter);
                        }
                    }
                }
            }

            return(encounters);
        }