<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!-- #include file=pet_conn.asp -->
<!--#include file="inc/plus_check.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 userWealth from [DV_user] where UserID="&DvBBS.UserId)
	  	
	money=rs("userWealth")

	rs.close
	
	sql = "SELECT * FROM mypetdata WHERE username='"&DvBBS.MemberName&"' "
	rs.open sql,connpet,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,imgset

'用很无聊的循环使用变量得到每种道具的名字……
dim rs3,swordname,necklacename,headname,bodyname,footname
set rs3 = connpet.execute("select * from petitemshop where itemclass='sword' and itemnum="&rs("item1"))
swordname = rs3("itemname")
rs3.close
set rs3 = connpet.execute("select * from petitemshop where itemclass='necklace' and itemnum="&rs("item2"))
necklacename = rs3("itemname")
rs3.close
set rs3 = connpet.execute("select * from petitemshop where itemclass='head' and itemnum="&rs("item3"))
headname = rs3("itemname")
rs3.close
set rs3 = connpet.execute("select * from petitemshop where itemclass='body' and itemnum="&rs("item4"))
bodyname = rs3("itemname")
rs3.close
set rs3 = connpet.execute("select * from petitemshop where itemclass='foot' and itemnum="&rs("item5"))
footname = rs3("itemname")
rs3.close

t=now()
today = date()
petlevel = sqr((Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)) * (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("item1Num")+rs("item2Num")+2+level1
petdef=rs("mypetdef")+rs("item3Num")+rs("item4Num")+rs("item5Num")+3+level1
imgset = rs("imgset") 

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 pethp<1 or rs("mypetsp")<1 then
	petdead="死亡"
else
	petdead="生存"
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=connpet.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~","petother.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 not Dvbbs.master and (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)

				'属性选择
				select case rs("mypetsx")
					case "金"
						if rs2("mypetsx") = "木" then atkrand=cint(atkrand*1.5)
						if rs2("mypetsx") = "土" then atkrand=cint(atkrand*0.75)
						if rs2("mypetsx") = "龙" then atkrand=cint(atkrand*0.85)

					case "木"
						if rs2("mypetsx") = "水" then atkrand=cint(atkrand*1.5)
						if rs2("mypetsx") = "金" then atkrand=cint(atkrand*0.75)
						if rs2("mypetsx") = "龙" then atkrand=cint(atkrand*0.85)

					case "水"
						if rs2("mypetsx") = "火" then atkrand=cint(atkrand*1.5)
						if rs2("mypetsx") = "木" then atkrand=cint(atkrand*0.75)
						if rs2("mypetsx") = "龙" then atkrand=cint(atkrand*0.85)

					case "火"
						if rs2("mypetsx") = "土" then atkrand=cint(atkrand*1.5)
						if rs2("mypetsx") = "水" then atkrand=cint(atkrand*0.75)
						if rs2("mypetsx") = "龙" then atkrand=cint(atkrand*0.85)

					case "土"
						if rs2("mypetsx") = "金" then atkrand=cint(atkrand*1.5)
						if rs2("mypetsx") = "火" then atkrand=cint(atkrand*0.75)
						if rs2("mypetsx") = "龙" then atkrand=cint(atkrand*0.85)

					case "无"
						if rs2("mypetsx") = "龙" then atkrand=cint(atkrand*0.85)

					case "龙"
                                                atkrand=cint(atkrand*1.5)
				end select
				atktemp=(rs("mypetatk")+rs("item1Num")+rs("item2Num")+2+level1)-(rs2("mypetdef")+rs2("item3Num")+rs2("item4Num")+rs2("item5Num")+3+level2)		'攻击+2表示武器至少提供1点攻击 防御+3表示防具至少提供1点防御
				atktmp=round(atktemp+atktemp*(atkrand/5))
				if (atktmp<1) then
					atk=atkrand
				elseif not Dvbbs.master and (atktmp>100) then
					atk=101
				elseif (atktmp>rs2("mypetmaxhp")) then
					atk=rs2("mypetmaxhp")
				else 
					atk=atktmp
				end if
				exp2=int(atk/10)
				
				atktemp2=(rs2("mypetatk")+rs2("item1Num")+rs2("item2Num")+2+level2)-(rs("mypetdef")+rs("item3Num")+rs("item4Num")+rs("item5Num")+3+level1)
				atktmp2=round(atktemp2+atktemp2*(defrand/5))
				if (atktmp2<1) then
					atk2=defrand
				elseif (atktmp2>100) then
					atk2=101
				elseif (atktmp2>rs("mypetmaxhp")) then
					atk2=rs("mypetmaxhp")
				else 
					atk2=atktmp2
				end if
				exp1=int(atk2/10)
				dim expz
				expz=exp1+exp2
				randomize
				exp1=cint(expz*rnd)+1
				exp2=expz-exp1+2


				petlevel = sqr((Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)))
				petshowlevel = int (petlevel + 1)
				userpetlevel = sqr((Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)) * (Log(rs("mypetexp")) / Log(10)) * (Log(rs("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
				connpet.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()
				connpet.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&"','你的宝宝受到攻击','防御成功，你的宝宝受到 "&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=""dv_plus/pet/attack0"& snum &".gif"" width=270 width=100><br><br>你的宝宝给了 "&atkname&" 的宝宝 "&atk&" 点攻击，<br>你增加了 "&exp1&" 点经验值，他（她）宝宝进行了反击，<br>使你受到 "&atk2&" 点攻击，<br>他（她）增加了 "&exp2&" 点经验值！","petbattle.asp?atkname="&atkname&"")
			end if
		end if
	end if
	
%>
<table  border="0" cellspacing="1" cellpadding="5" align="center" class=tableborder4>
  <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">
					<%
            		If IsNumeric(Dvbbs.MyUserInfo(12)) And IsNumeric(Dvbbs.MyUserInfo(13)) And Dvbbs.MyUserInfo(13)<>"" And Dvbbs.MyUserInfo(12)<>"" Then
            			If Clng(Dvbbs.MyUserInfo(13))=Clng(Dvbbs.Forum_Setting(39)) And Clng(Dvbbs.MyUserInfo(12))=Clng(Dvbbs.Forum_Setting(38)) Then
            			response.write "<img src="&Dvbbs.MyUserInfo(11)&">"
            			Else
            			response.write "<img src="&Dvbbs.MyUserInfo(11)&" width=60 height=60>"
            			End If
            		Else
            			response.write "<img src=dv_plus/pet/logo_2.gif>"
            		End If
					%>
					<br><img src=../dv_plus/pet/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>
						  宠物转生：<%=rs("relive")%><br>
						  宠物状态：<%=petdead%><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='dv_plus/pet/rpg/img_left.gif' width=3></TD>
							  <TD width=114 background="dv_plus/pet/rpg/img_backing.gif" height=13><img src='dv_plus/pet/rpg/orange.gif' width='<%=hpf%>%' height='9'><img src='dv_plus/pet/rpg/hp.gif' height='9'></td>
							  <TD width=3 height=13><IMG height=13 src='dv_plus/pet/rpg/img_right.gif' width=3></TD>
							</tr>
						  </table>
						  EXP : <%=petep%>%[<%=rs("mypetexp")%>] 
						  <table width='120' border='0' cellspacing='0' cellpadding='0' bordercolor='#000000'>
							<tr> 
							  <TD width=3 height=13><IMG height=13 src='dv_plus/pet/rpg/img_left.gif' width=3></TD>
							  <TD width=114 background="dv_plus/pet/rpg/img_backing.gif" height=13><img src='dv_plus/pet/rpg/blue.gif' width='<%=petep%>%' height='9'><img src='dv_plus/pet/rpg/exp.gif' height='9'></td>
							  <TD width=3 height=13><IMG height=13 src='dv_plus/pet/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="dv_plus/pet/pet/head/<%=rs("item3")%>.gif" alt="<%=headname%> 防御力 <%=rs("item3Num")%>"></div></td>
							<td width="35%">&nbsp;</td>
						</tr>
						<tr> 
							<td><div align="right"><img height=30 src="dv_plus/pet/pet/sword/<%=rs("item1")%>.gif" alt="<%=swordname%> 攻击力 <%=rs("item1Num")%>"></div></td>
							<td rowspan="2"><div align="center">
							<%if rs("imgset")=-1 then%>
							<img src='dv_plus/pet/pet/<%=petpic%>/<%=petpic%><%=levelpic%>.gif' border="0">
							<%else%>
							<img src='dv_plus/pet/pet/<%=petpic%>/<%=petpic%><%=imgset%>.gif' border="0">
							<%end if%>

							</div></td>
							<td><img src="dv_plus/pet/pet/body/<%=rs("item4")%>.gif" alt="<%=bodyname%> 防御力 <%=rs("item4Num")%>"></td>
						</tr>
						<tr> 
							<td><div align="right"><img src="dv_plus/pet/pet/necklace/<%=rs("item2")%>.gif" alt="<%=necklacename%> 攻击力 <%=rs("item2Num")%>" ></div></td>
							<td><img src="dv_plus/pet/pet/foot/<%=rs("item5")%>.gif" alt="<%=footname%> 防御力 <%=rs("item5Num")%>"></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><a href=pettop.asp?action=pkon>宠物竞技名单</a>&nbsp;&nbsp;点击宠物名字展开攻击&nbsp;&nbsp;&nbsp;&nbsp;
				  <% if not request("atkname")="" then%>
					<a href="petbattle.asp?atkname=<%=request("atkname")%>&action=atkpet"><font color=red>继续攻击</font><%=request("atkname")%>的宠物</a>
				  <%end if%>
				  </tr>
						  <th width="20%">宠物主人</th>
						  <th width="20%">宠物名字</th>
						  <th width="15%">宠物等级</th>
						  <th width="15%">宠物攻击力</th>
						  <th width="15%">宠物防御力</th>
						  <th width="15%">宠物状态</th>
					</table>
					  <!-- #include file=petpklist.asp -->
						<div align="right"></div></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
%>