public CNetDeckVO CreateOrSave(CNetDeckVO deckToSave, List <CNetCardVO> playerCards) { CNetDeckVO deck; lock (Decks) { deck = Decks.FirstOrDefault(d => deckToSave.Index == d.Index); } if (deck == null) { deck = AddDeck(deckToSave); } else { deck.Cards = deckToSave.Cards; deck.DeckName = deckToSave.DeckName; deck.IdCardPool = deckToSave.IdCardPool; deck.IdLimitedPool = deckToSave.IdLimitedPool; } deck.DeckLevel = deck.CalculateDeckLevel(Cards); deck.CoverCard = Cards.FirstOrDefault(c => c.Index == deckToSave.CoverCard.Index) ?? new CNetCardVO(); deck.SetCardInfo(playerCards); return(deck); }
private void RefreshAvailableDecks() { if (AvailableDecks.Count == 0) { for (var i = 1; i <= 9; i++) { var key = i.ToString(CultureInfo.InvariantCulture); var model = new AvailableDecksModel { Slot = key, AvailableDecks = new BindableCollection <DeckModel>(Decks.Where(x => x.Key == key || String.IsNullOrEmpty(x.Key))), SelectedDeck = Decks.FirstOrDefault(x => x.Key == key) }; model.PropertyChanged += AvailableDecksModel_OnPropertyChanged; AvailableDecks.Add(model); } NotifyOfPropertyChange(() => AvailableDecks); } else { for (var i = 1; i <= 9; i++) { var key = i.ToString(CultureInfo.InvariantCulture); AvailableDecks[i - 1].AvailableDecks = new BindableCollection <DeckModel>(Decks.Where(x => x.Key == key || String.IsNullOrEmpty(x.Key))); AvailableDecks[i - 1].PropertyChanged -= AvailableDecksModel_OnPropertyChanged; AvailableDecks[i - 1].SelectedDeck = Decks.FirstOrDefault(x => x.Key == key); AvailableDecks[i - 1].PropertyChanged += AvailableDecksModel_OnPropertyChanged; } NotifyOfPropertyChange(() => AvailableDecks); } }
public CNetDeckVO GetDeck(ulong id) { lock (Decks) { return(Decks.FirstOrDefault(x => x.Index == id)); } }
public override async Task Update() { IsLoadingDecks = true; Note = _repository.GetGameNote()?.ToString(); var deck = _repository.GetOpponentDeck(); Cards.Clear(); deck.Cards.ForEach(c => Cards.Add(c)); PlayerClass = deck.Class.ToString(); Decks.Clear(); await Task.Run(() => { var alldecks = _repository .GetAllDecksWithTag(Strings.ArchetypeTag) .Select(d => new ArchetypeDeck(d)) .ToList(); var results = ViewModelHelper.MatchArchetypes(deck, alldecks); results.ForEach(r => Decks.Add(r)); results.ForEach(r => _log.Info($"{r.Deck.Name} [{r.Similarity}, {r.Containment}]")); var firstDeck = Decks.FirstOrDefault(); if (firstDeck != null && firstDeck.Similarity > MatchResult.THRESHOLD) { DeckSelected(firstDeck); } IsLoadingDecks = false; IsNoteFocused = true; }); }
private Deck ActiveOrDefaultDeck() { Guid id = EndGame.Data.GetActiveDeckId(); Deck deck = null; if (id != Guid.Empty) { deck = Decks.SingleOrDefault(d => d.Id == id); } return(deck ?? Decks.FirstOrDefault()); }
public void AddDeck() { var deck = new DeckModel { Name = "New deck", Server = SelectedServer.Name }; deckManager.AddDeck(deck); RefreshDecks(); SelectedDeck = Decks.FirstOrDefault(x => x.Id == deck.Id); }
public override async Task Update() { IsNoteFocused = true; IsLoadingDecks = true; Note = _repository.GetGameNote()?.ToString(); Deck deck; if (EndGame.Settings.Get(Strings.DeveloperMode).Bool) { deck = _repository.GetOpponentDeckLive(); } else { deck = _repository.GetOpponentDeck(); } Cards.Clear(); deck.Cards.ForEach(c => Cards.Add(c)); PlayerClass = deck.Class.ToString(); Decks.Clear(); if (Cards.Count <= 0) { EndGame.Logger.Debug("NoteVM: Opponent deck is empty, skipping"); IsLoadingDecks = false; return; } await Task.Run(() => { var alldecks = _repository .GetAllDecksWithTag(Strings.ArchetypeTag) .Select(d => new ArchetypeDeck(d)) .ToList(); var format = EndGame.Data.GetGameFormat(); var results = ViewModelHelper.MatchArchetypes(format, deck, alldecks); results.ForEach(r => Decks.Add(r)); results.ForEach(r => _log.Debug($"Archetype: ({r.Similarity}, {r.Containment}) " + $"{r.Deck.DisplayName} ({r.Deck.Class})")); var firstDeck = Decks.FirstOrDefault(); if (firstDeck != null && firstDeck.Similarity > MatchResult.THRESHOLD) { DeckSelected(firstDeck); } IsLoadingDecks = false; }); }
private void RefreshDecks() { // deckManager.ClearCache(); var oldSelected = SelectedDeck; var d = deckManager.GetDecks(SelectedServer.Name, ShowHiddenDecks); Decks.Clear(); Decks.AddRange(d.ToModel()); if (oldSelected != null) { SelectedDeck = Decks.FirstOrDefault(x => x.Id == oldSelected.Id); } RefreshAvailableDecks(); }
/// <summary> /// Handles the message. /// </summary> /// <param name="message">The message.</param> public void Handle(DeckUpdated message) { if (message.Deck == null) { RefreshDecks(); return; } var found = Decks.FirstOrDefault(x => x.Id == message.Deck.Id); if (found != null) { found.MapFrom(message.Deck); } }
public void SaveAsNewDeck() { var deck = new DeckModel { Name = DeckName, Server = SelectedServer.Name, Key = DeckSlot, Notes = DeckNotes }; deckManager.AddDeck(deck); UpdateDeckImageFromBitmapImage(deck); RefreshDecks(); SelectedDeck = Decks.FirstOrDefault(x => x.Id == deck.Id); }
/// <summary> /// Handles the message. /// </summary> /// <param name="message">The message.</param> public void Handle(SelectDeck message) { if (message.Deck == null) { IsOpen = false; SelectedDeck = null; } else { SelectedServer = Servers.FirstOrDefault(x => x.Name == message.Deck.Server); if (message.Deck.Deleted) { ShowHiddenDecks = true; } RefreshDecks(); IsOpen = true; SelectedDeck = Decks.FirstOrDefault(x => x.Id == message.Deck.Id); } }
private void RefreshDecks() { if (SelectedServer == null || String.IsNullOrEmpty(SelectedServer.Name)) { return; } var current = SelectedDeck; var decks = deckManager.GetDecks(SelectedServer.Name).Select(x => x.ToModel()); this.decks.Clear(); this.decks.AddRange(decks); if (current != null) { SelectedDeck = Decks.FirstOrDefault(x => x.Id == current.Id); } else { SelectedDeck = Decks.FirstOrDefault(); } }
private void LoadGameResult(GameResultModel game) { EnsureInitialized(); SelectedGame = game; Hero = game.Hero; OpponentHero = game.OpponentHero; StartTime = game.Started; EndTime = game.Stopped; Victory = game.Victory; GoFirst = game.GoFirst; GameMode = game.GameMode; // force notify even if not changed NotifyOfPropertyChange(() => GameMode); Notes = game.Notes; Turns = game.Turns; ArenaSession = game.ArenaSession; LastGameId = game.Id; Conceded = game.Conceded; SelectedServer = servers.FirstOrDefault(x => x.Name == game.Server); if (game.Deck != null) { if (game.Deck.Deleted && Decks.All(x => x.Id != game.Deck.Id)) { var model = game.Deck.ToModel(); model.Name += " (deleted)"; Decks.Insert(0, model); } SelectedDeck = Decks.FirstOrDefault(x => x.Id == game.Deck.Id); } NotifyOfPropertyChange(() => CanSaveAsNew); //Execute.OnUIThread( // () => // { // var v = (UIElement)this.GetView(); // Panel.SetZIndex(v, 10); // }); }
/// <summary> /// Handles the message. /// </summary> /// <param name="message">The message.</param> public void Handle(DeckUpdated message) { if (message.Deck == null) { RefreshDecks(); return; } var found = Decks.FirstOrDefault(x => x.Id == message.Deck.Id); if (found != null) { found.MapFrom(message.Deck); } foreach (var gameResult in gameResults) { if (gameResult.Deck != null && gameResult.Deck.Id == message.Deck.Id) { gameResult.Deck = message.Deck; } } }
private void Update() { Note = _repository.GetGameNote()?.ToString(); var deck = _repository.GetOpponentDeck(); Cards.Clear(); deck.Cards.ForEach(c => Cards.Add(c)); PlayerClass = deck.Klass.ToString(); Decks.Clear(); var alldecks = _repository.GetAllArchetypeDecks(); var results = ViewModelHelper.MatchArchetypes(deck, alldecks); results.ForEach(r => Decks.Add(r)); results.ForEach(r => _log.Info($"{r.Deck.Name} [{r.Similarity}, {r.Containment}]")); var firstDeck = Decks.FirstOrDefault(); if (firstDeck != null && firstDeck.Similarity > MatchResult.THRESHOLD) { DeckSelected(firstDeck); } }
public DeckInformation GetDeck(long deckId) { return(Decks.FirstOrDefault((x) => { return x.Id == deckId; })); }
void Init() { PlayerHandler = new PlayerHandler(); Decks = DeckReader.ReadDeckNames(); Deck = Decks.FirstOrDefault(); }