/*
以下类别的潜能有效:
伤害加深=10%,魔攻=80%,魔法恢复=3,生命吸收=7,毁灭敌人魔法=5,概率双倍伤害=10%,概率击晕=10%,无视魔防=50%,无视防御=50%,暗杀=25%
伤害减免=5%,额外洗劫金币=5%,额外经验加成=5%,反戈一击=30,负面状态免疫=5%,额外元灵加成=5%,怒火增长加快=1,危险感知=30
*/

function gx_qianneng(){  //潜能更新
rpg.qianneng=null;rpg.qianneng=[];var arrdex=-1;
for(var i=0;i<rpg.zb.length;i++){if(rpg.zb[i]==null)continue;
var theqianneng=xml.getwp("zb",rpg.zb[i]).getAttribute("潜能")
if(theqianneng==null)continue;theqianneng=theqianneng.split(",");
for(j=0;j<theqianneng.length;j++)rpg.qianneng[++arrdex]=theqianneng[j].split("=")[0]+"="+wpzb.jinglianjia(theqianneng[j].split("=")[1],wpzb.getjinglian(rpg.zb[i]))}
if(jn.find("还施彼身")!=false){rpg.qianneng[++arrdex]="反戈一击="+xml.getjn("还施彼身").childNodes[jn.find("还施彼身")[1]-1].getAttribute("wl")}
if(jn.find("理财术")!=false){rpg.qianneng[++arrdex]="额外洗劫金币="+xml.getjn("理财术").childNodes[jn.find("理财术")[1]-1].getAttribute("wl")}
if(jn.find("弱点透视")!=false){var thewl1=parseInt(xml.getjn("弱点透视").childNodes[jn.find("弱点透视")[1]-1].getAttribute("wl"));
thewl1=jn.find("真·弱点透视")!=false?thewl1*2:thewl1;rpg.qianneng[++arrdex]="无视防御="+thewl1
}
if(jn.find("神圣使命")!=false){var thewl1=parseInt(xml.getjn("神圣使命").childNodes[jn.find("神圣使命")[1]-1].getAttribute("wl"));
thewl1=jn.find("真·神圣使命")!=false?thewl1*2:thewl1;rpg.qianneng[++arrdex]="无视魔防="+thewl1
}
rpg.zdbushu=120+getqianneng("危险感知")
}
function getqianneng(findtext){  //获取潜能
var leiji=0;for(var i=0;i<rpg.qianneng.length;i++){
var theqianneng=rpg.qianneng[i].split("=");
if(theqianneng[0]!=findtext)continue;leiji+=new Number(theqianneng[1].replace("%",""))
}
return leiji
}
var zy={
open:function(){  //职业开关
zy_table.style.display=zy_table.style.display=='none'?'':'none';zy.show(0)
},
find:function(findtext){  //查找职业的存在
for(var i=0;i<rpg.zy.length;i++){if(rpg.zy[i]==findtext)return true;}return false;
},
getzyname:function(hexi,xuhao){  //获得职业名
if(xuhao<0)return rpg.zy[0];if(xuhao>9)xuhao=9
var allzy="";switch(hexi){
case "武学系":allzy="勇者,斗士,武士,战士,武侠,浪侠,剑豪,鬼武者,影武者,战神";break;
case "魔攻系":allzy="魔术师,魔法师,大魔法师,魔导士,黑魔导师,五行使,大法师,狂魔,法神,魔尊";break;
case "祝福系":allzy="门徒,僧侣,祭司,大祭司,白魔导师,大牧师,主教,天使,大天使,天主";break;
case "军师系":allzy="学者,智者,学士,大学士,隐士,占星师,预言师,统帅,大军师,军神";break;
}return allzy.split(",")[xuhao]
},
show:function(num){  //职业卡切换
for(var i=0;i<zy_img.length;i++){zy_img[i].style.border="2 solid white";if(i==num)zy_img[i].style.border="2 solid red"}
var xuqiu="",jiangli="",hexi=zy_img[num].value;switch(num){
case 1:xuqiu="3=0=0=0";jiangli="攻击力,防御";break;
case 2:xuqiu="0=3=0=0";jiangli="魔力,魔防";break;
case 3:xuqiu="0=0=3=0";jiangli="防御,魔防";break;
case 4:xuqiu="0=0=0=3";jiangli="攻击力,魔力";break;
}
if(num==0){  //显示已进化职业
for(var i=0;i<zy_lie.length;i++){zy_lie[i].children[0].innerHTML="&nbsp;";zy_lie[i].children[1].innerHTML="&nbsp;";zy_lie[i].children[2].innerHTML="&nbsp;";}
zy_table.style.color="black";var tmyoubiao=-1,shangxian=zy_lie.length*3-1
var thei=rpg.zy.length>shangxian?rpg.zy.length-shangxian:0;
for(var i=thei;i<rpg.zy.length;i++){
var tmobj=zy_lie[Math.floor((i-thei)/3)].children;
tmyoubiao++;if(tmyoubiao!=0&&tmyoubiao%3==0)tmyoubiao=0;
tmobj[tmyoubiao].innerHTML=rpg.zy[i]
}
zy_lie[zy_lie.length-1].children[2].innerHTML="<font style='color:purple;cursor:hand;' onclick='cj_kuang.num=2;cj.show()'>隐藏属性</font>"
return;}

var col1=jn.getcol(hexi);  //显示各系所有职业
zy_table.style.color=col1;xuqiu=xuqiu.split("=");
var tmxuqiu=new Array('0','0','0','0'),tmjiangli=jiangli.split(","),len1=zy_lie.length
for(var i=0;i<len1;i++){ //穷举该系职业
var tmobj=zy_lie[i].children,ii=(len1-i)*15,zyname=zy.getzyname(hexi,len1-1-i)
for(var j=0;j<xuqiu.length;j++){tmxuqiu[j]=parseInt(tmxuqiu[j]);  //点需求
if(xuqiu[j]==1)tmxuqiu[j]=ii;if(xuqiu[j]==3)tmxuqiu[j]=ii*2;
}
var tmzyname=rpg.zy[0];if(i<len1-1)tmzyname=zy.getzyname(hexi,len1-2-i)
tmobj[0].innerHTML="<font xulv='"+ii+"' xumingwang='"+round(ii*ii*0.6)+"' xudian1='"+tmxuqiu[0]+"' xudian2='"+tmxuqiu[1]+"' xudian3='"+tmxuqiu[2]+"' xudian4='"+tmxuqiu[3]+"' onmousemove=\"showtmk('拥有名衔="+tmzyname+" 级别高于='+this.xulv+' 名望='+this.xumingwang+'<br>战心='+this.xudian1+' 魔心='+this.xudian2+' 守心='+this.xudian3+' 军心='+this.xudian4,'晋升名衔['+this.innerText+']需求:','"+col1+"','#eeeeee')\">"+zyname+"</font>";
var jltext="",jsok=" style='cursor:hand;' onmouseup=\"if(confirm('你确认现在晋升 ["+zyname+"] 名衔?'))zy.jinsheng("+(len1-i)+",'"+zyname+"',this.jiangli,this.jiadian,"+num+")\""
for(var j=0;j<tmjiangli.length;j++){jltext+=(tmjiangli[j]+"+"+(ii/3)+" ");  //奖励输出
}jltext+=("名望+"+(ii*2)+" 才能界限+3<br>速度+3 怒火+2 元灵+"+(ii*30));
if(wj[0].lv<ii||rpg.mingwang<round(ii*ii*0.6)||zy.find(tmzyname)==false)jsok=" style='color:gray;cursor:hand' onmousedown=\"alert('晋升所需的[名衔 级别 名望 ]不够,无法晋升')\""  //晋升条件测试
for(var j=0;j<tmxuqiu.length;j++){if(rpg.dian[j]<tmxuqiu[j]){jsok=" style='color:gray;cursor:hand;' onmousedown=\"alert('晋升所需的[加点]不够,无法晋升')\"";break;}}
var break1=false;for(var j=0;j<rpg.zy.length;j++){if(rpg.zy[j]==zyname){break1=true;break;}}
if(!break1){tmobj[1].innerHTML="<font style='color:gray'>"+(len1-i)+"+</font>";tmobj[2].innerHTML="<font shuaxin='"+num+"' jiadian='"+ii+"' jiangli='"+jiangli+"'"+jsok+" onmousemove=\"showtmk('"+jltext+"','晋升["+zyname+"]能力奖励')\">晋升</font>"}else{tmobj[1].innerHTML="<font style='color:"+col1+"'>√</font>";tmobj[2].innerHTML="<font onmousemove=\"showtmk('曾获得能力="+jltext+"','此名衔已晋升过')\">√</font>"}
}
},
find:function(findname){  //已有职业查找
for(var i=0;i<rpg.zy.length;i++){if(rpg.zy[i]==findname)return true}
return false
},
jinsheng:function(duanwei,zyname,jiangli,jiadian,shuaxin){  //奖励
if(duanwei>rpg.zhuanzhi.split("=")[0])rpg.zhuanzhi=duanwei+"="+zyname;
rpg.zy[rpg.zy.length]=zyname;jiangli=jiangli.split(",");jiadian=parseInt(jiadian);var jiadian2=jiadian/3
for(var i=0;i<jiangli.length;i++){switch(jiangli[i]){
case "攻击力":wj[0].act1+=jiadian2;wj[0].act2+=jiadian2;break;case "魔力":wj[0].mct1+=jiadian2;wj[0].mct2+=jiadian2;break;
case "防御":wj[0].def+=jiadian2;break;case "魔防":wj[0].mef+=jiadian2;break;
case "生命上限":wj[0].hp2+=jiadian2;break;case "魔法上限":wj[0].mp2+=jiadian2;break;
}}rpg.mingwang+=(jiadian*2);wj[0].lv2+=3;wj[0].sudu+=3;wj[0].nu2+=2;rpg.yuanling+=(jiadian*30)
tbzt.zhuangtai();gx_rpg();zy.show(shuaxin);gdtext(event.x,event.y,"恭喜您获得 ["+zyname+"] 的称号和奖励");
}
}

var tbzt={
zhuangtai:function(){  //状态显示
ztzhuanzhi.innerText=rpg.zhuanzhi.split("=")[0]+"段 "+rpg.zhuanzhi.split("=")[1]
zt[0].innerText=selwj.name;
zt[1].innerText=selwj.lv+"/"+selwj.lv2;zt[2].innerText=selwj.exp1+"/"+selwj.exp2;
zt[3].innerText=selwj.hp1+"/"+selwj.hp2;zt[4].innerText=selwj.mp1+"/"+selwj.mp2;
zt[5].innerText=selwj.nu2;zt[6].innerText=selwj.sudu;
zt[7].innerText=selwj.act1+"-"+selwj.act2;
zt[8].innerText=selwj.mct1+"-"+selwj.mct2;
zt[9].innerText=selwj.def;zt[10].innerText=selwj.mef;
zt[11].innerText=selwj.jingque+"%";zt[12].innerText=selwj.shanbi+"%";
zt[13].innerText=selwj.baoji+"%";zt[14].innerText=selwj.yili+"%";

zt[15].innerText=rpg.luck+"%";
zt[16].innerText=rpg.yd+rpg.yd2;
zt[17].innerText=rpg.mingwang;zt[18].innerText=rpg.yuanling;

zt[19].innerText=selwj.xingbie==null?"魔物":selwj.xingbie;zt[20].innerText=selwj.yuanming;
var temphg=$(selwj.haogan),temptxt="";zt[21].innerText=temphg+"/"+rpg.qingshang;
rpg.qingshang>=50?zt[21].innerText=temphg+"/"+rpg.qingshang+"max":zt[21].innerText=temphg+"/"+rpg.qingshang;
if(temphg<5)temptxt="仇恨你";if(temphg>=5)temptxt="讨厌你";
if(temphg>=10)temptxt="不搭理你";if(temphg>=15)temptxt="面熟而已";
if(temphg>=20)temptxt="看好你";if(temphg>=25)temptxt="重视你";
if(temphg>=30)temptxt="很要好";if(temphg>=35)temptxt="跟你暧昧";
if(temphg>=40)temptxt="亲密热恋";if(temphg>=45)temptxt="如胶似漆";
if(temphg>=50)temptxt="永爱你";

zt[22].innerText=temptxt;

dian[0].innerText=rpg.dian[0];dian[1].innerText=rpg.dian[1];dian[2].innerText=rpg.dian[2]
dian[3].innerText=rpg.dian[3];dian[4].innerText=rpg.usedian+"-"+rpg.usedian;
dian[4].tempdian=rpg.usedian;zy.show(0)

if(selwj==wj[0]){zt_fujia2.style.display='';zt_fujia1.style.display='none'}else{zt_fujia2.style.display='none';zt_fujia1.style.display=''}
if(zt_kuang.style.display=="none"&&zd.zdzhong==false&&tbfun.lr==false)tbfun.begin()
if(selwj!=wj[0])zy_table.style.display='none'
},
jiadian:function(){  //加点各项操作
var obj=event.srcElement,num=0,dianshu=parseInt(dian[4].tempdian)
for(var i=0;i<diancz.length;i++){if(obj==diancz[i]){num=i;break;}}
if(num<4){
if(dianshu<1)return;dianshu--;
dian[4].tempdian=dianshu;dian[4].innerText=dianshu+"-"+rpg.usedian;
dian[num].innerText=parseInt(dian[num].innerText)+1
}else if(num==4){
tbzt.zhuangtai()
}else if(num==5){
if(!confirm("慎重加点(直接影响后期职业养成)!一旦增加,难以更改,请最后确认."))return;
tbzt.dianjisuan("减去")
for(var i=0;i<4;i++)rpg.dian[i]=parseInt(dian[i].innerText)
rpg.usedian=parseInt(dian[4].tempdian);
tbzt.dianjisuan()
tbzt.zhuangtai();
}
},
dianjisuan:function(jian){  //加点必要计算
var tmdian=[],tmor=null;for(var i=0;i<4;i++){
if(jian!=null){tmdian[i]=-rpg.dian[i];tmor=Math.ceil}  //更新点数前要减去旧点数
else{tmdian[i]=rpg.dian[i];tmor=Math.floor}}
wj[0].act1+=tmdian[0];wj[0].act2+=tmdian[0];
wj[0].nu2+=tmor(tmdian[0]/10);wj[0].baoji+=tmor(tmdian[0]/30);

wj[0].mct2+=tmdian[1];wj[0].mp2+=tmdian[1]*2;wj[0].mp1+=tmdian[1]*2
wj[0].nu2+=tmor(tmdian[1]/10);wj[0].baoji+=tmor(tmdian[1]/30);

wj[0].hp2+=tmdian[2]*2;wj[0].hp1+=tmdian[2]*2;wj[0].mp2+=tmdian[2];wj[0].mp1+=tmdian[2];
wj[0].def+=tmor(tmdian[2]/10);wj[0].mef+=tmor(tmdian[2]/10);wj[0].shanbi+=tmor(tmdian[2]/30);

wj[0].hp2+=tmdian[3]*2;wj[0].hp1+=tmdian[3]*2;wj[0].mp2+=tmdian[3];wj[0].mp1+=tmdian[3];
wj[0].sudu+=tmor(tmdian[3]/10);wj[0].jingque+=tmor(tmdian[3]/20);
if(jian==null)return gx_rpg()
}
}