<!--#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
	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 basichpmoney,basicspmoney,basicexpmoney,atkmoney,defmoney,livemoney
		dim item1,item2,item3,item4,item5,item6,tmoney,petmoney
		basichpmoney=def_pet_basichpmoney
		basicspmoney=def_pet_basicspmoney
		basicexpmoney=def_pet_basicexpmoney
		livemoney=def_pet_livemoney

		'注册用户物品
		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")
		item1 = int(request("item1"))
		item2 = int(request("item2"))
		item3 = int(request("item3"))
		item4 = 0
		item5 = 0
		item6 = int(request("item6"))

		if request("action") = "" then
			action = "showroom"
		else
			action = lcase(request("action"))
		end if

		select case action
			case "countitem"
				if (item1<0 or item2<0 or item3<0 or item6<0) then
					call showmessage("你购买数量有错误，请重新购买~","YD_petitemshop.asp")
				else
					tmoney=item1*basichpmoney+item2*basicspmoney+item3*basicexpmoney+item4*atkmoney+item5*defmoney+item6*livemoney
				end if
			case "buyitem"
				petmoney=money
				tmoney=item1*basichpmoney+item2*basicspmoney+item3*basicexpmoney+item4*atkmoney+item5*defmoney+item6*livemoney

				if (petmoney<tmoney) then
					call showmessage("你没有那么多钱购买这些物品","YD_petitemshop.asp")
				elseif (item1<0 or item2<0 or item3<0 or item6<0) then
					call showmessage("你购买数量有错误，请重新购买~","YD_petitemshop.asp")
				else
					Dvbbs.execute("UPDATE [DV_user] SET userWealth=userWealth-"&tmoney&" WHERE username='"&DvBBS.MemberName&"'")
					Call UpdateUserInfo(-tmoney,0,0,0,0,0)		'道具Bug修正
					connpet.ExeCute("UPDATE useritem SET hpitem=hpitem+"&item1&",spitem=spitem+"&item2&",expitem=expitem+"&item3&",liveitem=liveitem+"&item6&" WHERE username='"&DvBBS.MemberName&"'")
					call showmessage("购买成功!<br><br>你HP药水增加了 "&item1&" 个<br>SP药水增加了 "&item2&" 个<br>EXP药水增加了 "&item3&" 个<br>复活药水增加了 "&item6&" 个！","YD_petmypet.asp")
				end if
		end select
	end if
	rs2.close
	rs.close    
	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>
      <table width="100%" cellspacing="0" cellpadding="0">
	<tr>
	  <td width="28%">
	    <table width="79%" 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>
	    <br>
	    <table width="79%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td width="100%" align="center">
		<!-- #include file=YD_petnav.asp --><br>
		<br><img src="YD_plus/YD_pet/PET/25.gif">
		</td>
	      </tr>
	    </table> 
	  </td>
	  <td width="72%"> 
	<%if action = "showroom" then%>
	    <form action=YD_petitemshop.asp name="name" mtehod=post>
	    <TABLE cellSpacing=3 cellPadding=3 width="100%" align=center valign="top">
	      <TR>
		<TD colspan="3" align="center">物品列表</TD>
	      </TR>
	      <TR>
		<TD width="12%" align=center><IMG height=35 src="YD_plus/YD_pet/PET/hp.gif" width=34><BR>HP药水</TD>
		<TD width="18%" align="center">
		增加宠物 <%=DEF_PET_basicusehp%> 点HP<BR>
		<FONT color=#ff0000>出售价格：</FONT><font color="#FF0000"><%=DEF_PET_basichpmoney%><%=DEF_PointsName%></font><BR>
		</TD>
		<TD width="19%" align=center>购买数量：
		<input name="item1" type="text" value="0" size="6" maxlength="5">
		<br>你所拥有数量：<%=hpitem%><BR>
		</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">
		补满宠物的SP<BR>
		<FONT color=#ff0000>出售价格：</FONT><font color="#FF0000"><%=def_pet_basicspmoney%><%=DEF_PointsName%></font></TD>
		<TD align=center>购买数量：
		<input name="item2" type="text" value="0" size="6" maxlength="5">
		<br>你所拥有数量：<%=spitem%><BR>
		</TD>
	      </TR>
	      <TR>
		<TD align=center><IMG height=35 src="YD_plus/YD_pet/PET/exp.gif" width=35><BR>EXP药水</TD>
		<TD align="center">
		随机增加宠物 10-<%=def_pet_basicuseexp+10%> 点EXP<BR>
		<FONT color=#ff0000>出售价格：</FONT><font color="#FF0000"><%=def_pet_basicexpmoney%><%=DEF_PointsName%></font>
		</TD>
		<TD align=center>购买数量：
		<input name="item3" type="text" value="0" size="6" maxlength="5">
		<br>你所拥有数量：<%=expitem%><BR>
		</TD>
	      </TR>
	      <TR>
		<TD align="center"><IMG height=35 src="YD_plus/YD_pet/PET/liv.gif" width=34><BR>复活药水</TD>
		<TD align="center">
		使你的宝宝复活<BR>
		<FONT color=#ff0000>出售价格：</FONT><font color="#FF0000"><%=def_pet_livemoney%><%=DEF_PointsName%></font>
		</TD>
		<TD align="center">购买数量：
		<input name="item6" type="text" value="0" size="6" maxlength="5">
		<br>你所拥有数量：<%=liveitem%><BR>
		</TD>
	      </TR>
	      <TR>
		<TD colspan="3" align="center">
		  <table width="100%" cellspacing="2" cellpadding="2">
		    <tr>
		      <td align="center">
			<input type="hidden" name="action" value="countitem">
			<input type="submit" name="submit" value="结帐购买">
		      </td>
		    </tr>
		  </table>
		</TD>
	      </TR>
	    </TABLE>
	    </form>
<%
	end if

	if action = "countitem" then
%>
	    <form action=YD_petitemshop.asp name="name" mtehod=post>
	    <TABLE cellSpacing=3 cellPadding=3 width="100%" align=center valign="top">
	      <TR>
		<TD width="49%" align="center">购买清单</TD>
	      </TR>
	      <TR>
		<TD align=center>
		  <table width="41%" cellspacing="2" cellpadding="2">
		    <tr>
		      <td width="44%" align="right">HP药水：</td>
		      <td width="56%"><%=item1%> 个</td>
		    </tr>
		    <tr>
		      <td align="right">SP药水：</td>
		      <td><%=item2%> 个</td>
		    </tr>
		    <tr>
		      <td align="right">EXP药水：</td>
		      <td><%=item3%> 个</td>
		    </tr>
		    <tr>
		      <td align="right">复活药水：</td>
		      <td><%=item6%> 个</td>
		    </tr>
		    <tr>
		      <td align="right">总计价格：</td>
		      <td><%=tmoney%> <font color="#000000"><%=DEF_PointsName%></font></td>
		    </tr>
		  </table>
		</TD>
	      </TR>
	      <TR>
		<TD align="center">
		  <TABLE cellSpacing=2 cellPadding=2 width="100%">
		    <TR>
		      <TD align=center> 
			<input type="hidden" name="item1" value="<%=item1%>">
			<input type="hidden" name="item2" value="<%=item2%>">
			<input type="hidden" name="item3" value="<%=item3%>">
			<input type="hidden" name="item6" value="<%=item6%>">
			<input type="hidden" name="action" value="buyitem">
			<input type="submit" value="购买">
		      </TD>
		    </TR>
		  </TABLE>
		</TD>
	      </TR>
	    </TABLE>
	    </form>
	<%end if%>
	  </td>
	</tr>
      </table> 
    </td>
  </tr>
</table>
<%
end sub
%>