<!--#include file="connection.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/plus_check.asp"-->
<!-- #include file="pet_conn.asp" -->
<%

dim menu,savem,rsbank,rssql,chentitle,chenbackasp,stats,errmsg,founderr

chentitle="宠物竞技场"
Dv_plus.name="petcenter"
Dv_plus.checklogin()
Dvbbs.LoadTemplates("")
Dvbbs.Stats="宠物竞技场"
Dvbbs.Nav()
Dvbbs.Head_var 0,"","宠物中心","petcenter.asp"

if DvBBS.UserId = 0 then
	AlarmErrmsg
else
    dim money,smoney,saveday,allmoney,time1,time2,time3,daikuang,dkdu,daiday,sucmsg
    dim Form_userphoto,Form_FaceUrl,Form_FaceWidth,Form_FaceHeight
    
    Dim Rs,SQL

	set rs=Dvbbs.execute("select Jamonery from [Jauser] where Jauid="&DvBBS.UserId)
      	
    money=rs("Jamonery")

	    

    rs.close
    

    

    sql = "SELECT * FROM mypetdata WHERE username='"&Dvbbs.MemberName&"' "
    rs.open sql,conn,1,3
    if rs.eof then
        call showmessage("你还没有宠物啊，快攒钱去买吧~","petshop.asp")
        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()
petlevel = (Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)) * (Log(rs("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("mypetname")
pethp=rs("mypethp")
petatk=rs("mypetatk")+rs("item1")+rs("item2")+2+level1
petdef=rs("mypetdef")+rs("item3")+rs("item4")+rs("item5")+3+level1
if(petshowlevel<2) then 
    petmaxhp=DEF_PET_basichp 
    else
    petmaxhp=DEF_PET_basichp+petshowlevel*5
end if
hpf= int (100 * (pethp / petmaxhp)) - 1

openpk1 = rs("openpk")
if (rs("openpk")<2) then
    petpk="等待挑战"
    else
    petpk="拒绝挑战"
end if
if ( hpf >= 98 ) then hpf = hpf - 2 end if
        

if(request("action") = "atkpet") then
    dim rs2,atkname
    dim userpetlevel,leveltmp,level2,atkrand,defrand,atktemp,atktemp2,exp1,exp2,userpetshowlevel,userhp,atktmp,atk,atktmp2,atk2
    atkname = request("atkname")
    set rs2=conn.execute("SELECT * FROM mypetdata WHERE username='"& atkname &"'")
    if rs2.eof then
        call showmessage("他（她）没有宠物，不能PK啊~","petbattle.asp")
    else
        userpetlevel=rs2("mypetlevel")
        time1=now()
        time2=DateDiff("s", rs("pktime"), time1)
        if(Dvbbs.MemberName = atkname) then
            call showmessage("干吗啊，自己打自己！","petbattle.asp")
            elseif (rs2("mypethp")<DEF_PET_petpkhp or rs2("mypetdead") = 1) then
                call showmessage("他（她）的宠物已经不行了，不能PK啊~","petbattle.asp")
            elseif (rs2("openpk")>1) then
                call showmessage("他（她）不接受PK~","petbattle.asp")
            elseif (openpk1>1) then
                call showmessage("你关闭了PK系统，所以不能PK~","petbattle.asp")
            elseif(time2<DEF_PET_petpktime) then
                time3=DEF_PET_petpktime-time2
            	call showmessage("不能连续攻击，请"& time3 &"秒后再攻击","petbattle.asp")
            else
                if (rs("mypetdead") = 1) then
                    call showmessage("你的宝宝好象已经挂了， 救活它再PK吧。","petbattle.asp")
                end if
                leveltmp=abs(petshowlevel-userpetlevel)
                if(leveltmp>DEF_PET_petpklv) then
                    call showmessage("你们两个级别相差太大，不能PK","petbattle.asp")
                end if
                level1=int(rs("mypetlevel")/2)
                level2=int(rs2("mypetlevel")/2)
                
                Randomize '初始化随机数生成器。
                atkrand=Int((10 * Rnd) + 0)
                Randomize '初始化随机数生成器。
                defrand=Int((10 * Rnd) + 0)
                atktemp=(rs("mypetatk")+rs("item1")+rs("item2")+2+level1)-(rs2("mypetdef")+rs2("item3")+rs2("item4")+rs2("item5")+3+level2)
                atktmp=round(atktemp+atktemp*(atkrand/5))
                if (atktmp<1) then
                    atk=atkrand
                elseif (atktmp>10) then
                    atk=10
                elseif (atktmp>rs2("mypetmaxhp")) then
                    atk=rs2("mypetmaxhp")
                else 
                    atk=atktmp
                end if
                exp1=int(atk/10)
                
                atktemp2=(rs2("mypetatk")+rs2("item1")+rs2("item2")+2+level2)-(rs("mypetdef")+rs("item3")+rs("item4")+rs("item5")+3+level1)
                atktmp2=round(atktemp2+atktemp2*(defrand/5))
                if (atktmp2<1) then
                    atk2=defrand
                elseif (atktmp2>10) then
                    atk2=10
                elseif (atktmp2>rs("mypetmaxhp")) then
                    atk2=rs("mypetmaxhp")
                else 
                    atk2=atktmp2
                end if
                exp2=int(atk2/10)


                petlevel = (Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10))
                petshowlevel = int (petlevel + 1)
                userpetlevel = (Log(rs2("mypetexp")) / Log(10)) * (Log(rs2("mypetexp")) / Log(10)) * (Log(rs2("mypetexp")) / Log(10))
                userpetshowlevel = int (userpetlevel + 1)
                
                if (rs2("mypethp")-atk<1) then
                    userhp=0
                    mypetdead=1
                else 
                   userhp=rs2("mypethp")-atk
                   mypetdead=0
                end if
                conn.ExeCute("UPDATE mypetdata SET mypetexp=mypetexp+"& exp2 &",mypetlevel="&userpetshowlevel&",mypethp="&userhp&",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.ExeCute("UPDATE mypetdata SET mypetexp=mypetexp+"&exp1&",mypetlevel="&petshowlevel&",mypethp="&pethp&",mypetdead="&mypetdead&",pktime='"&time2&"' WHERE username='"& Dvbbs.MemberName &"'")
                
                if DEF_PET_sendbattlemsg = 1 then '发送攻击短消息
                    Dvbbs.ExeCute("INSERT INTO Dv_Message (Incept, Sender, Title, Content, SendTime,flag, isSend) values('"&atkname&"','宠物管理员','你的宝宝受到攻击','防御成功，你的宝宝受到 "&Dvbbs.MemberName&" 的宝宝 "&atk&" 点攻击，你增加了 "&exp2&" 点经验值，你的宝宝进行了反击，使他（她）受到 "&atk2&" 点攻击，他（她）增加了 "&exp1&" 点经验值！','"&now&"','0','1')")
                    UPDATE_User_Msg(atkname)
                end if

                dim snum
                Randomize
                snum=Int((3 * Rnd) + 1)
                call showmessage("<br><img src=""images/attack0"& snum &".gif"" width=270 width=100><br><br>你的宝宝给了 "&atkname&" 的宝宝 "&atk&" 点攻击，<br>你增加了 "&exp1&" 点经验值，他（她）宝宝进行了反击，<br>使你受到 "&atk2&" 点攻击，<br>他（她）增加了 "&exp2&" 点经验值！","petbattle.asp")
            end if
        end if
    end if
    
%>
<table border="0" align="center" cellpadding="3" cellspacing="1" class="TableBorder1">
  <tr> 
    <th height="25">&nbsp;</th>
  </tr>
  <tr> 
    <td height="200" valign="top" class=TableBody1> 
      <table width="100%" border="0" cellspacing="1" cellpadding="5" align="center" class=TBone>
        <tr> 
          <td height=27 align="center" class=tbhead2><b><font class=HeadFont><%=stats%></font></b></td>
        </tr>
        <tr> 
          <td class=tbbg1> 
            <table width="100%"  border="0" align="center" cellpadding="3" cellspacing="3">
              <tr>
                <td width="24%" rowspan="3">
                  <div align="center"> 
                    <table width="79%"  border="0" align="center" cellpadding="3" cellspacing="3">
                      <tr>
                        <td width="100%">
                          <div align="center">我的资料</div>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <div align="center"> 
                            <script src=z_visual_const2.asp?n=1></script>
                            <br>
                            <img src=../images/blank.gif width=2 height=5><br>
                          </div>
                        </td>
                      </tr>
                      <tr> 
                        <td> 
                          <div align="center"> <nobr>现金货币: <%=money%></nobr> </div>
                        </td>
                      </tr>
                    </table>
                    <br>
                    <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("mypet")%> <br>
                          宠物级别：<%=petshowlevel%><br>
                          攻击力：<%=petatk%><br>
                          防御力：<%=petdef%><br>
                          宠物PK：<%=petpk%> <br>
                          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("item3")%>.gif" alt="宠物头盔"></div>
                            </td>
                            <td width="35%">&nbsp;</td>
                          </tr>
                          <tr> 
                            <td>
                              <div align="right"><img height=30 src="images/pet/sword/<%=rs("item1")%>.gif" alt="宠物武器"></div>
                            </td>
                            <td rowspan="2">
                              <div align="center"><img src='images/pet/<%=petpic%>/<%=petpic%><%=levelpic%>.gif'></div>
                            </td>
                            <td><img src="images/pet/body/<%=rs("item4")%>.gif" alt="我的盔甲"></td>
                          </tr>
                          <tr> 
                            <td>
                              <div align="right"><img src="images/pet/necklace/<%=rs("item2")%>.gif" alt="宠物项链" ></div>
                            </td>
                            <td><img src="images/pet/foot/<%=rs("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>HP药水拥有数量：<%=rs("hpitem")%> [<a href="petitemuse.asp?action=usehp" target="_blank">使用</a>]</div>
                      </td>
                      <td width="25%">
                        <div align="center">攻击力拥有数量：<%=rs("atkitem")%> [<a href="petitemuse.asp?action=useatk" target="_blank">使用</a>]</div>
                      </td>
                    </tr>
                    <tr> 
                      <td>
                        <div align=center>SP药水拥有数量：<%=rs("spitem")%> [<a href="petitemuse.asp?action=usesp" target="_blank">使用</a>]</div>
                      </td>
                      <td>
                        <div align="center">防御力拥有数量：<%=rs("defitem")%> [<a href="petitemuse.asp?action=usedef" target="_blank">使用</a>]</div>
                      </td>
                    </tr>
                    <tr> 
                      <td width="25%"> 
                        <div align="center">EXP药水拥有数量：<%=rs("expitem")%> [<a href="petitemuse.asp?action=useexp" target="_blank">使用</a>]</div>
                      </td>
                      <td>
                        <div align="center">复活拥有数量：<%=rs("liveitem")%> [<a href="petitemuse.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></div>
                                </div>
                              </td>
                            </tr>
                            <tr> 
                              <td colspan="2"></td>
                            </tr>
                          </table>
                        </form>
                        <div align="right"></div>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<% End If : End If :  Set Dv_plus=Nothing : Dvbbs.Footer%>
<%
'更新用户短信通知信息（新短信条数||新短讯ID||发信人名）
Sub UPDATE_User_Msg(username)
	Dim msginfo,i,UP_UserInfo,newmsg
	newmsg=newincept(username)
	If newmsg>0 Then
		msginfo=newincept(username) & "||" & inceptid(1,username) & "||" & inceptid(2,username)
	Else
		msginfo="0||0||null"
	End If
	'Dvbbs.execute("UPDATE [Dv_User] Set UserMsg='"&Dvbbs.CheckStr(msginfo)&"' WHERE username='"&Dvbbs.CheckStr(username)&"'")
	If username=Dvbbs.MemberName Then
		UP_UserInfo=Session(Dvbbs.CacheName & "UserID")
		UP_UserInfo(30)=msginfo
		Session(Dvbbs.CacheName & "UserID")=UP_UserInfo
	Else
		Call Dvbbs.NeedUpdateList(username,1)
	End If
End Sub

'统计留言
Function newincept(iusername)
Dim Rs
Rs=Dvbbs.execute("SELECT Count(id) FROM Dv_Message WHERE flag=0 And issend=1 And DelR=0 And incept='"& iusername &"'")
    newincept=Rs(0)
	Set Rs=nothing
	If isnull(newincept) Then newincept=0
End Function

Function inceptid(stype,iusername)
	Set Rs=Dvbbs.execute("SELECT top 1 id,sender FROM Dv_Message WHERE flag=0 And issend=1 And DelR=0 And incept='"& iusername &"'")
	If not rs.eof Then
		If stype=1 Then
			inceptid=Rs(0)
		Else
			inceptid=Rs(1)
		End If
	Else
		If stype=1 Then
			inceptid=0
		Else
			inceptid="null"
		End If
	End If
	Set Rs=nothing
End Function
%>