<!-- #include file=../include/skin.asp -->
<!-- #include file=include/con_pet.asp -->
<!-- #include file=pet_conn.asp -->
<%
tit="宠物装备店"
call web_head(2,0,0,0,0)


    dim menu,savem,rsbank,rssql,chentitle,chenbackasp,stats,errmsg,founderr
    dim money,smoney,saveday,allmoney,time1,time2,daikuang,dkdu,daiday,sucmsg
    dim Form_userphoto,Form_FaceUrl,Form_FaceWidth,Form_FaceHeight
    
    Dim item1,item2,item3,item4,item5
DEF_PointsName="金币"
set rs=joekoe_cms.exec("select * from user_data where username='"&login_username&"'",1)
    money=rs("emoney")
    rs.close 
	

	
	
	sql = "SELECT * FROM mypetdata WHERE username='"&login_username&"' "
	rs.open sql,connpet,1,3
	if rs.eof then
		call showmessage("你还没有宠物啊，快攒钱去买吧~","petshop.asp")
		else

item1=0
item2=0
item3=0
item4=0
item5=0

if rs("item1")<>0 then item1=1 end if
if rs("item2")<>0 then item2=1 end if
if rs("item3")<>0 then item3=1 end if
if rs("item4")<>0 then item4=1 end if
if rs("item5")<>0 then item5=1 end if



dim tmoney,sword,tmp,necklace,head,body,foot,rndNum
		
if request("action") = "" then
	action = "showroom"
	else
	action = lcase(request("action"))
end if


'注册用户物品
Dim Rs2,SQL2,hpitem,spitem,expitem,atkitem,defitem,liveitem,weopitem,amoritem
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")	
weopitem=rs2("weopitem")
amoritem=rs2("amoritem")




select case action
	case "buysword"
			if item1<>0 then
						call showmessage("你的身上装备了同类型物品<br><br>请卸下身上的物品后重新购买","petweaponshop.asp")
						else				
		sword = request("sword")

http = Request.ServerVariables("HTTP_REFERER")
If instr(http,"petweaponshop.asp")=0 Then
Response.Redirect "444.htm"
response.end
end if

		tmoney=clng(DEF_PET_perswordmoney*sword*(1+sword/10))
		tmp=sword-rs("item1")
		if (money<tmoney) then
			call showmessage("你没有那么多钱购买这些物品","petweaponshop.asp")
                  '从这改，做个记号
                  elseif (tmp<1) then
                  call showmessage("你现有的装备等级高于你购买的装备，不用再买了","petweaponshop.asp")
		        else
	 		call joekoe_cms.exec("UPDATE user_data SET emoney=emoney-" & tmoney & " WHERE username='"&login_username&"'",0)

	
			connpet.ExeCute("UPDATE mypetdata SET item1="&sword&" WHERE username='"&login_username&"'")
			randomize
			rndNum=clng((sword)*3)
			connpet.ExeCute("UPDATE mypetdata SET item1Num="&rndNum&" WHERE username='"&login_username&"'")
			call showmessage("购买成功，你的攻击力增加 "&rndNum&" 点！","petweaponshop.asp")

		end if
		end if
	case "buynecklace"
				if item2<>0 then
						call showmessage("你的身上装备了同类型物品<br><br>请卸下身上的物品后重新购买","petweaponshop.asp")
						else
		necklace = request("necklace")
http = Request.ServerVariables("HTTP_REFERER")
If instr(http,"petweaponshop.asp")=0 Then
Response.Redirect "444.htm"
response.end
end if
		tmoney=clng(DEF_PET_pernecklacemoney*necklace*(1+necklace/10))
		tmp=necklace-rs("item2")
		if (money<tmoney) then
			call showmessage("你没有那么多钱购买这些物品","petweaponshop.asp")
        elseif(tmp<1) then
            call showmessage("你现有的装备等级高于你购买的装备，不用再买了","petweaponshop.asp")
		else
	call joekoe_cms.exec("UPDATE user_data SET emoney=emoney-" & tmoney & " WHERE username='"&login_username&"'",0)
						connpet.ExeCute("UPDATE mypetdata SET item2="&necklace&" WHERE username='"&login_username&"'")
			randomize
			rndNum=clng((necklace)*3)
			connpet.ExeCute("UPDATE mypetdata SET item2Num="&rndNum&" WHERE username='"&login_username&"'")
		   call showmessage("购买成功，你的攻击力增加 "&rndNum&" 点！","petweaponshop.asp")

		end if
		end if
	case "buyhead"
				if item3<>0 then
						call showmessage("你的身上装备了同类型物品<br><br>请卸下身上的物品后重新购买","petweaponshop.asp")
						else
		head = request("head")
http = Request.ServerVariables("HTTP_REFERER")
If instr(http,"petweaponshop.asp")=0 Then
Response.Redirect "444.htm"
response.end
end if
		tmoney=clng(DEF_PET_perheadmoney*head*(1+head/10))
		tmp=head-rs("item3")
		if (money<tmoney) then
			call showmessage("你没有那么多钱购买这些物品","petweaponshop.asp")
        elseif(tmp<1) then
            call showmessage("你现有的装备等级高于你购买的装备，不用再买了","petweaponshop.asp")
		else
		call joekoe_cms.exec("UPDATE user_data SET emoney=emoney-" & tmoney & " WHERE username='"&login_username&"'",0)
			
			connpet.ExeCute("UPDATE mypetdata SET item3="& head &" WHERE username='"&login_username&"'")
			randomize
			rndNum=clng((head)*3)
			connpet.ExeCute("UPDATE mypetdata SET item3Num="&rndNum&" WHERE username='"&login_username&"'")
			call showmessage("购买成功，你的防御力增加 "& rndNum &" 点！","petweaponshop.asp")

		end if
		end if
	case "buybody"
				if item4<>0 then
						call showmessage("你的身上装备了同类型物品<br><br>请卸下身上的物品后重新购买","petweaponshop.asp")
						else
		body = request("body")
http = Request.ServerVariables("HTTP_REFERER")
If instr(http,"petweaponshop.asp")=0 Then
Response.Redirect "444.htm"
response.end
end if
		tmoney=clng(DEF_PET_perbodyemoney*body*(1+body/10))
		tmp=body-rs("item4")
		if (money<tmoney) then
			call showmessage("你没有那么多钱购买这些物品","petweaponshop.asp")
        elseif(tmp<1) then
            call showmessage("你现有的装备等级高于你购买的装备，不用再买了","petweaponshop.asp")
		else
                       call joekoe_cms.exec("UPDATE user_data SET emoney=emoney-" & tmoney & " WHERE username='"&login_username&"'",0)
            'call showmessage("购买成功，你的防御力增加 "&body&" 点！","petweaponshop.asp")



			call joekoe_cms.exec("UPDATE user_data SET emoney=emoney-" & tmoney & " WHERE username='"&login_username&"'",0)
			
			connpet.ExeCute("UPDATE mypetdata SET item4="&body&" WHERE username='"&login_username&"'")
			randomize
			rndNum=clng((body)*3)
			connpet.ExeCute("UPDATE mypetdata SET item4Num="&rndNum&" WHERE username='"&login_username&"'")
			call showmessage("购买成功，你的防御力增加 "&rndNum&" 点！","petweaponshop.asp")

		end if
		end if
	case "buyfoot"
				if item5<>0 then
						call showmessage("你的身上装备了同类型物品<br><br>请卸下身上的物品后重新购买","petweaponshop.asp")
						else
		foot = request("foot")
		
http = Request.ServerVariables("HTTP_REFERER")
If instr(http,"petweaponshop.asp")=0 Then
Response.Redirect "444.htm"
response.end
end if
		tmoney=clng(DEF_PET_perfootmoney*foot*(1+foot/10))
		tmp=foot-rs("item5")
		if (money<tmoney) then
			call showmessage("你没有那么多钱购买这些物品","petweaponshop.asp")
        elseif(tmp<1) then
            call showmessage("你现有的装备等级高于你购买的装备，不用再买了","petweaponshop.asp")
		else
	call joekoe_cms.exec("UPDATE user_data SET emoney=emoney-" & tmoney & " WHERE username='"&login_username&"'",0)
			connpet.ExeCute("UPDATE mypetdata SET item5="&foot&" WHERE username='"&login_username&"'")
			randomize
			rndNum=clng((foot)*3)
			connpet.ExeCute("UPDATE mypetdata SET item5Num="&rndNum&" WHERE username='"&login_username&"'")
			call showmessage("购买成功，你的防御力增加 "&rndNum&" 点！","petweaponshop.asp")

		end if
		end if


'upnum物品等级；uppoint升级点数；uptype升级物品；temp临时变量
	case "upwna"		
		dim uprnd,uptype,upnum,uppoint,upword
		uptype=cint(request("type"))
		upnum=cint(request("num"))

		if upnum=0 then
			call showmessage("0级装备无法升级!请购买高级装备！","petweaponshop.asp?action=showupdate")
		end if

		if money<DEF_UpWeopMoney then
			call showmessage("你的钱不够!","petweaponshop.asp?action=showupdate")
		elseif (uptype<=2 and rs2("weopitem")<upnum) or (uptype>2 and rs2("amoritem")<upnum) then
			'response.write uptype &" "&rs2("weopitem")&" "&rs2("amoritem")&" "& upnum
			call showmessage("你的升级材料不够!","petweaponshop.asp?action=showupdate")
		else
		


'升级成功率计算
			randomize
			uprnd=rnd*100+1
			if uprnd<=cint((80-upnum*5)/2) then			
				uppoint = 2	
				upword = "运气真好 恭喜你 加强值提高 <font color=red>2</font> 点！"

			elseif uprnd<=(80-upnum*5) then
				uppoint = 1
				upword = "运气不错 恭喜你 加强值提高 <font color=red>1</font> 点！"

			elseif uprnd <= cint((80-upnum*5)+20) then
				uppoint = 0
				upword = "运气不好 加强值没有得到提高！"

			else
				uppoint = -1
				upword = "运气不会这么差吧！加强值降低 1 点！<br><br><font color=red>请注意：等级越高的物品进行升级，越容易失败！</font>"

			end if
'升级点数限制			
			dim temp
			temp=0			
			select case uptype
			case 1
				if rs("item1Num") = rs("item1")*3+9 then
				uppoint = 0
				temp=1
				upword = "你的物品强度已经是最高了，无法在升级了！"
				upnum=0
				else				
				if rs("item1Num")+uppoint >= rs("item1")*3+9 then
				uppoint = rs("item1")*3+9-rs("item1Num")
				upword = "升级成功，你的物品强度已经是最高了！"

				end if
				end if
						
			case 2
				if rs("item2Num") = rs("item2")*3+9 then
				uppoint =0
				temp=1
				upword = "你的物品强度已经是最高了，无法在升级了！"
				upnum=0
				else				
				if rs("item2Num")+uppoint >= rs("item2")*3+9 then
				uppoint = rs("item2")*3+9-rs("item2Num")
				upword = "升级成功，你的物品强度已经是最高了！"

				end if
				end if			
			
			case 3
				if rs("item3Num") = rs("item3")*3+9 then
				uppoint = 0
				temp=1
				upword = "你的物品强度已经是最高了，无法在升级了！"
				upnum=0
				else				
				if rs("item3Num")+uppoint >= rs("item3")*3+9 then
				uppoint = rs("item3")*3+9-rs("item3Num")
				upword = "升级成功，你的物品强度已经是最高了！"

				end if
				end if			
			
			case 4
				if rs("item4Num") = rs("item4")*3+9 then
				uppoint = 0
				temp=1
				upword = "你的物品强度已经是最高了，无法在升级了！"
				upnum=0
				else				
				if rs("item4Num")+uppoint >= rs("item4")*3+9 then
				uppoint = rs("item4")*3+9-rs("item4Num")
				upword = "升级成功，你的物品强度已经是最高了！"
				end if
				end if			
			
			case 5
				if rs("item5Num") = rs("item5")*3+9 then
				uppoint = 0
				temp=1
				upword = "你的物品强度已经是最高了，无法再升级了！"
				upnum=0
				else				
				if rs("item5Num")+uppoint >= rs("item5")*3+9 then
				uppoint = rs("item5")*3+9-rs("item5Num")
				upword = "升级成功，你的物品强度已经是最高了！"
				
				end if
				end if			
			
			
			end select
			
			
'写入数据库
			SQL = "UPDATE mypetdata SET item"&uptype&"Num = item"&uptype&"Num + "&uppoint&" WHERE username='"&login_username&"'"
			connpet.ExeCute(SQL)
			
'删除所用的升级物品及资金
       '     if temp=1 then
		'	call showmessage(upword,"petweaponshop.asp?action=showupdate")
		'	else
			
			if uptype<=2 then
				
				connpet.ExeCute("UPDATE useritem SET weopitem = weopitem - "&upnum&" WHERE username='"&login_username&"'")
			else
				
				connpet.ExeCute("UPDATE useritem SET amoritem = amoritem - "&upnum&" WHERE username='"&login_username&"'")
			end if
			call joekoe_cms.exec("update user_data set emoney=emoney-" & DEF_UpWeopMoney & " WHERE name='"&login_username&"'",0)			
			end if
			call showmessage(upword,"petweaponshop.asp?action=showupdate")

'	end if
end select		
		
		
	end if
	rs2.close
	rs.close	
%>
<table width="760" border="0" cellspacing="1" cellpadding="5" align="center" class=TBone>
  <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" cellspacing="0" cellpadding="0">
<tr>
          <td width="28%" rowspan="2" valign="top">
<table width="79%"  border="0" align="center" cellpadding="3" cellspacing="3">
<tr><td width="100%"> <div align="center">我的资料</div></td>
</tr><%call pet_left("")%>
                  <tr> 
                    <td> <div align="center">
                        <nobr>用户<%=DEF_PointsName%>: <%=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><br><table width="79%" border="0" align="center" cellpadding="3" cellspacing="3">
<tr><td width="100%"><div align="center"><img src="images/pet/27.gif"></div></td>
</tr></table><br><div align="right"></div></td>
<td><table width="100%" border="0" cellspacing="2" cellpadding="2"><div align="center">
  <br><tr><td width="16%"><div align="center"><a href="petweaponshop.asp?action=showroom">武器柜台</a></div></td>
<td width="16%"><div align="center"><a href="petweaponshop.asp?action=shownecklace">项链柜台</a></div></td>
<td width="16%"><div align="center"><a href="petweaponshop.asp?action=showhead">头盔柜台</a></div></td>
<td width="16%"><div align="center"><a href="petweaponshop.asp?action=showbody">盔甲柜台</a></div></td>
<td width="16%"><div align="center"><a href="petweaponshop.asp?action=showfoot">鞋子柜台</a></div></td>
<td><div align="center"><a href="petweaponshop.asp?action=showupdate">升级柜台</a></div></td>
</tr></table></td></tr><tr><td width="72%"> 
<%
	if action<>"showupdate" then
	dim atkdef,MPO
	select case action

		case "showroom"
			sql = "SELECT * FROM petitemshop WHERE itemclass='sword' and itemNum <> 0 and itemNum<24"
			atkdef="攻击力"
			mpo=DEF_PET_perswordmoney
		
		case "shownecklace"
			sql = "SELECT * FROM petitemshop WHERE itemclass='necklace' and itemNum <> 0 and itemNum<15"
			atkdef="攻击力"
			mpo=DEF_PET_pernecklacemoney

		case "showhead"
			sql = "SELECT * FROM petitemshop WHERE itemclass='head' and itemNum <> 0 and itemNum<15"
			atkdef="防御力"
			mpo=DEF_PET_perheadmoney
		
		case "showbody"
			sql = "SELECT * FROM petitemshop WHERE itemclass='body' and itemNum <> 0 and itemNum<15"
			atkdef="防御力"
			mpo=DEF_PET_perbodyemoney

		case "showfoot"
			sql = "SELECT * FROM petitemshop WHERE itemclass='foot' and itemNum <> 0 and itemNum<15"
			atkdef="防御力"
			mpo=DEF_PET_perfootmoney

	end select
	rs.open sql,connpet,1,1
	rs.movefirst
%>
<form action=petweaponshop.asp name="name" method=post>
<TABLE class=text1 cellSpacing=1 cellPadding=3 width=530 align=center border=0><TR> 
<TD width=100><DIV align=center>名字</DIV></TD>
<TD width=100><DIV align=center>形象</DIV></TD>
<TD width=100><DIV align=center><%=atkdef%></DIV></TD>
<TD width=100><DIV align=center>价格</DIV></TD>
<TD width=100><div align=center>购买选项</div></TD>
</TR>
<%
if not rs.eof then
do while not rs.eof
%>
<TR><TD width=100><DIV align=center><%=rs("ItemName")%></DIV></TD>
<TD width=100><DIV align=center><IMG height=30 src="images/pet/<%=rs("ItemClass")%>/<%=rs("itemNum")%>.gif" width=30></DIV></TD>
<TD width=100><DIV align=center>＋<%=rs("itemNum")*3%></DIV></TD>
<TD><DIV align=center><%=clng(MPO*rs("itemNum")*(2+rs("itemNum")/5))%></DIV></TD>
<TD width=100 align=middle><div align="center"><input class='94kk' type="radio" name="<%=rs("itemclass")%>" value="<%=rs("itemNum")%>">购买</div></TD></TR>
<%
rs.movenext
loop
rs.movefirst
%>
<TR><TD colspan="5"><DIV align=center><br>
<input class='94kk' name="action" type="hidden" id="action" value="buy<%=rs("itemclass")%>">
<input class='94kk' type="submit" name="Submit2" value="结帐购买"></DIV>
</TD></TR></TABLE></form>
<%
end if
rs.close%>
<%
	else

	SQL = "SELECT * FROM mypetdata WHERE username='"&login_username&"'"
	set rs = connpet.execute(SQL)


	'用很无聊的循环使用变量得到每种道具的名字……
	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

%>
	<div align=center>
	<table class=text1 cellSpacing=1 cellPadding=3 width=530 align=center border=0 width="100%">
	<tr>
		<td width="25%" height="30" align=center>宠物装备</td>
		<td width="25%" height="30" align=center>目前加强值</td>
		<td width="25%" height="30" colspan=2 align=center>消耗材料</td>
		<td width="25%" height="30" align=center>升级 <br><font color=red>(每次将消耗<%=DEF_UpWeopMoney%><%=DEF_PointsName%>)</font></td>
	</tr>
	<tr><form action="petweaponshop.asp" method="post">
		<td width="25%" height="30" align=center><img height=30 src="images/pet/sword/<%=rs("item1")%>.gif" alt="<%=swordname%>"></td>
		<td width="25%" height="30" align=center>＋ <%=rs("item1Num")%></td>
		<td width="12.5%" height="30" align=right><img src="images/pet/wp.gif" width="40" height="40" border="0" alt="武器升级材料"></td>
		<td width="12.5%" height="30" align=left> × <%=rs("item1")%></td>
		<td width="25%" height="30" align=center><input class='94kk' type="submit" value="升级"></td>
		<input class='94kk' type="hidden" name="action" value="upwna">
		<input class='94kk' type="hidden" name="type" value="1">
		<input class='94kk' type="hidden" name="num" value="<%=rs("item1")%>">
		</form>
	</tr>
	<tr><form action="petweaponshop.asp" method="post">
		<td width="25%" height="30" align=center><img height=30 src="images/pet/necklace/<%=rs("item2")%>.gif" alt="<%=necklacename%>"></td>
		<td width="25%" height="30" align=center>＋ <%=rs("item2Num")%></td>
		<td width="12.5%" height="30" align=right><img src="images/pet/wp.gif" width="40" height="40" border="0" alt="武器升级材料"></td>
		<td width="12.5%" height="30" align=left> × <%=rs("item2")%></td>
		<td width="25%" height="30" align=center><input class='94kk' type="submit" value="升级"></td>
		<input class='94kk' type="hidden" name="action" value="upwna">
		<input class='94kk' type="hidden" name="type" value="2">
		<input class='94kk' type="hidden" name="num" value="<%=rs("item2")%>">
		</form>
	</tr>
	<tr><form action="petweaponshop.asp" method="post">
		<td width="25%" height="30" align=center><img height=30 src="images/pet/head/<%=rs("item3")%>.gif" alt="<%=headname%>"></td>
		<td width="25%" height="30" align=center>＋ <%=rs("item3Num")%></td>
		<td width="12.5%" height="30" align=right><img src="images/pet/am.gif" width="40" height="40" border="0" alt="防具升级材料"></td>
		<td width="12.5%" height="30" align=left> × <%=rs("item3")%></td>
		<td width="25%" height="30" align=center><input class='94kk' type="submit" value="升级"></td>
		<input class='94kk' type="hidden" name="action" value="upwna">
		<input class='94kk' type="hidden" name="type" value="3">
		<input class='94kk' type="hidden" name="num" value="<%=rs("item3")%>">
		</form>
	</tr>
	<tr><form action="petweaponshop.asp" method="post">
		<td width="25%" height="30" align=center><img height=30 src="images/pet/body/<%=rs("item4")%>.gif" alt="<%=bodyname%>"></td>
		<td width="25%" height="30" align=center>＋ <%=rs("item4Num")%></td>
		<td width="12.5%" height="30" align=right><img src="images/pet/am.gif" width="40" height="40" border="0" alt="防具升级材料"></td>
		<td width="12.5%" height="30" align=left> × <%=rs("item4")%></td>
		<td width="25%" height="30" align=center><input class='94kk' type="submit" value="升级"></td>
		<input class='94kk' type="hidden" name="action" value="upwna">
		<input class='94kk' type="hidden" name="type" value="4">
		<input class='94kk' type="hidden" name="num" value="<%=rs("item4")%>">
		</form>
	</tr>
	<tr><form action="petweaponshop.asp" method="post">
		<td width="25%" height="30" align=center><img height=30 src="images/pet/foot/<%=rs("item5")%>.gif" alt="<%=footname%>"></td>
		<td width="25%" height="30" align=center>＋ <%=rs("item5Num")%></td>
		<td width="12.5%" height="30" align=right><img src="images/pet/am.gif" width="40" height="40" border="0" alt="防具升级材料"></td>
		<td width="12.5%" height="30" align=left> × <%=rs("item5")%></td>
		<td width="25%" height="30" align=center><input class='94kk' type="submit" value="升级"></td>
		<input class='94kk' type="hidden" name="action" value="upwna">
		<input class='94kk' type="hidden" name="type" value="5">
		<input type="hidden" name="num" value="<%=rs("item5")%>">
		</form>
	</tr>
	</table>
	<br>
	<table class=text1 cellSpacing=1 cellPadding=3 width=530 align=center border=0 width="100%">
	<tr>
		<td colspan=2><div align=center>我目前拥有武器/防具升级材料</div></td>
	</tr>
	<tr>
		<td><img src="images/pet/wp.gif" width="40" height="40" border="0" alt="武器升级材料"> × <%=weopitem%> 个</td>
		<td><img src="images/pet/am.gif" width="40" height="40" border="0" alt="防具升级材料"> × <%=amoritem%> 个</td>
	</tr>
	</table>
	</div>
<%
	
rs.close
end if
%>
<br>
<br>
</td>
</tr></table>
</td></tr></table>
<%    
call web_end(0,0)
%>
