import sys
from java.lang import System
from java.util import Iterator
from ru.catssoftware import L2DatabaseFactory
from ru.catssoftware.tools.random import Rnd
from ru.catssoftware.gameserver.model.quest import State
from ru.catssoftware.gameserver.model.quest import QuestState
from ru.catssoftware.gameserver.model.quest.jython import QuestJython as JQuest
from time import gmtime, strftime
qn = "1235_ShadowName"
print "1235_ShadowName - Loaded"
NPC = 50016
ITEM = 4037 # итем необходимый для обмена
COST = 20 # стоимость
INAME = "Donate Coin" # название итема
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 == "step1":
if st.getQuestItemsCount(ITEM) < COST:
htmltext = "<html><body><center>Стоимость Смены ника: <font color=74bff5>"+str(COST)+" "+INAME+"</font><center></body></html>"
return htmltext
#elif player.getClanId():
#htmltext = "<html><body>Для смены ника вам необходимо выйти из клана<br>Вы сможете вступить вновь, сразу после смены ника<br>Если вы кланлидер - перекиньте клан на твинка</body></html>"
#return htmltext
htmltext = "<html><body><center>Стоимость услуги 10 Donate Coin<br><img src=\"L2UI.SquareBlank\" width=260 height=2><br1>"
htmltext += "Введите желаемый ник:"
htmltext += "<edit var=\"nick\" width=200 length=\"16\"><br>"
htmltext += "<button value=\"Проверить\" action=\"bypass -h Quest 1235_ShadowName step2_ $nick\" width=94 height=21 back=\"orm.but\" fore=\"orm.but\"><br>"
htmltext += "</center></body></html>"
elif event.startswith("step2_"):
nick = str(event.replace("step2_", ""))
nick = str(nick.replace(" ", ""))
htmltext = "<html><body><center><br><br>"
if nick == "":
htmltext += "Вы не ввели желаемый ник!<br><br>"
htmltext += "<a action=\"bypass -h Quest 1235_ShadowName step1\">Вернуться.</a></body></html>"
return htmltext
elif nick.startswith("GM.") or nick.startswith("ADM.") or nick.startswith("EGM.") or nick.startswith("-"):
htmltext += "Неправильный ник!<br><br>"
htmltext += "<a action=\"bypass -h Quest 1235_ShadowName step1\">Вернуться.</a></body></html>"
return htmltext
elif nick.endswith(".GM") or nick.endswith(".ADM") or nick.endswith(".EGM"):
htmltext += "Неправильный ник!<br><br>"
htmltext += "<a action=\"bypass -h Quest 1235_ShadowName step1\">Вернуться.</a></body></html>"
return htmltext
#<
cona=L2DatabaseFactory.getInstance().getConnection()
getcount=cona.prepareStatement("SELECT COUNT(char_name) FROM characters WHERE char_name=?")
getcount.setString(1,nick)
rsc=getcount.executeQuery()
if (rsc.next()):
if rsc.getInt(1) == 1:
htmltext = "Ник "+nick+" уже занят."
return htmltext
rsc.close()
getcount.close()
cona.close()
#<
htmltext += "Ник <font color=bef574>"+nick+"</font> свободен.<br>"
htmltext += "<a action=\"bypass -h Quest 1235_ShadowName step3_"+nick+"\" msg=\"Новый ник "+nick+". Уверены?\">Продолжить</a><br><br>"
htmltext += "<a action=\"bypass -h Quest 1235_ShadowName step1\">Я передумал</a></body></html>"
elif event.startswith("step3"):
nick = str(event.replace("step3_", ""))
if st.getQuestItemsCount(ITEM) < COST:
htmltext = "<html><body>Смена ника: <font color=74bff5>"+str(COST)+" "+INAME+"</font></center></body></html>"
return htmltext
#<
login = str(player.getAccountName())
name = str(player.getName())
date = str(strftime("%Y-%m-%d", gmtime()))
time = str(strftime("%H:%M:%S", gmtime()))
writelog=L2DatabaseFactory.getInstance().getConnection()
write=writelog.prepareStatement("INSERT INTO zz_donate_log (date,time,login,name,action,payment) VALUES (?,?,?,?,?,?)")
write.setString(1, date)
write.setString(2, time)
write.setString(3, login)
write.setString(4, name)
write.setString(5, "Nick: "+nick+"")
write.setInt(6, COST)
try :
write.executeUpdate()
write.close()
writelog.close()
except :
try : writelog.close()
except : pass
#<
player.setName(nick)
st.takeItems(ITEM,COST)
htmltext = "<html><body><center>Смена ника:<br>Готово.<br><font color=f5b974>Перезайдите!</font><br></body></html>"
else:
htmltext = "<html><body>Смена ника:<br>Oops!</center></body></html>"
return htmltext
def onTalk (self,npc,player):
st = player.getQuestState(qn)
npcId = npc.getNpcId()
if npcId == NPC:
self.startQuestTimer("step1",100,None,player)
return
QUEST = Quest(1235,qn,"custom")
QUEST.addStartNpc(NPC)
QUEST.addTalkId(NPC)