Advertisement
Asthard

Untitled

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