public void performAction(GameTime gameTime)
        {
            switch (type)
            {
                case BattleActionType.ATTACK:
                    foreach(Player t in target)
                    {
                        bool isenemy = (t.playerBase.playerType == PlayerType.ENEMY) ? false : true ;
                        Console.WriteLine("Melee Attack, isenemy=" + isenemy);
                        Texture2D cur;
                        Console.WriteLine("Target " + t.name + " has " + t.GetCurrentHealth() + " health." );
                        if (user.GetCurrentHealth() > 0 && battleSequence.state != BattleStageType.FLEE)
                        {
                            int previoushealth = t.GetCurrentHealth();
                            cur = user.UseSpell(t, spell);
                            int newHealth = t.GetCurrentHealth();
                            battleSequence.combatLog.Add(user.name + " has dealt " + (previoushealth - newHealth) + " to "  + t.name + ". ");

                        }
                        else
                            return;

                        Projectile proj = new Projectile();
                        if(isenemy)
                            proj.Initialize(cur, spell, new Vector2(battleSequence.enemyrec[0].rec.X, battleSequence.enemyrec[0].rec.Y), false, battleSequence.playerec[0].rec.X, battleSequence.playerec[0]);
                        else
                            proj.Initialize(cur, spell, new Vector2(battleSequence.playerec[0].rec.X, battleSequence.playerec[0].rec.Y), true, battleSequence.enemyrec[0].rec.X, battleSequence.enemyrec[0]);
                        battleSequence.projectiles.Enqueue(proj);

                    }

                    break;
                case BattleActionType.ITEM:
                    foreach (Player t in target)
                    {
                        Console.WriteLine("Item");
                        int previoushealth = t.GetCurrentHealth();
                        t.UseHealingItem(item);
                        int newHealth = t.GetCurrentHealth();
                        int diff = (newHealth - previoushealth);
                        if (diff == 0)
                        {
                            battleSequence.combatLog.Add(user.name +  " does not have a healing item.");
                        }
                        else
                        {
                            battleSequence.combatLog.Add(user.name + " has healed " + (newHealth - previoushealth) + ". ");
                        }
                    }
                    break;
                case BattleActionType.SPELL:
                    foreach (Player t in target)
                    {
                        bool isenemy = (t.playerBase.playerType == PlayerType.ENEMY)? false : true ;

                        Texture2D cur;
                        if (user.GetCurrentHealth() > 0 && battleSequence.state != BattleStageType.FLEE)
                        {
                            int previoushealth = t.GetCurrentHealth();
                            cur = user.UseSpell(t, spell);

                            int newHealth = t.GetCurrentHealth();
                            int difference = previoushealth - newHealth;
                            if (difference == 0)
                            {
                                battleSequence.combatLog.Add(user.name + "'s fire failed.");
                            }
                            else
                            {
                                battleSequence.combatLog.Add(user.name + "'s fire dealt " + (previoushealth - newHealth) + " to " + t.name + ". ");
                            }

                        }
                        else
                            return;
                        Projectile proj = new Projectile();
                        if (isenemy)
                            proj.Initialize(cur, spell, new Vector2(battleSequence.enemyrec[0].rec.X, battleSequence.enemyrec[0].rec.Y), false, battleSequence.playerec[0].rec.X, battleSequence.playerec[0]);
                        else
                            proj.Initialize(cur, spell, new Vector2(battleSequence.playerec[0].rec.X, battleSequence.playerec[0].rec.Y), true, battleSequence.enemyrec[0].rec.X, battleSequence.enemyrec[0]);
                        battleSequence.projectiles.Enqueue(proj);
                        //battleSequence.drawprojectile = true;
                    }
                    break;
                case BattleActionType.FLEE:
                    Console.Write("Fleeeing...");
                    if (battleSequence.AttemptToFlee())
                    {
                        Console.WriteLine("Success!");
                        //continueCombat = false;
                        battleSequence.combatLog.Add("You sucessfully flee.");
                        battleSequence.state = BattleStageType.FLEE;
                    }
                    else
                    {
                        battleSequence.combatLog.Add("You failed to flee.");
                        battleSequence.state = BattleStageType.ACTION;
                    }
                    break;
                default:
                    break;
            }

            if (battleSequence.state != BattleStageType.FLEE)
                battleSequence.state = BattleStageType.ACTION;
        }
        public void Update(GameTime gameTime)
        {
            for (int i = 0; i < playerec.Length; i++)
                playerec[i].Update(gameTime);

            for (int i = 0; i < enemyrec.Length; i++)
                enemyrec[i].Update(gameTime);

            if (!drawprojectile && projectiles.Count > 0)
            {
                currentprojectile = projectiles.Dequeue();
                shotprojectileat = (int)gameTime.TotalGameTime.TotalMilliseconds;
                drawprojectile = true;
                drawplayerhpattime = shotprojectileat + 2 * PROJECTILE_TIME;
            }
            if (drawplayerhpattime < gameTime.TotalGameTime.TotalMilliseconds)
            {
                drawplayerhp = true;
            }
            if (drawplayerhp && drawplayerhpattime + 1000 < gameTime.TotalGameTime.TotalMilliseconds)
            {
                drawplayerhp = false;
                drawplayerhpattime = Int32.MaxValue;
            }
            if (drawprojectile)
            {
                currentprojectile.Update(gameTime);
                int curtime = (int)gameTime.TotalGameTime.TotalMilliseconds;
                if (curtime - shotprojectileat > PROJECTILE_TIME)
                {
                    drawprojectile = false;
                }
            }

            if (!drawprojectile)
            {
                switch (state)
                {
                    case BattleStageType.ACTION:
                        if (enemies[0].player.GetCurrentHealth() <= 0)
                        {
                            state = BattleStageType.WIN;
                        }
                        if (party.partyMembers[0].GetCurrentHealth() <= 0)
                        {
                           state =  BattleStageType.LOSE;

                        }

                        if (state == BattleStageType.ACTION)
                        {
                            aButton.Update();
                            itemButton.Update();
                            fleeButton.Update();
                            spellButton.Update();
                        }
                        break;
                    case BattleStageType.FIGHT:
                        while (this.currentActions.Count > 0)
                        {
                            BattleAction a = this.currentActions.Dequeue();
                            a.performAction(gameTime);
                        }
                        //this.state = BattleStageType.ACTION;
                        break;
                    case BattleStageType.FLEE:
                        Console.WriteLine("FLEE STAGE?");
                        Event e = new Event();
                        e.setEventType(EventType.MAP_TRANSITION);
                        e.addProperty("x", xRet);
                        e.addProperty("y", yRet);
                        e.addProperty("mapfile", retMap);
                        Game1.addToEventQueue(e);
                        this.continueCombat = false;
                        break;
                    case BattleStageType.LOSE:
                        Event e1 = new Event();
                        e1.setEventType(EventType.MAP_TRANSITION);
                        e1.addProperty("x", xRet);
                        e1.addProperty("y", yRet);
                        e1.addProperty("mapfile", retMap);
                        Game1.addToEventQueue(e1);
                        Event e2 = new Event();
                        e2.setEventType(EventType.LOSE_GAME);
                        Game1.addToEventQueue(e2);
                        break;
                    case BattleStageType.WIN:
                        party.partyMembers[0].inventory.AddItem(enemies[0].prize);
                        Event e3 = new Event();
                        e3.setEventType(EventType.MAP_TRANSITION);
                        e3.addProperty("x", xRet);
                        e3.addProperty("y", yRet);
                        e3.addProperty("mapfile", retMap);
                        Game1.addToEventQueue(e3);
                        Event e4 = new Event();
                        e4.setEventType(EventType.MESSAGE);
                        e4.addProperty("text", "You looted " + enemies[0].prize.name);
                        Game1.addToEventQueue(e4);

                        break;
                }
            }
        }