var pkyoubiao=true,pktime1,pksouding=true,pkrpghp=0  //PK变量
var rpgfangxiang=0,pkmoshi=1  //战前记录方向 PK模式
var pktemptext='if(pkmoshi!=2){boypk.volume=-10000;girlpk.volume=-10000;bspk.volume=-10000;quanpk.volume=-10000;jianpk.volume=-10000;boypk.loop=0;girlpk.loop=0;bspk.loop=0;quanpk.loop=0;jianpk.loop=0;}clearInterval(pktime1);pktime1=null;pk1.style.display="none";pksouding=false;if(soundnum==0){bgsound1.volume=-300;}gx1();'
function bsgx(bsgximg,bsgxming,bsgxlv,bsgxhp,bsgxact,bsgxdef,bsgxcod,bsgxexp,bsgxaoyi,bsgxboos){
 //首次更新
if(nandu==1){
bsming=bsgxming;bslv=bsgxlv;bshp=bsgxhp;bsact=bsgxact;bsdef=bsgxdef;bshp2=bshp
bscod=bsgxcod;bsexp=bsgxexp;
}else{ //专家
bsming=bsgxming;bslv=bsgxlv;bshp=Math.ceil(bsgxhp*1.2);bsact=Math.ceil(bsgxact*1.1);
bsdef=Math.ceil(bsgxdef*1.1);bshp2=bshp
bscod=bsgxcod+2;bsexp=bsgxexp+1;
}
if(pk2.src.replace(/.*\/(.*?)/g,"$1")!=bsgximg)pk2.src="../image/guaiwu/"+bsgximg
bsgxaoyi==null?bsaoyi="无":bsaoyi=bsgxaoyi
if(bsgxboos!=null&&pkmoshi!=2){
if(bsgxboos=="优势"){yinxiao("boos1");}
else if(bsgxboos=="平均"){yinxiao("boos2");}
else if(bsgxboos=="恐怖"){yinxiao("boos3");}
else if(bsgxboos=="切磋"){yinxiao("boos4");}
}
var tempact="",tempdef="",tempmef=""
if(aoyi==0){aoyi1="无";}
else if(aoyi==1){aoyi1="蓄力";tempact="+"+lv;}
else if(aoyi==2){aoyi1="蓄力 水晶墙";tempact="+"+lv;tempdef="+"+lv;}
else if(aoyi==3){aoyi1="蓄力 水晶墙 魔法盾";tempact="+"+lv;tempdef="+"+lv;tempmef="+"+lv}
else if(aoyi==4){aoyi1="蓄力 水晶墙 魔法盾 疯速";tempact="+"+lv;tempdef="+"+lv;tempmef="+"+lv}
else if(aoyi==5){aoyi1="蓄力 水晶墙 魔法盾 疯速 圣光斩";tempact="+"+lv;tempdef="+"+lv;tempmef="+"+lv}
else if(aoyi>5){lv>69?aoyi2="真·圣光斩":aoyi2="圣光斩";aoyi1="蓄力 水晶墙 魔法盾 疯速 "+aoyi2+" 神の祝福";
tempact="+"+(lv*2);tempdef="+"+(lv*2);tempmef="+"+(lv*2)}
if(bsaoyi.indexOf("魔の审判")!=-1){tempact="+0";tempdef="+0";tempmef="+0"}
var tempxian="<font color='green'> - 后攻</font>",tempxian2="<font color='green'> - 先攻</font>";
if(bslv>lv){tempxian="<font color='green'> - 先攻</font>";tempxian2="<font color='green'> - 后攻</font>";}
if(aoyi>3){tempxian="<font color='green'> - 后攻</font>";tempxian2="<font color='green'> - 先攻</font>";}
if(bsaoyi.indexOf("恐惧")!=-1){
if(bsaoyi.indexOf("魔の审判")!=-1){tempact="-"+bslv;tempdef="-"+bslv;tempmef="-"+bslv;}
else if(aoyi>5){tempact="+"+(lv*2-bslv);tempdef="+"+(lv*2-bslv);tempmef="+"+(lv*2-bslv);}
else{tempact="+"+(lv-bslv);tempdef="+"+(lv-bslv);tempmef="+"+(lv-bslv);}
}

pk3.innerHTML='<font color=blue>'+bsgxming+tempxian+'</font><p><img src="../image/wupin/jian6.gif">'+bsact+' <img src="../image/wupin/dun13.gif">'+bsdef+' &nbsp; <img src="../image/wupin/exp.png">'+bsexp+' <img src="../image/wupin/cod.png">'+bscod+'<p><img src="../image/wupin/rpgaoyi1.png">:<font color=purple style="font-size:14px">'+bsaoyi+'</font><p><img src="../image/wupin/lv.png"> '+bslv+' &nbsp;<img src="../image/wupin/hp.png" style="filter:gray"><span style="color:red;" id=pkbshp>'+bshp+'/'+bshp2+'</span>'

pk5.innerHTML='<img src="../image/wupin/lv.png"> '+lv+' &nbsp;<img src="../image/wupin/hp.png"><span style="color:red" id=pkhp>'+hp1+'/'+hp2+'</span> <img src="../image/wupin/hp.png" style="filter:gray"><span style="color:#cccccc" id=pkhp2>-0</span><br><img src="../image/wupin/rpgaoyi1.png">:<font color=purple style="font-size:13px;">'+aoyi1+'</font><br><font style="font-size:16px"><img src="../image/wupin/jian6.gif">'+act+tempact+' <img src="../image/wupin/dun13.gif">'+def+tempdef+' <img src="../image/wupin/shizijia.gif">'+mef+tempmef+'</font><p><span style="color:red">'+youname+tempxian2+'</span><br><font color=gray>(ESC键逃跑,血不补你)</font>'
pk1.style.display="";var temps=230
if(pkmoshi==1){temps=120}else if(pkmoshi==2){temps=35}
pk2.style.filter="";pk4.style.filter="";
if(bsgxboos==null||pkmoshi==2){
if(pkmoshi==1||pkmoshi==3){setTimeout('pktime1=setInterval("pkjisuan()",'+temps+');',400);pkyinxiao()}
else{setTimeout('pktime1=setInterval("pkjisuan()",'+temps+');',200);pkyinxiao()}
}else{setTimeout('pkyinxiao();pktime1=setInterval("pkjisuan()",'+temps+');',2000)}
}
function pkyinxiao(){
if(swordsound){chisound.volume=-700;chisound.src='../sound/sword1.wav';}
if(pkmoshi!=2){
if(soundnum==0)bgsound1.volume=-1100
jianpk.volume=-600;jianpk.loop=-1;
quanpk.volume=-500;quanpk.loop=-1;
bspk.volume=-300;bspk.loop=-1;
if(yousex==true){
boypk.volume=-600;boypk.loop=-1;boypk.src='../sound/boypk.wav';
}else{
girlpk.volume=-700;girlpk.loop=-1;girlpk.src='../sound/girlpk.wav';
}
jianpk.src='../sound/jianpk.wav';quanpk.src='../sound/quanpk.wav';bspk.src='../sound/bspk.wav'
}
}
function pkjisuan(taopao){  //计算,虚拟战斗
if(pktime1==null)return false
if(taopao==true){  //逃跑
eval(pktemptext)
return false
}else if(bshp==0){  //怪失败
if(bsaoyi.indexOf("复活")!=-1){
if(pkmoshi!=2){yinxiao("boos1")}bsaoyi=bsaoyi.replace("复活","");bshp=bshp2;
}else{  //没复活
if(swordsound){
if(bsaoyi.indexOf("自爆")==-1&&bsaoyi.indexOf("审判粒子爆")==-1){yinxiao("pkend");}}
wupin.indexOf("幸运项链")==-1?cod+=bscod:cod+=bscod*2;
wupin.indexOf("战神之戒")==-1?exp1+=bsexp:exp1+=bsexp*2;
if(bsaoyi.indexOf("自爆")!=-1){yinxiao("zibao");
if(bsaoyi.indexOf("魔の审判")!=-1||aoyi<6)hp1-=bslv*10}
if(bsaoyi.indexOf("审判粒子爆")!=-1){yinxiao("zibao");hp1-=bslv*20}
if(wupin.indexOf("生命头巾")!=-1)hp1+=bslv*2
eval(pktemptext);
bsobj.removeNode();yi(rpgfangxiang);return false
}
}else if(hp1==0){  //主角死亡
eval(pktemptext);return false
}

var templv=true
if(bslv>lv)templv=false
if(aoyi>3)templv=true  //疯速
var tempact=act,tempdef=def,tempmef=mef
if(bsaoyi.indexOf("魔の审判")==-1){  //没有魔审判
if(aoyi>0)tempact+=lv;if(aoyi>1)tempdef+=lv;if(aoyi>2)tempmef+=lv  //神奥义,强化3项
if(aoyi>5){tempact+=lv;tempdef+=lv;tempmef+=lv}  //神祝福,在加强
}
if(aoyi>4&&pkyoubiao==true){aoyi>5?bshp-=lv*2:bshp-=lv;}  //圣光斩 真.圣光斩-奥义

var tempdef2=bsdef
if(bsaoyi.indexOf("铁甲")!=-1)tempdef2=tempact-1;
if(bsaoyi.indexOf("破防")!=-1)tempdef=0
if(bsaoyi.indexOf("恐惧")!=-1){tempact-=bslv;tempdef-=bslv;tempmef-=bslv}
if(bsaoyi.indexOf("吸血")!=-1&&pkyoubiao==false)bshp+=bslv
if(bsaoyi.indexOf("真爱")!=-1)bsdef=999
if(bsaoyi.indexOf("魔攻")!=-1)tempdef=tempmef
var temphp=hp1

if(pkyoubiao==true){  //游标是奇数
if(templv==true){  //主角级高先攻
if(tempact>tempdef2)bshp-=(tempact-tempdef2)
pk2.style.filter="invert";pk4.style.filter=""
}else{  //怪高先攻
pk4.style.filter="invert";pk2.style.filter=""
if(bsact>tempdef){hp1-=(bsact-tempdef)}else{hp1--}}
} else {  //偶数
if(templv==true){  //论到怪先攻.
pk4.style.filter="invert";pk2.style.filter=""
if(bsact>tempdef){hp1-=(bsact-tempdef)}else{hp1--}
}else{  //轮到主角先攻
pk2.style.filter="invert";pk4.style.filter=""
if(tempact>tempdef2)bshp-=(tempact-tempdef2)
}
}  //end pkyoubiao==true
if(bshp<0)bshp=0
if(hp1<0)hp1=0
pkbshp.innerText=bshp+"/"+bshp2;pkrpghp+=temphp-hp1;pkhp2.innerText="-"+pkrpghp
pkhp.innerText=hp1+"/"+hp2;
if(bsaoyi.indexOf("麻痹")!=-1){
if(Math.random()<0.2){templv==true?pkyoubiao=false:pkyoubiao=true;return false}
}
pkyoubiao=!pkyoubiao
} //end fun
function zhandou(){  //战斗分析
if(radio1.checked){pkmoshi=1}
else if(radio2.checked){pkmoshi=2}
else if(radio3.checked){pkmoshi=3}
pksouding=true;pkyoubiao=true;pkrpghp=0
var tempz2=bsobj.src.replace(/.*\/(.*?)/g,"$1")
var tempz=tempz2.replace(/\..+/g,"")
bsgx(tempz2,boosxml(tempz,"name"),parseInt(boosxml(tempz,"lv")),parseInt(boosxml(tempz,"hp1")),parseInt(boosxml(tempz,"act1")),parseInt(boosxml(tempz,"def1")),parseInt(boosxml(tempz,"cod")),parseInt(boosxml(tempz,"exp")),boosxml(tempz,"aoyi"),boosxml(tempz,"boos"))
}