public static void runBattle()
	{
		b1.cursorLock = true;
		if(!BATTLE_TYPE.equals("WILD"))
		{
			b1.addText(b1.trainer.type+" "+b1.trainer.name+" wants to fight!");
			try
			{
				Thread.sleep(3000);
			}
			catch(Exception ignored){}

			b1.showingTrainer=false;
			b1.addText(b1.trainer.type+" "+b1.trainer.name+" sent out "+enemy[enemyIndex].nickname+"!");
		}
		else
		{
			b1.addText("Wild "+enemy[enemyIndex].nickname+" appeared!");

			try
			{
				Thread.sleep(2000);
			}
			catch(Exception ignored){}

			b1.showingTrainer=false;
		}

		try
		{
			Thread.sleep(1000);
		}
		catch(Exception ignored){}

		b1.addText("GO! "+user[userIndex].nickname+"!");
		switchPkmn.play();

		System.out.println("Battle Type: "+BATTLE_TYPE);
		do
		{
			turn++;

			if (userLockedMove == -1)
			userCmd=0;
			else
				userCmd=userLockedMove;
			if (enemyLockedMove == -1)
			enemyCmd=0;
			else
				enemyCmd=enemyLockedMove;

			fixPPBug();
			while(b1.flicker[0] || b1.flicker[1])
			{

			}

			for(int i=0; i<userNumOfPokemon; i++)
			{
				if(user[i].originalTrainer==null||(!user[i].originalTrainer.equals(JokemonDriver.name)&&user[i].idNumber!=JokemonDriver.trainerIdNumber))
					user[i].IS_TRADED=true;
			}

			b1.addText("=========================");
			b1.addText("Turn: "+turn);

			b1.jsb.repaint();
			b1.text.repaint();
			b1.scroll.repaint();

			Inventory.throwingPokeBall=false;

			dudeCancel=false;
			if(userLockedMove==-1)
			b1.cursorLock = false;

			b1.updateUserPoke(user);

			b1.setScroll();

			b1.tooFront();

			Mechanics.participatedInBattle[userIndex]=true;

			userFainted=false;
			enemyFainted=false;
			if(Mechanics.turnsMultiTurn[1]<=0||user[userIndex].move[userCmd].sideEffect==Pokemon.Side_Effect.CHARGE)
			Mechanics.canAttack[0]=true;
			if(Mechanics.turnsMultiTurn[0]<=0||enemy[enemyIndex].move[enemyCmd].sideEffect==Pokemon.Side_Effect.CHARGE)
			Mechanics.canAttack[1]=true;

			if (userLockedMove == -1)
			userCmd=-5;

			//Print Current Battle Progress and Choose Command
			do
			{
				Pokedex.seen(enemy[enemyIndex].pokedexNumber-1);
				b1.updateUserPoke(user);
				if (userCmd==-1&&turn>1)
				{
					System.out.println("Dude");
					break;
				}
				if(userLockedMove==-1)
				printBattleProgress();
				else
				{
					try
					{
						Thread.sleep(3000);
					}
					catch(Exception ignored){}
				}

				if(userCmd==4)
				{
					//System.out.println("Return "+user[userIndex].nickname+"!");

					int randPhrase=(int)(Math.random()*3);

					if(randPhrase==0)
						b1.addText("Return "+user[userIndex].nickname+"!");
					else if(randPhrase==1)
						b1.addText("Good job, "+user[userIndex].nickname+"!");
					else if(randPhrase==2)
						b1.addText("That's enough "+user[userIndex].nickname+"!");

					userIndex=userSwitchPokemon();

					//System.out.println("GO! "+user[userIndex].nickname+"!");
					if(!switchCancel)
					{
						b1.addText("GO! "+user[userIndex].nickname+"!");

						try
						{
							Thread.sleep(1000);
						}
						catch(Exception ignored){}
					}
					else
					{
						b1.addText("You cancelled the switch!");
						b1.cursorLock=false;
						turn--;
					}
				}
				if(userCmd>-1&&userCmd<4)
				{
					if(Mechanics.hasPPAtAll(user[userIndex]))
					{
						if(!Mechanics.hasPP(user[userIndex].move[userCmd])||Mechanics.moveDisabled[0]==userCmd)
						userCmd=5;
					}
				}
			}
			while(userCmd<-1||userCmd>4);
			System.out.println("User Command Chosen");

			//Chooses enemy command
			if(BATTLE_TYPE.equals("WILD"))
				enemyCmd=run_AI_BASIC();
			else
				enemyCmd=run_AI_SMART();
			System.out.println("Enemy Command Chosen");

			b1.cursorLock = true;

			if(Inventory.throwingPokeBall)
				catchPokemon();

			//Checks who will move first
			if (!switchCancel&&!BATTLE_OVER)
			{
				b1.allowedToPaintExp=true;
				switch(Mechanics.determinePriority(user[userIndex],userCmd,enemy[enemyIndex],enemyCmd))
				{
					//User is first
					case 0:
						System.out.println("User outpaced Enemy");
						if (!dudeCancel)
						{
							checkPreMoveStatus(0);
							if(userCmd>=0&&userCmd<4&&Mechanics.canAttack[0]&&!userFainted&&Mechanics.hasRemainingPokemon(user,userNumOfPokemon))
							{

								if(user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.RAISE_STAT||
									user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.LOWER_STAT&&!nonPostingCase[0])
								{
									if(!Mechanics.awayFromBattle[1])
									hit=true;
									postAttackInfo(0);
								}

								useMove(0,userCmd);

								if(user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.DAMAGE||
									user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.INFLICT_STATUS||
									user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.SPECIAL&&!nonPostingCase[0])
								{
									postAttackInfo(0);
								}
							}
							checkPostMoveStatus(0);

							hit=false;
							sideHit=false;
							crit=false;
						}

						//Forces a Switch of Fainted Pokemon
						if(!Mechanics.isAlive(user[userIndex].health)&&Mechanics.hasRemainingPokemon(user,userNumOfPokemon))
						{
							try
							{
								Thread.sleep(2000);
								b1.addText("");
							}
							catch(Exception ignored){}
							b1.addText(user[userIndex].nickname+" fainted!");
							ko.play();
							userIndex=userSwitchPokemon();
							b1.addText("GO! "+user[userIndex].nickname+"!");

							userFainted=true;
							Mechanics.canAttack[1]=false;

							try
							{
								Thread.sleep(2000);
							}
							catch(Exception ignored){}
						}
						if(!Mechanics.isAlive(enemy[enemyIndex].health)&&Mechanics.hasRemainingPokemon(enemy,enemyNumOfPokemon))
						{
							try
							{
								Thread.sleep(2000);
								b1.addText("");
							}
							catch(Exception ignored){}
							b1.addText("Enemy "+enemy[enemyIndex].nickname+" fainted!");
							ko.play();

							Mechanics.calcExp(enemy[enemyIndex]);
							awardExp();

							enemyIndex=enemySwitchPokemon();
							b1.addText(b1.trainer.type+" "+b1.trainer.name+" sent out "+enemy[enemyIndex].nickname);
							enemyFainted=true;

							try
							{
								Thread.sleep(2000);
							}
							catch(Exception ignored){}
						}

						checkPreMoveStatus(1);
						if(enemyCmd>=0&&enemyCmd<4&&Mechanics.canAttack[1]&&!enemyFainted&&Mechanics.hasRemainingPokemon(enemy,enemyNumOfPokemon))
						{
							try
							{
								Thread.sleep(3000);
								b1.addText("");
							}
							catch(Exception ignored){}

							if(hasPP&&enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.RAISE_STAT||
								enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.LOWER_STAT&&!nonPostingCase[1])
							{
								if(!Mechanics.awayFromBattle[0])
								hit=true;
								postAttackInfo(1);
							}

							useMove(1,enemyCmd);

							if(hasPP&&enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.DAMAGE||
								enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.INFLICT_STATUS||
								enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.SPECIAL&&!nonPostingCase[1])
							{
								postAttackInfo(1);
							}
						}
						checkPostMoveStatus(1);

						hit=false;
						sideHit=false;
						crit=false;

						break;
					//Enemy is first
					case 1:
						System.out.println("Enemy outpaced User");
						checkPreMoveStatus(1);
						if(enemyCmd>=0&&enemyCmd<4&&Mechanics.canAttack[1]&&!enemyFainted&&Mechanics.hasRemainingPokemon(enemy,enemyNumOfPokemon))
						{
							if(hasPP&&enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.RAISE_STAT||
								enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.LOWER_STAT&&!nonPostingCase[1])
							{
								if(!Mechanics.awayFromBattle[0])
								hit=true;
								postAttackInfo(1);
							}

							useMove(1,enemyCmd);

							if(hasPP&&enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.DAMAGE||
								enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.INFLICT_STATUS||
								enemy[enemyIndex].move[enemyCmd].mainEffect==Pokemon.Primary_Effect.SPECIAL&&!nonPostingCase[1])
							{
								postAttackInfo(1);
							}

						}
						checkPostMoveStatus(1);

						hit=false;
						sideHit=false;
						crit=false;

						//Forces a Switch of Fainted Pokemon
						if(!Mechanics.isAlive(user[userIndex].health)&&Mechanics.hasRemainingPokemon(user,userNumOfPokemon))
						{
							try
							{
								Thread.sleep(2000);
								b1.addText("");
							}
							catch(Exception ignored){}

							b1.addText(user[userIndex].nickname+" fainted!");
							ko.play();
							userIndex=userSwitchPokemon();
							b1.addText("GO! "+user[userIndex].nickname+"!");

							userFainted=true;

							try
							{
								Thread.sleep(2000);
							}
							catch(Exception ignored){}
						}
						if(!Mechanics.isAlive(enemy[enemyIndex].health)&&Mechanics.hasRemainingPokemon(enemy,enemyNumOfPokemon))
						{
							try
							{
								Thread.sleep(2000);
								b1.addText("");
							}
							catch(Exception ignored){}

							b1.addText("Enemy "+enemy[enemyIndex].nickname+" fainted!");
							ko.play();

							Mechanics.calcExp(enemy[enemyIndex]);
							awardExp();

							enemyIndex=enemySwitchPokemon();
							b1.addText(b1.trainer.type+" "+b1.trainer.name+" sent out "+enemy[enemyIndex].nickname);

							enemyFainted=true;
							Mechanics.canAttack[0]=false;

							try
							{
								Thread.sleep(2000);
							}
							catch(Exception ignored){}

						}
						if (!dudeCancel)
						{
							try
							{
								Thread.sleep(3000);
								b1.addText("");
							}
							catch(Exception ignored){}

							checkPreMoveStatus(0);
							if(userCmd>=0&&userCmd<4&&Mechanics.canAttack[0]&&!userFainted&&Mechanics.hasRemainingPokemon(user,userNumOfPokemon))
							{
								if(user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.RAISE_STAT||
									user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.LOWER_STAT&&!nonPostingCase[0])
								{
									if(!Mechanics.awayFromBattle[1])
									hit=true;
									postAttackInfo(0);
								}

								useMove(0,userCmd);

								if(user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.DAMAGE||
									user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.INFLICT_STATUS||
									user[userIndex].move[userCmd].mainEffect==Pokemon.Primary_Effect.SPECIAL&&!nonPostingCase[0])
								{
									postAttackInfo(0);
								}
							}
							checkPostMoveStatus(0);

							hit=false;
							sideHit=false;
							crit=false;
						}

						break;
				}
			}

			if(Mechanics.isAlive(user[userIndex].health)&&Mechanics.hasRemainingPokemon(user,userNumOfPokemon)&&!switchCancel
				&&Mechanics.isAlive(enemy[enemyIndex].health)&&Mechanics.hasRemainingPokemon(enemy,enemyNumOfPokemon))
			{
				try
				{
					Thread.sleep(2000);
				}
				catch(Exception ignored){}
			}

			if(switchCancel)
				switchCancel = false;

			dudeCancel = false;
			b1.updateUserPoke(user);

			//Forces a Switch of Fainted Pokemon
			if(!Mechanics.isAlive(user[userIndex].health)&&Mechanics.hasRemainingPokemon(user,userNumOfPokemon))
			{
				b1.addText(user[userIndex].nickname+" fainted!");
				ko.play();
				userIndex=userSwitchPokemon();
				b1.addText("GO! "+user[userIndex].nickname+"!");

				userFainted=true;

				try
				{
					Thread.sleep(2000);
					b1.addText("");
				}
				catch(Exception ignored){}
			}
			if(!Mechanics.isAlive(enemy[enemyIndex].health)&&Mechanics.hasRemainingPokemon(enemy,enemyNumOfPokemon))
			{
				b1.addText("Enemy "+enemy[enemyIndex].nickname+" fainted!");
				ko.play();

				Mechanics.calcExp(enemy[enemyIndex]);
				awardExp();

				enemyIndex=enemySwitchPokemon();
				b1.addText(b1.trainer.type+" "+b1.trainer.name+" sent out "+enemy[enemyIndex].nickname);

				enemyFainted=true;

				try
				{
					Thread.sleep(2000);
					b1.addText("");
				}
				catch(Exception ignored){}
			}

			nonPostingCase[0]=false;
			nonPostingCase[1]=false;
			checkFainted();
			effectDecrementor(0);
			effectDecrementor(1);

		}
		while(!BATTLE_OVER&&Mechanics.hasRemainingPokemon(user,userNumOfPokemon)&&Mechanics.hasRemainingPokemon(enemy,enemyNumOfPokemon));

		b1.cursorLock = true;
		b1.addText("");

		try
		{
			Thread.sleep(2000);
		}
		catch(Exception ignored){}

		if(BATTLE_OVER)
		{
			System.out.println("Battle Ended Unnaturally");
		}
		else
		{
			if(Mechanics.hasRemainingPokemon(user,userNumOfPokemon))
			{
				b1.addText("Enemy "+enemy[enemyIndex].nickname+" fainted!");
				ko.play();
				try
				{
					Thread.sleep(3000);
				}
				catch(Exception ignored){}

				Mechanics.calcExp(enemy[enemyIndex]);
				awardExp();
				checkEvolutions();
				b1.addText("You Win!");
				if(!BATTLE_TYPE.equals("WILD"))
				{
					int moneyGain=(int)(Math.random()*enemy[0].getBaseStatTotal())+10*enemy[0].level;
					Inventory.money+=moneyGain;
					b1.addText("Received $"+moneyGain+" for winning!");
				}
			}
			else
			{
				b1.addText(user[userIndex].nickname+" fainted!");
				ko.play();
				b1.addText("You have no usable Pokemon!");
				try
				{
					Thread.sleep(3000);
				}
				catch(Exception ignored){}
				b1.addText("You black out!");
				try
				{
					Thread.sleep(3000);
				}
				catch(Exception ignored){}

				b1.addText("Warped to last Pokemon Center!");
				gameOver.play();

				stopMusic();

				JokemonDriver.area = JokemonDriver.Area.Pokecenter;
				JokemonDriver.location.x = 4;
				JokemonDriver.location.y = 3;
				JokemonDriver.direction = 90;
				JokemonDriver.makeTheArea = true;
				JokemonDriver.performingAction = true;
				JokemonDriver.setTransition(true);
			}
		}

		b1.addText("========Battle Over========");

		b1.allowedToPaintExp=true;
		b1.updateUserPoke(user);
		fixPPBug();
		//stopLoopLowHP();

		if(!BATTLE_OVER)
		{
			stopMusic();
	    	if(Mechanics.hasRemainingPokemon(user,userNumOfPokemon))
	    	battleOver.loop();
	    	BATTLE_OVER=true;
	    	lowHP.stop();
		}

		try
		{
			Thread.sleep(1000);
		}
		catch(Exception ignored){}

		b1.addText("==Press Any Key to Continue==");

		for(int i=0; i<6; i++)
		{
			if(revert[i]!=null)
			{
				revert[i].status=user[i].status;
				revert[i].exp=user[i].exp;
				user[i]=revert[i];
				user[i].species=revertSpecies[i];
				System.out.println(user[i]);
			}
		}
		
		for(int i=0; i<6; i++)
		{
			if(user[i]!=null)
			{
				user[i].atkStage=0;
				user[i].defStage=0;
				user[i].speedStage=0;
				user[i].spclStage=0;
				user[i].evaStage=0;
				
				user[i].atk=Mechanics.calcOtherStat(user[i].baseATK,user[i].ATK_IV,user[i].ATK_EV,user[i].level);
				user[i].def=Mechanics.calcOtherStat(user[i].baseDEF,user[i].DEF_IV, user[i].DEF_EV,user[i].level);
				user[i].spcl=Mechanics.calcOtherStat(user[i].baseSPCL,user[i].SPCL_IV,user[i].SPCL_EV,user[i].level);
				user[i].speed=Mechanics.calcOtherStat(user[i].baseSPEED,user[i].SPEED_IV,user[i].SPEED_EV,user[i].level);
			}
		}

		b1.createPokemonImages();

		while(!TERMINATE)
		{
			try
			{
				Thread.sleep(10);
			}
			catch(Exception ignored){}
		}

		gameOver.stop();
		battleOver.stop();
		lowHP.stop();
		stopMusic();

		System.out.println("Battle Ended");
		System.out.println();

		b1.endBattleWindow();
	}