<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/plus_check.asp"-->
<!--#include file="YD_pet_conn.asp"-->

<%
dim menu,savem,rsbank,rssql,chentitle,chenbackasp,stats,errmsg,founderr,action
chentitle="我的宠物"
Dv_plus.name="petcenter"
'Dv_plus.checklogin()
Dvbbs.LoadTemplates("")
Dvbbs.Stats="我的宠物"
Dvbbs.Nav()
Dvbbs.Head_var 0,"","宠物中心","YD_petcenter.asp"

if DvBBS.UserId = 0 then
	AlarmErrmsg
else
	'宠物插件状态
	if DEF_PET_close>1 then
		'暂时关掉开始
		if not dvbbs.master then
			call showmessage("调试中,请以后再来~","index.asp")
		end if
		'暂时关掉结束
	end if

	dim money,smoney,saveday,allmoney,time1,time2,daikuang,dkdu,daiday,sucmsg,hpmaxskill,maxhp
	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("你还没有宠物啊，快攒钱去买吧~","YD_petshop.asp")
	else
		dim today,pett,petlevel,petep,petshowlevel,levelpic,intval,level1,petpic,pethp,petmaxhp,atkskill,defskill,lifeskill,luckskill,learnskill
		dim petatk,petdef,updat,petsp,petsex,petpk
		dim hpf,spf,mypetdead,petdead,mypetsex,str,ski,def,vit,szd,szd1,szd2,szd3,szd4,tszd,skill,tskill,it,skill1,skill2,skill3,skill4,skill5,skill6,speed
		dim item1,item2,item3,item4,item5,mypet,mypetsx,imgset	

		'宠物物品
		item1 = rs("item1")
		if isNull(item1) or item1="" then item1=0
		item2 = rs("item2")
		if isNull(item2) or item2="" then item2=0
		item3 = rs("item3")
		if isNull(item3) or item3="" then item3=0
		item4 = rs("item4")
		if isNull(item4) or item4="" then item4=0
		item5 = rs("item5")
		if isNull(item5) or item5="" then item5=0

		'用很无聊的循环使用变量得到每种道具的名字……
		dim rs3,swordname,necklacename,headname,bodyname,footname
		set rs3 = connpet.execute("select * from petitemshop where itemclass='sword' and itemnum="&item1)
		swordname = rs3("itemname")
		rs3.close
		set rs3 = connpet.execute("select * from petitemshop where itemclass='necklace' and itemnum="&item2)
		necklacename = rs3("itemname")
		rs3.close
		set rs3 = connpet.execute("select * from petitemshop where itemclass='head' and itemnum="&item3)
		headname = rs3("itemname")
		rs3.close
		set rs3 = connpet.execute("select * from petitemshop where itemclass='body' and itemnum="&item4)
		bodyname = rs3("itemname")
		rs3.close
		set rs3 = connpet.execute("select * from petitemshop where itemclass='foot' and itemnum="&item5)
		footname = rs3("itemname")
		rs3.close
		today = date()
		pett= DateDiff("d", rs("petregdate"), today)
		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)
		petpic=rs("mypetname")
		pethp=rs("mypethp")

		str=rs("str")
		ski=rs("ski")
		def=rs("def")
		vit=rs("vit")
		speed=rs("speed")+def
		szd=rs("szd")+petshowlevel*5-str-ski-def-vit
		skill=rs("skill")+petshowlevel-rs("atkskill")-rs("defskill")-rs("lifeskill")-rs("luckskill")-rs("learnskill")-rs("hpmaxskill")
		petatk=rs("mypetatk")+rs("item1Num")+rs("item2Num")+int(str/2)
		petdef=rs("mypetdef")+rs("item3Num")+rs("item4Num")+rs("item5Num")+int(ski/2)
		updat=0

		'获取生命上限
		hpmaxskill=1
		if rs("hpmaxskill")>0 then
			hpmaxskill=1+rs("hpmaxskill")/100
		end if 
		if rs("hpmaxskill")>30 then
			hpmaxskill=1.2+rs("hpmaxskill")/100
		end if 
		if rs("hpmaxskill")>100 then
			hpmaxskill=1.5+rs("hpmaxskill")/100
		end if 
		petmaxhp = int((rs("mypetmaxhp")+vit)*hpmaxskill)
		petsp=rs("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("mypetsex")<2 then 
			petsex="雄"
		else
			petsex="雌"
		end if

		if rs("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

		dim petkill
		if petdead="死亡" then
			petkill="d-"
		else
			petkill=""
		end if

		if updat=1 then
			sql = "UPDATE mypetdata SET mypetlevel="& petshowlevel &",mypethp="& pethp &",mypetsp="&petsp&",mypetdead="&mypetdead&",petregdate="&Pet_NowString&" WHERE username='"& DvBBS.MemberName &"'"
			connpet.ExeCute(sql)
			updat=0
		end if

		'宠物的攻击技能
		atkskill="atkskill_0"
		if rs("atkskill")>0 then
			atkskill="atkskill_1"
		end if

		if rs("atkskill")>30 then
			atkskill="atkskill_2"
		end if

		if rs("atkskill")>100 then
			atkskill="atkskill_3"
		end if

		'宠物的防御技能
		defskill="defskill_0"
		if rs("defskill")>0 then
			defskill="defskill_1"
		end if

		if rs("defskill")>30 then
			defskill="defskill_2"
		end if

		if rs("defskill")>100 then
			defskill="defskill_3"
		end if

		'宠物的治疗技能
		lifeskill="lifeskill_0"
		if rs("lifeskill")>0 then
			lifeskill="lifeskill_1"
		end if

		if rs("lifeskill")>30 then
			lifeskill="lifeskill_2"
		end if

		if rs("lifeskill")>100 then
			lifeskill="lifeskill_3"
		end if

		'宠物的幸运技能
		luckskill="luckskill_0"

		if rs("luckskill")>0 then
			luckskill="luckskill_1"
		end if

		if rs("luckskill")>30 then
			luckskill="luckskill_2"
		end if

		if rs("luckskill")>100 then
			luckskill="luckskill_3"
		end if

		'宠物的学习技能
		learnskill="learnskill_0"

		if rs("learnskill")>0 then
			learnskill="learnskill_1"
		end if

		if rs("learnskill")>30 then
			learnskill="learnskill_2"
		end if

		if rs("learnskill")>100 then
			learnskill="learnskill_3"
		end if

		'宠物的血魔技能
		hpmaxskill="hpmaxskill_0"

		if rs("hpmaxskill")>0 then
			hpmaxskill="hpmaxskill_1"
		end if

		if rs("hpmaxskill")>30 then
			hpmaxskill="hpmaxskill_2"
		end if

		if rs("hpmaxskill")>100 then
			hpmaxskill="hpmaxskill_3"
		end if

		item1 = rs("item1")
		item2 = rs("item2")
		item3 = rs("item3")
		item4 = rs("item4")
		item5 = rs("item5")
		mypet = rs("mypet")
		mypetsx = rs("mypetsx")
		imgset = rs("imgset") 
	end if

	'注册用户物品
	Dim Rs1,SQL1,hpitem,spitem,expitem,liveitem,weopitem,amoritem
	sql1 = "SELECT * FROM useritem WHERE username='"&Dvbbs.MemberName&"' "
	set rs1=connpet.ExeCute(sql1)
	hpitem=rs1("hpitem")
	spitem=rs1("spitem")
	expitem=rs1("expitem")
	liveitem=rs1("liveitem")	
	weopitem=rs1("weopitem")
	amoritem=rs1("amoritem")
	rs1.close
	szd1 = int(request("szd1"))
	szd2 = int(request("szd2"))
	szd3 = int(request("szd3"))
	szd4 = int(request("szd4"))

	if  request("action") = "" and szd>0 then
		action = "show"
	else
		action = lcase(request("action"))
	end if

	select case action
		case "sure"
			if (szd1<0 or szd2<0 or szd3<0 or szd4<0) then
				call showmessage("天哪，素质点不能是负的~","YD_petmypet.asp")
			end if
		case "add"
			tszd=szd-szd1-szd2-szd3-szd4
			if (tszd<0) then
				call showmessage("你没有那么多的素质点","YD_petmypet.asp")
			elseif (szd1<0 or szd2<0 or szd3<0 or szd4<0) then
				call showmessage("你输入的素质点有误，请重新输入~","YD_petmypet.asp")
			else
				Call UpdateUserInfo(-tszd,0,0,0,0,0)
				connpet.ExeCute("UPDATE mypetdata SET str=str+"&szd1&",ski=ski+"&szd2&",def=def+"&szd3&",vit=vit+"&szd4&" WHERE username='"&DvBBS.MemberName&"'")
				call showmessage("加点成功!<br><br>力量增加了 "&szd1&" 点<br>皮肤增加了 "&szd2&" 点<br>敏捷增加了 "&szd3&" 点<br>体力增加了 "&szd4&" 点","YD_petmypet.asp")
			end if
		case "addskill"
			tskill=skill
			skill1=rs("atkskill")
			skill2=rs("defskill")
			skill3=rs("lifeskill")
			skill4=rs("luckskill")
			skill5=rs("learnskill")
			skill6=rs("hpmaxskill")
			it=request("it")
			if it=1 then skill1=skill1+1 end if
			if it=2 then skill2=skill2+1 end if
			if it=3 then skill3=skill3+1 end if
			if it=4 then skill4=skill4+1 end if
			if it=5 then skill5=skill5+1 end if
			if it=6 then skill6=skill6+1 end if

			if (skill-1<0) then
				call showmessage("你没有那么多的技能点","YD_petmypet.asp")
			elseif (skill=0) then
				call showmessage("你输入的技能点有误，请重新输入~","YD_petmypet.asp")
			else
				Call UpdateUserInfo(-skill,0,0,0,0,0)
				connpet.ExeCute("UPDATE mypetdata SET atkskill="&skill1&",defskill="&skill2&",lifeskill="&skill3&",luckskill="&skill4&",learnskill="&skill5&",hpmaxskill="&skill6&" WHERE username='"&DvBBS.MemberName&"'")
				call showmessage("加点成功~","YD_petmypet.asp")
			end if	
	end select
	call main()
End If
Set Dv_plus=Nothing
Dvbbs.Footer

sub main()
%>
<table class=tableborder1 cellspacing=1 cellpadding=3 align=center>
  <tr>
    <th height=27 align=center><%=Dvbbs.stats%></th>
  </tr>
  <tr>
    <td class=TableBody1 width="100%">
      <table width="554" align="center" cellpadding="3" cellspacing="3">
	<tr>
	  <td width="178" rowspan="3" align="center"> 
	    <table width="79%"  border="0" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td width="100%" align="center">我的资料</td>
	      </tr>
	      <tr>
		<td align="center">
		<%
		'用户头像调用开始
		If IsNumeric(Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userwidth").text) And IsNumeric(Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userheight").text) And Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userheight").text<>"" And Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userwidth").text<>"" Then
			If Clng(Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userheight").text)=Clng(Dvbbs.Forum_Setting(39)) And Clng(Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userwidth").text)=Clng(Dvbbs.Forum_Setting(38)) Then
				response.write "<img src="&Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userface").text&">"
			Else
				response.write "<img src="&Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userface").text&" width=100 height=100>"
			End If
		Else
			response.write "<img src=images/logo_2.gif>"
		End If
		'用户头像调用结束
		%>
		</td>
	      </tr>
	      <tr>
		<td align="center"><nobr>现金货币: <%=money%></nobr></td>
	      </tr>
	    </table>
	    <br>
	    <table width="90%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td><!--#include file=YD_petnav.asp--></td>
	      </tr>
	    </table>
	    <br>
	    <br>
	    <table width="79%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td width="100%" align="center"><img src="YD_plus/YD_pet/PET/26.gif"></td>
	      </tr>
	    </table>
	  </td>
	  <td width="648">
	    <table width="494" cellspacing="2" cellpadding="2">
	      <tr>
		<td width="335">　
		  <table width="286" cellspacing="2" cellpadding="2">
		    <tr>
		      <td width="187">　</td>
		      <td width="105" align="center"><img src="YD_plus/YD_pet/PET/head/<%=rs("item3")%>.gif" alt="<%=headname%> 防御力 <%=rs("item3Num")%>"></td>
		      <td width="170">　</td>
		    </tr>
		    <tr>
		      <td width="187" align="right"><img height=30 src="YD_plus/YD_pet/PET/sword/<%=rs("item1")%>.gif" alt="<%=swordname%> 攻击力 <%=rs("item1Num")%>"></td>
		      <td rowspan="2" width="105" align="center">
			<%if rs("imgset")=-1 then%>
				<img src="YD_plus/YD_pet/PET/<%=petpic%>/<%=petkill%><%=petpic%><%=levelpic%>.gif" border="0">
			<%else%>
				<img src="YD_plus/YD_pet/PET/<%=petpic%>/<%=petkill%><%=petpic%><%=imgset%>.gif" border="0">
			<%end if%>
		      </td>
		      <td width="170"><img src="YD_plus/YD_pet/PET/body/<%=rs("item4")%>.gif" alt="<%=bodyname%> 防御力 <%=rs("item4Num")%>"></td>
		    </tr>
		    <tr> 
		      <td width="187" align="right"><img src="YD_plus/YD_pet/PET/necklace/<%=rs("item2")%>.gif" alt="<%=necklacename%> 攻击力 <%=rs("item2Num")%>"></td>
		      <td width="170"><img src="YD_plus/YD_pet/PET/foot/<%=rs("item5")%>.gif" alt="<%=footname%> 防御力 <%=rs("item5Num")%>"></td>
		    </tr>
		  </table>
		</td>
		<td width=33%>
		 HP : <%=pethp%> / <%=petmaxhp%>
		<br>
		  <table width=120 cellspacing="0" cellpadding="0">
		    <tr>
		      <TD width=3 height=13><IMG height=13 src="YD_plus/YD_pet/RPG/img_left.gif" width=3></TD>
		      <TD width=114 background=YD_plus/YD_pet/RPG/img_backing.gif height=13><img src="YD_plus/YD_pet/RPG/orange.gif" width="<%=hpf%>%" height="9"><img src="YD_plus/YD_pet/RPG/hp.gif" height="9"></td>
		      <TD width=3 height=13><IMG height=13 src="YD_plus/YD_pet/RPG/img_right.gif" width=3></TD>
		    </tr>
		  </table>
		SP : <%=petsp%> / <%=DEF_PET_basicsp%>
		<br>
		  <table width="120" cellspacing="0" cellpadding="0">
		    <tr>
		      <TD width=3 height=13><IMG height=13 src="YD_plus/YD_pet/RPG/img_left.gif" width=3></TD>
		      <TD width=114 background=YD_plus/YD_pet/RPG/img_backing.gif height=13><img src="YD_plus/YD_pet/RPG/green.gif" width="<%=spf%>%" height="9"><img src="YD_plus/YD_pet/RPG/mp.gif" height="9"></td>
		      <TD width=3 height=13><IMG height=13 src="YD_plus/YD_pet/RPG/img_right.gif" width=3></TD>
		    </tr>
		  </table>
		EXP : <%=petep%>%[<%=rs("mypetexp")%>]
		<br>
		  <table width="120" cellspacing="0" cellpadding="0">
		    <tr>
		      <TD width=3 height=13><IMG height=13 src="YD_plus/YD_pet/RPG/img_left.gif" width=3></TD>
		      <TD width=114 background=YD_plus/YD_pet/RPG/img_backing.gif height=13><img src="YD_plus/YD_pet/RPG/blue.gif" width="<%=petep%>%" height="9"><img src="YD_plus/YD_pet/RPG/exp.gif" height="9"></td>
		      <TD width=3 height=13><IMG height=13 src="YD_plus/YD_pet/RPG/img_right.gif" width=3></TD>
		    </tr>
		  </table>
		</td>
	      </tr>
	    </table>
	    <table width="100%" cellpadding="1" cellspacing="1">
	      <tr>
		<td width="33%" align="left">
		宠物名称：<%=mypet%><br>
		宠物性别：<%=petsex%><br>
		宠物状态：<%=petdead%><br>
		宠物属性：<%=mypetsx%><br>
		宠物PK：<%=petpk%><br>
		宠物转生：<%=rs("relive")%><br>
		宠物级别：<%=petshowlevel%>
		</td>
		<td width="33%">
		力量：<%=str%><br>
		皮肤：<%=ski%><br>
		敏捷：<%=def%><br>
		体力：<%=vit%><br>
		攻击力：<%=petatk%><br>
		防御力：<%=petdef%><br>
		攻击速度：<%=speed%>
		</td>
		<td width="33%">
		<%if action = "show" then%>
			<form action=YD_petmypet.asp name="name" mtehod=post>
			剩余素质点：<%=szd%><br>
			力量 +
			<input name="szd1" type="text" value="0" size="6" maxlength="5"><br>
			皮肤 +
			<input name="szd2" type="text" value="0" size="6" maxlength="5"><br>
			敏捷 +
			<input name="szd3" type="text" value="0" size="6" maxlength="5"><br>
			体力 +
			<input name="szd4" type="text" value="0" size="6" maxlength="5"><br>
			<input type="hidden" name="action" value="sure">
			<input type="submit" name="submit" value="加点">
			</form>
		<%end if%>

		<%if action = "sure" then%>
			<form action=YD_petmypet.asp name="name" mtehod=post>
			力量 + <%=szd1%> 点<br>
			皮肤 + <%=szd2%> 点<br>
			敏捷 + <%=szd3%> 点<br>
			体力 + <%=szd4%> 点<br>
			<input type="hidden" name="szd1" value="<%=szd1%>">
			<input type="hidden" name="szd2" value="<%=szd2%>">
			<input type="hidden" name="szd3" value="<%=szd3%>">
			<input type="hidden" name="szd4" value="<%=szd4%>">
			<input type="hidden" name="action" value="add">
			<input type="submit" value="确定">
			</form>
		<%end if%>
		</td>
	      </tr>
	    </table>
	  </td>
	</tr>
	<tr>
	  <td width="650" align="left">
	    <table cellpadding="0" cellspacing="0" width="495">
	      <tr>
		<td width="67" align="center"><a href="YD_petmypet.asp?action=addskill&it=1"><img src="YD_plus/YD_pet/PET/skill/<%=atkskill%>.jpg" border="0" width="42" height="48" alt="增加攻击技能？"></a></td>
		<td width="67" align="center"><a href="YD_petmypet.asp?action=addskill&it=2"><img src="YD_plus/YD_pet/PET/skill/<%=defskill%>.jpg" border="0" width="42" height="48" alt="增加防御技能？"></a></td>
		<td width="67" align="center"><a href="YD_petmypet.asp?action=addskill&it=3"><img src="YD_plus/YD_pet/PET/skill/<%=lifeskill%>.jpg" border="0" width="42" height="48" alt="增加治疗技能？"></a></td>
		<td width="68" align="center"><a href="YD_petmypet.asp?action=addskill&it=4"><img src="YD_plus/YD_pet/PET/skill/<%=luckskill%>.jpg" border="0" width="42" height="48" alt="增加幸运技能？"></a></td>
		<td width="68" align="center"><a href="YD_petmypet.asp?action=addskill&it=5"><img src="YD_plus/YD_pet/PET/skill/<%=learnskill%>.jpg" border="0" width="42" height="48" alt="增加学习技能？"></a></td>
		<td width="42" align="center"><a href="YD_petmypet.asp?action=addskill&it=6"><img src="YD_plus/YD_pet/PET/skill/<%=hpmaxskill%>.jpg" border="0" width="42" height="48" alt="增加生命技能？"></a></td>
		<td width="335" align="left">&nbsp;攻击技能：<%=rs("atkskill")%><br>
		&nbsp;防御技能：<%=rs("defskill")%><br>
		&nbsp;幸运技能：<%=rs("luckskill")%><br>
		&nbsp;总技能点：<%=rs("skill")+petshowlevel%><br>
		</td>
		<td width="398" align="left">&nbsp;治疗技能：<%=rs("lifeskill")%><br>
		&nbsp;生命技能：<%=rs("hpmaxskill")%><br>
		&nbsp;学习技能：<%=rs("learnskill")%><br>
		&nbsp;剩余技能：<%=skill%><br>
		</td>
	      </tr>
	    </table>
	  </td>
	</tr>
	<tr>
	  <td width="648">
	    <TABLE cellSpacing=3 cellPadding=3 width="100%" align=center>
	      <TR> 
		<TD colspan="4" align="center">★★★ <a href="YD_petitbox.asp">宠物物品箱</a> ★★★</TD>
	      </TR>
	      <tr>
		<TD width="25%" align=center><IMG height=35 src="YD_plus/YD_pet/PET/hp.gif" width=34><BR>HP药水</TD>
		<TD width="25%" align=center>拥有数量：<%=hpitem%><BR>[<a href="YD_petitemuse.asp?action=usehp">使用</a>]</TD>
		<TD width="25%" align=center><IMG height=35 src="YD_plus/YD_pet/PET/exp.gif" width=35><BR>EXP药水</TD>
		<TD width="25%" align=center>拥有数量：<%=expitem%><BR>[<a href="YD_petitemuse.asp?action=useexp">使用</a>]</TD>
	      </tr>
	      <tr>
		<TD align=center><img height=35 src="YD_plus/YD_pet/PET/sp.gif" width=35><BR>SP药水</TD>
		<TD align=center>拥有数量：<%=spitem%><BR>[<a href="YD_petitemuse.asp?action=usesp">使用</a>]</TD>
		<TD align=center><IMG height=35 src="YD_plus/YD_pet/PET/liv.gif" width=34><BR>复活药水</TD>
		<TD align=center>拥有数量：<%=liveitem%><BR>[<a href="YD_petitemuse.asp?action=uselive">使用</a>]</TD>
	      </tr>
	      <TR> 
		<TD colspan="4" align=center>　</TD>
	      </TR>
	    </TABLE>
	  </td>
	</tr>
      </table>
    </td>
  </tr>
</table>
<%
end sub
%>