//Check if stored name matches name from line. If neq, minion has been transformed -> save the new minion instead
        public void checkIfNameMatches(string[] nameandid)
        {
            string       id      = nameandid[1];
            string       newName = nameandid[0];
            DrawableCard c       = minions[id];

            if (c.getName().Equals("UnknownCard"))
            {
                return;
            }

            string oldName = c.getName();

            if (!oldName.Equals(newName))
            {
                int temp = c.BoardPosition;
                minions[id] = DrawableCard.makeDrawable(CardCreatorFactory.createFromName(newName).setId(int.Parse(id)));
                minions[id].BoardPosition = temp;
                if (board.p1Board.Contains(c))
                {
                    board.p1Board.Remove(c);
                    board.p1Board.Add(minions[id]);
                }
                Console.WriteLine("Minion changed: " + oldName + " to " + minions[id].getReadableName());
            }
        }
 private void button8_Click(object sender, EventArgs e)
 {
     board = new DrawableHearthstoneBoard();
     board.p1Board.Add(DrawableCard.makeDrawable(CardCreatorFactory.createFromName(CardCreatorFactory.Cards.DragonspawnLieutenant)));
     board.p1Board.Add(DrawableCard.makeDrawable(CardCreatorFactory.createFromName(CardCreatorFactory.Cards.DragonspawnLieutenant)));
     //       board.p1Board.Add(DrawableCard.makeDrawable(CardCreatorFactory.createFromName(CardCreatorFactory.Cards.DragonspawnLieutenant)));
     board.p2Board.Add(DrawableCard.makeDrawable(CardCreatorFactory.createFromName(CardCreatorFactory.Cards.MalGanis)));
     board.illidanPlayer = 1;
     board.drawBoardState(new Point(50, 50), new Point(50, 300), this);
 }
        public override void addNewMinionToBoard(BoardSide current, Card c, int position, bool overAllow)
        {
            DrawableCard d = DrawableCard.makeDrawable(c);

            switch (d.getName())
            {
            case "Guard Bot": d.pictureID = "BOT_218t"; break;

            case "Rat": d.pictureID = "CFM_316t"; break;

            case "Hyena": d.pictureID = "ULD_154t"; break;

            case "Microbot": d.pictureID = "BOT_312t"; break;

            case "Spider": d.pictureID = "OG_216a"; break;

            case "Voidwalker": d.pictureID = "CS2_065"; break;

            case "Robosaur": d.pictureID = "BOT_537t"; break;

            case "Imp": d.pictureID = "TB_BaconUps_030t"; break;

            case "Finkle Einhorn": d.pictureID = "EX1_finkle"; break;

            case "Big Bad Wolf": d.pictureID = "KAR_005a"; break;

            case "Ironhide Runt": d.pictureID = "TRL_232t"; break;

            case "Damaged Golem": d.pictureID = "skele21"; break;

            case "Bronze Warden": d.pictureID = "BGS_034"; break;

            case "Jo-E Bot": d.pictureID = "BOT_445t"; break;

            default: d.pictureID = "CFM_316t"; break;
            }

            base.addNewMinionToBoard(current, d, position, overAllow);
        }
        public void handleInput(string line)
        {
            if (line.Equals(""))
            {
                return;
            }
            line = line.Substring(0, line.Length - 1) + "|";



            if (line.Contains("TRANSITIONING card") && line.Contains("to FRIENDLY PLAY (Hero)"))
            {
                string name = getNameAndId(line)[0];
                if (name.Equals(HeroNames.Bob))
                {
                    return;
                }
                string id = getNameAndId(line)[1];
                Console.WriteLine("Hero Discovered:" + nameIDString(line) + " initializing new game");
                heroId   = id;
                heroName = getNameAndId(line)[0];
                startNewGame();
            }
            if (line.Contains("TRANSITIONING") && line.Contains("FRIENDLY PLAY (Hero Power)"))
            {
                string name = getNameAndId(line)[0];
                switch (name)
                {
                case HeroPower.Deathwing: Console.WriteLine("Hero power discovered: deathwing"); playerIsDW = true;  break;

                case HeroPower.Illidan: Console.WriteLine("Hero power discovered: illidan"); playerIsIllidan = true; break;

                case HeroPower.Patchwerk: Console.WriteLine("Hero power discovered: patchwerk"); expectedHealth = 50; actualHealth = 50; maxHealth = 50; break;
                }
                playerHeroPwr = name;
            }


            if (line.Contains("cardId=BOT_312e") && line.Contains("from  -> ") && line[line.Length - 2].Equals(' '))
            {
                Console.WriteLine("Next minion to recieve buff will get menace");
                menacebuffswaiting++;
            }
            //   if (line.Contains("DEATHRATTLE value=1") && line.Contains("ProcessChanges()"))
            // {
            //   string[] a = getNameAndId(line);
            // Card c = minions[a[1]];
            //if (c.typeMatches(Card.Type.Murloc))
            //{
            //  c.addEffect(new ArtificialSummon(CardCreatorFactory.Cards.Plant, 2));
            //    Console.WriteLine("Recieved plant buff on " + nameIDString(line));
            //Console.ReadLine();
            // }
            // }



            if (line.Contains("entityName="))
            {
                string[] a = getNameAndId(line);
                if (!minions.ContainsKey(a[1]))
                {
                    minions.Add(a[1], DrawableCard.makeDrawable(CardCreatorFactory.createFromName(a[0]).setId(int.Parse(a[1]))));
                }
                else
                {
                    checkIfNameMatches(a);
                }
            }

            if (line.Contains("tag=BACON_MINION_IS_LEVEL_TWO"))
            {
                string[]     a = getNameAndId(line);
                DrawableCard c = minions[a[1]];
                if (c.golden)
                {
                    return;
                }
                c.makeGolden();
                Console.WriteLine("Found golden: " + nameIDString(line) + "!!!!");
            }

            if (combat && !waitingForStart)
            {
                if (line.Contains("TRANSITIONING") && line.Contains("entityName=Refresh") && line.Contains("FRIENDLY PLAY"))
                {
                    Console.WriteLine("COMBAT OVER!!!");

                    lookForAttacker();
                    board  = new DrawableHearthstoneBoard();
                    combat = false;
                }
                if (line.Contains("entityName="))
                {
                    string[] a = getNameAndId(line);
                    if (!minions.ContainsKey(a[1]))
                    {
                        minions.Add(a[1], DrawableCard.makeDrawable(CardCreatorFactory.createFromName(a[0]).setId(int.Parse(a[1]))));
                    }
                }
                if (line.Contains("tag=COPIED_FROM_ENTITY_ID value=") && !line.Contains("tag=COPIED_FROM_ENTITY_ID value=0") && line.Contains("ProcessChanges()"))
                {
                    string newvalue = getStringBetween(line, "tag=COPIED_FROM_ENTITY_ID value=", " ");
                    Console.WriteLine(nameIDString(line) + "getting copied over from " + newvalue);
                    string[] a = getNameAndId(line);
                    if (minions.ContainsKey(newvalue))
                    {
                        minions[a[1]] = ((DrawableCard)minions[newvalue].copy().setId(int.Parse(a[1])));
                    }
                }



                return;
            }


            if (line.Contains("zone from FRIENDLY PLAY -> ") && line[line.Length - 2].Equals(' '))
            {
                string id = getNameAndId(line)[1];
                Console.WriteLine("Friendly minion sold:" + nameIDString(line));
                board.p1Board.Remove(minions[id]);
                //boardgui.redrawBoard(board);
            }
            if (line.Contains("pos from") && line.Contains("->") && !combat)
            {
                string id = getNameAndId(line)[1];
                checkIfNameMatches(getNameAndId(line));
                if (board.p1Board.Contains(minions[id]))
                {
                    Console.WriteLine("Friendly minion change pos:" + nameIDString(line) + " to " + line[line.Length - 2]);
                    minions[id].BoardPosition = int.Parse((line[line.Length - 2]).ToString());
                }
            }



            if (line.Contains("TRANSITIONING card [entityName=Tavern Tier ") && line.Contains(" to ") && line[line.Length - 2].Equals(' ') && !combat)
            {
                string tier = line[line.IndexOf("Tavern Tier") + 12].ToString();
                Console.WriteLine("Upgrade to tier " + tier);
                taverntier = int.Parse(tier);
            }

            if (line.Contains("TRANSITIONING card") && line.Contains("to FRIENDLY PLAY") && line[line.Length - 2].Equals('Y'))
            {
                string id = getNameAndId(line)[1];
                Console.WriteLine("Friendly minion added:" + nameIDString(line));
                string cardID = getStringBetween(line, "cardId=", " ");
                minions[id].pictureID = cardID;
                if (board.p1Board.Contains(minions[id]))
                {
                    return;
                }
                board.p1Board.Add(minions[id]);
                minions[id].printState();
                //   boardgui.redrawBoard(board);
            }

            if (line.Contains("TRANSITIONING card") && line.Contains("to OPPOSING PLAY") && line[line.Length - 2].Equals('Y') && combat)
            {
                string id = getNameAndId(line)[1];
                Console.WriteLine("Enemy minion added:" + getNameAndId(line)[0] + " id:" + id);
                if (lookForEntity(id))
                {
                    minions[id].makeGolden();
                }
                board.p2Board.Add(minions[id]);
                string cardID = getStringBetween(line, "cardId=", " ");
                minions[id].pictureID = cardID;
                minions[id].printState();
            }

            if (line.Contains("tag=PLAYER_TECH_LEVEL value=") && line.Contains("ProcessChanges"))
            {
                string newvalue = getStringBetween(line, "tag=PLAYER_TECH_LEVEL value=", " ");
                startRound(newvalue, getStringBetween(line, "name=", "]"), opponentHeroPWR);
            }

            if (line.Contains("Thuzad") && line.Contains("OPPOSING PLAY (Hero)"))
            {
                Console.WriteLine("Kel'Thuzad detected");
                startRound("0", HeroNames.KelThuzad, "");
            }
            if (line.Contains("TRANSITIONING") && line.Contains("OPPOSING PLAY (Hero Power)"))
            {
                string name = getNameAndId(line)[0];
                switch (name)
                {
                case HeroPower.Deathwing: Console.WriteLine("Hero power discovered: deathwing"); break;

                case HeroPower.Illidan: Console.WriteLine("Hero power discovered: illidan"); break;
                }
                opponentHeroPWR = name;
            }

            /* if (line.Contains("tag=COPIED_FROM_ENTITY_ID value=") && !line.Contains("tag=COPIED_FROM_ENTITY_ID value=0") && line.Contains("ProcessChanges()"))
             * {
             *   string newvalue = getStringBetween(line, "tag=COPIED_FROM_ENTITY_ID value=", " ");
             *   Console.WriteLine(nameIDString(line) + "getting copied over from " + newvalue);
             *   string[] a = getNameAndId(line);
             *   if (minions.ContainsKey(newvalue))
             *       minions[a[1]] = ((DrawableCard)minions[newvalue].copy());
             *   Console.ReadLine();
             *
             * }*/

            if (line.Contains("TRANSITIONING") && line.Contains("entityName=Refresh") && line[line.Length - 2].Equals(' '))
            {
                Console.WriteLine("COMBAT STARTS!!!");
                //boardgui.disableButtons();
                waitingForStart = true;
                combat          = true;
            }
            if (line.Contains("tag=ATK value=") && line.Contains("ProcessChanges"))
            {
                string[] a = getNameAndId(line);
                checkIfNameMatches(a);
                Card c = minions[a[1]];

                string newvalue = getStringBetween(line, "tag=ATK value=", " ");
                c.setAtk(int.Parse(newvalue));
                if (menacebuffswaiting > 0)
                {
                    Console.WriteLine("Added menace buff on " + nameIDString(line));
                    for (int i = 0; i < menacebuffswaiting; i++)
                    {
                        c.addEffect(new ArtificialSummon(CardCreatorFactory.Cards.Microbot, 3));
                    }
                    menacebuffswaiting = 0;
                }

                if (board.containsCard(c))
                {
                    Console.WriteLine("Attack changed on " + nameIDString(line) + " to " + newvalue);
                }
            }
            if (line.Contains("tag=HEALTH value=") && line.Contains("ProcessChanges"))
            {
                string[] a = getNameAndId(line);
                Card     c = minions[a[1]];

                string newvalue = getStringBetween(line, "tag=HEALTH value=", " ");
                c.setHp(int.Parse(newvalue));

                if (board.containsCard(c))
                {
                    Console.WriteLine("Health changed on " + nameIDString(line) + " to " + newvalue);
                }
            }
            if (line.Contains("tag=DIVINE_SHIELD value=1") && line.Contains("ProcessChanges"))
            {
                string[] a = getNameAndId(line);
                Card     c = minions[a[1]];
                c.setDivineShield(true);
                if (board.containsCard(c))
                {
                    Console.WriteLine("Recieved Divine Shield on " + nameIDString(line));
                }
            }
            if (line.Contains("tag=POISONOUS value=1") && line.Contains("ProcessChanges"))
            {
                string[] a = getNameAndId(line);
                Card     c = minions[a[1]];
                c.setPoisonous(true);
                if (board.containsCard(c))
                {
                    Console.WriteLine("Recieved poisonous on " + nameIDString(line));
                }
            }

            if (line.Contains("tag=WINDFURY value=1") && line.Contains("ProcessChanges"))
            {
                string[] a = getNameAndId(line);
                Card     c = minions[a[1]];
                c.setWindfury(true);
                if (board.containsCard(c))
                {
                    Console.WriteLine("Recieved Windfury on " + nameIDString(line));
                }
            }

            if (line.Contains("tag=TAUNT value=1") && line.Contains("ProcessChanges"))
            {
                string[] a = getNameAndId(line);
                Card     c = minions[a[1]];
                c.setTaunt(true);
                if (board.containsCard(c))
                {
                    Console.WriteLine("Recieved taunt on " + nameIDString(line));
                }
            }
        }