<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!-- #include file=pet_conn.asp -->
<!--#include file="inc/plus_check.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,"","宠物中心","petcenter.asp"

if DvBBS.UserId = 0 then
	AlarmErrmsg
else
    dim allpetpeople,mypetname,mypet,levelpic,mypetlevel,username
    Dim Rs,SQL
    SQL = "SELECT * FROM mypetdata WHERE username='"&Dvbbs.MemberName&"'"
    set rs = connpet.execute(SQL)
    if rs.eof then
            call showmessage("你还没有宠物啊，快攒钱去买吧~","petshop.asp")
		else

dim t,today,petdiff,pett,petlevel,petep,petshowlevel,intval,level1,level2,petpic,pethp,petmaxhp
dim petatk,petdef,updat,newpettoday,petsp,petsex,petpk
dim hpf,spf,mypetdead,petdead,mypetsex
dim item1,item2,item3,item4,item5,mypetsx,hpitem,atkitem,spitem,defitem,expitem,liveitem,imgset

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

t=now()
today = date()
petdiff = DateDiff("d", rs("petregdate"), t)

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/2)
level2=int(petshowlevel/2)
petpic=rs("mypetname")
pethp=rs("mypethp")
petatk=rs("mypetatk")+rs("item1Num")+rs("item2Num")+2+level1
petdef=rs("mypetdef")+rs("item3Num")+rs("item4Num")+rs("item5Num")+3+level1
if(petshowlevel<2) then 
	petmaxhp=DEF_PET_basichp
else
	petmaxhp=DEF_PET_basichp+petshowlevel*5
end if
petsp=rs("mypetsp")-pett*DEF_PET_basicsp2
if(petsp>DEF_PET_basicsp) then petsp=DEF_PET_basicsp end if
hpf= int (100 * (pethp / petmaxhp)) - 1
spf= int (100 * (petsp / DEF_PET_basicsp)) - 1
if (pethp<0) then pethp=0 end if
if (petsp<0) then petsp=0 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
			
item1 = rs("item1")
item2 = rs("item2")
item3 = rs("item3")
item4 = rs("item4")
item5 = rs("item5")
mypet = rs("mypet")
mypetsx = rs("mypetsx")
hpitem = rs("hpitem")
imgset = rs("imgset")
dim petkill
if petdead="死亡" then
	petkill="d-"
else
	petkill=""
end if
	end if

action=request("action")
select case action
	case "risk"
	
	dim rs2,monsid,maxatk,minatk,maxdef,mindef,atkrnd,defrnd,dropgoods,monshp,dropwp,dropam,riskexp,monssx,monsx,monslv
	dim time1,time2,atkrand,defrand,atktemp,atk,atktemp2,atk2,atktmp,atktmp2,monsclass,riskmoney

		monsid=cint(request("monsid"))
		set rs2 = connpet.execute("select * from [petmonster] where id="&monsid)
		
		maxatk = rs2("Maxatk")
		minatk = rs2("Minatk")
		maxdef = rs2("Maxdef")
		mindef = rs2("Mindef")
		monshp = rs2("MonsHP")
		dropwp = rs2("Dropwp")
		dropam = rs2("Dropam")
		monslv = rs2("Monslevel")
		rs2.close

		randomize
		atkrnd = clng(Minatk+(Maxatk-Minatk)*rnd)
		defrnd = clng(Mindef+(Maxdef-Mindef)*rnd)
		
		randomize
		monsx = cint(rnd*6)+1
		select case monsx
			case 1
				monssx = "金"
				monsclass = "devil"
			case 2
				monssx = "木"
				monsclass = "green"
			case 3
				monssx = "水"
				monsclass = "bird"
			case 4
				monssx = "火"
				monsclass = "dragon"
			case 5
				monssx = "土"
				monsclass = "bst"
			case 6
				monssx = "水"
				monsclass = "bleb"
			case 7
				monssx = "无"
				monsclass = "flower"
		end select

		time1=now()
		time2=DateDiff("s", rs("risktime"), time1)
		if (rs("mypetdead") = 1) then
			call showmessage("你的宝宝好象已经挂了， 救活它再冒险吧。","petrisk.asp")
		elseif time2<7 then
			call showmessage("别打那么快，心急吃不了热豆腐。","petrisk.asp")
		elseif petshowlevel>10 and monsid=1 then
			call showmessage("你的级别太高了，还是到别的地方冒险吧。","petrisk.asp")
		else

			Randomize '攻击
			atkrand=Int((10 * Rnd) + 0)
			Randomize '防御
			defrand=Int((10 * Rnd) + 0)
			Randomize '掉宝
			dropgoods=Int((99 * rnd) + 1)

			select case rs("mypetsx") '解决属性
				case "金"
					if monssx = "木" then atkrand=cint(atkrand*1.5)
					if monssx = "土" then atkrand=cint(atkrand*0.75)

				case "木"
					if monssx = "水" then atkrand=cint(atkrand*1.5)
					if monssx = "金" then atkrand=cint(atkrand*0.75)

				case "水"
					if monssx = "火" then atkrand=cint(atkrand*1.5)
					if monssx = "木" then atkrand=cint(atkrand*0.75)

				case "火"
					if monssx = "土" then atkrand=cint(atkrand*1.5)
					if monssx = "水" then atkrand=cint(atkrand*0.75)

				case "土"
					if monssx = "金" then atkrand=cint(atkrand*1.5)
					if monssx = "火" then atkrand=cint(atkrand*0.75)

                                case "龙"
                                        atkrand=cint(atkrand*1.5)

			end select
		
			atktemp=(rs("mypetatk")+rs("item1Num")+rs("item2Num")+2)-defrnd
			atktmp=round(atktemp+atktemp*(atkrand/5))
			if (atktmp<1) then
				atk=atkrand+1
			elseif atktmp>Monshp then
				atk=Monshp
			else 
				atk=atktmp
			end if
			riskexp = int(atk/10*1.5)+1

			atktemp2=atkrnd-(rs("mypetdef")+rs("item3Num")+rs("item4Num")+rs("item5Num")+3)
			atktmp2=round(atktemp2+atktemp2*(defrand/5))
			
			if (atktmp2<1) then
				atk2=defrand+1
			elseif atktmp2>rs("mypetmaxhp") then
				atk2=rs("mypetmaxhp")
			else 
				atk2=atktmp2
			end if

			if (pethp-atk2<1) then
				pethp=0
				mypetdead=1
				riskexp=0
			else
				pethp=pethp-atk2
				mypetdead=0
			end if

			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)
			
			'掉宝
			if mypetdead=0 then
				if dropgoods<dropwp then
					connpet.ExeCute("update mypetdata set weopitem=(weopitem+1) where username='"&DvBBS.MemberName&"'")
				elseif dropgoods>dropam then
					connpet.ExeCute("update mypetdata set amoritem=(amoritem+1) where username='"&DvBBS.MemberName&"'")
				else
					if Monslv > 10 then		'修正10级以上,钱过多，鼓励新手：）	绿光光	 2005-4-8
						Monslv = Monslv /10
					end if
					riskmoney = cint(dropgoods * Monslv / 10)
					Dvbbs.execute("update [DV_user] set userwealth = userwealth+"&riskmoney&" where username='"&DvBBS.MemberName&"'")
					Call UpdateUserInfo(riskmoney,0,0,0,0,0)	'道具Bug修正啦~ 绿光光	 2005-4-8
				end if
			end if

			time2=now()
			connpet.ExeCute("UPDATE mypetdata SET mypetexp=mypetexp+" & riskexp & ",mypetlevel=" & petshowlevel & ",mypethp=" & pethp & ",mypetdead=" & mypetdead & ",risktime='" & time2 & "' WHERE username='"& DvBBS.MemberName &"'")

		dim riskmsg
		if mypetdead=0 then
			riskmsg="<br><div ailgn=center><h3>宝宝大作战</h3></div><br><img src='images/pet/risk.gif' border=0><br><br>你的对手是<br><img src=images/pet/" & monsclass & "/" & monsclass & monsid & ".gif border=0><br>你造成 " & atk & " 点伤害，损失 " & atk2 & " 点ＨＰ 获得 " & riskexp & " 点经验！"
			if dropgoods<dropwp then
				riskmsg=riskmsg & "<br>恭喜你获得以下宝物<br><img src=images/pet/wp.gif><br>武器升级材料"
			elseif dropgoods>dropam then
				riskmsg=riskmsg & "<br>恭喜你获得以下宝物<br><img src=images/pet/am.gif><br>防具升级材料"
			else
				riskmsg=riskmsg & "<br>你获得了 " & riskmoney & DEF_PointsName				
			end if
		else
			riskmsg="<br><div ailgn=center><h3>宝宝大作战</h3></div><br><img src='images/pet/risk.gif' border=0><br><br>你的对手是<br><img src=images/pet/" & monsclass & "/" & monsclass & monsid & ".gif border=0><br><font color=red>你的宠物不幸阵亡了！</font>"
		end if
			'response.write atktmp&"<br>"&atk&"<br>"&atktmp2&"<br>"&atk2&"<br>"&atkrnd&"<br>"&atkrand&"<br>"&defrand&"<br>"&atktemp2
			call showmessage(riskmsg,"petrisk.asp")
			
		end if
	case else
%>
<table width="100%" 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="2" cellpadding="2">
						<tr> 
							<td width="35%">&nbsp;</td>
							<td width="20%"> <div align="center"><img src="images/pet/head/<%=rs("item3")%>.gif" alt="<%=headname%> 防御力 <%=rs("item3Num")%>"></div></td>
							<td width="35%">&nbsp;</td>
						</tr>
						<tr> 
							<td><div align="right"><img height=30 src="images/pet/sword/<%=rs("item1")%>.gif" alt="<%=swordname%> 攻击力 <%=rs("item1Num")%>"></div></td>
							<td rowspan="2"><div align="center">
							<%if rs("imgset")=-1 then%>
							<img src='images/pet/<%=petpic%>/<%=petkill%><%=petpic%><%=levelpic%>.gif' border="0">
							<%else%>
							<img src='images/pet/<%=petpic%>/<%=petkill%><%=petpic%><%=imgset%>.gif' border="0">
							<%end if%>
							</div></td>
							<td><img src="images/pet/body/<%=rs("item4")%>.gif" alt="<%=bodyname%> 防御力 <%=rs("item4Num")%>"></td>
						</tr>
						<tr> 
							<td><div align="right"><img src="images/pet/necklace/<%=rs("item2")%>.gif" alt="<%=necklacename%> 攻击力 <%=rs("item2Num")%>" ></div></td>
							<td><img src="images/pet/foot/<%=rs("item5")%>.gif" alt="<%=footname%> 防御力 <%=rs("item5Num")%>"></td>
						</tr>
						</table>
				  <table width='100%' border='0' cellpadding='1' cellspacing='1'>
					<tr> 
					  <td align="right"> <div align="right">
						  <table width="80%" border="0" align="center" cellpadding="2" cellspacing="2">
							<tr>
							  <td>宠物名称：<%=mypet%> <br>
								攻击力：<%=petatk%><br>
								防御力：<%=petdef%> <br>
								宠物状态：<%=petdead%><br>
								宠物级别：<%=petshowlevel%> <br>
								宠物转生：<%=rs("relive")%> <br>
								HP : <%=pethp%> / <%=petmaxhp%><br> 
								<table width='120' border='0' cellspacing='0' cellpadding='0' bordercolor='#000000'>
								  <tr> 
									<TD width=3 height=13><IMG height=13 src='images/rpg/img_left.gif' width=3></TD>
									<TD width=114 background=images/rpg/img_backing.gif height=13><img src='images/rpg/orange.gif' width='<%=hpf%>%' height='9'><img src='images/rpg/hp.gif' height='9'></td>
									<TD width=3 height=13><IMG height=13 src='images/rpg/img_right.gif' width=3></TD>
								  </tr>
								</table>
								SP : <%=petsp%> / <%=DEF_PET_basicsp%><br> <table width='120' border='0' cellspacing='0' cellpadding='0' bordercolor='#000000'>
								  <tr> 
									<TD width=3 height=13><IMG height=13 src='images/rpg/img_left.gif' width=3></TD>
									<TD width=114 background=images/rpg/img_backing.gif height=13><img src='images/rpg/green.gif' width='<%=spf%>%' height='9'><img src='images/rpg/mp.gif' height='9'></td>
									<TD width=3 height=13><IMG height=13 src='images/rpg/img_right.gif' width=3></TD>
								  </tr>
								</table>
								EXP : <%=petep%>%[<%=rs("mypetexp")%>]<br> <table width='120' border='0' cellspacing='0' cellpadding='0' bordercolor='#000000'>
								  <tr> 
									<TD width=3 height=13><IMG height=13 src='images/rpg/img_left.gif' width=3></TD>
									<TD width=114 background=images/rpg/img_backing.gif height=13><img src='images/rpg/blue.gif' width='<%=petep%>%' height='9'><img src='images/rpg/exp.gif' height='9'></td>
									<TD width=3 height=13><IMG height=13 src='images/rpg/img_right.gif' width=3></TD>
								  </tr>
								</table></td>
							</tr>
						  </table>
						</div></td>
					</tr>
				  </table>
				  <TABLE cellSpacing=3 cellPadding=3 width="100%" align=center border=0>
					<TR> 
					  <TD width="25%"> <DIV align=center><IMG height=35 src="images/pet/hp.gif" width=34><BR>
						  HP药水</DIV></TD>
					  <TD width="25%"> <DIV align=center>拥有数量：<%=hpitem%> 
						  <BR>
						  [<a href="petitemuse.asp?action=usehp">使用</a>]</DIV></TD>
						  </tr>
					 <tr> 
                            <td width="25%"  bgcolor="#0066CC"> 
                              <div align="left"><b><font color="#ffffff">冒险大陆</font></b></div>
                            </td>
                            <td width="25%"  bgcolor="#0066CC"> 
                              <div align="left" ><b><font color="#ffffff">地点说明</font></b></div>
                            </td>
                          </tr>
                          <tr> 
                            <td width="50%" align="right"> 
                              <div align="left">新手村</div>
                            </td>
                            <td width="50%" align="right"> 
                              <div align="left">适合10级以下新手</div>
                            </td>
                          </tr>
                          <tr> 
                            <td width="50%" align="right"> 
                              <div align="left">藏宝洞</div>
                            </td>
                            <td width="50%" align="right"> 
                              <div align="left">适合90级~100级</div>
                            </td>
                          </tr>
                          <tr> 
                            <td width="50%" align="right"> 
                              <div align="left">狩猎城堡</div>
                            </td>
                            <td width="50%" align="right"> 
                              <div align="left">适合20级~30级</div>
                            </td>
                          </tr>
                          <tr> 
                            <td width="50%" align="right"> 
                              <div align="left">狩猎船</div>
                            </td>
                            <td width="50%" align="right"> 
                              <div align="left">适合60级~70级</div>
                            </td>
                          </tr>
                          <tr> 
                            <td width="50%" align="right"> 
                              <div align="left">迷失森林</div>
                            </td>
                            <td width="50%" align="right"> 
                              <div align="left">适合50级~60级</div>
                            </td>
                          </tr>
                          <tr> 
                            <td width="50%" align="right"> 
                              <div align="left">冰峰山</div>
                            </td>
                            <td width="50%" align="right"> 
                              <div align="left">适合80级~90级</div>
                            </td>
                          <tr> 
                            <td width="50%" align="right"> 
                              <div align="left">云中城堡</div>
                            </td>
                            <td width="50%" align="right"> 
                              <div align="left">适合100级以上</div>
                            </td>
                          </tr>
						  </tr></table>
				  <br>
				  <br>
				  <br>
				  <br> <div align="right"></div></td>
				<td width="72%"> <div align="center">
				<map name="petrisk">
				<area href="petrisk.asp?action=risk&monsid=1" shape="circle" coords="204, 393, 32" alt="新手村 0-10级">
				<area href="petrisk.asp?action=risk&monsid=2" shape="circle" coords="143, 290, 31" alt="兽人营地 10-20级">
				<area href="petrisk.asp?action=risk&monsid=3" shape="circle" coords="233, 196, 42" alt="狩猎城堡 20-30级">
				<area href="petrisk.asp?action=risk&monsid=4" shape="circle" coords="127, 188, 37" alt="昆虫之岛 30-40级">
				<area href="petrisk.asp?action=risk&monsid=5" shape="circle" coords="316, 206, 26" alt="屠夫之家 40-50级">
				<area href="petrisk.asp?action=risk&monsid=6" shape="circle" coords="349, 150, 37" alt="迷失森林 50-60级">
				<area href="petrisk.asp?action=risk&monsid=7" shape="circle" coords="457, 217, 36" alt="狩猎船 60-70级">
				<area href="petrisk.asp?action=risk&monsid=8" shape="circle" coords="427, 95, 34" alt="噩梦平原 70-80级">
				<area href="petrisk.asp?action=risk&monsid=9" shape="circle" coords="283, 71, 40" alt="冰峰山 80-90级">
				<area href="petrisk.asp?action=risk&monsid=10" shape="circle" coords="285, 317, 48" alt="藏宝洞 90-100级">
				<area href="petrisk.asp?action=risk&monsid=11" shape="circle" coords="546, 143, 26" alt="云中城 100级以上">
				</map>
				<img border="0" src="images/pet/map.jpg" width="579" height="442" usemap="#petrisk">
				</div></td>
			  </tr>
			</table>

	</td></tr></table>
<%end select : End If :   Set Dv_plus=Nothing : Dvbbs.Footer %>