<!--#include file="setup_pet.asp"-->
<!--#include file="pet_config.asp"-->
<!--#include file="pet_conn.asp"-->
<%
top
if Request.Cookies("username")=empty then error("<li>您还未<a href=login.asp>登录</a>论坛")

    dim money,smoney,saveday,allmoney,time1,time2,time3,daikuang,dkdu,daiday,sucmsg
    dim Form_userphoto,Form_FaceUrl,Form_FaceWidth,Form_FaceHeight
    
    Dim Rs_pet,SQL_pet

	set rs_pet=conn.execute("select money from [user] where username='"&Request.Cookies("username")&"'")
      	
    money=rs_pet("money")

	    

    rs_pet.close

    

    sql_pet = "SELECT * FROM mypetdata WHERE username='"&Request.Cookies("username")&"' "
    rs_pet.open sql_pet,conn_pet,1,3
    if rs_pet.eof then
        error("你在论坛还没有宠物啊，<a href=petshop.asp>抢先去买一个吧~</a>")
        else

dim t,today,petdiff,pett,petlevel,petep,petshowlevel,levelpic,intval,level1,petpic,pethp,petmaxhp
dim petatk,petdef,updat,newpettoday,petsp,petsex,petpk
dim hpf,spf,mypetdead,petdead,mypetsex,openpk1
dim item1,item2,item3,item4,item5,mypet,mypetsx,hpitem,atkitem,spitem,defitem,expitem,liveitem        
t=now()
today = date()
petdiff = DateDiff("d", rs_pet("petregdate"), today)
petlevel = (Log(rs_pet("mypetexp")) / Log(10)) * (Log(rs_pet("mypetexp")) / Log(10)) * (Log(rs_pet("mypetexp")) / Log(10))
petep = int (100 * (petlevel - int (petlevel)))
petshowlevel = int (petlevel + 1)
levelpic=int(petshowlevel/10)
if levelpic>10 then levelpic=11 end if
level1=int(petshowlevel/2)
petpic=rs_pet("mypetname")
pethp=rs_pet("mypethp")
petmaxhp=rs_pet("mypetmaxhp")
petatk=rs_pet("mypetatk")+rs_pet("item1")+rs_pet("item2")+2+level1
petdef=rs_pet("mypetdef")+rs_pet("item3")+rs_pet("item4")+rs_pet("item5")+3+level1
updat=0
newpettoday = Now()
if petshowlevel<2 then 
    petmaxhp = DEF_PET_basichp
else
    petmaxhp=DEF_PET_basichp + petshowlevel*5
end if
if pethp > petmaxhp then
    pethp = petmaxhp
end if
petsp=rs_pet("mypetsp")-pett*DEF_PET_basicsp2
if petsp>DEF_PET_basicsp then
    petsp=DEF_PET_basicsp
end if 
if pett>0 then
    updat=1
end if
hpf= int(100 * (pethp / petmaxhp)) - 1
spf= int(100 * (petsp / DEF_PET_basicsp)) - 1
if pethp<1 then
    pethp=0
    mypetdead=1
    updat=1
elseif petsp<1 then
    petsp=0
    mypetdead=1
    updat=1
else 
    mypetdead=0
    updat=1
end if
if pethp<1 or petsp<1 then
    petdead="死亡"
else
    petdead="生存"
end if
if rs_pet("mypetsex")<2 then 
    petsex="雄"
    else 
    petsex="雌"
end if
openpk1 = rs_pet("openpk")
if (rs_pet("openpk")<2) then
    petpk="等待挑战"
else
    petpk="拒绝挑战"
end if
if hpf >= 98 then hpf = hpf - 2 end if
if spf >= 98 then spf = spf - 2 end if

if updat=1 then
    sql_pet = "UPDATE mypetdata SET mypetlevel="& petshowlevel &",mypethp="& pethp &",mypetsp="&petsp&",mypetmaxhp="&petmaxhp&",mypetdead="&mypetdead&",petregdate='"&newpettoday&"' WHERE username='"&Request.Cookies("username")&"'"
    rs_pet.update
    updat=0


mypethp = rs_pet("mypethp")
mypetmaxhp = rs_pet("mypetmaxhp")
mypetsp = rs_pet("mypetsp")
mypetdead =rs_pet("mypetdead")

basichp=def_pet_basichp
basicsp=DEF_PET_basicsp
basicusehp=def_pet_basicusehp
basicuseexp=def_pet_basicuseexp
atkup=def_pet_atkup
defup=def_pet_defup
hptemp=mypetmaxhp-mypethp
pettoday = now()


if(request("action") = "atkpet") then
    dim rs_pet2,atkname
    dim userpetlevel,leveltmp,level2,atkrand,defrand,atktemp,atktemp2,exp1,exp2,userpetshowlevel,userhp,atktmp,atk,atktmp2,atk2
    atkname = request("atkname")
    set rs_pet2=conn_pet.execute("SELECT * FROM mypetdata WHERE username='"& atkname &"'")
    if rs_pet2.eof then
         error("他（她）没有宠物，不能PK啊~")
    else
        userpetlevel=rs_pet2("mypetlevel")
        time1=now()
        time2=DateDiff("s", rs_pet("pktime"), time1)
        if(Request.Cookies("username") = atkname) then
             error("干吗啊，自己打自己！")
            elseif (rs_pet2("mypethp")<DEF_PET_petpkhp or rs_pet2("mypetdead") = 1) then
                 error("他（她）的宠物已经不行了，不能PK啊~")
            elseif (rs_pet2("openpk")>1) then
                 error("他（她）不接受PK~")
            elseif (openpk1>1) then
                 error("你关闭了PK系统，所以不能PK~")
            elseif(time2<DEF_PET_petpktime) then
                time3=DEF_PET_petpktime-time2
            	 error("不能连续攻击，请"& time3 &"秒后再攻击")
            else
                if (rs_pet("mypetdead") = 1) then
                     error("你的宝宝好象已经挂了， 救活它再PK吧。")
                end if
                leveltmp=abs(petshowlevel-userpetlevel)
                if(leveltmp>DEF_PET_petpklv) then
                    error("你们两个级别相差太大，不能PK.")

 end if
		
                level1=int(rs_pet("mypetlevel")/2)
                level2=int(rs_pet2("mypetlevel")/2)
                
                Randomize '初始化随机数生成器。
                atkrand=Int((10 * Rnd) + 0)
                Randomize '初始化随机数生成器。
                defrand=Int((10 * Rnd) + 0)
                atktemp=(rs_pet("mypetatk")+rs_pet("item1")+rs_pet("item2")+2+level1)-(rs_pet2("mypetdef")+rs_pet2("item3")+rs_pet2("item4")+rs_pet2("item5")+3+level2)
                atktmp=round(atktemp+atktemp*(atkrand/5))
                if (atktmp<1) then
                    atk=atkrand
     
                elseif (atktmp>rs_pet2("mypetmaxhp")) then
                    atk=rs_pet2("mypetmaxhp")
                else 
                    atk=atktmp
                end if
                exp1=int(atk)
                
                atktemp2=(rs_pet2("mypetatk")+rs_pet2("item1")+rs_pet2("item2")+2+level2)-(rs_pet("mypetdef")+rs_pet("item3")+rs_pet("item4")+rs_pet("item5")+3+level1)
                atktmp2=round(atktemp2+atktemp2*(defrand/5))
                if (atktmp2<1) then
                    atk2=defrand

                elseif (atktmp2>rs_pet("mypetmaxhp")) then
                    atk2=rs_pet("mypetmaxhp")
                else 
                    atk2=atktmp2
                end if
                exp2=int(atk2)
                petlevel = (Log(rs_pet("mypetexp")) / Log(10)) * (Log(rs_pet("mypetexp")) / Log(10)) * (Log(rs_pet("mypetexp")) / Log(10))
                petshowlevel = int (petlevel + 1)
            if(petshowlevel<2 ) then
                mypetmaxhp=basichp
            else 
                mypetmaxhp=basichp+petshowlevel*5+5
            end if
                userpetlevel = (Log(rs_pet2("mypetexp")) / Log(10)) * (Log(rs_pet2("mypetexp")) / Log(10)) * (Log(rs_pet2("mypetexp")) / Log(10))
                userpetshowlevel = int (userpetlevel + 1)
            if(userpetshowlevel<2 ) then
                userpetmaxhp=basichp+5
            else 
                userpetmaxhp=basichp+petshowlevel*5+5
            end if
            
            
                if (rs_pet2("mypethp")-atk<1) then
                    userhp=0
                    mypetdead=1
                else 
                   userhp=rs_pet2("mypethp")-atk
                   mypetdead=0
                end if


                conn_pet.ExeCute("UPDATE mypetdata SET mypetexp=mypetexp+"& exp2 &",mypetlevel="&userpetshowlevel&",mypethp="&userhp&",mypetmaxhp="&mypetmaxhp&",mypetdead="&mypetdead&" WHERE username='"&atkname&"'")
                
                if (pethp-atk2<1) then
                    pethp=0
                    mypetdead=1
                else
                    pethp=pethp-atk2
                    mypetdead=0
                end if
                
                time2=now()
                conn_pet.ExeCute("UPDATE mypetdata SET mypetexp=mypetexp+"&exp1&",mypetlevel="&petshowlevel&",mypethp="&pethp&",mypetmaxhp="&userpetmaxhp&",mypetdead="&mypetdead&",pktime='"&time2&"' WHERE username='"&Request.Cookies("username")&"'")
                

if DEF_PET_sendbattlemsg = 1 then '发送攻击短消息
sql="insert into message(author,incept,content) values ('"&Request.Cookies("username")&"','"&atkname&"','【系统消息】：你的宝宝受到"&Request.Cookies("username")&"的宝宝"&atk&"点攻击，你增加了 "&exp2&" 点经验值，你的宝宝进行了反击，使他(她)的宠物受到 "&atk2&" 点攻击，他(她)的宠物增加了 "&exp1&"点经验值')"
conn.Execute(SQL)
conn.execute("update [user] set newmessage=newmessage+1 where username='"&atkname&"'")
		dim snum
                Randomize
                snum=Int((3 * Rnd) + 1)
               
	message="<li><br><img src=""images/attack0"& snum &".gif"" width=270 width=100><br><br>你的宝宝给了 "&atkname&" 的宝宝 "&atk&" 点攻击，<br>你增加了 "&exp1&" 点经验值，他（她）宝宝进行了反击，<br>使你受到 "&atk2&" 点攻击，<br>他（她）增加了 "&exp2&" 点经验值！"



				succeed(message&"<meta http-equiv=refresh content=3;url='petbattle.asp'")

               end if
            end if
        end if
	  end if
	  end if
end if
%>
<title>宠物竞技场</title>
<table border=0 width=97% align=center cellspacing=1 cellpadding=4 class=a2>
<tr class=a3>
<td height=25>&nbsp;<img src=images/Forum_nav.gif>&nbsp; <%ClubTree%> → 
<a href="petcenter.asp">宠物中心</a></td>
</tr>
</table>
<table width="100%"  border="0" align="center" cellpadding="3" cellspacing="3">
<tr><td width="24%" rowspan="3"><div align="center"> 
                    <table width="90%"  border="0" align="center" cellpadding="3" cellspacing="3">
                      <tr>
                        <td><div align="center"></div>
<!-- #include file=petnav.asp --></td>
                      </tr>
                    </table>
                  </div>
<div align="center"></div></td>
                <td width="76%"> 
                  <table width='100%' border='0' cellpadding='1' cellspacing='1'>
                    <tr> 
                      <td width='33%'><div align="left"> 我的宠物状态 <br>
                          宠物名称：<%=rs_pet("mypet")%> <br>
                          宠物级别：<%=petshowlevel%><br>
                          攻击力：<%=petatk%><br>
                          防御力：<%=petdef%><br>
                          宠物PK：<%=petpk%> <br>
                          EXP: <%=petep%>%<br>

<table width='120' border='0' cellspacing='0' cellpadding='0' bordercolor='#000000'><tr><TD width=3 height=13><IMG height=13 src='images/rpg/img_left.gif' width=3></TD>
<TD width=114 background=images/rpg/img_backing.gif height=13><img src='images/rpg/blue.gif' width='<%=petep%>%' height='9'><img src='images/rpg/exp.gif' height='9'></td>
<TD width=3 height=13><IMG height=13 src='images/rpg/img_right.gif' width=3></TD>
</tr></table>
 
                          HP : <%=pethp%> / <%=petmaxhp%> 
                          <table width='120' border='0' cellspacing='0' cellpadding='0' bordercolor='#000000'>
                            <tr> 
                              <TD width=3 height=13><IMG height=13 src='images/rpg/img_left.gif' width=3></TD>
                              <TD width=114 background=images/rpg/img_backing.gif height=13><img src='images/rpg/orange.gif' width='<%=hpf%>%' height='9'><img src='images/rpg/hp.gif' height='9'></td>
                              <TD width=3 height=13><IMG height=13 src='images/rpg/img_right.gif' width=3></TD>
                            </tr>
                          </table>
                        </div></td>
                      <td><table width="100%" border="0" cellspacing="2" cellpadding="2">
                          <tr> 
                            <td width="35%">&nbsp;</td>
                            <td width="20%"> <div align="center"><img src="images/pet/head/<%=rs_pet("item3")%>.gif" alt="宠物头盔"></div></td>
                            <td width="35%">&nbsp;</td>
                          </tr>
                          <tr> 
                            <td><div align="right"><img height=30 src="images/pet/sword/<%=rs_pet("item1")%>.gif" alt="宠物武器"></div></td>
                            <td rowspan="2"><div align="center">
                      <%if pethp<1 then%>
                      <img src='images/pet/<%=petpic%>/<%=petpic%><%=levelpic%>.gif' style=filter:GRAY>
                      <%else%>
                      <img src='images/pet/<%=petpic%>/<%=petpic%><%=levelpic%>.gif'>
                      <%end if%></div></td>
                            <td><img src="images/pet/body/<%=rs_pet("item4")%>.gif" alt="我的盔甲"></td>
                          </tr>
                          <tr> 
                            <td><div align="right"><img src="images/pet/necklace/<%=rs_pet("item2")%>.gif" alt="宠物项链" ></div></td>
                            <td><img src="images/pet/foot/<%=rs_pet("item5")%>.gif" alt="宠物鞋子"></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table>
                </td>
              </tr>
<tr><td><TABLE cellSpacing=3 cellPadding=3 width="100%" align=center border=0>
                    <TR> 
                      <TD width="25%"> <DIV align=center>治愈药水拥有数量：<%=rs_pet("hpitem")%> 
                          [<a href="petmypet.asp?action=usehp" target="_blank">使用</a>]</DIV></TD>
                      <TD width="25%"><div align="center">攻击力拥有数量：<%=rs_pet("atkitem")%> 
                          [<a href="petmypet.asp?action=useatk" target="_blank">使用</a>]</div></TD>
                    </TR>
                    <TR> 
                      <TD><DIV align=center>糖果拥有数量：<%=rs_pet("spitem")%> [<a href="petmypet.asp?action=usesp" target="_blank">使用</a>]</DIV></TD>
                      <TD><div align="center">防御力拥有数量：<%=rs_pet("defitem")%> [<a href="petmypet.asp?action=usedef" target="_blank">使用</a>]</div></TD>
                      </TR>
                    <TR> 
                      <TD width="25%"> <div align="center">EXP药水拥有数量：<%=rs_pet("expitem")%> 
                          [<a href="petmypet.asp?action=useexp" target="_blank">使用</a>]</div></TD>
                      <TD><div align="center">复活拥有数量：<%=rs_pet("liveitem")%> [<a href="petmypet.asp?action=uselive" target="_blank">使用</a>]</div></TD>
                    </TR>
                  </TABLE>
                  <table width="100%" border="0" cellspacing="2" cellpadding="2">
                    <tr> 
                      <td> <form action="petbattle.asp" mtehod=post>
                          <table width="100%" height="100%" border="0" align="center" cellpadding="2" cellspacing="2">
                            <tr> 
                              <td width="34%"><div align="right">攻击目标宠物(请写其主人名字)：</div></td>
                              <td width="66%"><div align="center"> <div align="left">
                                  <input type="text" name="atkname">
                                  <input type="hidden" name="action" value="atkpet">
                                  <input type="submit" name="Submit" value="点到为止">
                                  &nbsp;<a href="pettop.asp?action=pkon">查看竞技场选手名单</a></a></div></td>
                            </tr>
                            <tr> 
                              <td colspan="2"></td>
                            </tr>
                          </table>
                        </form>
                        <div align="right"></div></td>
                    </tr>
                  </table></td>
</tr></table>
<%
htmlend
%>
