<!--#include file="Class_PetStatus.asp"-->
<% 
Class PetPurchaseClass


Private TheType,TotalMoney,EquipId,EquipLv,MyEquipLv

Public property Let PurchaseType(value) 
TheType=value 
End Property 

Public property Let PurChaseMoney(value) 
TotalMoney=value 
End Property 

Public property Let GetEquipId(value) 
EquipId=value 
End Property 

Public property Let GetEquipLv(value) 
EquipLv=value 
End Property 

Public property Let GetMyEquipLv(value) 
MyEquipLv=value 
End Property 


Public Sub Purchase

Set Pet=New SQLString
With Pet
.TableName="PetData"

Select Case TheType
Case "BuyPet"

Money=conn.execute("select UserMoney from [BBSXP_Users] where UserName='"&CookieUserName&"'")(0)

Randomize '初始化随机数生成器

PetHp = DEF_PET_basichp
PetSp = DEF_PET_basicsp
PetMp = 100
PetMaxMp = 100
PetSex = Int((2 * Rnd) + 1)

PetSort=Request("PetSort")
PetSortSql="SELECT * FROM [PetSort] Where PetID="&PetSort&" Order By PetID desc"
Set RsPetSort=ConnPet.Execute(PetSortSql)

PetName=RsPetSort(1)
PetFolder=RsPetSort(2)
PetAttribute=RsPetSort(4)
PetDefaultAtk=RsPetSort(6)
PetDefaultDef=RsPetSort(7)
PetPrice=RsPetSort(8)

if PetDefaultAtk=0 then PetDefaultAtk = Int((10 * Rnd) + 1) end if
if PetDefaultDef=0 then PetDefaultDef = Int((10 * Rnd) + 1) end if

rs.open "SELECT * FROM [PetData] where username='"&CookieUserName&"'",ConnPet,1,3
if not rs.eof then
error("你已经有一个宠物了，做人不要三心两意啊~")
elseif request("PetSort") = "" then
error("你还没有选定你要的宝宝啊，请重新选择")
elseif money < PetPrice then
error("你没有足够的钱买宠物") 
else


.SQLType=0
.AddField "UserName",CookieUserName
.AddField "MyPet",PetName
.AddField "PetName",PetFolder
.AddField "PetLevel",1
.AddField "PetExp",1
.AddField "PetHp",PetHp
.AddField "PetMaxHp",PetHp
.AddField "PetMp",PetMp
.AddField "PetMaxMp",PetMaxMp
.AddField "PetSp",PetSp
.AddField "PetMajor","游民"
.AddField "PetAtk",PetDefaultAtk
.AddField "PetDef",PetDefaultDef
.AddField "PetDead",0
.AddField "PetSex",PetSex
.AddField "PetSx",PetAttribute
.AddField "PetFeedDate",Date()
.AddField "PetRegDate",Date()
.AddField "HpItem",1
.AddField "SpItem",1
.AddField "ExpItem",0
.AddField "OpenPK",1
ConnPet.Execute(.ReturnSQL)

Conn.Execute("Update [BBSXP_Users] Set UserMoney=UserMoney-"&PetPrice&" where UserName='"&CookieUserName&"'")

message="<li>你已经拥有个一个"&PetStyle&"宝宝，一定要好好照顾他/她啊<li><a href='PetMyPet.asp'>马上去看看我的宠物</a>"
succeed(message&"<meta http-equiv=refresh content=3;url='PetMyPet.asp'")

End if

Case "BuyItem"

if Money<TotalMoney then error("你没有那么多钱购买这些物品.")
.SQLType=1
.where="UserName='"&CookieUserName&"'"
.AddField "HpItem",HpItem+HpAmount
.AddField "SpItem",SpItem+SpAmount
.AddField "ExpItem",ExpItem+ExpAmount
.AddField "AtkItem",AtkItem+AtkAmount
.AddField "DefItem",DefItem+DefAmount
.AddField "LiveItem",LiveItem+LiveAmount
ConnPet.Execute(.ReturnSQL)


Conn.Execute("Update [BBSXP_Users] Set UserMoney=UserMoney-"&TotalMoney&" where username='"&CookieUserName&"'")
message="<li>购买成功!<br><br>"
message=message&"你治愈药水增加了 "&HpAmount&" 个<br>"
message=message&"粮食增加了 "&SpAmount&" 个<br>"
message=message&"EXP药水增加了 "&ExpAmount&" 个<br>"
message=message&"对武器施法的卷轴增加了 "&AtkAmount&" 个<br>"
message=message&"对盔甲施法的卷轴增加了 "&DefAmount&" 个<br>"
message=message&"魂之精增加了 "&LiveAmount&" 个！<br><br>"
message=message&"<li><a href='PetPropertyShop.asp'>返回道具&装备商店</a>"
succeed(message&"<meta http-equiv=refresh content=3;url='PetPropertyShop.asp'")

Case "BuyEquip"

Select Case EquipId
Case "Item1":EquipType="攻击"
Case "Item2":EquipType="攻击"
Case "Item3":EquipType="防御"
Case "Item4":EquipType="防御"
Case "Item5":EquipType="防御"
End Select


CheckEquipLv=EquipLv-MyEquipLv

if (Money<TotalMoney) then

    error("你没有那么多钱购买这些物品")
        elseif (CheckEquipLv<1) then
    error("你现有的装备等级高于你购买的装备，不用再买了")
        else

Conn.Execute("Update [BBSXP_Users] Set UserMoney=UserMoney-"&TotalMoney&" where username='"&CookieUserName&"'")

ConnPet.ExeCute("UPDATE [PetData] SET "&EquipId&"="&EquipLv&" WHERE UserName='"&CookieUserName&"'")
message="<li>购买成功，你的"&EquipType&"力增加 "&EquipLv&" 点！<li><a href='PetPropertyShop.asp'>返回道具&装备商店</a>"
succeed(message&"<meta http-equiv=refresh content=3;url='PetPropertyShop.asp'")
end if


Case "BuySkill"

Rs=ConnPet.execute("SELECT * FROM [PetData] where username='"&CookieUserName&"'")
skill1=Rs("skill1")
skill2=Rs("skill2")
Set Rs=Nothing
EverGetSkill=0

Money=conn.execute("select UserMoney from [BBSXP_Users] where UserName='"&CookieUserName&"'")(0)

if request("Skill")="" then
error("你还没有选定你要的技能啊，请重新选择.")
elseif money<1000 then
error("你没有足够的钱买该技能.") 
End if

SkillSort=request.form("skill")

select case SkillSort
case 1
if skill1=1 then EverGetSkill=1 end if
case 2
if skill2=1 then EverGetSkill=1 end if
End Select

if EverGetSkill=1 then 
error("你已经拥有这个技能了，不需要再次购买.") 
else
.SQLType=1
.where="UserName='"&CookieUserName&"'"
.AddField "Skill"&SkillSort,1
ConnPet.Execute(.ReturnSQL)

NowMoney=Money-1000
.clear
.TableName="BBSXP_Users"
.SQLType=1
.where="UserName='"&CookieUserName&"'"
.AddField "UserMoney",NowMoney
Conn.Execute(.ReturnSQL)


message="<li>你的宠物已经掌握的此技能，一定要好好利用哦.<li><a href='PetMyPet.asp'>马上去看看我的宠物</a>"
succeed(message&"<meta http-equiv=refresh content=3;url='PetMyPet.asp'")

End if
End Select
End With
Set Pet=Nothing

End Sub


End class 
%>