Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.54 KB | None | 0 0
  1. import net
  2. import player
  3. import item
  4. import snd
  5. import shop
  6. import net
  7. import wndMgr
  8. import app
  9. import chat
  10. import constInfo
  11. import ui
  12. import uiCommon
  13. import mouseModule
  14. import localeInfo
  15. import chr
  16.  
  17. ###################################################################################################
  18. ## Shop
  19. class ShopDialog(ui.ScriptWindow):
  20.  
  21. def __init__(self):
  22. ui.ScriptWindow.__init__(self)
  23. self.tooltipItem = 0
  24. self.xShopStart = 0
  25. self.yShopStart = 0
  26. self.vid = 0
  27. self.questionDialog = None
  28. self.popup = None
  29. self.itemBuyQuestionDialog = None
  30.  
  31. def __del__(self):
  32. ui.ScriptWindow.__del__(self)
  33.  
  34. def Refresh(self):
  35. getItemID=shop.GetItemID
  36. getItemCount=shop.GetItemCount
  37. setItemID=self.itemSlotWindow.SetItemSlot
  38. for i in xrange(shop.SHOP_SLOT_COUNT):
  39. itemCount = getItemCount(i)
  40.  
  41. if itemCount <= 1:
  42. itemCount = 0
  43. setItemID(i, getItemID(i), itemCount)
  44.  
  45. wndMgr.RefreshSlot(self.itemSlotWindow.GetWindowHandle())
  46.  
  47. def SetItemData(self, pos, itemID, itemCount, itemPrice):
  48. shop.SetItemData(pos, itemID, itemCount, itemPrice)
  49.  
  50. def LoadDialog(self):
  51. try:
  52. PythonScriptLoader = ui.PythonScriptLoader()
  53. PythonScriptLoader.LoadScriptFile(self, "UIScript/shopdialog.py")
  54. except:
  55. import exception
  56. exception.Abort("ShopDialog.LoadDialog.LoadObject")
  57.  
  58. try:
  59. GetObject = self.GetChild
  60. self.itemSlotWindow = GetObject("ItemSlot")
  61. self.btnBuy = GetObject("BuyButton")
  62. self.btnSell = GetObject("SellButton")
  63. self.btnClose = GetObject("CloseButton")
  64. self.titleBar = GetObject("TitleBar")
  65. except:
  66. import exception
  67. exception.Abort("ShopDialog.LoadDialog.BindObject")
  68.  
  69. self.itemSlotWindow.SetSlotStyle(wndMgr.SLOT_STYLE_NONE)
  70. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EMPTY", self.SelectEmptySlot)
  71. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EXIST", self.SelectItemSlot)
  72. self.itemSlotWindow.SAFE_SetButtonEvent("RIGHT", "EXIST", self.UnselectItemSlot)
  73.  
  74. self.itemSlotWindow.SetOverInItemEvent(ui.__mem_func__(self.OverInItem))
  75. self.itemSlotWindow.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem))
  76.  
  77. self.btnBuy.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  78. self.btnBuy.SetToggleDownEvent(ui.__mem_func__(self.OnBuy))
  79.  
  80. self.btnSell.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  81. self.btnSell.SetToggleDownEvent(ui.__mem_func__(self.OnSell))
  82.  
  83. self.btnClose.SetEvent(ui.__mem_func__(self.AskClosePrivateShop))
  84.  
  85. self.titleBar.SetCloseEvent(ui.__mem_func__(self.Close))
  86.  
  87. self.Refresh()
  88.  
  89. def Destroy(self):
  90. self.Close()
  91. self.ClearDictionary()
  92.  
  93. self.tooltipItem = 0
  94. self.itemSlotWindow = 0
  95. self.btnBuy = 0
  96. self.btnSell = 0
  97. self.btnClose = 0
  98. self.titleBar = 0
  99. self.vid = 0
  100. self.questionDialog = None
  101. self.popup = None
  102.  
  103. def Open(self, vid, type=0):
  104. self.vid=int(vid)
  105. isPrivateShop = False
  106. isMainPlayerPrivateShop = False
  107. myshop=False
  108. for i in xrange(len(constInfo.MyShops)):
  109. if int(constInfo.MyShops[i]["vid"]) == int(self.vid):
  110. myshop=True
  111. self.vid=int(constInfo.MyShops[i]["id"])
  112. chr.SelectInstance(self.vid)
  113. if chr.GetRace() == 30000 or not chr.IsNPC(self.vid):
  114. isPrivateShop = True
  115. if player.IsMainCharacterIndex(self.vid):
  116. myshop=True
  117. self.vid=""
  118. if myshop == True:
  119. isMainPlayerPrivateShop = True
  120.  
  121. self.btnBuy.Hide()
  122. self.btnSell.Hide()
  123. self.btnClose.Show()
  124.  
  125. else:
  126.  
  127. isMainPlayerPrivateShop = False
  128.  
  129. self.btnBuy.Show()
  130. self.btnSell.Show()
  131. self.btnClose.Hide()
  132. shop.Open(isPrivateShop, isMainPlayerPrivateShop)
  133. self.Refresh()
  134. self.SetTop()
  135. self.Show()
  136.  
  137. (self.xShopStart, self.yShopStart, z) = player.GetMainCharacterPosition()
  138.  
  139. def Close(self):
  140. self.OnCloseQuestionDialog()
  141. shop.Close()
  142. net.SendShopEndPacket()
  143. self.CancelShopping()
  144. self.tooltipItem.HideToolTip()
  145. self.Hide()
  146.  
  147. def AskClosePrivateShop(self):
  148. questionDialog = uiCommon.QuestionDialog()
  149. questionDialog.SetText(localeInfo.PRIVATE_SHOP_CLOSE_QUESTION)
  150. questionDialog.SetAcceptEvent(ui.__mem_func__(self.OnClosePrivateShop))
  151. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  152. questionDialog.Open()
  153. self.questionDialog = questionDialog
  154.  
  155. return TRUE
  156.  
  157. def OnClosePrivateShop(self):
  158. net.SendChatPacket("/close_shop "+str(self.vid))
  159. self.OnCloseQuestionDialog()
  160. return True
  161.  
  162. def OnPressEscapeKey(self):
  163. self.Close()
  164. return TRUE
  165.  
  166. def OnPressExitKey(self):
  167. self.Close()
  168. return TRUE
  169.  
  170. def OnBuy(self):
  171. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_BUY_INFO)
  172. app.SetCursor(app.BUY)
  173. self.btnSell.SetUp()
  174.  
  175. def OnSell(self):
  176. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  177. app.SetCursor(app.SELL)
  178. self.btnBuy.SetUp()
  179.  
  180. def CancelShopping(self):
  181. self.btnBuy.SetUp()
  182. self.btnSell.SetUp()
  183. app.SetCursor(app.NORMAL)
  184.  
  185. def __OnClosePopupDialog(self):
  186. self.pop = None
  187.  
  188. def SellAttachedItem(self):
  189.  
  190. if shop.IsPrivateShop():
  191. mouseModule.mouseController.DeattachObject()
  192. return
  193.  
  194. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  195. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  196. attachedCount = mouseModule.mouseController.GetAttachedItemCount()
  197. if player.SLOT_TYPE_INVENTORY == attachedSlotType:
  198.  
  199. itemIndex = player.GetItemIndex(attachedSlotPos)
  200. item.SelectItem(itemIndex)
  201.  
  202. if item.IsAntiFlag(item.ANTIFLAG_SELL):
  203. popup = uiCommon.PopupDialog()
  204. popup.SetText(localeInfo.SHOP_CANNOT_SELL_ITEM)
  205. popup.SetAcceptEvent(self.__OnClosePopupDialog)
  206. popup.Open()
  207. self.popup = popup
  208.  
  209. elif player.IsValuableItem(attachedSlotPos):
  210.  
  211. itemPrice = item.GetISellItemPrice()
  212.  
  213. if item.Is1GoldItem():
  214. itemPrice = attachedCount / itemPrice / 5
  215. else:
  216. itemPrice = itemPrice * max(1, attachedCount) / 5
  217.  
  218. itemName = item.GetItemName()
  219.  
  220. questionDialog = uiCommon.QuestionDialog()
  221. questionDialog.SetText(localeInfo.DO_YOU_SELL_ITEM(itemName, attachedCount, itemPrice))
  222.  
  223. questionDialog.SetAcceptEvent(lambda arg1=attachedSlotPos, arg2=attachedCount: self.OnSellItem(arg1, arg2))
  224. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  225. questionDialog.Open()
  226. self.questionDialog = questionDialog
  227.  
  228. else:
  229. self.OnSellItem(attachedSlotPos, attachedCount)
  230.  
  231. else:
  232. snd.PlaySound("sound/ui/loginfail.wav")
  233.  
  234. mouseModule.mouseController.DeattachObject()
  235.  
  236. def OnSellItem(self, slotPos, count):
  237. net.SendShopSellPacketNew(slotPos, count)
  238. snd.PlaySound("sound/ui/money.wav")
  239. self.OnCloseQuestionDialog()
  240.  
  241. def OnCloseQuestionDialog(self):
  242. if self.questionDialog:
  243. self.questionDialog.Close()
  244.  
  245. self.questionDialog = None
  246.  
  247. def SelectEmptySlot(self, selectedSlotPos):
  248.  
  249. isAttached = mouseModule.mouseController.isAttached()
  250. if isAttached:
  251. self.SellAttachedItem()
  252.  
  253. def UnselectItemSlot(self, selectedSlotPos):
  254. if shop.IsPrivateShop():
  255. self.AskBuyItem(selectedSlotPos)
  256. else:
  257. net.SendShopBuyPacket(selectedSlotPos)
  258.  
  259. def SelectItemSlot(self, selectedSlotPos):
  260.  
  261. isAttached = mouseModule.mouseController.isAttached()
  262. if isAttached:
  263. self.SellAttachedItem()
  264.  
  265. else:
  266.  
  267. if TRUE == shop.IsMainPlayerPrivateShop():
  268. return
  269.  
  270. curCursorNum = app.GetCursor()
  271. if app.BUY == curCursorNum:
  272. self.AskBuyItem(selectedSlotPos)
  273.  
  274. elif app.SELL == curCursorNum:
  275. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  276.  
  277. else:
  278. selectedItemID = shop.GetItemID(selectedSlotPos)
  279. itemCount = shop.GetItemCount(selectedSlotPos)
  280.  
  281. type = player.SLOT_TYPE_SHOP
  282. if shop.IsPrivateShop():
  283. type = player.SLOT_TYPE_PRIVATE_SHOP
  284.  
  285. mouseModule.mouseController.AttachObject(self, type, selectedSlotPos, selectedItemID, itemCount)
  286. mouseModule.mouseController.SetCallBack("INVENTORY", ui.__mem_func__(self.DropToInventory))
  287. snd.PlaySound("sound/ui/pick.wav")
  288.  
  289. def DropToInventory(self):
  290. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  291. self.AskBuyItem(attachedSlotPos)
  292.  
  293. def AskBuyItem(self, slotPos):
  294. itemIndex = shop.GetItemID(slotPos)
  295. itemPrice = shop.GetItemPrice(slotPos)
  296. itemCount = shop.GetItemCount(slotPos)
  297.  
  298. item.SelectItem(itemIndex)
  299. itemName = item.GetItemName()
  300.  
  301. itemBuyQuestionDialog = uiCommon.QuestionDialog()
  302. if app.ENABLE_MULTISHOP:
  303. if shop.GetBuyWithItem(slotPos) != 0:
  304. itemBuyQuestionDialog.SetText(localeInfo.DO_YOU_BUY_ITEM(itemName, itemCount, localeInfo.NumberToWithItemString(shop.GetBuyWithItemCount(slotPos), item.GetItemName())))
  305. else:
  306. itemBuyQuestionDialog.SetText(localeInfo.DO_YOU_BUY_ITEM(itemName, itemCount, localeInfo.NumberToMoneyString(itemPrice)))
  307. itemBuyQuestionDialog.SetAcceptEvent(lambda arg=TRUE: self.AnswerBuyItem(arg))
  308. itemBuyQuestionDialog.SetCancelEvent(lambda arg=FALSE: self.AnswerBuyItem(arg))
  309. itemBuyQuestionDialog.Open()
  310. itemBuyQuestionDialog.pos = slotPos
  311. self.itemBuyQuestionDialog = itemBuyQuestionDialog
  312.  
  313. def AnswerBuyItem(self, flag):
  314.  
  315. if flag:
  316. pos = self.itemBuyQuestionDialog.pos
  317. net.SendShopBuyPacket(pos)
  318.  
  319. self.itemBuyQuestionDialog.Close()
  320. self.itemBuyQuestionDialog = None
  321.  
  322. def SetItemToolTip(self, tooltipItem):
  323. self.tooltipItem = tooltipItem
  324.  
  325. def OverInItem(self, slotIndex):
  326. if mouseModule.mouseController.isAttached():
  327. return
  328.  
  329. if 0 != self.tooltipItem:
  330. self.tooltipItem.SetShopItem(slotIndex)
  331.  
  332. def OverOutItem(self):
  333. if 0 != self.tooltipItem:
  334. self.tooltipItem.HideToolTip()
  335.  
  336. def OnUpdate(self):
  337.  
  338. USE_SHOP_LIMIT_RANGE = 1000
  339.  
  340. (x, y, z) = player.GetMainCharacterPosition()
  341. if abs(x - self.xShopStart) > USE_SHOP_LIMIT_RANGE or abs(y - self.yShopStart) > USE_SHOP_LIMIT_RANGE:
  342. self.Close()
  343.  
  344.  
  345. class MallPageDialog(ui.ScriptWindow):
  346. def __init__(self):
  347. ui.ScriptWindow.__init__(self)
  348.  
  349. def __del__(self):
  350. ui.ScriptWindow.__del__(self)
  351.  
  352. def Destroy(self):
  353. self.ClearDictionary()
  354.  
  355. def Open(self):
  356. scriptLoader = ui.PythonScriptLoader()
  357. scriptLoader.LoadScriptFile(self, "uiscript/mallpagedialog.py")
  358.  
  359. self.GetChild("titlebar").SetCloseEvent(ui.__mem_func__(self.Close))
  360.  
  361. (x, y)=self.GetGlobalPosition()
  362. x+=10
  363. y+=30
  364.  
  365. MALL_PAGE_WIDTH = 600
  366. MALL_PAGE_HEIGHT = 480
  367.  
  368. app.ShowWebPage(
  369. "http://metin2.co.kr/08_mall/game_mall/login_fail.htm",
  370. (x, y, x+MALL_PAGE_WIDTH, y+MALL_PAGE_HEIGHT))
  371.  
  372. self.Lock()
  373. self.Show()
  374.  
  375. def Close(self):
  376. app.HideWebPage()
  377. self.Unlock()
  378. self.Hide()
  379.  
  380. def OnPressEscapeKey(self):
  381. self.Close()
  382. return TRUE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement