/// <summary> /// Load the Characters from the Selected List into the Battle Engine /// Making a copy of the character. /// </summary> // Load all characters public void LoadCharacters() { //differentiate multiples of the same character by appending a number //and add them to the characterList for (int i = 0; i < SelectedCharacters.Count; i++) { if (i == 0) { SelectedCharacters[i].Name = SelectedCharacters[i].Name + " " + (i + 1).ToString(); } else { //take off last number and append current number string word = SelectedCharacters[i].Name; string[] words = word.Split(' '); string keep = words[0]; SelectedCharacters[i].Name = keep + ' ' + (i + 1).ToString(); } BattleEngine.CharacterList.Add(new Character(SelectedCharacters[i])); } //some weird bug with population, so cleared selected chars and repopulated SelectedCharacters.Clear(); foreach (Character character in BattleEngine.CharacterList) { SelectedCharacters.Add(new Character(character)); } }
// Clear current lists so they can get rebuilt public void ClearCharacterLists() { AvailableCharacters.Clear(); SelectedCharacters.Clear(); ExecuteLoadDataCommand(); }
// Clear current lists so they can get rebuilt public void ClearCharacterLists() { DatasetChars.Clear(); SelectedCharacters.Clear(); ExecuteLoadDataCommand(); }
// Command that Loads the Data private async Task ExecuteLoadDataCommand() { if (IsBusy) { return; } IsBusy = true; try { // Reload the Available character list from the Character View Model AvailableCharacters.Clear(); var availableCharacters = CharactersViewModel.Instance.Dataset; foreach (var data in availableCharacters) { AvailableCharacters.Add(data); } // Reload the Selected Monster List from the Battle engine monster list SelectedMonsters.Clear(); var selectedMon = BattleEngine.MonsterList; foreach (var mon in selectedMon) { SelectedMonsters.Add(mon); } // Reload the Selected Character List from the Battle engine character list SelectedCharacters.Clear(); var selectedChar = BattleEngine.CharacterList; foreach (var ch in selectedChar) { SelectedCharacters.Add(ch); } // Reload the availItems List from the Battle engine itemspool list availItems.Clear(); var avaItems = BattleEngine.ItemPool; foreach (var it in avaItems) { availItems.Add(it); } } // Catch any exceptions catch (Exception ex) { Debug.WriteLine(ex); } // Set isBusy to false finally { IsBusy = false; } }
// Call to database to ensure most recent public Character Get(string id) { var myData = SelectedCharacters.FirstOrDefault(arg => arg.Id == id); if (myData == null) { return(null); } return(myData); }
// Returned a Character by its name // Name is now unique for each character // For example, BigWig 1 and BigWig 4 has the same Guid // but different name public Character GetByName(string name) { var myData = SelectedCharacters.FirstOrDefault(arg => arg.Name == name); if (myData == null) { return(null); } return(myData); }
// Command that Loads the Data private async Task ExecuteLoadDataCommand() { if (IsBusy) { return; } IsBusy = true; try { // SelectedCharacters, no need to change them. // Reload the Character List from the Character View Moel AvailableCharacters.Clear(); var availableCharacters = CharactersViewModel.Instance.Dataset; foreach (var data in availableCharacters) { AvailableCharacters.Add(data); } //for refreshing characters and monsters on battle main page SelectedCharacters.Clear(); var selectedChars = BattleEngine.CharacterList; foreach (var data in selectedChars) { SelectedCharacters.Add(data); } FightingMonsters.Clear(); var fightingMonsters = BattleEngine.MonsterList; foreach (var data in fightingMonsters) { FightingMonsters.Add(data); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
// Used to sync observables to actual public void SyncMonsterAndCharacterLists() { FightingMonsters.Clear(); // Add monsters to battle foreach (var monster in BattleEngine.MonsterList) { FightingMonsters.Add(monster); } SelectedCharacters.Clear(); // Add characters to battle foreach (var character in BattleEngine.CharacterList) { SelectedCharacters.Add(character); } return; }
// Call to database to add a character to party public bool SelectedListAdd(Character data) { SelectedCharacters.Add(data); return(true); }
// Call to database to remove a character from the party public bool SelectedListRemove(Character data) { SelectedCharacters.Remove(data); return(true); }