<!--#include file="setup_pet.asp"-->
<!-- #include file=pet_conn.asp -->
<!--#include file=pet_config.asp-->
<%
top
if Request.Cookies("username")=empty then error("<li>您还未<a href=login.asp>登录</a>论坛")

	
    dim money,smoney,saveday,allmoney,time1,time2,daikuang,dkdu,daiday,sucmsg
    dim Form_userphoto,Form_FaceUrl,Form_FaceWidth,Form_FaceHeight
    
    Dim Rs_pet,SQL_pet

	set rs_pet=conn.execute("select money from [user] where username='"&Request.Cookies("username")&"'")
      	
    money=rs_pet("money")

	    

    rs_pet.close
    

    
    sql_pet = "SELECT * FROM mypetdata WHERE username='"&Request.Cookies("username")&"'"
    rs_pet.open sql_pet,conn_pet,1,3
    if rs_pet.eof then
        error("你还没有宠物啊，<a href=petshop.asp>快攒钱去买吧~</a>")
        else

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



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

pett= DateDiff("d", rs_pet("petregdate"), today)

petlevel = (Log(rs_pet("mypetexp")) / Log(10)) * (Log(rs_pet("mypetexp")) / Log(10)) * (Log(rs_pet("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)
petpic=rs_pet("mypetname")
pethp=rs_pet("mypethp")
petmaxhp=rs_pet("mypetmaxhp")
petatk=rs_pet("mypetatk")+rs_pet("item1")+rs_pet("item2")+2+level1
petdef=rs_pet("mypetdef")+rs_pet("item3")+rs_pet("item4")+rs_pet("item5")+3+level1
updat=0
newpettoday = Now()
if petshowlevel<2 then 
    petmaxhp = DEF_PET_basichp
else 
    petmaxhp=DEF_PET_basichp + petshowlevel*5
end if

if pethp > petmaxhp then
    pethp = petmaxhp
end if

petsp=rs_pet("mypetsp")-pett*DEF_PET_basicsp2
if petsp>DEF_PET_basicsp then
    petsp=DEF_PET_basicsp
end if    
if pett>0 then
    updat=1
end if
hpf= int(100 * (pethp / petmaxhp)) - 1
spf= int(100 * (petsp / DEF_PET_basicsp)) - 1
if pethp<1 then
    pethp=0
    mypetdead=1
    updat=1
elseif petsp<1 then
    petsp=0
    mypetdead=1
    updat=1
else 
    mypetdead=0
    updat=1
end if
item1 = rs_pet("item1")
item2 = rs_pet("item2")
item3 = rs_pet("item3")
item4 = rs_pet("item4")
item5 = rs_pet("item5")
mypet = rs_pet("mypet")
mypetsx = rs_pet("mypetsx")
hpitem = rs_pet("hpitem")
atkitem = rs_pet("atkitem")
spitem = rs_pet("spitem")
defitem = rs_pet("defitem")
expitem = rs_pet("expitem")
liveitem = rs_pet("liveitem")
if pethp<1 or petsp<1 then
    petdead="死亡"
else
    petdead="生存"
end if
if rs_pet("mypetsex")<2 then 
    petsex="雄"
    else 
    petsex="雌"
end if
if rs_pet("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

if updat=1 then

 
 

    sql_pet = "UPDATE mypetdata SET mypetlevel="& petshowlevel &",mypethp="& pethp &",mypetsp="&petsp&",mypetmaxhp="&petmaxhp&",mypetdead="&mypetdead&",petregdate='"&newpettoday&"' WHERE username='"&Request.Cookies("username")&"'"
    rs_pet.update
    updat=0


mypethp = rs_pet("mypethp")
mypetmaxhp = rs_pet("mypetmaxhp")
mypetsp = rs_pet("mypetsp")
mypetdead =rs_pet("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
hptemp=mypetmaxhp-mypethp
pettoday = now()


select case lcase(request("action"))
    case "usehp"
        if(hpitem<1) then
            message="<li>你没有治愈药水"
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        elseif(mypethp=mypetmaxhp or mypetdead=1) then
            if (mypethp=mypetmaxhp) then
                message="<li>你的宝宝体力充沛，不用喝药水了"
				succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
            else 
                message="<li>先把宝宝救活再说吧:("
				succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
            end if
        elseif(hptemp<basicusehp) then
            conn_pet.ExeCute("UPDATE mypetdata SET mypethp=mypetmaxhp,hpitem=hpitem-1 WHERE username='"&Request.Cookies("username")&"'")
            message="<li>使用成功，你的宝宝HP增加了 "& hptemp &" ！"
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        else
            conn_pet.ExeCute("UPDATE mypetdata SET mypethp=mypethp+"&basicusehp&",hpitem=hpitem-1 WHERE username='"&Request.Cookies("username")&"'")
             message="<li>使用成功，你的宝宝HP增加了 "&basicusehp&" ！"
			 succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        end if
    case "usesp"
        if (spitem<1 or mypetdead=1) then
               if (spitem<1) then
                message="<li>你没有糖果"
				succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
               else 
                message="<li>先救活宝宝再喂它吧:("
				succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
               end if
        else
            conn_pet.ExeCute("UPDATE mypetdata SET mypetsp="&basicsp&",spitem=spitem-1,petregdate='"&pettoday&"' WHERE username='"&Request.Cookies("username")&"'")
            message="<li>使用成功，你的宝宝吃饱了 ！"
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        end if
    case "useexp"
        if (expitem<1 or mypetdead=1) then
            if (expitem<1) then
               message="<li>你没有EXP药水"
			   succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
               else 
               message="<li>先救活宝宝再喂它吧:("
			   succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
            end if
        else
            petlevel = (Log(rs_pet("mypetexp")+basicuseexp) / Log(10)) * (Log(rs_pet("mypetexp")+basicuseexp) / Log(10)) * (Log(rs_pet("mypetexp")+basicuseexp) / Log(10))
            petshowlevel = int (petlevel + 1)
            if(petshowlevel<2 ) then
                mypetmaxhp=basichp
            else 
                mypetmaxhp=basichp+petshowlevel*5
            end if
            conn_pet.ExeCute("UPDATE mypetdata SET mypetexp=mypetexp+"&basicuseexp&",expitem=expitem-1,mypetlevel="&petshowlevel&",mypetmaxhp="&mypetmaxhp&" WHERE username='"&Request.Cookies("username")&"'")
            message="<li>使用成功，你的宝宝EXP增加了 "& basicuseexp &"！"
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        end if
    case "useatk"
        if (atkitem<1) then
            message="<li>你没有对武器施法的卷轴"
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        else
        Randomize
        	adatk=fix(rnd*atkup)+0
            conn_pet.ExeCute("UPDATE mypetdata SET mypetatk=mypetatk+"&adatk&",atkitem=atkitem-1 WHERE username='"&Request.Cookies("username")&"'")
            if (adatk=0) then
            message="<li>施法失败...卷轴消失了..."
            else
            message="<li>使用成功，你的宝宝攻击力增加了 "& adatk &" ！"
            end if
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        end if
    case "usedef"
        if (defitem<1) then
            message="<li>你没有对盔甲施法的卷轴"
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        else
                Randomize
        	addef=fix(rnd*defup)+0
            conn_pet.Execute("UPDATE mypetdata SET mypetdef=mypetdef+"&addef&",defitem=defitem-1 WHERE username='"&Request.Cookies("username")&"'")
            if (addef=0) then
            message="<li>施法失败...卷轴消失了..."
            else
            message="<li>使用成功，你的宝宝防御力增加了 "& addef &" ！"
            end if
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        end if
    case "uselive"
        if (liveitem<1) then
            message="<li>你没有复活卷轴"
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        elseif(mypetdead<1) then
            message="<li>你的宝宝还没有死，干吗复活啊？"
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        else
            conn_pet.ExeCute("UPDATE mypetdata SET mypethp="& mypetmaxhp &",mypetsp="& basicsp &",liveitem=liveitem-1,petregdate='"& pettoday &"',mypetdead=0 WHERE username='"&Request.Cookies("username")&"'")
            message="<li>使用成功，你的宝宝复活了 ！"
			succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
        end if
end select

end if
end if


%>
<title>我的宠物</title>
<table border=0 width=<%=dkuan%> align=center cellspacing=1 cellpadding=4 class=a2>
<tr class=a3>
<td height=25>&nbsp;<img src=images/Forum_nav.gif>&nbsp; <%ClubTree%> → 
<a href="petcenter.asp">宠物中心</a></td>
</tr>
</table><br>
    


<table width="<%=dkuan%>"  border="0" align="center" cellpadding="3" cellspacing="3">
<tr><td width="24%" rowspan="3"><div align="center"> 
<table width="90%"  border="0" align="center" cellpadding="3" cellspacing="3">
<tr><td><div align="center"></div>
<!-- #include file=petnav.asp --></td></tr></table>
<table width="79%" border="0" align="center" cellpadding="3" cellspacing="3">
<tr><td width="100%"><div align="center"><img src="images/pet/25.gif"></div></td></tr></table></div>
<div align="center"></div></td><td width="76%"><table width="100%" border="0" cellspacing="2" cellpadding="2" align="center">
                    <tr> 
                      <td width="35%">&nbsp;</td>
                      <td width="20%">
<div align="center"><img src="images/pet/head/<%=item3%>.gif" alt="宠物头盔"></div></td>
                      <td width="35%">&nbsp;</td>
                    </tr>
                    <tr> 
                      <td><div align="right"><img height=30 src="images/pet/sword/<%=item1%>.gif" alt="宠物武器"></div></td>
                      <td rowspan="2"><div align="center">
                      <%if pethp<1 or petsp<1 then%>
                      <img src='images/pet/<%=petpic%>/<%=petpic%><%=levelpic%>.gif' style=filter:GRAY>
                      <%else%>
                      <img src='images/pet/<%=petpic%>/<%=petpic%><%=levelpic%>.gif'>
                      <%end if%>
                      </div></td>
                      <td><img src="images/pet/body/<%=item4%>.gif" alt="宠物盔甲"></td>
                    </tr>
                    <tr> 
                      <td><div align="right"><img src="images/pet/necklace/<%=item2%>.gif" alt="宠物项链" ></div></td>
                      <td><img src="images/pet/foot/<%=item5%>.gif" alt="宠物手套"></td>
                    </tr>
                  </table>
                  <br>
                  <table width='100%' border='0' cellpadding='1' cellspacing='1'>
                    <tr><td width='33%'><div align="left">宠物名称：<%=mypet%>
                          <br>
                          宠物性别：<%=petsex%><br>
                          攻击力：<%=petatk%><br>
                          防御力：<%=petdef%></div></td>
                      <td width='33%'> 宠物状态：<%=petdead%><br>
                        宠物级别：<%=petshowlevel%><br>
                        宠物属性：<%=mypetsx%><br>
                        宠物PK：<%=petpk%></td>
                      <td width='33%'> 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%>%<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>
                </td>
              </tr>
<tr><td><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 alt="增加宠物HP值"><BR>
                          治愈药水</DIV></TD>
                      <TD width="25%"> <DIV align=center>拥有数量：<%=hpitem%> 
                          <BR>
                          [<a href="?action=usehp">使用</a>]</DIV></TD>
                      <TD width="25%"><div align="center"> <IMG height=35 src="images/pet/wj.gif" width=34 alt="随机增加宠物攻击力"><BR>
                          对武器施法的卷轴</div></TD>
                      <TD width="25%"><div align="center">拥有数量：<%=atkitem%><BR>
                          [<a href="?action=useatk">使用</a>]</div></TD>
                    </TR>
                    <TR> 
                      <TD><DIV align=center><img height=35 src="images/pet/sp.gif" width=35 alt="补充宠物sp值"><BR>
                          糖果</DIV></TD>
                      <TD><DIV align=center>拥有数量：<%=spitem%><BR>
                          [<a href="?action=usesp">使用</a>]</DIV></TD>
                      <TD><div align="center"><IMG height=35 src="images/pet/fang.gif" width=34 alt="随机增加宠物防御力"><BR>
                          对盔甲施法的卷轴</div></TD>
                      <TD><div align="center">拥有数量：<%=defitem%><BR>
                          [<a href="?action=usedef">使用</a>]</div></TD>
                    </TR>
                    <TR> 
                      <TD><DIV align=center><IMG height=35 src="images/pet/exp.gif" width=35 alt="增加宠物经验值"><BR>
                          EXP药水</DIV></TD>
                      <TD width="25%"> <div align="center">拥有数量：<%=expitem%><BR>
                          [<a href="?action=useexp">使用</a>]</div></TD>
                      <TD><div align="center"><br>
                          <IMG height=35 src="images/pet/fuhuo.gif" width=34 alt="复活你的宠物"><BR>
                          <font color="#000000">复活卷轴</font></div></TD>
                      <TD><div align="center">拥有数量：<%=liveitem%><BR>
                          [<a href="?action=uselive">使用</a>]</div></TD>
                    </TR>
                  </TABLE></td>
</tr></table>
<%
htmlend
%>
