<!-- #include file=../include/skin.asp -->
<!-- #include file=include/con_pet.asp -->
<!-- #include file=pet_conn.asp -->
<%
dim menu,savem,rsbank,rssql,chentitle,chenbackasp,stats,errmsg,founderr,hpmaxskill,maxhp

tit="使用道具"
call web_head(2,0,0,0,0)

	sql = "SELECT * FROM mypetdata WHERE username='"&login_username&"' "
	set rs=connpet.ExeCute(sql)
	if rs.eof then
Response.Write "<script language=JavaScript>{alert('你还没有宠物啊，快攒钱去买吧~');(location.href = 'petshop.asp')}</script>"
else

'注册用户物品
Dim Rs2,SQL2,hpitem,spitem,expitem,liveitem
sql2 = "SELECT * FROM useritem WHERE username='"&login_username&"' "
set rs2=connpet.ExeCute(sql2)
hpitem=rs2("hpitem")
spitem=rs2("spitem")
expitem=rs2("expitem")
'atkitem=rs2("atkitem")
'defitem=rs2("defitem")
liveitem=rs2("liveitem")



	
dim mypethp,mypetmaxhp,mypetsp,mypetdead,basichp,basicsp,basicusehp,basicuseexp,atkup,defup,hptemp,pettoday,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")
pettoday = now()
		
 '获取生命上限
   	      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







'call showmessage(""& hpitem &"","petitemshop.asp")

select case lcase(request("action"))
	
'使用 hp药水	
	case "usehp"
		if(hpitem<1) then

Response.Write "<script language=JavaScript>{alert('你没有HP药水，请到道具店购买.');(location.href = 'petitemshop.asp')}</script>"
		elseif(mypethp = mypetmaxhp or mypetdead=1) then
			if (mypethp = mypetmaxhp) then

Response.Write "<script language=JavaScript>{alert('你的宝宝体力充沛，不用喝药水了!');(location.href = 'petmypet.asp')}</script>"
			else 

Response.Write "<script language=JavaScript>{alert('先把宝宝救活再说吧:(');(location.href = 'petitemshop.asp')}</script>"
			end if
		elseif(hptemp<basicusehp) then
			connpet.ExeCute("UPDATE mypetdata SET mypethp="&mypetmaxhp&" WHERE username='"&login_username&"'")
			connpet.ExeCute("UPDATE useritem SET hpitem=hpitem-1 WHERE username='"& login_username&"'")
	
Response.Write "<script language=JavaScript>{alert('使用成功，你的宝宝HP增加了 "& hptemp &" ');(location.href = 'petmypet.asp')}</script>"		
		else
			connpet.ExeCute("UPDATE mypetdata SET mypethp=mypethp+"&basicusehp&" WHERE username='"&login_username&"'")
			connpet.ExeCute("UPDATE useritem SET hpitem=hpitem-1 WHERE username='"& login_username&"'")

Response.Write "<script language=JavaScript>{alert('使用成功，你的宝宝HP增加了 "& basicusehp &" ');(location.href = 'petmypet.asp')}</script>"
		end if
		if rs("mypethp")>maxhp then
		connpet.ExeCute("UPDATE mypetdata SET mypethp="&mypetmaxhp&",hpitem=hpitem-1 WHERE username='"& login_username &"'")
		end if



'使用 sp药水
	case "usesp"
		if (spitem<1 or mypetdead=1) then
			   if (spitem<1) then
'call showmessage("你没有SP药水，请到道具店购买","petitemshop.asp")
Response.Write "<script language=JavaScript>{alert('你没有SP药水，请到道具店购买');(location.href = 'petitemshop.asp')}</script>"
			   else 
'call showmessage("先救活宝宝再喂它吧:(","petitemshop.asp")
Response.Write "<script language=JavaScript>{alert('先救活宝宝再喂它吧:(');(location.href = 'petitemshop.asp')}</script>"
			   end if
		else
			connpet.ExeCute("UPDATE mypetdata SET mypetsp="&basicsp&",petregdate='"&pettoday&"' WHERE username='"& login_username &"'")
			connpet.ExeCute("UPDATE useritem SET spitem=spitem-1 WHERE username='"& login_username &"'")

'call showmessage("使用成功，你的宝宝SP吃饱了 ！","petmypet.asp")
Response.Write "<script language=JavaScript>{alert('使用成功，你的宝宝SP吃饱了 ！');(location.href = 'petmypet.asp')}</script>"
		end if

'使用 exp药水
	case "useexp"
		if (expitem<1 or mypetdead=1) then
			if (expitem<1) then
'call showmessage("你没有EXP药水，请到道具店购买","petitemshop.asp")
Response.Write "<script language=JavaScript>{alert('你没有EXP药水，请到道具店购买！');(location.href = 'petitemshop.asp')}</script>"
			   else 
'call showmessage("先救活宝宝再喂它吧:(","petitemshop.asp")
Response.Write "<script language=JavaScript>{alert('先救活宝宝再喂它吧:(！');(location.href = 'petitemshop.asp')}</script>"
			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='"& login_username &"'")
			connpet.ExeCute("UPDATE useritem SET expitem=expitem-1 WHERE username='"& login_username &"'")


Response.Write "<script language=JavaScript>{alert('使用成功，你的宝宝EXP增加了 "& basicuseexp &"！');(location.href = 'petmypet.asp')}</script>"
		end if

'使用 攻击药水
'
'	case "useatk"
'		if (atkitem<1) then
'call showmessage("你没有攻击力药水，请到道具店购买","petmypet.asp")
Response.Write "<script language=JavaScript>{alert('你没有攻击力药水，请到道具店购买');(location.href = 'petmypet.asp')}</script>"
'		else
'			randomize
'			atkup=cint(atkup*rnd)+1
'			connpet.ExeCute("UPDATE mypetdata SET mypetatk=mypetatk+"&atkup&",atkitem=atkitem-1 WHERE username='"& login_username &"'")
'			call showmessage("使用成功，你的宝宝攻击力增加了 "& atkup &" ！","petmypet.asp")
'		end if
'
'使用 防御药水
'	case "usedef"
'		if (defitem<1) then
'			call showmessage("你没有防御力药水，请到道具店购买","petmypet.asp")
'		else
'			randomize
'			defup=cint(defup*rnd)+1
'			connpet.Execute("UPDATE mypetdata SET mypetdef=mypetdef+"&defup&",defitem=defitem-1 WHERE username='"& login_username &"'")
'			call showmessage("使用成功，你的宝宝防御力增加了 "& defup &" ！","petmypet.asp")
'		end if

'使用复活药水
	case "uselive"
		if (liveitem<1) then
'call showmessage("你没有复活药水","petmypet.asp")
Response.Write "<script language=JavaScript>{alert('你没有复活药水!');(location.href = 'petmypet.asp')}</script>"
		elseif(mypetdead<1) then
'call showmessage("你的宝宝还没有死，干吗复活啊？","petmypet.asp")
Response.Write "<script language=JavaScript>{alert('你的宝宝还没有死，干吗复活啊？');(location.href = 'petmypet.asp')}</script>"
		else
			connpet.ExeCute("UPDATE mypetdata SET mypethp=1,mypetsp=1,petregdate='"& pettoday &"',mypetdead=0 WHERE username='"& login_username &"'")
			connpet.ExeCute("UPDATE useritem SET liveitem=liveitem-1 WHERE username='"& login_username &"'")

Response.Write "<script language=JavaScript>{alert('使用成功，你的宝宝复活了 ！');(location.href = 'petmypet.asp')}</script>"
		end if
end select
	

end if
 	rs2.close
	rs.close
%>