Guest User

123

a guest
Aug 19th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.35 KB | None | 0 0
  1. import ancient2 as net
  2. import player
  3. import item
  4. import snd
  5. import shop
  6. import ancient2 as net
  7. import wndMgr
  8. import app
  9. import chat
  10.  
  11. import ui
  12. import uiCommon
  13. import mouseModule
  14. import localeInfo
  15. import chr
  16. import constInfo
  17.  
  18. ###################################################################################################
  19. ## Shop
  20. class ShopDialog(ui.ScriptWindow):
  21.  
  22. def __init__(self):
  23. ui.ScriptWindow.__init__(self)
  24. self.tooltipItem = 0
  25. self.xShopStart = 0
  26. self.yShopStart = 0
  27.  
  28. self.questionDialog = None
  29. self.popup = None
  30. self.itemBuyQuestionDialog = None
  31. self.vid = 0
  32.  
  33. def __del__(self):
  34. ui.ScriptWindow.__del__(self)
  35.  
  36. def __GetRealIndex(self, i):
  37. return self.tabIdx * shop.SHOP_SLOT_COUNT + i
  38.  
  39. def Refresh(self):
  40. getItemID=shop.GetItemID
  41. getItemCount=shop.GetItemCount
  42. setItemID=self.itemSlotWindow.SetItemSlot
  43. for i in xrange(shop.SHOP_SLOT_COUNT):
  44. idx = self.__GetRealIndex(i)
  45. itemCount = getItemCount(idx)
  46. if itemCount <= 1:
  47. itemCount = 0
  48. setItemID(i, getItemID(idx), itemCount)
  49.  
  50. if app.SHOP_FREE_ICON:
  51. if shop.GetItemPrice(idx) < 100000: #Pret trebuie sa fie mai mic decat 100k.
  52. self.itemSlotWindow.EnableShopFreeIcon(i)
  53.  
  54. wndMgr.RefreshSlot(self.itemSlotWindow.GetWindowHandle())
  55.  
  56. def SetItemData(self, pos, itemID, itemCount, itemPrice):
  57. shop.SetItemData(pos, itemID, itemCount, itemPrice)
  58.  
  59. def LoadDialog(self):
  60. try:
  61. PythonScriptLoader = ui.PythonScriptLoader()
  62. PythonScriptLoader.LoadScriptFile(self, "UIScript/shopdialog.py")
  63. except:
  64. import exception
  65. exception.Abort("ShopDialog.LoadDialog.LoadObject")
  66.  
  67. smallTab1 = None
  68. smallTab2 = None
  69. smallTab3 = None
  70. middleTab1 = None
  71. middleTab2 = None
  72.  
  73. try:
  74. GetObject = self.GetChild
  75. self.itemSlotWindow = GetObject("ItemSlot")
  76. self.btnBuy = GetObject("BuyButton")
  77. self.btnBuy2 = GetObject("BuyButton2")
  78. self.btnSell = GetObject("SellButton")
  79. self.btnClose = GetObject("CloseButton")
  80. self.titleBar = GetObject("TitleBar")
  81. middleTab1 = GetObject("MiddleTab1")
  82. middleTab2 = GetObject("MiddleTab2")
  83. smallTab1 = GetObject("SmallTab1")
  84. smallTab2 = GetObject("SmallTab2")
  85. smallTab3 = GetObject("SmallTab3")
  86. except:
  87. import exception
  88. exception.Abort("ShopDialog.LoadDialog.BindObject")
  89.  
  90. self.itemSlotWindow.SetSlotStyle(wndMgr.SLOT_STYLE_NONE)
  91. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EMPTY", self.SelectEmptySlot)
  92. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EXIST", self.SelectItemSlot)
  93. self.itemSlotWindow.SAFE_SetButtonEvent("RIGHT", "EXIST", self.UnselectItemSlot)
  94.  
  95. self.itemSlotWindow.SetOverInItemEvent(ui.__mem_func__(self.OverInItem))
  96. self.itemSlotWindow.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem))
  97.  
  98. self.btnBuy.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  99. self.btnBuy.SetToggleDownEvent(ui.__mem_func__(self.OnBuy))
  100.  
  101. self.btnBuy2.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  102. self.btnBuy2.SetToggleDownEvent(ui.__mem_func__(self.OnBuy))
  103. self.btnSell.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  104. self.btnSell.SetToggleDownEvent(ui.__mem_func__(self.OnSell))
  105.  
  106. self.btnClose.SetEvent(ui.__mem_func__(self.AskClosePrivateShop))
  107.  
  108. self.titleBar.SetCloseEvent(ui.__mem_func__(self.Close))
  109.  
  110. self.smallRadioButtonGroup = ui.RadioButtonGroup.Create([[smallTab1, lambda : self.OnClickTabButton(0), None], [smallTab2, lambda : self.OnClickTabButton(1), None], [smallTab3, lambda : self.OnClickTabButton(2), None]])
  111. self.middleRadioButtonGroup = ui.RadioButtonGroup.Create([[middleTab1, lambda : self.OnClickTabButton(0), None], [middleTab2, lambda : self.OnClickTabButton(1), None]])
  112.  
  113. self.__HideMiddleTabs()
  114. self.__HideSmallTabs()
  115.  
  116. self.tabIdx = 0
  117. self.coinType = shop.SHOP_COIN_TYPE_GOLD
  118.  
  119. self.Refresh()
  120.  
  121. def __ShowBuySellButton(self):
  122. self.btnBuy.Show()
  123. self.btnSell.Show()
  124.  
  125. def __ShowMiddleTabs(self):
  126. self.middleRadioButtonGroup.Show()
  127.  
  128. def __ShowSmallTabs(self):
  129. self.smallRadioButtonGroup.Show()
  130.  
  131. def __HideBuySellButton(self):
  132. self.btnBuy.Hide()
  133. self.btnSell.Hide()
  134.  
  135. def __HideMiddleTabs(self):
  136. self.middleRadioButtonGroup.Hide()
  137.  
  138. def __HideSmallTabs(self):
  139. self.smallRadioButtonGroup.Hide()
  140.  
  141. def __SetTabNames(self):
  142. if shop.GetTabCount() == 2:
  143. self.middleRadioButtonGroup.SetText(0, shop.GetTabName(0))
  144. self.middleRadioButtonGroup.SetText(1, shop.GetTabName(1))
  145. elif shop.GetTabCount() == 3:
  146. self.smallRadioButtonGroup.SetText(0, shop.GetTabName(0))
  147. self.smallRadioButtonGroup.SetText(1, shop.GetTabName(1))
  148. self.smallRadioButtonGroup.SetText(2, shop.GetTabName(2))
  149.  
  150.  
  151. def Destroy(self):
  152. self.Close()
  153. self.ClearDictionary()
  154.  
  155. self.tooltipItem = 0
  156. self.itemSlotWindow = 0
  157. self.btnBuy = 0
  158. self.btnSell = 0
  159. self.btnClose = 0
  160. self.titleBar = 0
  161.  
  162. self.questionDialog = None
  163. self.popup = None
  164. self.vid = 0
  165. def Open(self, vid, type=0):
  166. self.vid=int(vid)
  167. isPrivateShop = FALSE
  168. isMainPlayerPrivateShop = FALSE
  169. myshop=FALSE
  170. #if chr.IsNPC(vid):
  171. # isPrivateShop = FALSE
  172. #else:
  173. # isPrivateShop = TRUE
  174. for i in xrange(len(constInfo.MyShops)):
  175. if int(constInfo.MyShops[i]["vid"]) == int(self.vid):
  176. myshop=TRUE
  177. self.vid=int(constInfo.MyShops[i]["id"])
  178. chr.SelectInstance(self.vid)
  179. if chr.GetRace() == 30000 or not chr.IsNPC(self.vid):
  180. isPrivateShop = TRUE
  181.  
  182. if player.IsMainCharacterIndex(self.vid):
  183. myshop=TRUE
  184. self.vid=""
  185. if myshop == TRUE:
  186. self.btnBuy.Hide()
  187. self.btnBuy2.Hide()
  188. self.btnSell.Hide()
  189. self.btnClose.Show()
  190. #if myshop == TRUE:
  191. # isMainPlayerPrivateShop = TRUE
  192. #
  193. # self.btnBuy.Hide()
  194. # self.btnSell.Hide()
  195. # self.btnClose.Show()
  196. elif myshop == FALSE and isPrivateShop == TRUE:
  197. self.btnBuy2.Show()
  198. self.btnBuy.Hide()
  199. self.btnSell.Hide()
  200. self.btnClose.Hide()
  201. else:
  202.  
  203. isMainPlayerPrivateShop = FALSE
  204.  
  205. self.btnBuy.Show()
  206. self.btnSell.Show()
  207. self.btnBuy2.Hide()
  208. self.btnClose.Hide()
  209.  
  210. #self.btnBuy.Show()
  211. #self.btnSell.Show()
  212. #self.btnClose.Hide()
  213.  
  214. shop.Open(isPrivateShop, isMainPlayerPrivateShop)
  215.  
  216. self.tabIdx = 0
  217.  
  218. if isPrivateShop:
  219. self.__HideMiddleTabs()
  220. self.__HideSmallTabs()
  221. else:
  222. if shop.GetTabCount() == 1:
  223. self.__ShowBuySellButton()
  224. self.__HideMiddleTabs()
  225. self.__HideSmallTabs()
  226. elif shop.GetTabCount() == 2:
  227. self.__HideBuySellButton()
  228. self.__ShowMiddleTabs()
  229. self.__HideSmallTabs()
  230. self.__SetTabNames()
  231. self.middleRadioButtonGroup.OnClick(0)
  232. elif shop.GetTabCount() == 3:
  233. self.__HideBuySellButton()
  234. self.__HideMiddleTabs()
  235. self.__ShowSmallTabs()
  236. self.__SetTabNames()
  237. if app.ENABLE_RENEWAL_SHOPEX:
  238. self.middleRadioButtonGroup.OnClick(0)
  239. else:
  240. self.middleRadioButtonGroup.OnClick(1)
  241.  
  242. self.Refresh()
  243. self.SetTop()
  244.  
  245. self.Show()
  246.  
  247. (self.xShopStart, self.yShopStart, z) = player.GetMainCharacterPosition()
  248.  
  249. def Close(self):
  250. if self.itemBuyQuestionDialog:
  251. self.itemBuyQuestionDialog.Close()
  252. self.itemBuyQuestionDialog = None
  253. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  254. if self.questionDialog:
  255. self.OnCloseQuestionDialog()
  256. shop.Close()
  257. net.SendShopEndPacket()
  258. self.CancelShopping()
  259. self.tooltipItem.HideToolTip()
  260. self.Hide()
  261.  
  262. def GetIndexFromSlotPos(self, slotPos):
  263. return self.tabIdx * shop.SHOP_SLOT_COUNT + slotPos
  264.  
  265. def OnClickTabButton(self, idx):
  266. self.tabIdx = idx
  267. self.Refresh()
  268.  
  269. def AskClosePrivateShop(self):
  270. questionDialog = uiCommon.QuestionDialog()
  271. questionDialog.SetText(localeInfo.PRIVATE_SHOP_CLOSE_QUESTION)
  272. questionDialog.SetAcceptEvent(ui.__mem_func__(self.OnClosePrivateShop))
  273. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  274. questionDialog.Open()
  275. self.questionDialog = questionDialog
  276.  
  277. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(1)
  278.  
  279. return TRUE
  280.  
  281. def OnClosePrivateShop(self):
  282. net.SendChatPacket("/close_shop "+str(self.vid))
  283. self.OnCloseQuestionDialog()
  284. return TRUE
  285.  
  286. def OnPressEscapeKey(self):
  287. self.Close()
  288. return TRUE
  289.  
  290. def OnPressExitKey(self):
  291. self.Close()
  292. return TRUE
  293.  
  294. def OnBuy(self):
  295. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_BUY_INFO)
  296. app.SetCursor(app.BUY)
  297. self.btnSell.SetUp()
  298.  
  299. def OnSell(self):
  300. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  301. app.SetCursor(app.SELL)
  302. self.btnBuy.SetUp()
  303.  
  304. def CancelShopping(self):
  305. self.btnBuy.SetUp()
  306. self.btnSell.SetUp()
  307. app.SetCursor(app.NORMAL)
  308.  
  309. def __OnClosePopupDialog(self):
  310. self.pop = None
  311. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  312.  
  313. ## ??? ??? ?? ??.
  314. def SellAttachedItem(self):
  315.  
  316. if shop.IsPrivateShop():
  317. mouseModule.mouseController.DeattachObject()
  318. return
  319.  
  320. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  321. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  322. attachedCount = mouseModule.mouseController.GetAttachedItemCount()
  323. attachedItemIndex = mouseModule.mouseController.GetAttachedItemIndex()
  324.  
  325. if player.SLOT_TYPE_INVENTORY == attachedSlotType or player.SLOT_TYPE_DRAGON_SOUL_INVENTORY == attachedSlotType:
  326.  
  327. itemIndex = player.GetItemIndex(attachedSlotPos)
  328. item.SelectItem(itemIndex)
  329.  
  330. if item.IsAntiFlag(item.ANTIFLAG_SELL):
  331. popup = uiCommon.PopupDialog()
  332. popup.SetText(localeInfo.SHOP_CANNOT_SELL_ITEM)
  333. popup.SetAcceptEvent(self.__OnClosePopupDialog)
  334. popup.Open()
  335. self.popup = popup
  336. return
  337.  
  338. itemtype = player.INVENTORY
  339.  
  340. if player.SLOT_TYPE_DRAGON_SOUL_INVENTORY == attachedSlotType:
  341. itemtype = player.DRAGON_SOUL_INVENTORY
  342.  
  343. if player.IsValuableItem(itemtype, attachedSlotPos):
  344.  
  345. itemPrice = item.GetISellItemPrice()
  346.  
  347. if item.Is1GoldItem():
  348. itemPrice = attachedCount / itemPrice / 5
  349. else:
  350. itemPrice = itemPrice * max(1, attachedCount) / 5
  351.  
  352. itemName = item.GetItemName()
  353.  
  354. questionDialog = uiCommon.QuestionDialog()
  355. questionDialog.SetText(localeInfo.DO_YOU_SELL_ITEM(itemName, attachedCount, itemPrice))
  356.  
  357. questionDialog.SetAcceptEvent(lambda arg1=attachedSlotPos, arg2=attachedCount, arg3 = itemtype: self.OnSellItem(arg1, arg2, arg3))
  358. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  359. questionDialog.Open()
  360. self.questionDialog = questionDialog
  361.  
  362. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(1)
  363.  
  364. else:
  365. self.OnSellItem(attachedSlotPos, attachedCount, itemtype)
  366.  
  367. else:
  368. snd.PlaySound("sound/ui/loginfail.wav")
  369.  
  370. mouseModule.mouseController.DeattachObject()
  371.  
  372. def OnSellItem(self, slotPos, count, itemtype):
  373. net.SendShopSellPacketNew(slotPos, count, itemtype)
  374. snd.PlaySound("sound/ui/money.wav")
  375. self.OnCloseQuestionDialog()
  376.  
  377. def OnCloseQuestionDialog(self):
  378. if not self.questionDialog:
  379. return
  380.  
  381. self.questionDialog.Close()
  382. self.questionDialog = None
  383. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  384.  
  385. def SelectEmptySlot(self, selectedSlotPos):
  386.  
  387. isAttached = mouseModule.mouseController.isAttached()
  388. if isAttached:
  389. self.SellAttachedItem()
  390.  
  391. def UnselectItemSlot(self, selectedSlotPos):
  392. if constInfo.GET_ITEM_QUESTION_DIALOG_STATUS() == 1:
  393. return
  394. if shop.IsPrivateShop():
  395. self.AskBuyItem(selectedSlotPos)
  396. else:
  397. net.SendShopBuyPacket(self.__GetRealIndex(selectedSlotPos))
  398.  
  399. def SelectItemSlot(self, selectedSlotPos):
  400. if constInfo.GET_ITEM_QUESTION_DIALOG_STATUS() == 1:
  401. return
  402.  
  403. isAttached = mouseModule.mouseController.isAttached()
  404. selectedSlotPos = self.__GetRealIndex(selectedSlotPos)
  405. if isAttached:
  406. self.SellAttachedItem()
  407.  
  408. else:
  409.  
  410. if TRUE == shop.IsMainPlayerPrivateShop():
  411. return
  412.  
  413. curCursorNum = app.GetCursor()
  414. if app.BUY == curCursorNum:
  415. self.AskBuyItem(selectedSlotPos)
  416.  
  417. elif app.SELL == curCursorNum:
  418. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  419.  
  420. else:
  421. selectedItemID = shop.GetItemID(selectedSlotPos)
  422. itemCount = shop.GetItemCount(selectedSlotPos)
  423.  
  424. type = player.SLOT_TYPE_SHOP
  425. if shop.IsPrivateShop():
  426. type = player.SLOT_TYPE_PRIVATE_SHOP
  427.  
  428. mouseModule.mouseController.AttachObject(self, type, selectedSlotPos, selectedItemID, itemCount)
  429. mouseModule.mouseController.SetCallBack("INVENTORY", ui.__mem_func__(self.DropToInventory))
  430. snd.PlaySound("sound/ui/pick.wav")
  431.  
  432. def DropToInventory(self):
  433. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  434. self.AskBuyItem(attachedSlotPos)
  435.  
  436. def AskBuyItem(self, slotPos):
  437. slotPos = self.__GetRealIndex(slotPos)
  438.  
  439. itemIndex = shop.GetItemID(slotPos)
  440. itemPrice = shop.GetItemPrice(slotPos)
  441. itemCount = shop.GetItemCount(slotPos)
  442.  
  443. item.SelectItem(itemIndex)
  444. itemName = item.GetItemName()
  445.  
  446. itemBuyQuestionDialog = uiCommon.QuestionDialog()
  447. itemBuyQuestionDialog.SetText(localeInfo.DO_YOU_BUY_ITEM(itemName, itemCount, localeInfo.NumberToMoneyString(itemPrice)))
  448. itemBuyQuestionDialog.SetAcceptEvent(lambda arg=TRUE: self.AnswerBuyItem(arg))
  449. itemBuyQuestionDialog.SetCancelEvent(lambda arg=FALSE: self.AnswerBuyItem(arg))
  450. itemBuyQuestionDialog.Open()
  451. itemBuyQuestionDialog.pos = slotPos
  452. self.itemBuyQuestionDialog = itemBuyQuestionDialog
  453.  
  454. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(1)
  455.  
  456. def AnswerBuyItem(self, flag):
  457.  
  458. if flag:
  459. pos = self.itemBuyQuestionDialog.pos
  460. net.SendShopBuyPacket(pos)
  461.  
  462. self.itemBuyQuestionDialog.Close()
  463. self.itemBuyQuestionDialog = None
  464.  
  465. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  466.  
  467. def SetItemToolTip(self, tooltipItem):
  468. self.tooltipItem = tooltipItem
  469.  
  470. def OverInItem(self, slotIndex):
  471. slotIndex = self.__GetRealIndex(slotIndex)
  472. if mouseModule.mouseController.isAttached():
  473. return
  474.  
  475. if self.tooltipItem:
  476. if app.ENABLE_RENEWAL_SHOPEX:
  477. PriceType = shop.GetItemPriceType(slotIndex)
  478. if PriceType == 1:
  479. self.tooltipItem.SetShopItem(slotIndex)
  480. elif PriceType == 2:
  481. self.tooltipItem.SetShopItemBySecondaryCoin(slotIndex)
  482. else:
  483. self.tooltipItem.SetShopItemByShopEx(slotIndex, PriceType)
  484. else:
  485. if shop.SHOP_COIN_TYPE_GOLD == shop.GetTabCoinType(self.tabIdx):
  486. self.tooltipItem.SetShopItem(slotIndex)
  487. else:
  488. self.tooltipItem.SetShopItemBySecondaryCoin(slotIndex)
  489.  
  490. def OverOutItem(self):
  491. if 0 != self.tooltipItem:
  492. self.tooltipItem.HideToolTip()
  493.  
  494. def OnUpdate(self):
  495.  
  496. USE_SHOP_LIMIT_RANGE = 1000
  497.  
  498. (x, y, z) = player.GetMainCharacterPosition()
  499. if abs(x - self.xShopStart) > USE_SHOP_LIMIT_RANGE or abs(y - self.yShopStart) > USE_SHOP_LIMIT_RANGE:
  500. self.Close()
  501.  
  502.  
  503. class MallPageDialog(ui.ScriptWindow):
  504. def __init__(self):
  505. ui.ScriptWindow.__init__(self)
  506.  
  507. def __del__(self):
  508. ui.ScriptWindow.__del__(self)
  509.  
  510. def Destroy(self):
  511. self.ClearDictionary()
  512.  
  513. def Open(self):
  514. scriptLoader = ui.PythonScriptLoader()
  515. scriptLoader.LoadScriptFile(self, "uiscript/mallpagedialog.py")
  516.  
  517. self.GetChild("titlebar").SetCloseEvent(ui.__mem_func__(self.Close))
  518.  
  519. (x, y)=self.GetGlobalPosition()
  520. x+=10
  521. y+=30
  522.  
  523. MALL_PAGE_WIDTH = 600
  524. MALL_PAGE_HEIGHT = 480
  525.  
  526. app.ShowWebPage(
  527. "http://metin2.co.kr/08_mall/game_mall/login_fail.htm",
  528. (x, y, x+MALL_PAGE_WIDTH, y+MALL_PAGE_HEIGHT))
  529.  
  530. self.Lock()
  531. self.Show()
  532.  
  533. def Close(self):
  534. app.HideWebPage()
  535. self.Unlock()
  536. self.Hide()
  537.  
  538. def OnPressEscapeKey(self):
  539. self.Close()
  540. return TRUE
  541.  
Advertisement
Add Comment
Please, Sign In to add comment