import sys
from java.util import Iterator
from net.sf.l2j.util import Rnd
from net.sf.l2j.gameserver.serverpackets import CreatureSay
from net.sf.l2j.gameserver.model.quest import State
from net.sf.l2j.gameserver.model.quest import QuestState
from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest
from net.sf.l2j import L2DatabaseFactory
from net.sf.l2j.gameserver.serverpackets import SystemMessage
from net.sf.l2j.gameserver.model import L2ItemInstance
from net.sf.l2j.gameserver.model import L2World
from net.sf.l2j.gameserver.serverpackets import ConfirmDlg
from net.sf.l2j.gameserver.serverpackets import UserInfo
from net.sf.l2j.gameserver.serverpackets import CharInfo
from net.sf.l2j.gameserver.serverpackets import InventoryUpdate
from net.sf.l2j.gameserver.datatables import ItemTable
from net.sf.l2j.gameserver.idfactory import IdFactory
qn = "q8032_MarketBuy"
NPC = [80007]
LIMIT = 12
FIRMONEY = "Adena"
SECMONEY = "Coin of Luck"
RAZDELY = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
#
trans = {1: "Weapon", 2: "Armor", 3: "Resource", 4: "Recipe", 5: "Spellbook", 6: "Soulshot", 7: "AncientAdena", 8: "Scroll", 9: "Crystal", 10: "Potion", 11: "Tatoo", 12: "Arrow", 13: "SoulCrystal", 14: "Rod", 15: "QuestItems", 16: "Life Stone"}
sorts = {1: "Weapon", 2: "Armor", 3: "Resource", 4: "Recipe", 5: "Spellbook", 6: "Soulshot", 7: "AncientAdena", 8: "Scroll", 9: "Crystal", 10: "Potion", 11: "Tatoo", 12: "Arrow", 13: "SoulCrystal", 14: "Rod", 15: "QuestItems", 16: "LifeStone"}
class Quest (JQuest) :
def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)
def onAdvEvent (self,event,npc,player):
st = player.getQuestState(qn)
if event == "list" :
st.unset("stranic")
st.unset("moreitem")
st.unset("morecount")
st.unset("moreprice")
htmltext = "<html><body>Cписок товаров:<br>"
htmltext += "<table width=300><tr>"
counter = 0
for i in RAZDELY:
counter += 1
razdel = trans.get(i, str(""))
htmltext += "<td><button value=\""+str(razdel)+"\" action=\"bypass -h Quest q8032_MarketBuy show_"+str(i)+"\" width=45 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td>"
if counter==5:
htmltext += "</tr><tr>"
counter = 0
htmltext += "</tr></table><br>"
htmltext += "<table width=300><tr><td></td><td>Последние "+str(LIMIT)+":</td></tr>"
con=L2DatabaseFactory.getInstance().getConnection()
listitems=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE mag.itemId>1 AND magicon.itemId=mag.itemId LIMIT 0,?")
listitems.setInt(1, int(LIMIT))
rs=listitems.executeQuery()
while (rs.next()) :
obj=rs.getInt("ownerId")
nick=rs.getString("char_name")
itemname=rs.getString("ItemName")
ench=rs.getInt("enchLvl")
item=rs.getInt("itemId")
grade=rs.getInt("itemGrade")
itype=rs.getString("itemType")
itemobj=rs.getInt("itemObjId")
count=rs.getInt("count")
price=rs.getInt("prise")
money=rs.getInt("money")
icon=rs.getString("itemIcon")
try :
chk = count
if money == 57:
prmoney = str("Adena")
dmoney = str(FIRMONEY)
else:
prmoney = str("COL")
dmoney = str(SECMONEY)
s = str(price)
for i in xrange(len(s)-3,s[0] in ('+','-'),-3):
s=s[:i]+','+s[i:]
pprice = "<font color=00CCFF>"+str(s)+"</font>"
count = (count > 1 and str(count)) or str("")
if chk == 1:
htmltext += "<tr><td><img src=\"Icon."+str(icon)+"\" width=32 height=32></td><td><a msg=\"Купить "+str(itemname)+" у "+str(nick)+" за "+str(s)+" "+dmoney+"?\" action=\"bypass -h Quest q8032_MarketBuy bye_"+str(itemobj)+"\">"+count+" "+str(itemname)+"</a> <br1> "+str(pprice)+" "+prmoney+"; PM: "+str(nick)+"</td></tr>"
else:
htmltext += "<tr><td><img src=\"Icon."+str(icon)+"\" width=32 height=32></td><td><a action=\"bypass -h Quest q8032_MarketBuy showm_"+str(itemobj)+"_"+str(item)+"\">"+count+" "+str(itemname)+"</a> <br1> "+str(pprice)+" "+prmoney+"; PM: "+str(nick)+"</td></tr>"
except :
try : insertion.close()
except : pass
try :
con.close()
except :
pass
htmltext += "</table><br></body></html>"
elif event.startswith("str_"):
search = str(event.replace("str_", ""))
iotype,zagluwka,grade=search.split("_")
iotype,zagluwka,grade=int(iotype),int(zagluwka),int(grade)
strlist = int(zagluwka - 1)
strCount = st.getInt("stranic")
sortType = sorts.get(iotype, str(""))
razdel = trans.get(iotype, str(""))
htmltext = "<html><body><a action=\"bypass -h Quest q8032_MarketBuy list\">Cписок товаров</a>: "+razdel+"<br>"
#>
if iotype > 0:
htmltext += ""
else:
htmltext += "<table width=300><tr>"
counter = 0
for i in RAZDELY:
counter += 1
razdel = trans.get(i, str(""))
htmltext += "<td><button value=\""+str(razdel)+"\" action=\"bypass -h Quest q8032_MarketBuy show_"+str(i)+"\" width=45 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td>"
if counter==5:
htmltext += "</tr><tr>"
counter = 0
htmltext += "</tr></table><br>"
ones = {1: 0, 2: LIMIT}
one = ones.get(zagluwka, int(LIMIT*strlist))
two = LIMIT
con=L2DatabaseFactory.getInstance().getConnection()
#>
if iotype == 0:
sql=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE mag.itemId>1 AND magicon.itemId=mag.itemId LIMIT ?,?")
sql.setInt(1, one)
sql.setInt(2, two)
elif iotype == 1 or iotype == 2 or iotype == 6 or iotype == 9 or iotype == 12:
htmltext += "<table width=300><tr><td><button value=\"NG\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_0\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"D\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_1\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"C\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_2\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"B\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_3\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"A\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_4\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"S\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_5\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr></table>"
if grade == 0 or grade == 99:
sql=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE l2Type=? AND magicon.itemId=mag.itemId LIMIT ?,?")
sql.setString(1, sortType)
sql.setInt(2, one)
sql.setInt(3, two)
else:
sql=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE l2Type=? AND itemGrade=? AND magicon.itemId=mag.itemId LIMIT ?,?")
sql.setString(1, sortType)
sql.setInt(2, grade)
sql.setInt(3, one)
sql.setInt(4, two)
elif iotype > 2 and iotype <16:
if grade == 0 or grade == 99:
sql=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE l2Type=? AND magicon.itemId=mag.itemId LIMIT ?,?")
sql.setString(1, sortType)
sql.setInt(2, one)
sql.setInt(3, two)
else:
sql=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE l2Type=? AND itemGrade=? AND magicon.itemId=mag.itemId LIMIT ?,?")
sql.setString(1, sortType)
sql.setInt(2, grade)
sql.setInt(3, one)
sql.setInt(4, two)
rs=sql.executeQuery()
htmltext += "<table width=300><tr><td></td><td>Страница: "+str(zagluwka)+"</td></tr>"
#>
while (rs.next()) :
obj=rs.getInt("ownerId")
nick=rs.getString("char_name")
itemname=rs.getString("ItemName")
ench=rs.getInt("enchLvl")
item=rs.getInt("itemId")
grade=rs.getInt("itemGrade")
itype=rs.getString("itemType")
itemobj=rs.getInt("itemObjId")
count=rs.getInt("count")
price=rs.getInt("prise")
money=rs.getInt("money")
icon=rs.getString("itemIcon")
try :
chk = count
if money == 57:
prmoney = str("Adena")
dmoney = str(FIRMONEY)
else:
prmoney = str("COL")
dmoney = str(SECMONEY)
s = str(price)
for i in xrange(len(s)-3,s[0] in ('+','-'),-3):
s=s[:i]+','+s[i:]
pprice = "<font color=00CCFF>"+str(s)+" "+prmoney+"</font>"
count = (count > 1 and str(count)) or str("")
if chk == 1:
htmltext += "<tr><td><img src=\"Icon."+str(icon)+"\" width=32 height=32></td><td><a msg=\"Купить "+str(itemname)+" у "+str(nick)+" за "+str(s)+" "+dmoney+"?\" action=\"bypass -h Quest q8032_MarketBuy bye_"+str(itemobj)+"\">"+count+" "+str(itemname)+"</a> <br1> "+str(pprice)+" "+prmoney+"; PM: "+str(nick)+"</td></tr>"
else:
htmltext += "<tr><td><img src=\"Icon."+str(icon)+"\" width=32 height=32></td><td><a action=\"bypass -h Quest q8032_MarketBuy showm_"+str(itemobj)+"_"+str(item)+"\">"+count+" "+str(itemname)+"</a> <br1> "+str(pprice)+" "+prmoney+"; PM: "+str(nick)+"</td></tr>"
except :
try : sql.close()
except : pass
try :
con.close()
except :
pass
htmltext += "</table><br>Страницы: "
prvsego = range(1,strCount)
for i in prvsego:
htmltext += "<a action=\"bypass -h Quest q8032_MarketBuy str_"+str(iotype)+"_"+str(i)+"_"+str(grade)+"\">"+str(i)+"</a> "
htmltext += "</body></html>"
elif event.startswith("show_"):
iotype = int(event.replace("show_", ""))
sortType = sorts.get(iotype, str(""))
razdel = trans.get(iotype, str(""))
iotype = str(iotype)
htmltext = "<html><body><a action=\"bypass -h Quest q8032_MarketBuy list\">Cписок товаров</a>: "+razdel+"<br>"
con=L2DatabaseFactory.getInstance().getConnection()
if iotype == "1" or iotype == "2" or iotype == "6" or iotype =="9" or iotype =="12":
htmltext += "<table width=300><tr><td><button value=\"NG\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_0\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"D\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_1\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"C\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_2\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"B\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_3\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"A\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_4\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"S\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_5\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr></table>"
htmltext += "<table width=300><tr><td></td><td>Последние "+str(LIMIT)+":</td></tr>"
sql=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE l2Type=? AND magicon.itemId=mag.itemId LIMIT 0,?")
sql.setString(1, sortType)
sql.setInt(2, int(LIMIT))
else:
htmltext += "<table width=300><tr><td></td><td></td><td></td><td></td></tr>"
sql=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE l2Type=? AND magicon.itemId=mag.itemId LIMIT 0,?")
sql.setString(1, sortType)
sql.setInt(2, int(LIMIT))
htmltext += "<tr><td></td><td>Предмет</td></tr>"
rs=sql.executeQuery()
while (rs.next()) :
obj=rs.getInt("ownerId")
nick=rs.getString("char_name")
itemname=rs.getString("ItemName")
ench=rs.getInt("enchLvl")
item=rs.getInt("itemId")
grade=rs.getInt("itemGrade")
itype=rs.getString("l2Type")
ltype=rs.getString("itemType")
itemobj=rs.getInt("itemObjId")
count=rs.getInt("count")
price=rs.getInt("prise")
money=rs.getInt("money")
icon=rs.getString("itemIcon")
try :
chk = count
if money == 57:
prmoney = str("Adena")
dmoney = str(FIRMONEY)
else:
prmoney = str("COL")
dmoney = str(SECMONEY)
s = str(price)
for i in xrange(len(s)-3,s[0] in ('+','-'),-3):
s=s[:i]+','+s[i:]
pprice = "<font color=00CCFF>"+str(s)+"</font>"
count = (count > 1 and str(count)) or str("")
if chk == 1:
htmltext += "<tr><td><img src=\"Icon."+str(icon)+"\" width=32 height=32></td><td><a msg=\"Купить "+str(itemname)+" у "+str(nick)+" за "+str(s)+" "+dmoney+"?\" action=\"bypass -h Quest q8032_MarketBuy bye_"+str(itemobj)+"\">"+count+" "+str(itemname)+"</a> <br1> "+str(pprice)+" "+prmoney+"; PM: "+str(nick)+"</td></tr>"
else:
htmltext += "<tr><td><img src=\"Icon."+str(icon)+"\" width=32 height=32></td><td><a action=\"bypass -h Quest q8032_MarketBuy showm_"+str(itemobj)+"_"+str(item)+"\">"+count+" "+str(itemname)+"</a> <br1> "+str(pprice)+" "+prmoney+"; PM: "+str(nick)+"</td></tr>"
except :
try : sql.close()
except : pass
try :
con.close()
except :
pass
htmltext += "</table><br>"
cona=L2DatabaseFactory.getInstance().getConnection()
getcount=cona.prepareStatement("SELECT COUNT(l2Type) FROM z_market_sell WHERE l2Type=?")
getcount.setString(1, sortType)
rsc=getcount.executeQuery()
if (rsc.next()):
rows = rsc.getInt(1)
vsego = int((rows/LIMIT)+2)
if vsego > 3:
htmltext += "Страницы: "
st.set("stranic",str(vsego))
prvsego = range(1,vsego)
for i in prvsego:
htmltext += ""
htmltext += " <a action=\"bypass -h Quest q8032_MarketBuy str_"+str(iotype)+"_"+str(i)+"_99\">"+str(i)+"</a> "
else:
htmltext += ""
rsc.close()
getcount.close()
cona.close()
htmltext += "</body></html>"
elif event.startswith("iotype_"):
search = str(event.replace("iotype_", ""))
iotype,grade=search.split("_")
iotype,grade=int(iotype),int(grade)
sortType = sorts.get(iotype, str(""))
razdel = trans.get(iotype, str(""))
link = str(iotype)
grades = {0: str("NG"),1: str("[D]"), 2: str("[C]"), 3: str("[B]"), 4: str("[A]"), 5: str("[S]")}
pgrade = grades.get(grade, str(""))
htmltext = "<html><body><a action=\"bypass -h Quest q8032_MarketBuy list\">Cписок товаров</a>: <a action=\"bypass -h Quest q8032_MarketBuy show_"+link+"\">"+razdel+"</a>: "+pgrade+" <br>"
htmltext += "<table width=300><tr><td><button value=\"NG\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_0\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"D\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_1\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"C\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_2\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"B\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_3\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"A\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_4\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td><button value=\"S\" action=\"bypass -h Quest q8032_MarketBuy iotype_"+str(iotype)+"_5\" width=25 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr></table>"
htmltext += "<table width=300><tr><td></td><td>Предмет</td></tr>"
con=L2DatabaseFactory.getInstance().getConnection()
listitems=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE l2Type=? AND itemGrade=? AND magicon.itemId=mag.itemId LIMIT 0,?")
listitems.setString(1, sortType)
listitems.setInt(2, grade)
listitems.setInt(3, int(LIMIT))
rs=listitems.executeQuery()
while (rs.next()) :
obj=rs.getInt("ownerId")
nick=rs.getString("char_name")
itemname=rs.getString("ItemName")
ench=rs.getInt("enchLvl")
item=rs.getInt("itemId")
grade=rs.getInt("itemGrade")
itype=rs.getString("itemType")
itemobj=rs.getInt("itemObjId")
count=rs.getInt("count")
price=rs.getInt("prise")
money=rs.getInt("money")
icon=rs.getString("itemIcon")
try :
chk = count
if money == 57:
prmoney = str("Adena")
dmoney = str(FIRMONEY)
else:
prmoney = str("COL")
dmoney = str(SECMONEY)
s = str(price)
for i in xrange(len(s)-3,s[0] in ('+','-'),-3):
s=s[:i]+','+s[i:]
pprice = "<font color=00CCFF>"+str(s)+"</font>"
count = (count > 1 and str(count)) or str("")
if chk == 1:
htmltext += "<tr><td><img src=\"Icon."+str(icon)+"\" width=32 height=32></td><td><a msg=\"Купить "+str(itemname)+" у "+str(nick)+" за "+str(s)+" "+dmoney+"?\" action=\"bypass -h Quest q8032_MarketBuy bye_"+str(itemobj)+"\">"+count+" "+str(itemname)+"</a> <br1> "+str(pprice)+" "+prmoney+"; PM: "+str(nick)+"</td></tr>"
else:
htmltext += "<tr><td><img src=\"Icon."+str(icon)+"\" width=32 height=32></td><td><a action=\"bypass -h Quest q8032_MarketBuy showm_"+str(itemobj)+"_"+str(item)+"\">"+count+" "+str(itemname)+"</a> <br1> "+str(pprice)+" "+prmoney+"; PM: "+str(nick)+"</td></tr>"
except :
try : insertion.close()
except : pass
try :
con.close()
except :
pass
htmltext += "</table><br>"
cona=L2DatabaseFactory.getInstance().getConnection()
getcount=cona.prepareStatement("SELECT COUNT(itemGrade) FROM z_market_sell WHERE l2Type=? AND itemGrade=?")
getcount.setString(1, str(sortType))
getcount.setInt(2, grade)
rsc=getcount.executeQuery()
if (rsc.next()):
rows = rsc.getInt(1)
vsego = int((rows/LIMIT)+2)
if vsego > 3:
htmltext += "Страницы: "
st.set("stranic",str(vsego))
prvsego = range(1,vsego)
for i in prvsego:
htmltext += ""
htmltext += " <a action=\"bypass -h Quest q8032_MarketBuy str_"+str(iotype)+"_"+str(i)+"_"+str(grade)+"\">"+str(i)+"</a> "
else:
htmltext += ""
rsc.close()
getcount.close()
cona.close()
htmltext += "</body></html>"
elif event.startswith("bye_"):
itemObjId = int(event.replace("bye_", ""))
#=====#
cona=L2DatabaseFactory.getInstance().getConnection()
getcount=cona.prepareStatement("SELECT COUNT(itemObjId) FROM z_market_sell WHERE itemObjId=?")
getcount.setInt(1, itemObjId)
rsc=getcount.executeQuery()
if (rsc.next()):
if rsc.getInt(1)>0:
conn=L2DatabaseFactory.getInstance().getConnection()
byeitem=conn.prepareStatement("SELECT * FROM z_market_sell WHERE itemObjId=?")
byeitem.setInt(1, itemObjId)
rs=byeitem.executeQuery()
while (rs.next()) :
owner=rs.getInt("ownerId")
nick=rs.getString("char_name")
itemname=rs.getString("ItemName")
ench=rs.getInt("enchLvl")
item=rs.getInt("itemId")
grade=rs.getInt("itemGrade")
itype=rs.getString("itemType")
itemobj=rs.getInt("itemObjId")
count=rs.getInt("count")
price=rs.getInt("prise")
money=rs.getInt("money")
try :
chkprice = int(count*price)
if money == 57:
pmoney = str(FIRMONEY)
else:
pmoney = str(SECMONEY)
if st.getQuestItemsCount(money) >= chkprice:
price = int(count*price)
st.takeItems(money,price)
if ench == 0:
st.giveItems(item,count)
enchant = str("")
else:
st.giveItems(item,count,ench)
enchant = " +"+str(ench)+""
st.getPlayer().sendPacket(SystemMessage.sendString("Куплено "+str(count)+" "+(itemname)+" у "+str(nick)+" за "+str(price)+" "+pmoney+"!"));
htmltext = "<html><body>Куплено <font color=LEVEL>"+str(count)+" "+(itemname)+"</font> у "+str(nick)+" за "+str(price)+" "+pmoney+"!<br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a></body></html>"
#
seller = L2World.getInstance().getPlayer(nick)
if seller:
seller.sendPacket(SystemMessage.sendString("Предмет "+str(count)+" "+(itemname)+" был продан на аукционе!"));
seller.sendPacket(ConfirmDlg(614,"Предмет "+str(count)+" "+(itemname)+" был продан на аукционе!"))
#
pvin = ""+str(count)+" "+str(itemname)+""
private=L2DatabaseFactory.getInstance().getConnection()
newItemObj = IdFactory.getInstance().getNextId()
off=private.prepareStatement("INSERT INTO z_market_private (ownerId,ItemName,itemObjId,prise,money) VALUES (?,?,?,?,?)")
off.setInt(1, owner)
off.setString(2, pvin)
off.setInt(3, newItemObj)
off.setInt(4, price)
off.setInt(5, money)
try :
off.executeUpdate()
off.close()
private.close()
except :
try : private.close()
except : pass
#
con=L2DatabaseFactory.getInstance().getConnection()
kupleno=con.prepareStatement("DELETE FROM z_market_sell WHERE itemObjId = ?")
kupleno.setInt(1, itemObjId)
try :
kupleno.executeUpdate()
kupleno.close()
con.close()
except :
try : con.close()
except : pass
else:
htmltext = "<html><body>У вас не хватает "+pmoney+"<br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a></body></html>"
except :
try :
byeitem.close()
except : pass
try :
conn.close()
except :
pass
#
else:
htmltext = "<html><body>Предмет уже кто-то купил ): <br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a></body></html>"
else:
htmltext = "<html><body>Oops!<br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a></body></html>"
rsc.close()
getcount.close()
cona.close()
elif event.startswith("showm_"):
search = str(event.replace("showm_", ""))
obj,itemid=search.split("_")
obj,itemid=int(obj),int(itemid)
con=L2DatabaseFactory.getInstance().getConnection()
listitems=con.prepareStatement("SELECT * FROM `z_market_sell` mag, `z_market_icons` magicon WHERE mag.itemObjId=? AND magicon.itemId=?")
listitems.setInt(1, obj)
listitems.setInt(2, itemid)
rs=listitems.executeQuery()
while (rs.next()) :
icon=rs.getString("itemIcon")
itemname=rs.getString("ItemName")
nickname=rs.getString("char_name")
grade=rs.getInt("itemGrade")
enchan=rs.getInt("enchLvl")
count=rs.getInt("count")
price=rs.getInt("prise")
money=rs.getInt("money")
try :
st.set("moreitem",str(obj))
st.set("morecount",str(count))
st.set("moreprice",str(price))
if money == 57:
dmoney = str(FIRMONEY)
else:
dmoney = str(SECMONEY)
mprice = int(count*price)
s = str(price)
for i in xrange(len(s)-3,s[0] in ('+','-'),-3):
s=s[:i]+','+s[i:]
pprice = "<font color=00CCFF>"+str(s)+" "+dmoney+"</font>"
grades = {1: "d", 2: "c", 3: "b", 4: "a", 5: "s"}
pgrade = grades.get(grade, str(""))
enchant = (enchan > 0 and " +"+str(enchan)+"") or str("")
htmltext = "<html><body>Вы выбрали:<br>"
htmltext += "<table width=300><tr><td><img src=\"Icon."+str(icon)+"\" width=32 height=32></td><td><font color=LEVEL>"+str(itemname)+" "+str(enchant)+"</font><br1>Цена: "+str(pprice)+"; Продавец: "+str(nickname)+"</td></tr></table>"
htmltext += "<br>В продаже: "+str(count)+""
htmltext += "<br>Сколько хотите купить?:"
htmltext += "<edit var=\"cols\" width=200 length=\"10\"><br>"
htmltext += "<button value=\"Ok\" action=\"bypass -h Quest q8032_MarketBuy byem_ $cols _ xz\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"><br>"
htmltext += "<br><a msg=\"Скупить все "+str(count)+" "+str(itemname)+" у "+str(nickname)+" за "+str(mprice)+" adena?\" action=\"bypass -h Quest q8032_MarketBuy bye_"+str(obj)+"\">Скупить всё</a><br>"
htmltext += "<br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a></body></html>"
except :
try : listitems.close()
except : pass
try :
con.close()
except :
pass
elif event.startswith("byem_ "):
search = str(event.replace("byem_ ", ""))
search,ptype=search.split("_")
search,ptype=str(search),str(ptype)
search = str(search.replace(" ", ""))
ptype = str(ptype.replace(" ", ""))
if search == "":
htmltext = "<html><body>Вы не указали количество.<br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a></body></html>"
return htmltext
wantcount = int(search)
itemObjId = st.getInt("moreitem")
itemCount = st.getInt("morecount")
onePrice = st.getInt("moreprice")
#=====#
cona=L2DatabaseFactory.getInstance().getConnection()
getcount=cona.prepareStatement("SELECT COUNT(itemObjId) FROM z_market_sell WHERE itemObjId=?")
getcount.setInt(1, itemObjId)
rsc=getcount.executeQuery()
if (rsc.next()):
if rsc.getInt(1)>0:
conn=L2DatabaseFactory.getInstance().getConnection()
byeitem=conn.prepareStatement("SELECT * FROM z_market_sell WHERE itemObjId=?")
byeitem.setInt(1, itemObjId)
rs=byeitem.executeQuery()
while (rs.next()) :
owner=rs.getInt("ownerId")
nick=rs.getString("char_name")
itemname=rs.getString("ItemName")
ench=rs.getInt("enchLvl")
item=rs.getInt("itemId")
grade=rs.getInt("itemGrade")
itype=rs.getString("itemType")
itemobj=rs.getInt("itemObjId")
count=rs.getInt("count")
price=rs.getInt("prise")
money=rs.getInt("money")
try :
writepr = price
price = int(onePrice*wantcount)
ost = int(count-wantcount)
if money == 57:
pmoney = str(FIRMONEY)
else:
pmoney = str(SECMONEY)
if wantcount > count:
htmltext = "<html><body>Неправильное количество предметов!<br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a></body></html>"
elif st.getQuestItemsCount(money) >= price:
st.takeItems(money,price)
if ench == 0:
st.giveItems(item,wantcount)
enchant = str("")
else:
st.giveItems(item,wantcount,ench)
enchant = " +"+str(ench)+""
st.getPlayer().sendPacket(SystemMessage.sendString("Куплено "+str(wantcount)+" "+(itemname)+" у "+str(nick)+" за "+str(price)+" "+pmoney+"!"));
htmltext = "<html><body>Куплено <font color=LEVEL>"+str(wantcount)+" "+(itemname)+"</font> у "+str(nick)+" за "+str(price)+" "+pmoney+"!<br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a></body></html>"
#
seller = L2World.getInstance().getPlayer(nick)
if seller:
seller.sendPacket(SystemMessage.sendString("Предмет "+str(wantcount)+" "+(itemname)+" был продан на аукционе!"));
seller.sendPacket(ConfirmDlg(614,"Предмет "+str(wantcount)+" "+(itemname)+" был продан на аукционе!"))
#
pvin = ""+str(wantcount)+" "+str(itemname)+""
newItemObj = IdFactory.getInstance().getNextId()
private=L2DatabaseFactory.getInstance().getConnection()
off=private.prepareStatement("INSERT INTO z_market_private (ownerId,ItemName,itemObjId,prise,money) VALUES (?,?,?,?,?)")
off.setInt(1, owner)
off.setString(2, pvin)
off.setInt(3, newItemObj)
off.setInt(4, price)
off.setInt(5, money)
try :
off.executeUpdate()
off.close()
private.close()
except :
try : private.close()
except : pass
#
if ost>0:
con=L2DatabaseFactory.getInstance().getConnection()
kupleno=con.prepareStatement("UPDATE z_market_sell SET count=?, prise=? WHERE itemObjId =?")
kupleno.setInt(1, ost)
kupleno.setInt(2, writepr)
kupleno.setInt(3, itemObjId)
try :
kupleno.executeUpdate()
kupleno.close()
con.close()
except :
try : con.close()
except : pass
else:
con=L2DatabaseFactory.getInstance().getConnection()
kupleno=con.prepareStatement("DELETE FROM z_market_sell WHERE itemObjId = ?")
kupleno.setInt(1, itemObjId)
try :
kupleno.executeUpdate()
kupleno.close()
con.close()
except :
try : con.close()
except : pass
else:
htmltext = "<html><body>У вас не хватает "+pmoney+"</body></html>"
except :
try :
byeitem.close()
except : pass
try :
conn.close()
except :
pass
#
else:
htmltext = "<html><body>Предмет уже кто-то купил ):<br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a> </body></html>"
else:
htmltext = "<html><body>Oops!<br><br><a action=\"bypass -h Quest q8032_MarketBuy list\">Вернуться.</a></body></html>"
rsc.close()
getcount.close()
cona.close()
return htmltext
def onTalk (self,npc,player):
st = player.getQuestState(qn)
npcId = npc.getNpcId()
if npcId == NPC:
htmltext = "privetstvie.htm"
return "htmltext
QUEST = Quest(8032,qn,"custom")
for npcId in NPC:
QUEST.addStartNpc(npcId)
QUEST.addTalkId(npcId)