<!--#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,hpmaxskill,maxhp
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 Rs,SQL
	sql = "SELECT * FROM mypetdata WHERE username='"&Dvbbs.MemberName&"' "
	set rs=connpet.ExeCute(sql)
	if rs.eof then
		call showmessage("你还没有宠物啊，快攒钱去买吧~","YD_petshop.asp")
		else
		'注册用户物品
		Dim Rs2,SQL2,hpitem,spitem,expitem,liveitem
		sql2 = "SELECT * FROM useritem WHERE username='"&Dvbbs.MemberName&"' "
		set rs2=connpet.ExeCute(sql2)
		hpitem=rs2("hpitem")
		spitem=rs2("spitem")
		expitem=rs2("expitem")
		liveitem=rs2("liveitem")

		dim mypethp,mypetmaxhp,mypetsp,mypetdead,basichp,basicsp,basicusehp,basicuseexp,atkup,defup,hptemp,petlevel
		dim petshowlevel,hp,vit
		mypethp = rs("mypethp")
		mypetsp = rs("mypetsp")
		mypetdead =rs("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
		vit=rs("vit")

		'获取生命上限
		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
		mypetmaxhp = int((rs("mypetmaxhp")+vit)*hpmaxskill)
		hptemp=mypetmaxhp-mypethp

		select case lcase(request("action"))
			'使用 hp药水	
			case "usehp"
				if(hpitem<1) then
					call showmessage("你没有HP药水，请到道具店购买","YD_petitemshop.asp")
				elseif(mypethp = mypetmaxhp or mypetdead=1) then
					if (mypethp = mypetmaxhp) then
						call showmessage("你的宝宝体力充沛，不用喝药水了","YD_petmypet.asp")
					else
						call showmessage("先把宝宝救活再说吧:(","YD_petitemshop.asp")
					end if
				elseif(hptemp<basicusehp) then
					connpet.ExeCute("UPDATE mypetdata SET mypethp="&mypetmaxhp&" WHERE username='"& DvBBS.MemberName &"'")
					connpet.ExeCute("UPDATE useritem SET hpitem=hpitem-1 WHERE username='"& DvBBS.MemberName &"'")
					call showmessage("使用成功，你的宝宝HP增加了 "& hptemp &" ！","YD_petrisk.asp")			
				else
					connpet.ExeCute("UPDATE mypetdata SET mypethp=mypethp+"&basicusehp&" WHERE username='"& DvBBS.MemberName &"'")
					connpet.ExeCute("UPDATE useritem SET hpitem=hpitem-1 WHERE username='"& DvBBS.MemberName &"'")
					call showmessage("使用成功，你的宝宝HP增加了 "&basicusehp&" ！","YD_petrisk.asp")
				end if
				if rs("mypethp")>maxhp then
					connpet.ExeCute("UPDATE mypetdata SET mypethp="&mypetmaxhp&",hpitem=hpitem-1 WHERE username='"& DvBBS.MemberName &"'")
				end if
			'使用 sp药水
			case "usesp"
				if (spitem<1 or mypetdead=1) then
					if (spitem<1) then
						call showmessage("你没有SP药水，请到道具店购买","YD_petitemshop.asp")
					else
						call showmessage("先救活宝宝再喂它吧:(","YD_petitemshop.asp")
					end if
				else
					connpet.ExeCute("UPDATE mypetdata SET mypetsp="&basicsp&",petregdate="&Pet_NowString&" WHERE username='"& DvBBS.MemberName &"'")
					connpet.ExeCute("UPDATE useritem SET spitem=spitem-1 WHERE username='"& DvBBS.MemberName &"'")
					call showmessage("使用成功，你的宝宝SP吃饱了 ！","YD_petmypet.asp")
				end if
			'使用 exp药水
			case "useexp"
				if (expitem<1 or mypetdead=1) then
					if (expitem<1) then
						call showmessage("你没有EXP药水，请到道具店购买","YD_petitemshop.asp")
			   		else
						call showmessage("先救活宝宝再喂它吧:(","YD_petitemshop.asp")
					end if
				else
					Randomize
					basicuseexp=cint(basicuseexp*rnd)+10
					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)
					mypetmaxhp=maxhp
					connpet.ExeCute("UPDATE mypetdata SET mypetexp=mypetexp+"&basicuseexp&",mypetlevel="&petshowlevel&"  WHERE username='"& DvBBS.MemberName &"'")
					connpet.ExeCute("UPDATE useritem SET expitem=expitem-1 WHERE username='"& DvBBS.MemberName &"'")
					call showmessage("使用成功，你的宝宝EXP增加了 "& basicuseexp &"！","YD_petmypet.asp")
				end if
			'使用复活药水
			case "uselive"
				if (liveitem<1) then
					call showmessage("你没有复活药水","YD_petmypet.asp")
				elseif(mypetdead<1) then
					call showmessage("你的宝宝还没有死，干吗复活啊？","YD_petmypet.asp")
				else
					connpet.ExeCute("UPDATE mypetdata SET mypethp="& mypetmaxhp &"/2,mypetsp=5000,petregdate="&Pet_NowString&",mypetdead=0 WHERE username='"& DvBBS.MemberName &"'")
					connpet.ExeCute("UPDATE useritem SET liveitem=liveitem-1 WHERE username='"& DvBBS.MemberName &"'")
					call showmessage("使用成功，你的宝宝复活了 ！","YD_petmypet.asp")
				end if
		end select
	end if
 	rs2.close
	rs.close
end if	
%>