Пример #1
0
        internal void GameStart()
        {
            try
            {
                //MetaLog.Info("Opponent Class: " + Core.Game.MatchInfo.OpposingPlayer.Name, "GameStart");
                MetaLog.Info("Game Mode: " + Core.Game.CurrentGameMode, "GameStart");
                MetaLog.Info("Game Format: " + Core.Game.CurrentFormat, "GameStart");
                MetaLog.Info("Region: " + Core.Game.CurrentRegion, "GameStart");
                MetaLog.Info("Mode: " + Core.Game.CurrentMode, "GameStart");

                _trackOpponentCards.Clear();
                _trackPlayerCards.Clear();

                if (_validGameMode)
                {
                    _opponentTurnCount = 0;
                    _playerTurnCount   = 0;

                    MetaLog.Info("New Game Started. Waiting for opponent to play cards.", "GameStart");
                }
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
Пример #2
0
        private async void CheckForUpdate()
        {
            try
            {
                var latest = await GitHub.CheckForUpdate("adnanc", "HDT.Plugins.MetaDetector", Version);

                if (latest != null)
                {
                    //_MainWindow.newVersionAvailable();
                    //VersionWindow newVersion = new VersionWindow();
                    //newVersion.Show();
                    string pluginDLL = Path.Combine(Config.Instance.DataDir, @"Plugins\MetaDetector\MetaDetector.tmp");

                    using (WebClient wc = new WebClient())
                    {
                        wc.DownloadFileCompleted += (wc_DownloadFileCompleted);
                        wc.DownloadFileAsync(new Uri("https://s3.amazonaws.com/metadetector/MetaDetector.dll"), pluginDLL);
                    }
                }
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
Пример #3
0
        internal async Task <string> sendCardStats()
        {
            try
            {
                MetaLog.Info("Uploading Game to MetaStats.net ...", "sendRequest");

                string url = "http://metastats.net/metadetector/stats.php?a=Stats&v=0.0.2";


                string postData = GetCardStats();

                if (postData != "")
                {
                    WebClient client = new WebClient();
                    byte[]    data   = Encoding.UTF8.GetBytes(postData);
                    //byte[] data = Compress.Zip(postData);
                    Uri uri      = new Uri(url);
                    var response = Encoding.UTF8.GetString(await client.UploadDataTaskAsync(uri, "POST", data));

                    MetaLog.Info("Game Upload Done", "sendRequest");

                    return(response);
                }

                return(null);
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
                return(null);
            }
        }
        private void LoadMetaDecks()
        {
            try
            {
                if (checkNewVersion())
                {
                    return;
                }

                if (File.Exists(_deckFilename))
                {
                    _metaDecks = XmlManager <List <Deck> > .Load(_deckFilename);

                    _matchedDecks = new List <Deck>(_metaDecks);

                    //_mainWindow.updateDeckList(_metaDecks);
                    //Log.Info(code.ToString());
                }
                else
                {
                    if (!Directory.Exists(_deckDirectory))
                    {
                        Directory.CreateDirectory(_deckDirectory);
                    }

                    DownloadMetaFile();
                    //_metaDecks.Clear();
                    //XmlManager<List<Deck>>.Save(_deckFilename, _metaDecks);
                }
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
        public bool checkNewVersion()
        {
            try
            {
                string   currentVersion = _appConfig.currentVersion;
                DateTime lastCheck      = _appConfig.lastCheck;

                if ((DateTime.Now - lastCheck).TotalDays > 3)
                {
                    MetaLog.Info("Checking for new version of Meta File");
                    WebClient client        = new WebClient();
                    String    versionNumber = client.DownloadString("http://ec2-54-88-223-252.compute-1.amazonaws.com/metaversion.php");

                    if (versionNumber.Trim() != "")
                    {
                        if (versionNumber != currentVersion)
                        {
                            DownloadMetaFile();

                            _appConfig.currentVersion = versionNumber;
                            _appConfig.lastCheck      = DateTime.Now;
                            _appConfig.Save();
                            return(true);
                        }
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
                return(false);
            }
        }
Пример #6
0
        public void PlayerHeroPower()
        {
            try
            {
                CardInfo temp = new CardInfo();

                temp.cardId       = "HERO_POWER";
                temp.cardName     = "Hero Power";
                temp.turn         = Convert.ToInt16(Math.Ceiling(Core.Game.GameEntity.GetTag(GameTag.TURN) / 2.0));
                temp.mana         = Core.Game.OpponentEntity.GetTag(GameTag.RESOURCES);
                temp.manaOverload = Core.Game.OpponentEntity.GetTag(GameTag.OVERLOAD_OWED);
                temp.activePlayer = "Player";

                _trackPlayerCards.Add((_playerTurnCount * 500), temp);

                /*_cardsPlayed.Add("HERO_POWER", Convert.ToInt16(Math.Ceiling(Core.Game.GameEntity.GetTag(GameTag.TURN) / 2.0)), false, -1, false, -1,
                 *  Core.Game.MatchInfo.OpposingPlayer.StandardRank, Core.Game.MatchInfo.OpposingPlayer.StandardLegendRank, Core.Game.MatchInfo.LocalPlayer.StandardRank,
                 *  Core.Game.MatchInfo.LocalPlayer.StandardLegendRank, Core.Game.MatchInfo.RankedSeasonId,
                 *  "Hero Power", Core.Game.PlayerEntity.GetTag(GameTag.RESOURCES), Core.Game.PlayerEntity.GetTag(GameTag.OVERLOAD_OWED), "Player");
                 */
                MetaLog.Info("Turn " + _playerTurnCount + ": Player Hero Power", "PlayerHeroPower");
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
Пример #7
0
        public MetaStats(MetaConfig conf)
        {
            try
            {
                //_mainWindow = new OpDeckWindow();

                _appConfig           = conf;
                _opponentCardsPlayed = new List <Card>();
                bool showBubble = false;

                if (showBubble)
                {
                    try
                    {
                        NotificationWindow notify = new NotificationWindow();
                        notify.Show();
                    }
                    catch (Exception ex)
                    {
                        MetaLog.Error(ex);
                    }
                }

                MetaLog.Initialize();

                MetaLog.Info("Meta Stats Initialized", "MetaStats");
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
Пример #8
0
 public void OnUnload()
 {
     _MetaDetector.saveConfig();
     _MainWindow.Close();
     _MetaDetector = null;
     _MainWindow   = null;
     MetaLog.Info("Plugin Unload Successful");
 }
Пример #9
0
 private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
 {
     try
     {
         System.Diagnostics.Process.Start(e.Uri.ToString());
     }
     catch (Exception ex)
     {
         MetaLog.Error(ex);
     }
 }
Пример #10
0
 public void PlayerDraw(Card c)
 {
     try
     {
         updatePlayerHandCards();
         //Core.Game.Player.PlayerCardList.Where(x => !x.IsCreated).ToDictionary( g=>g.Id, g=>g.Count);
     }
     catch (Exception ex)
     {
         MetaLog.Error(ex);
     }
 }
 public void OnButtonPress()
 {
     try
     {
         SettingsWindow wndSettings = new SettingsWindow(_appConfig.userKey);
         wndSettings.Show();
     }
     catch (Exception ex)
     {
         MetaLog.Error(ex);
     }
 }
        internal void OpponentPlay(Card cardPlayed)
        {
            if (_validGameMode)
            {
                MetaLog.Info("Opponent Played: " + cardPlayed.Name);
                _opponentCardsPlayed.Add(cardPlayed);

                if (cardPlayed.Id != "GAME_005") //ignore the coin
                {
                    _opponentCardCount++;
                    updateDecks();
                }
            }
        }
Пример #13
0
        internal void PlayerMulligan(Card c)
        {
            try
            {
                _trackPlayerCards.FirstOrDefault(x => x.Value.cardId == c.Id).Value.mulligan = true;
                //_trackPlayerCards.FirstOrDefault(x => x.Value.cardId == c.Id).Value.cardId = "";

                MetaLog.Info("Player Mulliganed " + c.Name, "PlayerMulligan");
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
        private void updateDecks()
        {
            if (_validGameMode)
            {
                try
                {
                    List <Deck> displayDecks = new List <Deck>();

                    if (_opponentCardCount > 0)
                    {
                        displayDecks = matchMetaDeck();

                        if (_matchedDecks.Count == 0 || _matchedDecks == null)
                        {
                            _mainWindow.updateText("No Decks Found.", Brushes.IndianRed);
                            return;
                        }
                        else if (_matchedDecks.Count > 0)
                        {
                            //_mainWindow.updateCardsCount(Core.Game.Opponent.RevealedEntities.Where(x => (x.IsInDeck || x.IsMinion || x.IsSpell || x.IsWeapon) && !x.Info.Created && !x.Info.Stolen).Count());
                            _mainWindow.updateCardsCount(Core.Game.Opponent.OpponentCardList.Where(x => !x.IsCreated).Count());

                            if (_opponentCardCount > _opponentCardCheck)
                            {
                                _opponentCardCheck = _opponentCardCount;

                                if (_opponentCardCount > 5)
                                {
                                    int count = _opponentCardCount;
                                    foreach (Deck d in _matchedDecks)
                                    {
                                        _metaDecks.Find(x => x.DeckId == d.DeckId).Note = (Convert.ToInt32(_metaDecks.Find(x => x.DeckId == d.DeckId).Note) + count).ToString();
                                    }
                                    _statsUpdated = true;
                                }
                            }
                        }

                        if (displayDecks != null)
                        {
                            _mainWindow.updateDeckList(displayDecks);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MetaLog.Error(ex);
                }
            }
        }
Пример #15
0
        public void PlayerPlay(Card cardPlayed)
        {
            try
            {
                updatePlayerHandCards();
                updatePlayerBoardEntities();

                MetaLog.Info("Turn " + _playerTurnCount + ": Player Played - " + cardPlayed.Name, "PlayerPlay");
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
        public void OnLoad()
        {
            try
            {
                if (!Directory.Exists(pluginDir))
                {
                    Directory.CreateDirectory(pluginDir);
                }

                _appConfig = MetaConfig.Load();
                _appConfig.Save();

                _MetaStats            = new MetaStats(_appConfig);
                _MetaDetectorMenuItem = new PluginMenu(_appConfig.userKey);

                GameEvents.OnGameStart.Add(_MetaStats.GameStart);
                GameEvents.OnGameEnd.Add(_MetaStats.GameEnd);

                GameEvents.OnTurnStart.Add(_MetaStats.TurnStart);

                GameEvents.OnOpponentPlay.Add(_MetaStats.OpponentPlay);
                GameEvents.OnOpponentDraw.Add(_MetaStats.OpponentDraw);

                GameEvents.OnOpponentCreateInPlay.Add(_MetaStats.OpponentCreateInPlay);
                GameEvents.OnOpponentCreateInDeck.Add(_MetaStats.OpponentCreateInDeck);
                GameEvents.OnOpponentHeroPower.Add(_MetaStats.OpponentHeroPower);
                GameEvents.OnOpponentSecretTriggered.Add(_MetaStats.OpponentSecretTriggered);
                GameEvents.OnOpponentPlayToGraveyard.Add(_MetaStats.OpponentPlayToGraveyard);
                GameEvents.OnOpponentMulligan.Add(_MetaStats.OpponentMulligan);

                GameEvents.OnPlayerDraw.Add(_MetaStats.PlayerDraw);
                GameEvents.OnPlayerPlay.Add(_MetaStats.PlayerPlay);
                GameEvents.OnPlayerCreateInPlay.Add(_MetaStats.PlayerCreateInPlay);
                GameEvents.OnPlayerCreateInDeck.Add(_MetaStats.PlayerCreateInDeck);
                GameEvents.OnPlayerHeroPower.Add(_MetaStats.PlayerHeroPower);
                GameEvents.OnPlayerMulligan.Add(_MetaStats.PlayerMulligan);

                CheckForUpdate();

                //_MainWindow.Show();
                //_MainWindow.Visibility = System.Windows.Visibility.Hidden;
                MetaLog.Info("Plugin Load Successful");
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
                MetaLog.Info("Plugin Load Unsuccessful");
            }
        }
Пример #17
0
 public void OpponentPlay(Card cardPlayed)
 {
     try
     {
         updateOpponentCardsPlayed();
         if (cardPlayed != null)
         {
             MetaLog.Info("Turn " + _opponentTurnCount + ": Opponent Played - " + cardPlayed.Name, "OpponentPlay");
         }
     }
     catch (Exception ex)
     {
         MetaLog.Error(ex);
     }
 }
Пример #18
0
        public void OpponentDraw()
        {
            try
            {
                foreach (Entity e in Core.Game.Entities.Select(x => x.Value).Where(x => !x.IsHero &&
                                                                                   !x.IsHeroPower && x.GetTag(GameTag.CONTROLLER) == Core.Game.Opponent.Id))
                {
                    if (e.CardId == null || e.CardId == "")
                    {
                        if (_trackOpponentCards.Where(x => x.Key == e.Id).Count() > 0)
                        {
                            _trackOpponentCards[e.Id].turnDrawn    = e.Info.Turn;
                            _trackOpponentCards[e.Id].mulligan     = e.Info.Mulliganed;
                            _trackOpponentCards[e.Id].isCreated    = e.Info.Created;
                            _trackOpponentCards[e.Id].activePlayer = "Opponent";

                            if (e.GetTag(GameTag.CREATOR) > 0)
                            {
                                _trackOpponentCards[e.Id].createdBy = Core.Game.Entities[e.GetTag(GameTag.CREATOR)].CardId;
                            }
                        }
                        else
                        {
                            CardInfo tempInfo = new CardInfo();

                            tempInfo.turnDrawn    = e.Info.Turn;
                            tempInfo.mulligan     = e.Info.Mulliganed;
                            tempInfo.isCreated    = e.Info.Created;
                            tempInfo.activePlayer = "Opponent";

                            if (e.GetTag(GameTag.CREATOR) > 0)
                            {
                                tempInfo.createdBy = Core.Game.Entities[e.GetTag(GameTag.CREATOR)].CardId;
                            }

                            _trackOpponentCards.Add(e.Id, tempInfo);

                            tempInfo = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
Пример #19
0
 void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
 {
     try
     {
         string tempFile  = Path.Combine(Config.Instance.DataDir, @"Plugins\MetaDetector\MetaDetector.tmp");
         string pluginDLL = Path.Combine(Config.Instance.DataDir, @"Plugins\MetaDetector\MetaDetector.dll");
         if (File.Exists(tempFile))
         {
             File.Copy(tempFile, pluginDLL, true);
             File.Delete(tempFile);
         }
     }
     catch (Exception ex)
     {
         MetaLog.Error(ex);
     }
 }
 private void DownloadMetaFile()
 {
     try
     {
         using (WebClient wc = new WebClient())
         {
             wc.DownloadProgressChanged += wc_DownloadProgressChanged;
             wc.DownloadFileCompleted   += (wc_DownloadFileCompleted);
             wc.DownloadFileAsync(new Uri("https://s3.amazonaws.com/metadetector/metaDecks.xml.gz"), _deckFilename + ".gz");
         }
     }
     catch (Exception ex)
     {
         _mainWindow.updateText("Unable to download Meta File.", Brushes.PaleVioletRed);
         MetaLog.Error(ex);
     }
 }
Пример #21
0
        public void Save()
        {
            try
            {
                if (!Directory.Exists(configDirectory))
                {
                    Directory.CreateDirectory(configDirectory);
                }

                var serializer = new XmlSerializer(typeof(MetaConfig));
                using (var writer = new StreamWriter(configPath))
                    serializer.Serialize(writer, this);
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
        void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            try
            {
                _mainWindow.updateText("Meta File Downloaded", Brushes.LightGreen);
                FileInfo fi = new FileInfo(_deckFilename + ".gz");
                DecompressFile(fi);

                if (File.Exists(_deckFilename))
                {
                    _metaDecks = XmlManager <List <Deck> > .Load(_deckFilename);
                }
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
Пример #23
0
        public string GetCardStats()
        {
            try
            {
                var serializer = new XmlSerializer(typeof(GameStats));

                using (StringWriter textWriter = new StringWriter())
                {
                    serializer.Serialize(textWriter, this);
                    return(textWriter.ToString());
                }
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
                return("");
            }
        }
        public NotificationWindow()
        {
            try
            {
                InitializeComponent();


                Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
                {
                    try
                    {
                        Window MainWindow = this;
                        if (MainWindow != null)
                        {
                            PresentationSource MainWindowPresentationSource = PresentationSource.FromVisual(MainWindow);
                            if (MainWindowPresentationSource != null)
                            {
                                Matrix m = MainWindowPresentationSource.CompositionTarget.TransformToDevice;
                                var thisDpiWidthFactor  = m.M11;
                                var thisDpiHeightFactor = m.M22;

                                var workingAreaWidth  = SystemParameters.WorkArea.Width * thisDpiWidthFactor;
                                var workingAreaHeight = SystemParameters.WorkArea.Height * thisDpiHeightFactor;

                                var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
                                var corner    = transform.Transform(new Point(workingAreaWidth, workingAreaHeight));


                                this.Left = corner.X - this.ActualWidth - 20;
                                this.Top  = corner.Y - this.ActualHeight - 20;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MetaLog.Error(ex);
                    }
                }));
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
Пример #25
0
        private void updatePlayerBoardEntities()
        {
            try
            {
                foreach (Entity e in Core.Game.Player.Board.Where(x => !x.IsHero && !x.IsHeroPower))
                {
                    CardInfo temp;
                    if (_trackPlayerCards.TryGetValue(e.Id, out temp))
                    {
                        _trackPlayerCards[e.Id].turn         = e.Info.Turn;
                        _trackPlayerCards[e.Id].cardName     = e.Card.Name;
                        _trackPlayerCards[e.Id].activePlayer = "Player";

                        if (e.GetTag(GameTag.CREATOR) > 0)
                        {
                            _trackPlayerCards[e.Id].isCreated = e.Info.Created;
                            _trackPlayerCards[e.Id].createdBy = Core.Game.Entities[e.GetTag(GameTag.CREATOR)].CardId;
                        }
                    }
                    else
                    {
                        CardInfo tempInfo = new CardInfo();

                        tempInfo.turn         = e.Info.Turn;
                        tempInfo.cardId       = e.CardId;
                        tempInfo.cardName     = e.Card.Name;
                        tempInfo.isCreated    = e.Info.Created;
                        tempInfo.activePlayer = "Player";

                        if (e.GetTag(GameTag.CREATOR) > 0)
                        {
                            tempInfo.createdBy = Core.Game.Entities[e.GetTag(GameTag.CREATOR)].CardId;
                        }

                        _trackPlayerCards.Add(e.Id, tempInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
Пример #26
0
 internal void TurnStart(ActivePlayer activePlayer)
 {
     try
     {
         if (ActivePlayer.Player == activePlayer)
         {
             _playerTurnCount = Convert.ToInt16(Math.Ceiling(Core.Game.GameEntity.GetTag(GameTag.TURN) / 2.0));
             updateOpponentCardsPlayed();
         }
         else
         {
             _opponentTurnCount = Convert.ToInt16(Math.Ceiling(Core.Game.GameEntity.GetTag(GameTag.TURN) / 2.0));
         }
     }
     catch (Exception ex)
     {
         MetaLog.Error(ex);
     }
 }
Пример #27
0
        public void Save()
        {
            try
            {
                this.cardsPlayed = cardsPlayed.OrderBy(x => x.turn).ThenBy(x => x.activePlayer).ToList();
                if (!Directory.Exists(statsDirectory))
                {
                    Directory.CreateDirectory(statsDirectory);
                }

                var serializer = new XmlSerializer(typeof(GameStats));
                using (var writer = new StreamWriter(statsPath))
                    serializer.Serialize(writer, this);
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }
        public MetaDetector(OpDeckWindow mainWindow)
        {
            _mainWindow    = new OpDeckWindow();
            _mainWindow    = mainWindow;
            _lastGuessDeck = new Deck();

            _metaDecks    = new List <Deck>();
            _matchedDecks = new List <Deck>();
            _statsUpdated = false;

            _opponentCardsPlayed = new List <Card>();

            _appConfig = MyConfig.Load();
            _appConfig.Save();
            MetaLog.Initialize();

            LoadMetaDecks();

            MetaLog.Info("Meta Detector Initialized");
        }
        internal void GameStart()
        {
            MetaLog.Info("Game Mode: " + Core.Game.CurrentGameMode);
            checkGameMode();

            if (_validGameMode)
            {
                _opponentCardCheck = 2;
                _opponentCardCount = 0;
                _opponentTurnCount = 0;

                //if (_mainWindow.Visibility == System.Windows.Visibility.Hidden || _mainWindow.Visibility == System.Windows.Visibility.Collapsed)
                //    _mainWindow.Show();

                _mainWindow.updateCardsCount(_opponentCardCount);
                _mainWindow.resetWindow(_metaDecks);

                MetaLog.Info("New Game Started. Waiting for opponent to play cards.");
            }
        }
Пример #30
0
        private void updatePlayerHandCards()
        {
            try
            {
                foreach (var e in Core.Game.Entities.Where(x => x.Value.CardId != null && x.Value.CardId != "" &&
                                                           !x.Value.IsHero && !x.Value.IsHeroPower && x.Value.IsInHand &&
                                                           x.Value.GetTag(GameTag.CONTROLLER) == Core.Game.Player.Id).ToList())
                {
                    if (_trackPlayerCards.Where(x => x.Key == e.Value.Id).Count() > 0)
                    {
                        if (_trackPlayerCards[e.Value.Id].turnDrawn == 0 && e.Value.Info.Turn > 0)
                        {
                            _trackPlayerCards[e.Value.Id].turnDrawn = e.Value.Info.Turn;
                        }
                    }
                    else
                    {
                        MetaLog.Info("Turn " + _playerTurnCount + ": Player Draws " + e.Value.LocalizedName);
                        CardInfo tempInfo = new CardInfo();

                        tempInfo.turnDrawn    = e.Value.Info.Turn;
                        tempInfo.mulligan     = e.Value.Info.Mulliganed;
                        tempInfo.cardId       = e.Value.CardId;
                        tempInfo.cardName     = e.Value.Card.Name;
                        tempInfo.isCreated    = e.Value.Info.Created;
                        tempInfo.activePlayer = "Player";

                        if (e.Value.GetTag(GameTag.CREATOR) > 0)
                        {
                            tempInfo.createdBy = Core.Game.Entities[e.Value.GetTag(GameTag.CREATOR)].CardId;
                        }

                        _trackPlayerCards.Add(e.Value.Id, tempInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                MetaLog.Error(ex);
            }
        }