var xiaoxiang="boy1.jpg",ceng=1,ceng2=1,youname="东方不败",yousex=true  //rpg
var lv=1,hp1=800,hp2=1600,act=10,def=0,mef=0,nandu=1,swordsound=true
var cod=0,exp1=0,exp2=10,aoyi=0,key1=0,key2=0,key3=0,key4=0,key5=0 
var katong=1,wupin="",delsuoding=false,miaozhong=0
var bsming="slm",bslv=1,bshp=100,bsact=10,bsdef=10  //boos
var bscod=1,bsexp=1,bsobj,bshp2=0,bsaoyi="无"
var tdlie=13  //可用网阵
var tdwid=51,tdhei=41  //主角横竖移动单位
var sizetime=null,shutusuoding=false,caidansuoding=false  //自适应分辨率计时器 锁定变量
var yiji2=""  //存储主角方向,备用.
var intd=162,yidongkey=4,yidongzhen=1,img1left=0,img1top=0,buchang=3 //主角默认装载 rpgflash变量
var time1=null,time1youbiao=0,yidongzhen2=1  //boosflash变量
var suoding=true,msgyoubiao=0,msgshangxian=1,msgtd  //情景对话
var msgneirong=new Array(),msgboosming="",msgboosimg="",msgdongzuo=""  //情景对话2
function jieju(whatjieju){  //结局
location.replace('../vmlflash/cg2.htm?love='+escape(whatjieju))
}
function rpgdelete(){  //死亡
delsuoding=true;from1.style.filter="gray";rpgimg.style.filter="gray";
img1.src="../image/yongshi/youdel.png"
if(yousex==true){img1.style.clip="rect(0 25% 25% 0)";img1.style.top=img1top;yidongzhen=1}else{img1.style.clip="rect(50% 100% 75% 75%)";img1.style.top=img1top-80;yidongzhen=4}
img1.style.left=img1left-(yidongzhen*35)+35
yinxiao("youdel")
}
function setuser(setuser1,setvalue){  //userdata操作
caidan.setAttribute(setuser1,setvalue)
}
function getuser(getuser1){  //userdata操作
var tempc=caidan.getAttribute(getuser1)
if(isNaN(parseInt(tempc))==true){  //is字符
return tempc
}else{  //is数字
return parseInt(tempc)
}}
function gxwupin(awpname,awpnum){   //物品处理
if(wupin==""&&awpnum<0){return "你没有"};yinxiao("lv");
if(wupin==""){wupin+=awpname+"="+awpnum;return "已增加"}  //为空
if(wupin.indexOf(awpname)!=-1){  //已有此物
var temprgp=new RegExp(".*?"+awpname+"\\=(\\d+).*","gi")  //数量检索
var templen=parseInt(wupin.replace(temprgp,"$1"))  //得到数量
templen+=awpnum  //+-
temprgp=new RegExp("("+awpname+"\\=)\\d+","gi")  //更新
templen<=0?wupin=wupin.replace(temprgp,""):wupin=wupin.replace(temprgp,"$1"+templen)
return wupin
}else{  //如包裹暂没此物
if(awpnum<0)return "你没有"
wupin+=awpname+"="+awpnum;return "已增加"
}}
function gx1(gxtd){  //左栏更新
if(parseInt(rpglv.innerText)!=lv)rpglv.innerText=lv
if(parseInt(rpghp.innerText)!=hp1){
if(hp1>=hp2)hp1=hp2;
if(hp1<=0){hp1=0;rpghp.innerText=0;rpgdelete();return false}
rpghp.innerText=hp1;
}
rpghp2.innerText="/"+hp2;
if(aoyi>5){rpgact.innerText=act+"+"+lv*2;rpgdef.innerText=def+"+"+lv*2;rpgmef.innerText=mef+"+"+lv*2;}else{
aoyi>0?rpgact.innerText=act+"+"+lv:rpgact.innerText=act;
aoyi>1?rpgdef.innerText=def+"+"+lv:rpgdef.innerText=def;
aoyi>2?rpgmef.innerText=mef+"+"+lv:rpgmef.innerText=mef;
}
if(parseInt(rpgcod.innerText)!=cod)rpgcod.innerText=cod
if(parseInt(rpgexp1.innerText)!=exp1)rpgexp1.innerText=exp1;
rpgexp2.innerText="/"+exp2;
if(aoyi>5){rpgaoyi.innerText="+"+aoyi+"(战神の力)"}else if(aoyi>4){rpgaoyi.innerText="+"+aoyi+"(圣光斩)"}
else if(aoyi>3){rpgaoyi.innerText="+"+aoyi+"(疯速)"}else if(aoyi>2){rpgaoyi.innerText="+"+aoyi+"(魔法盾)"}
else if(aoyi>1){rpgaoyi.innerText="+"+aoyi+"(水晶墙)"}else if(aoyi>0){rpgaoyi.innerText="+"+aoyi+"(蓄力)"}
else if(aoyi==0){rpgaoyi.innerText="+"+aoyi}
if(parseInt(rpgkey1.innerText)!=key1)rpgkey1.innerText=key1
if(parseInt(rpgkey2.innerText)!=key2)rpgkey2.innerText=key2
if(parseInt(rpgkey3.innerText)!=key3)rpgkey3.innerText=key3
if(parseInt(rpgkey4.innerText)!=key4)rpgkey4.innerText=key4
if(parseInt(rpgkey5.innerText)!=key5)rpgkey5.innerText=key5
if(exp1>=exp2)shengji()
if(gxtd!=null)gxtd.value=null  //是否删地形
}
function yinxiao(soundleixing){  //音效
switch(soundleixing){
case "key":iskey.volume=0;iskey.src="../sound/key.wav";break;
case "shop":qitasound.volume=-500;qitasound.src='../sound/shop.wav';break;
case "lv":lvup.volume=-500;lvup.src="../sound/lvup.wav";break;
case "duihua":boxsound.volume=-500;boxsound.src="../sound/tanhua.wav";break;
case "xianjing":quanpk.volume=-300;quanpk.loop=0;quanpk.src='../sound/quanpk.wav';break;
case "chi":chisound.volume=-200;chisound.src='../sound/chi.wav';break;
case "shikong":chisound.volume=-400;chisound.src='../sound/shikong.wav';break;
case "zibao":qitasound.volume=-200;qitasound.src='../sound/qita/zibao.wav';break;
case "pkend":qitasound.volume=-300;qitasound.src='../sound/sword2.wav';break;
case "boos1":chisound.volume=-400;qitasound.volume=-400;yousex==true?tempsound="boy":tempsound="girl";
chisound.src='../sound/qita/boos1.wav';setTimeout('qitasound.src="../sound/qita/boos"+tempsound+"1.wav"',1000);break;
case "boos2":chisound.volume=-500;qitasound.volume=-200;yousex==true?tempsound="boy":tempsound="girl";
chisound.src='../sound/qita/boos2.wav';setTimeout('qitasound.src="../sound/qita/boos"+tempsound+"2.wav"',1500);break;
case "boos3":chisound.volume=-200;qitasound.volume=-400;
chisound.src='../sound/qita/boos3.wav';setTimeout('qitasound.src="../sound/qita/boosgirlboy3.wav"',1000);break;
case "boos4":chisound.volume=-300;qitasound.volume=-200;
chisound.src='../sound/qita/boos4.wav';setTimeout('qitasound.src="../sound/qita/boosgirlboy4.wav"',500);break;
case "youdel":chisound.volume=-400;
yousex==true?temps="boydel":temps="girldel";
chisound.src="../sound/qita/"+temps+"1.wav";
setTimeout("chisound.src='../sound/qita/"+temps+"1.wav'",1500)
setTimeout("chisound.src='../sound/qita/"+temps+"2.wav'",3000)
setTimeout("if(delsuoding)chisound.src='../sound/qita/"+temps+"1.wav'",5500)
setTimeout("if(delsuoding)chisound.src='../sound/qita/"+temps+"2.wav'",7000)
setTimeout("if(caidan.style.display=='none'&&delsuoding==true)alert('喂!别傻看了,你挂老^-^,看完本说明点[确定],然后游戏中按下S或X启动[游戏菜单],可以[读取进度]或者[重新开始]游戏.')",10000)
break;
}}
function document.body.onmousewheel(){  //鼠中
if(caidansuoding==false){event.wheelDelta>0?document.body.scrollTop-=10:document.body.scrollTop+=10;}
}
function window.onresize(){  //适应分辨率
if(sizetime==null){
var tempsize="clearTimeout(sizetime);sizetime=null;try{tab1.style.left=(document.body.offsetWidth-tab1.offsetWidth)/2;tab1.style.top=(document.body.offsetHeight-tab1.offsetHeight)/2;pk1.style.top=tab1.offsetTop+70;pk1.style.left=tab1.offsetLeft+350;box1.style.left=tab1.offsetLeft+330;shop1.style.left=pk1.style.left;shop1.style.top=tab1.offsetTop+150;mikuang1.style.left=tab1.offsetLeft+300;mikuang1.style.top=tab1.offsetTop+200;caidan.style.left=tab1.offsetLeft+220;caidan.style.top=tab1.offsetTop+50;}catch(e){}"
sizetime=setTimeout(tempsize,500)}
}
function delcks(){   //删COOKIES,线上必须删
var dates = new Date();
dates.setDate(dates.getDate()-2365)
document.cookie="fywmt1=1;expires="+dates.toGMTString()  //删测试阶段命名fywmt1
document.cookie="shenmoduijue=1;expires="+dates.toGMTString() 
}
function getcks(){   //读COOKIES
if(document.cookie==""){
alert("请先进入引导页,设置基本的游戏参数,否则,游戏将使用默认男性人物如下:\n\n性别:男  名称:东方不败")
yousex=true;xiaoxiang="boy1.jpg";youname="东方不败"
return false;
}
cookies=document.cookie.split('; ')
var temp1=-1
for(var i=0;i<cookies.length;i++){if(cookies[i].indexOf("shenmoduijue=")==0)temp1=i}  //找到shenmoduijue存储组
if(temp1==-1)return false
var cks=cookies[temp1].substr(13).split(",")  //逗号分割
if(cks.length!=2){  //如果cks小于本版正常的数组数，那么就删除、使用默认设置
alert("cookies简单存储内容过期,现在自动转到游戏最初引导界面..");delcks();
location.replace('../game.htm')
return false
}
if(cks[0].indexOf("boy")!=-1){yousex=true}else{yousex=false}
xiaoxiang=cks[0]+".jpg";youname=unescape(cks[1])
}
var uidom=new ActiveXObject("Microsoft.XMLDOM");uidom.async=false;uidom.load("../rs_xml/xml_uixml.xml")
var juqingdom=new ActiveXObject("Microsoft.XMLDOM");juqingdom.async=false;juqingdom.load("../rs_xml/xml_juqing.xml")
var ditudom=new ActiveXObject("Microsoft.XMLDOM");ditudom.async=false;ditudom.load("../rs_xml/xml_ditu.xml")
var boosdom=new ActiveXObject("Microsoft.XMLDOM");boosdom.async=false;boosdom.load("../rs_xml/xml_boos.xml")
var yuansudom=new ActiveXObject("Microsoft.XMLDOM");yuansudom.async=false;yuansudom.load("../rs_xml/xml_yuansu.xml")
var menudom=new ActiveXObject("Microsoft.XMLDOM");menudom.async=false;menudom.load("../rs_xml/xml_menu.xml")
var midom=new ActiveXObject("Microsoft.XMLDOM");midom.async=false;midom.load("../rs_xml/xml_mi.xml")
var xmlerr="文件加载错误!游戏可能将无法正常运行!\n\n也有可能是网络迟缓造成,请刷新本页重新加载!"
if(uidom.parseError.errorCode!=0)alert("异常:视图UI-XML"+xmlerr)
if(juqingdom.parseError.errorCode!=0)alert("异常:剧情-XML"+xmlerr)
if(ditudom.parseError.errorCode!=0)alert("异常:地图-XML"+xmlerr)
if(boosdom.parseError.errorCode!=0)alert("异常:怪物-XML"+xmlerr)
if(yuansudom.parseError.errorCode!=0)alert("异常:元素-XML"+xmlerr)
if(menudom.parseError.errorCode!=0)alert("异常:菜单-XML"+xmlerr)
if(midom.parseError.errorCode!=0)alert("异常:迷题-XML"+xmlerr)
var mitisuoding=false
function showmixml(mixmlname,rpghuida){  //迷题
var tempdom=midom.getElementsByTagName(mixmlname)[0]
if(rpghuida==null){
mikuang1.style.top=tab1.offsetTop+30;mikuang1.style.left=(document.body.offsetWidth/2)-250
var tempmi="<center>有奖迷题之(<font color=red>"+mixmlname.replace("miti","")+"</font>),完全鼠标操作!<br>"
if(tempdom.getAttribute("src")!=null)tempmi+="<img src='../image/mitiimg/"+tempdom.getAttribute("src")+"'></center>"
tempmi+="</center><font color=red style='font-size:14px'>介绍:</font><font style='color:purple;font-size:14px;'>"+tempdom.text+"</font><br>"
tempdom.getAttribute("tishi")==null?tempmi+="<font color=red style='font-size:14px'>提示:无</font><p>":tempmi+="<font color=red style='font-size:14px'>提示:"+tempdom.getAttribute("tishi")+"</font><br>";
tempmi+="<font color=red style='font-size:14px'>你的答案:</font><input type=text id=mitext style='font-size:14px;width:140' onkeypress='if(event.keyCode==13)this.nextSibling.onclick()'><input style='font-size:14px' type=button value='确定答题' onclick=showmixml('"+mixmlname+"',mitext.value)><input style='font-size:14px;' type=button value='取消答题' onclick='mikuang1.style.display=\"none\";mitisuoding=false'><center style='color:gray;font-size:14px;'>注意:乱用符号,出错后果自负哦.</center>"
mikuang1.innerHTML=tempmi;mikuang1.style.display="";mitisuoding=true
}else{
if(rpghuida.replace(/ /g,"").length==0)return alert("你没填答题内容!");
if(rpghuida.toLowerCase()==tempdom.getAttribute("right")){mikuang1.style.display="none";mitisuoding=false;bsobj.outerHTML="";eval(tempdom.getAttribute("code"));yinxiao('lv');gx1();}else{alert("答案不正确!请根据提示仔细想想,及检查有无错别字!");}
}
}
function menuxml(){  //输出menuxml
document.write(menudom.getElementsByTagName("caidan")[0].text+"\n\n")
}
function yuansuxml(whatnum){  //返回元素
var tempx=yuansudom.getElementsByTagName("n"+whatnum)[0]
if(tempx==null)return null
return tempx.getAttribute("img")+",,,"+tempx.getAttribute("id")+",,,"+tempx.getAttribute("wid")+",,,"+tempx.getAttribute("hei")+",,,"+tempx.getAttribute("mar")+",,,"+tempx.getAttribute("touming")+",,,"+tempx.getAttribute("value")
}
function boosxml(listname,listattname){  //返回怪物节点
return boosdom.getElementsByTagName(listname)[0].getAttribute(listattname)
}
function getxml(f_nodename,f_whoxml){  //获取XML节点
var t_dom=uidom
if(f_whoxml==2){  //地图
t_dom=ditudom
var temptxt=t_dom.getElementsByTagName(f_nodename)[0]
return temptxt.getAttribute("rpgtdshang")+",,,,,"+temptxt.getAttribute("rpgtdxia")+",,,,,"+temptxt.getAttribute("backsound")+",,,,,"+temptxt.getAttribute("jihao")+",,,,,"+temptxt.getAttribute("shitu")+",,,,,"+temptxt.text
}
if(f_whoxml==1){  //剧情XML
t_dom=juqingdom
var tempvalue=t_dom.getElementsByTagName(f_nodename)[0].getAttribute("dz")
if(tempvalue==null){
return t_dom.getElementsByTagName(f_nodename)[0].text
}else{
return tempvalue+"tempvalue"+t_dom.getElementsByTagName(f_nodename)[0].text
}}
var t_ay=f_nodename.split(",")  //UIXML界面输出
if(t_ay.length!=0){
for(var i=0;i<t_ay.length;i++){
document.write(t_dom.getElementsByTagName(t_ay[i])[0].text+"\n\n")
}}else{
document.write(t_dom.getElementsByTagName(f_nodename)[0].text+"\n\n")
}}