Izya12 / league17

// ==UserScript==
// @name          league17
// @description          Greets the world...or no
// @version        0.3
// @grant       none
// @include       http://game.league17.ru/*
// ==/UserScript==

(function (window, undefined) {

var myBox = document.createElement('div');
myBox.id = 'myBox';

var myBox1 = document.createElement('div');
	myBox1.id = 'myBox1';

var myInfo = document.createElement('div');
myInfo.id = 'myInfoBox';

	document.body.appendChild(myBox1);
	myBox1.appendChild(myBox);


var AllPokes = [];
var baseHPfs = 0;
var AllBaseHPpoks = [0,78,60,80,39,58,78,44,59,79,45,50,60,40,45,65,40,63,83,30,55,40,65,35,60,35,60,50,75,55,70,90,46,61,81,70,95,38,73,115,140,40,75,45,60,75,35,60,60,70,10,35,40,65,50,80,40,65,55,90,40,65,90,25,40,55,70,80,90,50,65,80,40,80,40,55,80,50,65,90,95,25,50,52,35,60,65,90,80,105,30,50,30,45,60,35,60,85,30,55,40,60,60,95,50,60,50,50,90,40,65,80,105,250,65,105,30,55,45,80,30,60,40,70,65,65,65,65,75,20,95,130,48,55,130,65,65,65,35,70,30,60,80,160,90,90,90,41,61,91,106,100,45,60,80,39,58,78,50,65,85,35,85,60,100,40,55,40,70,85,75,125,20,50,90,35,55,40,65,55,70,90,75,70,100,70,90,35,55,75,55,30,75,65,55,95,65,95,60,95,60,48,190,70,50,75,100,65,75,60,90,65,70,20,80,55,60,90,40,50,50,100,55,35,75,45,65,65,45,75,75,90,90,85,73,55,35,50,45,45,45,95,255,90,115,100,50,70,100,106,106,100,40,50,70,45,60,80,50,70,100,35,70,38,78,45,50,60,50,60,40,60,80,40,70,90,40,60,40,60,28,38,68,40,70,60,60,60,80,150,31,61,1,64,84,104,72,144,50,30,50,70,50,50,50,60,70,30,60,40,70,60,60,65,65,50,70,100,45,70,130,170,60,70,70,60,80,60,45,50,80,50,70,45,75,73,73,70,70,50,110,43,63,40,60,66,86,45,75,20,95,70,60,44,64,20,40,99,65,65,95,50,80,70,90,110,35,55,55,100,43,45,65,95,40,60,80,80,80,80,80,80,100,100,105,100,50,55,75,95,44,64,76,53,64,84,40,55,85,59,79,37,77,45,60,80,40,60,97,97,30,60,40,60,70,30,70,60,55,85,45,70,76,111,75,90,150,55,65,60,100,49,71,45,63,103,57,67,50,20,100,76,50,58,68,108,135,40,70,68,108,40,70,48,83,74,49,69,45,60,90,70,70,110,115,100,75,75,85,86,65,65,75,110,85,68,60,45,70,50,75,80,75,100,90,91,110,150,120,80,100,70,100,120,100,45,60,75,65,90,110,55,75,95,45,60,45,65,85,41,64,50,75,50,75,50,75,76,116,50,62,80,45,75,55,70,85,55,67,60,110,103,75,85,105,50,75,105,120,75,45,55,75,30,40,60,40,60,45,70,70,50,60,95,70,105,75,50,70,50,65,72,38,58,54,74,55,75,50,80,40,60,55,75,45,60,70,45,65,110,62,75,36,51,71,60,80,55,50,70,69,114,55,100,165,50,70,44,74,40,60,60,35,65,85,55,75,50,60,60,46,66,76,55,95,70,50,80,109,45,65,77,59,89,45,65,95,70,100,70,110,85,58,52,72,92,55,85,91,91,91,79,79,100,100,89,125,91,100,71,56,61,88,40,59,75,41,54,72,38,85,45,62,78,38,45,80,62,86,44,54,78,66,123,67,95,75,62,74,45,59,60,78,101,62,82,53,86,42,72,50,65,50,71,44,62,58,82,77,123,95,78,67,50,45,68,90,57,43,85,49,65,55,95,40,85,126,126,108,50,80,80];


function ShowSettingBox()
{
	myBox.innerHTML += '<div class=\'myBoxElem\'><input type=\'checkbox\' class=\'inps\' id=\'af_cb\'> Авто бой &nbsp</div> ';
	myBox.innerHTML	+= '<div class=\'myBoxElem\'><input type=\'checkbox\' class=\'inps\' id=\'sh_iv\'> Show IV HP </div> <br> ';
	myBox.innerHTML	+= '<div class=\'myBoxElem\'><input type=\'checkbox\' class=\'inps\' id=\'statist\'> Статистика </div>  ';
	var sd1 = document.createElement('div');
		sd1.className = 'subdiv';
	sd1.innerHTML += '<div class=\'myBoxElem\' > <input type=\'checkbox\' class=\'inps\' id=\'at1\' checked> Атака 1 &nbsp</div> &nbsp&nbsp&nbsp';
	sd1.innerHTML += '<div class=\'myBoxElem\' > <input type=\'checkbox\' class=\'inps\' id=\'at2\' checked> Атака 2 &nbsp</div><br>';
	sd1.innerHTML += '<div class=\'myBoxElem\' > <input type=\'checkbox\' class=\'inps\' id=\'at3\' checked> Атака 3 &nbsp</div> &nbsp&nbsp&nbsp';
	sd1.innerHTML += '<div class=\'myBoxElem\' > <input type=\'checkbox\' class=\'inps\' id=\'at4\' checked> Атака 4 &nbsp</div>';
	document.getElementById('myBox').appendChild(sd1);
myBox.innerHTML += 'Не убивать: <input type=\'text\' value=\'16; 167; 32; 29; 37; 51; 52; 56; 58; 60; 66; 76; 86; 89; 96; 100; 109; 113; 115; 116; 120; 127; 145; 146; 186; 198; 206; 210; 214; 222; 243; 244; 251; 257; 270; 283; 325; 328; 331; 333; 351; 363; 403; 412; 417; 453; 455; 469; 531; 541; 546; 568; 569; 588; 616; 618; 627; 629; 631; 632;\' id=\'dontkick\'><br> <input type=\'checkbox\' id=\'signalon\' checked> ';


	scr1 = document.createElement('script');
	scr1.text = '(' +
		(function(){
			var myAudio = document.createElement('audio');
			myAudio.id = 'ring';
			var mAs = document.createElement('source');
			mAs.src = 'http://vignette1.wikia.nocookie.net/arezista/images/7/72/T1_signal.ogg/revision/latest?cb=20140608100327&path-prefix=ru';
			document.getElementById('myBox').appendChild(myAudio);
			myAudio.appendChild(mAs);
			var stdiv = document.createElement('div');
				stdiv.id = 'statisticdiv';
			document.body.appendChild(stdiv);
			var btnStat = document.createElement('button');
				btnStat.innerHTML = 'Показать сводку';
			var fshowst = function()
				{
					var sd = document.getElementById('statisticdiv');
					if(sd.style.display == 'none')
					{
						sd.style.display = 'block';
					}
					else {sd.style.display = 'none';}
				};
			btnStat.onclick = fshowst;
			document.getElementById('myBox').appendChild(btnStat);

			var myHd = 0;
			var dragdiv = document.createElement('div');
			dragdiv.id = 'dragdiv';
			dragdiv.innerHTML = '';
			dragdiv.onmousedown = function(){ myHd = 1; };
			dragdiv.onmouseup = function(){ myHd = 0;   };
			var f1 = function(){ if(myHd==1){ document.getElementById('myBox1').style.top = event.pageY -17 +'px';
											  document.getElementById('myBox1').style.left = event.pageX -100 +'px';
												if (window.getSelection) { window.getSelection().removeAllRanges();}
											}
                               };

			dragdiv.onmousemove = f1;
			document.body.onmousemove = f1;

			var btn1 = document.createElement('div');
			btn1.id = 'myButn1';
			btn1.style.display = 'none';
			btn1.innerHTML = 'overHR';

			var f2 = function InitShowTip (event) {
                if (event.initMouseEvent) {     // all browsers except IE before version 9
                    var mouseEvent = document.createEvent ("MouseEvent");
                    mouseEvent.initMouseEvent ("mouseover", true, true, window, 0,
                                                event.screenX, event.screenY, event.clientX, event.clientY,
                                                event.ctrlKey, event.altKey, event.shiftKey, event.metaKey,
                                                0, null);
					var dfi = document.getElementById('divFightH');
					if ( dfi !== undefined )
					{
						var dfi2 = dfi.getElementsByClassName('barHP')[0];
						if(dfi2 !== undefined)
						{
							dfi2.dispatchEvent (mouseEvent);
						}
					}
                }
			};
			btn1.onclick = f2;
			document.getElementById('myBox1').appendChild(btn1);

			var sp2 = document.getElementById('myBox');
			document.getElementById('myBox1').insertBefore(dragdiv,sp2);

			var css = document.createElement("style");
			css.type = "text/css";
			css.innerHTML = "#myBox { width:200px; height:200px; background:#e5eef8;  overflow-y:scroll; border-radius:0 0 15px 0; margin:0px; padding:0; border:1px solid #f0f6fc;} ";
			css.innerHTML += ".inps { margin:0 0 0 0; padding:0;} ";
			css.innerHTML += " #dragdiv { width:200px; height:30px; background:#d1d9e6; border:1px solid #afb8c5; border-radius:15px 15px 0 0; text-align:center; margin:0px; padding:0; cursor:move;}";
			css.innerHTML += " #myBox1 { width:200px;  background:#FFFFFF;  left:890px; top:400px; position:absolute; border-radius:15px;   }";
			css.innerHTML += " #dontkick {height:10px;}  #signalon {height:10px;}";
			css.innerHTML += " .myBoxElem { background:#e0eee7; border-radius:10px; display:inline-block; font-size:10px; padding:2px;}";
			css.innerHTML += " .subdiv { background:#e0e7ee; border-radius:10px; padding:5px; font-size:10px; }";
			css.innerHTML += "#statisticdiv { display:none; position:absolute; top:130px; left:250px; overflow:scroll; width:450px; height:450px; background: #e6e8f9;}";
			document.body.appendChild(css);

			}).toString() + ')()';
	document.body.appendChild(scr1);
	myBox.appendChild(myInfo);
}

//----------------------cookies_function_start---------------------
// возвращает cookie с именем name, если есть, если нет, то undefined
function getCookie(name) {
  var matches = document.cookie.match(new RegExp(
    "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  ));
  return matches ? decodeURIComponent(matches[1]) : undefined;
}

function setCookie(name, value, options) {
  options = options || {};

  var expires = options.expires;

  if (typeof expires == "number" && expires) {
    var d = new Date();
    d.setTime(d.getTime() + expires * 1000);
    expires = options.expires = d;
  }
  if (expires && expires.toUTCString) {
    options.expires = expires.toUTCString();
  }

  value = encodeURIComponent(value);

  var updatedCookie = name + "=" + value;

  for (var propName in options) {
    updatedCookie += "; " + propName;
    var propValue = options[propName];
    if (propValue !== true) {
      updatedCookie += "=" + propValue;
    }
  }

  document.cookie = updatedCookie;
}

//----------------------cookies_function_end---------------------

var AllEnemies = 0,
	AllEnemiesS = 0;

function SoundSignal(signal)
{
	if ( signal==1 )
	{
		document.getElementById('ring').play();
	}
	else
	{
		document.getElementById('ring').pause();
		document.getElementById('ring').currentTime = 0;
	}
}



//------------------------------------new Version

function TestStatusFight()
{
	var noone = document.getElementById('divFightAction').innerHTML;
	if ( noone.indexOf('\u043D\u0438\u0447') != -1 ) return 1; //ничья
	if ( noone.indexOf('\u043E\u0431\u0435\u0434') != -1  ) {  return 2; } //победа
	var pbd = document.getElementById('divFightI');
	pbd = pbd.getElementsByClassName('pokemonBoxDummy')[0];
	if (pbd !== undefined) return 3; //покемон убит/сменен

	return 0; //активная стадия боя
}

function CaptchaTest()
{
	var tm = document.getElementById('divFightCaptcha');
	var i1 = tm.getElementsByTagName('img');

	if ( i1[0].src !== undefined && tm.style.display != 'none' )
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

function TestWeather()
{
	var divW = document.getElementById('divFightWeather');
	if( divW.getElementsByClassName('w3')[0] !== undefined )
	{
		return 1; //град
	}
	else if( divW.getElementsByClassName('w4')[0] !== undefined )
	{
		return 2; //песчаная буря
	}
	else return 0; //благоприятная
}

function TestEnemy()
{
	var enemyDiv = document.getElementById('divFightH');
	var enemyNum = enemyDiv.getElementsByClassName('image');
	var nPok = 0;
	var shining = 0;
	if ( enemyNum[0] !== undefined )
	{
		enemyNum = enemyNum[0].getElementsByTagName('img');
		if (enemyNum[0] !== undefined)
		{
			enemyNum = enemyNum[0].src;

			var startPos = enemyNum.indexOf('.png');
			nPok = enemyNum.substring( startPos-3, startPos );

			if ( enemyNum.indexOf('norm') != -1  && enemyNum.indexOf('shine') == -1 )
			{
				shining = 0; // norm-pokemon
			}
			else if ( enemyNum.indexOf('norm') == -1  && enemyNum.indexOf('shine') != -1 )
			{
				shining = 1; //shine-pokemon
			}
			else
			{
				shining = 2; //smt interest?
			}
		}
		else
		{
			nPok = -1;
		}

		var lvl = enemyDiv.getElementsByClassName('lvl')[0];
		lvl = lvl.innerHTML;
		lvl = lvl*1;
	}
	else
	{
		nPok = -1;
	}

	return [nPok, shining, lvl];
}

function TestDivFight()
{
	var fightIs = document.getElementById('divVisioFight');
	//есть ли бой
	if (fightIs.style.display != 'none')
	{
		return 1;
	}
	return 0;
}

function CountWildIVhp(statHP,lvl,baseHP)
{
	var maxivHP = Math.floor(100*(statHP-9.5-lvl)/lvl-(baseHP*2)-0.0001);
	var minivHP = Math.ceil(100*(statHP-10.5-lvl)/lvl-(baseHP*2));
	var res = [];
	res[0] = minivHP;  res[1] = maxivHP;
	return (res);
}

function TestIVhp(nPok)
{
	if (nPok>0)
	{
		var hp = document.getElementById('myButn1');
			hp.click();
		var tip = document.body.getElementsByClassName('tip')[0];

		hp = tip.innerHTML;
		hp = hp.substring(hp.indexOf('/')+2,hp.indexOf('/')+6);

		var lvl = document.getElementById('divFightH');

		var ivDiv = document.getElementById('ivhpDiv');
		if(ivDiv===undefined)
		{
			ivDiv = document.createElement('span');
			ivDiv.id = 'ivhpDiv';
			ivDiv.style.fontSize = '12px';
			lvl.getElementsByClassName('name')[0].appendChild(ivDiv);
		}

		lvl = lvl.getElementsByClassName('lvl')[0];
		lvl = lvl.innerHTML;

		var IVhp = CountWildIVhp(hp,lvl,AllBaseHPpoks[nPok*1]);

		ivDiv.innerHTML = ' (hp: ' + IVhp[0] + '-' + IVhp[1] + ')';

		return IVhp;
	}
	else return [0,0];
}

function TestSettings()
{
	//myInfo.innerHTML = '';
	var attacks = [];
	var AllSoundOn;
	var AF;
	var sIV;
	var numpoksdontkick = [];

	var AFcb = document.getElementById('af_cb');
	if( AFcb.checked ) AF = 1;
	else AF = 0;

	var at1 = document.getElementById('at1');
	if( at1.checked ) attacks[0] = 1;
	else attacks[0] = 0;

	var at2 = document.getElementById('at2');
	if( at2.checked ) attacks[1] = 1;
	else attacks[1] = 0;

	var at3 = document.getElementById('at3');
	if( at3.checked ) attacks[2] = 1;
	else attacks[2] = 0;

	var at4 = document.getElementById('at4');
	if( at4.checked ) attacks[3] = 1;
	else attacks[3] = 0;

	var so = document.getElementById('signalon');
	if( so.checked ) AllSoundOn = 1;
	else  AllSoundOn = 0;

	var st = document.getElementById('statist');
	if( st.checked ) st = 1;
	else  st = 0;

	var shiv = document.getElementById('sh_iv');
	if( shiv.checked ) { sIV=1; } else sIV =0;

	var pl1 = document.getElementById('ring');
	if ( pl1.ended ) { document.getElementById('ring').currentTime = 0; document.getElementById('ring').play(); }



	var dk = document.getElementById('dontkick');
	var pdk = dk.value;
	var temp_pdk = pdk;
	var i=0;
	while ( temp_pdk.indexOf(';') != -1 )
	{
		numpoksdontkick[i] = 1*temp_pdk.substring( temp_pdk.indexOf(';')-3, temp_pdk.indexOf(';') );
		temp_pdk = temp_pdk.substring( temp_pdk.indexOf(';')+1, temp_pdk.length );
		i++;
	}
	var countofdkick = i;

	myInfo.innerHTML += 'Убито:' + countofdkick + 'поков.<br>';

	var AllSettings = [AF,attacks,AllSoundOn,countofdkick,numpoksdontkick,sIV,st];

	//-----saving_settings-------------
	var timeexp = new Date(new Date().getTime() + 7*24*60*60 * 1000 );
	var tobj = { expires: timeexp.toUTCString()};
	setCookie("l17usa1",attacks[0],tobj);	setCookie("l17usa2",attacks[1],tobj);	setCookie("l17usa3",attacks[2],tobj);	setCookie("l17usa4",attacks[3],tobj);
	setCookie("wmtbk",pdk,tobj); 	setCookie("allsd",AllSoundOn,tobj);

	return AllSettings;
}

function LoadSettings()
{
	var temp = getCookie("l17usa1");
	var opt;
	if (temp!==undefined)
	{
		opt = document.getElementById('at1');
		if(temp==1){opt.checked=true;}else{opt.checked=false;}
	}
	temp = getCookie("l17usa2");
	if (temp!==undefined)
	{
		opt = document.getElementById('at2');
		if(temp==1){opt.checked=true;}else{opt.checked=false;}
	}
	temp = getCookie("l17usa3");
	if (temp!==undefined)
	{
		opt = document.getElementById('at3');
		if(temp==1){opt.checked=true;}else{opt.checked=false;}
	}
	temp = getCookie("l17usa4");
	if (temp!==undefined)
	{
		opt = document.getElementById('at4');
		if(temp==1){opt.checked=true;}else{opt.checked=false;}
	}
	temp = getCookie("wmtbk");
	if (temp!==undefined)
	{
		opt = document.getElementById('dontkick');
		opt.value = temp;
	}
	temp = getCookie("allsd");
	if (temp!==undefined)
	{
		opt = document.getElementById('signalon');
		if(temp==1){opt.checked=true;}else{opt.checked=false;}
	}
}

function TestIfAttackForbidden(cnpdk,npdk,curnPok,shining)
{
	if (shining==1) return 1;
	for (i=0;i<cnpdk;i++)
	{
		if ( curnPok == npdk[i] ) return 1;
	}
	return 0;
}

function IssetPP(attacks)
{
	var fm = document.getElementById('divFightI');
	var moves = fm.getElementsByClassName('moveBox');
	var pp1 = [];
	var stopIt=0;
	var allattacks;

	for (var i=0;i<4;i++)
	{

		pp1[i] = moves[i].getElementsByClassName('divMoveParams');
		if(pp1[i][0] !== undefined)
		{
			pp1[i] = pp1[i][0].innerHTML;
			pp1[i] = pp1[i].substring(pp1[i].indexOf(':')+1,pp1[i].indexOf('/'));
			pp1[i] = pp1[i]*1; //сколько осталось ышо ПП у атаки текущего цикла
		}
		else {pp1[i] = 0;}
	}

	allattacks = attacks[0]*pp1[0] + attacks[1]*pp1[1] + attacks[2]*pp1[2] + attacks[3]*pp1[3];

	if (attacks[0]==1 && pp1[0]!==0) {stopIt =1;}
	else
		if (attacks[1]==1 && pp1[1]!==0) {stopIt =1;}
		else
			if (attacks[2]==1 && pp1[2]!==0) {stopIt =1;}
			else
				if (attacks[3]==1 && pp1[3]!==0) {stopIt =1;}
				else stopIt = 0;
	if (allattacks==1) pp1[4] = 1;
	if (stopIt === 0 ) return 0;

	return pp1;
}

function AutoFight(AF,attacks,PP)
{
	var fm = document.getElementById('divFightI');
	var all_m = fm.getElementsByClassName('moves');
	if (all_m[0] !== undefined)
	{
		var moves = fm.getElementsByClassName('moveBox');
		var curAt = -1;
		var num_cycle = Math.round(Math.random()*3);
		switch(num_cycle)
		{
			case 0:
			{
				if (attacks[0] == 1)
				{ curAt = 0; }	else {	num_cycle = 1;	}
			} break;
			case 1:
			{
				if (attacks[1] == 1)
				{ curAt = 1; } else { num_cycle = 2; }
			} break;
			case 2:
			{
				if (attacks[2] == 1)
				{ curAt = 2; } else { num_cycle = 3; }
			} break;
			case 3:
			{
				if (attacks[3] == 1)
				{ curAt = 3; } else { num_cycle = 0; }
			} break;
			default: num_cycle = 0;
		}

		if (curAt != -1)
		{
			var dm = moves[curAt].getElementsByClassName('divMoveInfo');
			if(AF==1 && all_m[0].style.display != 'none' && PP[curAt]!==0)
			{
				dm[0].click();
				return 0;
			}
		}
		else return 1;
	}
}

function WildOff()
{
	var wild = document.getElementById('divInputButtons');
	wild = wild.getElementsByClassName('btnSwitchWilds');
	wild = wild[0];
	if(wild.className.indexOf('pressed')!=-1)
		wild.click();
}

function CloseFightDiv(isAF)
{
	var fm = document.getElementById('divFightI');
	var all_m = fm.getElementsByClassName('moves');
	var fbuttons = document.getElementById('divFightButtons');
	var allfb = fbuttons.getElementsByClassName('button');
	if( all_m[0].style.display == 'none' && isAF==1 )
	{
		AllEnemies ++;
		allfb[4].click();
	}
}

//-----------------------------------------------------
function AddPokInStatistic(number)
{
	if (number>0 && number<730)
	{
		if(AllPokes[number] !== undefined)
		{ AllPokes[number] ++; }
		else
		{ AllPokes[number] = 1; }
	}
}

function PokStatisticToHTML()
{
	var result_HTML = 'Убитые поки. <br>';
	for (var i=0; i<721; i++)
	{
		if (AllPokes[i] !== undefined && AllPokes[i] !== 0 )
		{
			var proc =Math.round(AllPokes[i]*10000/AllEnemiesS)/100;
			result_HTML += i + ': ' + AllPokes[i] + '(' + proc + '%)' + '<br>';
		}
	}
	result_HTML += 'Всего ' + AllEnemiesS;
	return result_HTML;
}

function ShowStatistic()
{
	var divHTML = PokStatisticToHTML();
	document.getElementById('statisticdiv').innerHTML = divHTML;
}

function clearStatistic()
{
	for (var i=0; i<721; i++)
	{
		if (AllPokes[i] !== undefined )
		{
			AllPokes[i] = 0;
		}
	}
	AllEnemiesS = 0;
}

//-----------------------------------------------------------

var s1=0;
var pok=0,oldpok=0;

function main()
{
	var pok1 = 0;
	myInfo.innerHTML = '';
	var TS = TestSettings();
	if (TS[2] === 0)	s1 = 0;
	SoundSignal(s1);
	var IV = [0,0];

	s1 = 0;
	var TDF = TestDivFight(); //открыт ли див боя
	if ( TDF == 1 )
	{
		if (TS[5]==1)
		{
			var TE1 = TestEnemy();
			IV = TestIVhp(TE1[0]); // проверка гена хп
		}
		var TSF = TestStatusFight(); //проверка статуса боя
		if (TSF===0)
		{
			var CT = CaptchaTest(); //проверка капчи
			if (CT===0)
			{
				var TW = TestWeather(); //проверка погоды
				if(TW !== 0) { s1 = 1; }
				else s1 = 0;
				var TE = TestEnemy(); //проверка соперника
				pok1 = TE;

				var TIAF = TestIfAttackForbidden(TS[3],TS[4],TE[0],TE[1]);
				if (TIAF === 0 && IV[1]<36)
				{
					var IPP = IssetPP(TS[1]);
					if (IPP!==0 && IPP[4]!=1)
					{
						var wAF = AutoFight(TS[0],TS[1], IPP);
					}
					else
					{
						if (IPP[4] == 1)
						{
							AutoFight(TS[0],TS[1], IPP);
							WildOff();
							s1=1;
						}
						else
						{
							WildOff();
							s1=1;
						}
					}
				}
				else { s1=1; }
			}
			else { s1 = 1; }
		}
		else
		{
			if (TSF == 1 || TSF == 2) // если победа/ничья
			{
				oldpok = pok;
				if(TS[6]==1)
				{
					AllEnemiesS ++ ;
					AddPokInStatistic(pok*1);
				}
				CloseFightDiv(TS[0]);
			}
			else { WildOff(); }
		}
	}
	if (pok1[0]!==undefined) { pok = pok1[0];}
	else { pok = 0; }

	if(TS[6]==1){ ShowStatistic(); }
	else {clearStatistic();}

	myInfo.innerHTML += 'Пок #' + pok + '(was #' + oldpok + ')<br>';
	myInfo.innerHTML += 'Всего убито: ' + AllEnemies + '<br>';
}

ShowSettingBox();
LoadSettings();

t1 = setInterval(function(){ main(); },1000);

})(window);