Guest User

Untitled

a guest
Jul 30th, 2018
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.18 KB | None | 0 0
  1. import app
  2. import ui
  3. import snd
  4. import shop
  5. import mouseModule
  6. import player
  7. import chr
  8. import net
  9. import uiCommon
  10. import localeInfo
  11. import chat
  12. import item
  13. import systemSetting #±èÁØÈ£
  14. import player #±èÁØÈ£
  15. import constInfo
  16. import os
  17.  
  18. ##### DISABLE/ENABLE SHOP VISIT COLOR ###
  19. SHOP_VISIT=True
  20. ##### SHOP VISIT COLOR #####
  21. SHOP_VISIT_COLOR=0xFF00C8FF
  22. ###########################
  23. g_isBuildingPrivateShop = False
  24.  
  25. g_itemPriceDict={}
  26.  
  27. g_privateShopAdvertisementBoardDict={}
  28. def GetShopNamesRange():
  29. val=1.000
  30. try:
  31. with open("shop.cfg", 'r') as f:
  32. val=float(f.read().replace('\n', ''))
  33. except IOError:
  34. pass
  35. return float(val)
  36. def SetShopNamesRange(pos):
  37. with open("shop.cfg", 'w+') as f:
  38. f.write(str(pos))
  39. f.close()
  40. def Clear():
  41. global g_itemPriceDict
  42. global g_isBuildingPrivateShop
  43. g_itemPriceDict={}
  44. g_isBuildingPrivateShop = False
  45.  
  46. def IsPrivateShopItemPriceList():
  47. global g_itemPriceDict
  48. if g_itemPriceDict:
  49. return True
  50. else:
  51. return False
  52.  
  53. def IsBuildingPrivateShop():
  54. global g_isBuildingPrivateShop
  55. if player.IsOpenPrivateShop() or g_isBuildingPrivateShop:
  56. return True
  57. else:
  58. return False
  59.  
  60. def SetPrivateShopItemPrice(itemVNum, itemPrice):
  61. global g_itemPriceDict
  62. g_itemPriceDict[int(itemVNum)]=itemPrice
  63.  
  64. def GetPrivateShopItemPrice(itemVNum):
  65. try:
  66. global g_itemPriceDict
  67. return g_itemPriceDict[itemVNum]
  68. except KeyError:
  69. return 0
  70.  
  71. def UpdateADBoard():
  72. for key in g_privateShopAdvertisementBoardDict.keys():
  73. g_privateShopAdvertisementBoardDict[key].Show()
  74.  
  75. def DeleteADBoard(vid):
  76. if not g_privateShopAdvertisementBoardDict.has_key(vid):
  77. return
  78.  
  79. del g_privateShopAdvertisementBoardDict[vid]
  80.  
  81.  
  82. class PrivateShopAdvertisementBoard(ui.ThinBoard):
  83. def __init__(self):
  84. ui.ThinBoard.__init__(self, "UI_BOTTOM")
  85. self.shopAdvertismentBoardSeen = []
  86. self.vid = None
  87. self.__MakeTextLine()
  88.  
  89. def __del__(self):
  90. ui.ThinBoard.__del__(self)
  91.  
  92. def __MakeTextLine(self):
  93. self.textLine = ui.TextLine()
  94. self.textLine.SetParent(self)
  95. self.textLine.SetWindowHorizontalAlignCenter()
  96. self.textLine.SetWindowVerticalAlignCenter()
  97. self.textLine.SetHorizontalAlignCenter()
  98. self.textLine.SetVerticalAlignCenter()
  99. self.textLine.Show()
  100.  
  101. def Open(self, vid, text):
  102. self.vid = vid
  103.  
  104. self.textLine.SetText(text)
  105. if vid in self.shopAdvertismentBoardSeen:
  106. self.textLine.SetPackedFontColor(SHOP_VISIT_COLOR)
  107. self.textLine.UpdateRect()
  108. self.SetSize(len(text)*6 + 10*2, 20)
  109. self.Show()
  110.  
  111. g_privateShopAdvertisementBoardDict[vid] = self
  112.  
  113. def OnMouseLeftButtonUp(self):
  114. if not self.vid:
  115. return
  116. net.SendOnClickPacket(self.vid)
  117. if self.vid != player.GetMainCharacterIndex():
  118. self.textLine.SetPackedFontColor(SHOP_VISIT_COLOR)
  119. self.shopAdvertismentBoardSeen.append(self.vid)
  120. return True
  121.  
  122. def OnUpdate(self):
  123. if not self.vid:
  124. return
  125. if systemSetting.IsShowSalesText():
  126.  
  127. if chr.GetInstanceType(self.vid) not in [chr.INSTANCE_TYPE_PLAYER,chr.INSTANCE_TYPE_NPC]:
  128. self.Hide()
  129. if GetShopNamesRange() == 1.000:
  130. self.Show()
  131. (x, y) = chr.GetProjectPosition(self.vid, 220)
  132. self.SetPosition(x - self.GetWidth() / 2, y - self.GetHeight() / 2)
  133. else:
  134. LIMIT_RANGE = abs(constInfo.SHOPNAMES_RANGE * GetShopNamesRange())
  135. (to_x, to_y, to_z) = chr.GetPixelPosition(self.vid)
  136. (my_x, my_y, my_z) = player.GetMainCharacterPosition()
  137. if abs(my_x - to_x) <= LIMIT_RANGE and abs(my_y - to_y) <= LIMIT_RANGE:
  138. (x, y) = chr.GetProjectPosition(self.vid, 220)
  139. self.SetPosition(x - self.GetWidth() / 2, y - self.GetHeight() / 2)
  140. self.Show()
  141. else:
  142. self.Hide()
  143. self.SetPosition(-10000, 0)
  144. else:
  145. for key in g_privateShopAdvertisementBoardDict.keys():
  146. if player.GetMainCharacterIndex() == key:
  147. g_privateShopAdvertisementBoardDict[key].Show()
  148. x, y = chr.GetProjectPosition(player.GetMainCharacterIndex(), 220)
  149. g_privateShopAdvertisementBoardDict[key].SetPosition(x - self.GetWidth()/2, y - self.GetHeight()/2)
  150. else:
  151. g_privateShopAdvertisementBoardDict[key].Hide()
  152.  
  153. class PrivateShopBuilder(ui.ScriptWindow):
  154.  
  155. def __init__(self):
  156. ui.ScriptWindow.__init__(self)
  157.  
  158. self.__LoadWindow()
  159. self.itemStock = {}
  160. self.tooltipItem = None
  161. self.priceInputBoard = None
  162. self.days = 0
  163. self.title = ""
  164. if app.WJ_ENABLE_TRADABLE_ICON:
  165. self.interface = None
  166. self.wndInventory = None
  167. self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  168.  
  169. def __del__(self):
  170. ui.ScriptWindow.__del__(self)
  171.  
  172. def __LoadWindow(self):
  173. try:
  174. pyScrLoader = ui.PythonScriptLoader()
  175. pyScrLoader.LoadScriptFile(self, "UIScript/PrivateShopBuilder.py")
  176. except:
  177. import exception
  178. exception.Abort("PrivateShopBuilderWindow.LoadWindow.LoadObject")
  179.  
  180. try:
  181. GetObject = self.GetChild
  182. self.nameLine = GetObject("NameLine")
  183. self.itemSlot = GetObject("ItemSlot")
  184. self.btnOk = GetObject("OkButton")
  185. self.btnClose = GetObject("CloseButton")
  186. self.titleBar = GetObject("TitleBar")
  187. except:
  188. import exception
  189. exception.Abort("PrivateShopBuilderWindow.LoadWindow.BindObject")
  190.  
  191. self.btnOk.SetEvent(ui.__mem_func__(self.OnOk))
  192. self.btnClose.SetEvent(ui.__mem_func__(self.OnClose))
  193. self.titleBar.SetCloseEvent(ui.__mem_func__(self.OnClose))
  194.  
  195. self.itemSlot.SetSelectEmptySlotEvent(ui.__mem_func__(self.OnSelectEmptySlot))
  196. self.itemSlot.SetSelectItemSlotEvent(ui.__mem_func__(self.OnSelectItemSlot))
  197. self.itemSlot.SetOverInItemEvent(ui.__mem_func__(self.OnOverInItem))
  198. self.itemSlot.SetOverOutItemEvent(ui.__mem_func__(self.OnOverOutItem))
  199.  
  200. def Destroy(self):
  201. self.ClearDictionary()
  202.  
  203. self.nameLine = None
  204. self.itemSlot = None
  205. self.btnOk = None
  206. self.btnClose = None
  207. self.titleBar = None
  208. self.priceInputBoard = None
  209. if app.WJ_ENABLE_TRADABLE_ICON:
  210. self.interface = None
  211. self.wndInventory = None
  212. self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  213.  
  214. def Open(self, title,days):
  215.  
  216. self.days = days
  217. self.title = title
  218.  
  219. if len(title) > 25:
  220. title = title[:22] + "..."
  221.  
  222. self.itemStock = {}
  223. shop.ClearPrivateShopStock()
  224. self.nameLine.SetText(title)
  225. self.SetCenterPosition()
  226. self.Refresh()
  227. self.Show()
  228. if app.WJ_ENABLE_TRADABLE_ICON:
  229. self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  230. self.interface.SetOnTopWindow(player.ON_TOP_WND_PRIVATE_SHOP)
  231. self.interface.RefreshMarkInventoryBag()
  232.  
  233. global g_isBuildingPrivateShop
  234. g_isBuildingPrivateShop = True
  235.  
  236. def Close(self):
  237. global g_isBuildingPrivateShop
  238. g_isBuildingPrivateShop = False
  239.  
  240. self.title = ""
  241. self.itemStock = {}
  242. shop.ClearPrivateShopStock()
  243. self.Hide()
  244. if self.priceInputBoard:
  245. self.priceInputBoard.Close()
  246. self.priceInputBoard = None
  247.  
  248. if app.WJ_ENABLE_TRADABLE_ICON:
  249. for privatePos, (itemInvenPage, itemSlotPos) in self.lockedItems.items():
  250. if itemInvenPage == self.wndInventory.GetInventoryPageIndex():
  251. self.wndInventory.wndItem.SetCanMouseEventSlot(itemSlotPos)
  252.  
  253. self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  254. self.interface.SetOnTopWindow(player.ON_TOP_WND_NONE)
  255. self.interface.RefreshMarkInventoryBag()
  256.  
  257. def SetItemToolTip(self, tooltipItem):
  258. self.tooltipItem = tooltipItem
  259.  
  260. def Refresh(self):
  261. getitemVNum=player.GetItemIndex
  262. getItemCount=player.GetItemCount
  263. setitemVNum=self.itemSlot.SetItemSlot
  264. delItem=self.itemSlot.ClearSlot
  265.  
  266. for i in xrange(shop.SHOP_SLOT_COUNT):
  267.  
  268. if not self.itemStock.has_key(i):
  269. delItem(i)
  270. continue
  271.  
  272. pos = self.itemStock[i]
  273.  
  274. itemCount = getItemCount(*pos)
  275. if itemCount <= 1:
  276. itemCount = 0
  277. setitemVNum(i, getitemVNum(*pos), itemCount)
  278.  
  279. self.itemSlot.RefreshSlot()
  280. if app.WJ_ENABLE_TRADABLE_ICON:
  281. self.RefreshLockedSlot()
  282.  
  283. def ReadFilePrice(self,vnum,count):
  284. d = "shops"
  285. if not os.path.exists(d):
  286. os.makedirs(d)
  287. oldPrice=0
  288. n=d+"/"+str(vnum)+"_"+str(count)+".txt"
  289. if os.path.exists(n):
  290. fd = open( n,'r')
  291. oldPrice=int(fd.readlines()[0])
  292.  
  293. return oldPrice
  294. def SaveFilePrice(self,vnum,count,price):
  295. d = "shops"
  296. if not os.path.exists(d):
  297. os.makedirs(d)
  298. n=d+"/"+str(vnum)+"_"+str(count)+".txt"
  299. f = file(n, "w+")
  300. f.write(str(price))
  301. f.close()
  302.  
  303.  
  304. def OnSelectEmptySlot(self, selectedSlotPos):
  305.  
  306. isAttached = mouseModule.mouseController.isAttached()
  307. if isAttached:
  308. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  309. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  310. mouseModule.mouseController.DeattachObject()
  311.  
  312. if player.SLOT_TYPE_INVENTORY != attachedSlotType and player.SLOT_TYPE_DRAGON_SOUL_INVENTORY != attachedSlotType:
  313. return
  314. attachedInvenType = player.SlotTypeToInvenType(attachedSlotType)
  315. count = player.GetItemCount(attachedInvenType, attachedSlotPos)
  316.  
  317. itemVNum = player.GetItemIndex(attachedInvenType, attachedSlotPos)
  318. item.SelectItem(itemVNum)
  319.  
  320.  
  321.  
  322. if item.IsAntiFlag(item.ANTIFLAG_GIVE) or item.IsAntiFlag(item.ANTIFLAG_MYSHOP):
  323. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.PRIVATE_SHOP_CANNOT_SELL_ITEM)
  324. return
  325.  
  326. if app.WJ_ENABLE_TRADABLE_ICON and player.SLOT_TYPE_INVENTORY == attachedSlotType:
  327. self.CantTradableItem(selectedSlotPos, attachedSlotPos)
  328.  
  329. priceInputBoard = uiCommon.MoneyInputDialog()
  330.  
  331. priceInputBoard.SetTitle(localeInfo.PRIVATE_SHOP_INPUT_PRICE_DIALOG_TITLE)
  332. priceInputBoard.SetAcceptEvent(ui.__mem_func__(self.AcceptInputPrice))
  333. priceInputBoard.SetCancelEvent(ui.__mem_func__(self.CancelInputPrice))
  334. priceInputBoard.SetMaxLength(16)
  335. priceInputBoard.Open()
  336.  
  337. itemPrice=self.ReadFilePrice(itemVNum,count)
  338.  
  339. if itemPrice>0:
  340. priceInputBoard.SetValue(itemPrice)
  341.  
  342. self.priceInputBoard = priceInputBoard
  343. self.priceInputBoard.itemVNum = itemVNum
  344. self.priceInputBoard.sourceWindowType = attachedInvenType
  345. self.priceInputBoard.sourceSlotPos = attachedSlotPos
  346. self.priceInputBoard.targetSlotPos = selectedSlotPos
  347.  
  348. def OnSelectItemSlot(self, selectedSlotPos):
  349.  
  350. isAttached = mouseModule.mouseController.isAttached()
  351. if isAttached:
  352. snd.PlaySound("sound/ui/loginfail.wav")
  353. mouseModule.mouseController.DeattachObject()
  354.  
  355. else:
  356. if not selectedSlotPos in self.itemStock:
  357. return
  358.  
  359. invenType, invenPos = self.itemStock[selectedSlotPos]
  360. shop.DelPrivateShopItemStock(invenType, invenPos)
  361. snd.PlaySound("sound/ui/drop.wav")
  362. if app.WJ_ENABLE_TRADABLE_ICON:
  363. (itemInvenPage, itemSlotPos) = self.lockedItems[selectedSlotPos]
  364. if itemInvenPage == self.wndInventory.GetInventoryPageIndex():
  365. self.wndInventory.wndItem.SetCanMouseEventSlot(itemSlotPos)
  366.  
  367. self.lockedItems[selectedSlotPos] = (-1, -1)
  368.  
  369. del self.itemStock[selectedSlotPos]
  370.  
  371. self.Refresh()
  372.  
  373. def AcceptInputPrice(self):
  374.  
  375. if not self.priceInputBoard:
  376. return True
  377.  
  378. text = self.priceInputBoard.GetText()
  379.  
  380. if not text:
  381. return True
  382.  
  383. if not text.isdigit():
  384. return True
  385.  
  386. if int(text) <= 0:
  387. return True
  388.  
  389. attachedInvenType = self.priceInputBoard.sourceWindowType
  390. sourceSlotPos = self.priceInputBoard.sourceSlotPos
  391. targetSlotPos = self.priceInputBoard.targetSlotPos
  392.  
  393. for privatePos, (itemWindowType, itemSlotIndex) in self.itemStock.items():
  394. if itemWindowType == attachedInvenType and itemSlotIndex == sourceSlotPos:
  395. shop.DelPrivateShopItemStock(itemWindowType, itemSlotIndex)
  396. del self.itemStock[privatePos]
  397.  
  398. price = int(self.priceInputBoard.GetText())
  399.  
  400. if IsPrivateShopItemPriceList():
  401. SetPrivateShopItemPrice(self.priceInputBoard.itemVNum, price)
  402.  
  403. shop.AddPrivateShopItemStock(attachedInvenType, sourceSlotPos, targetSlotPos, price)
  404. count = player.GetItemCount(attachedInvenType, sourceSlotPos)
  405. vnum = player.GetItemIndex(attachedInvenType, sourceSlotPos)
  406. self.SaveFilePrice(vnum,count,price)
  407. self.itemStock[targetSlotPos] = (attachedInvenType, sourceSlotPos)
  408. snd.PlaySound("sound/ui/drop.wav")
  409.  
  410. self.Refresh()
  411.  
  412. #####
  413.  
  414. self.priceInputBoard = None
  415. return True
  416.  
  417. def CancelInputPrice(self):
  418. if app.WJ_ENABLE_TRADABLE_ICON:
  419. itemInvenPage = self.priceInputBoard.sourceSlotPos / player.INVENTORY_PAGE_SIZE
  420. itemSlotPos = self.priceInputBoard.sourceSlotPos - (itemInvenPage * player.INVENTORY_PAGE_SIZE)
  421. if self.wndInventory.GetInventoryPageIndex() == itemInvenPage:
  422. self.wndInventory.wndItem.SetCanMouseEventSlot(itemSlotPos)
  423.  
  424. self.lockedItems[self.priceInputBoard.targetSlotPos] = (-1, -1)
  425.  
  426. if self.priceInputBoard:
  427. self.priceInputBoard.Close()
  428. self.priceInputBoard = None
  429. return True
  430.  
  431. def OnOk(self):
  432.  
  433. if not self.title:
  434. return
  435.  
  436. if 0 == len(self.itemStock):
  437. return
  438.  
  439. shop.BuildPrivateShop(self.title,self.days)
  440. self.Close()
  441.  
  442. def OnClose(self):
  443. self.Close()
  444.  
  445. def OnPressEscapeKey(self):
  446. self.Close()
  447. return True
  448.  
  449. def OnOverInItem(self, slotIndex):
  450.  
  451. if self.tooltipItem:
  452. if self.itemStock.has_key(slotIndex):
  453. self.tooltipItem.SetPrivateShopBuilderItem(*self.itemStock[slotIndex] + (slotIndex,))
  454.  
  455. def OnOverOutItem(self):
  456. if self.tooltipItem:
  457. self.tooltipItem.HideToolTip()
  458.  
  459. if app.WJ_ENABLE_TRADABLE_ICON:
  460. def CantTradableItem(self, destSlotIndex, srcSlotIndex):
  461. itemInvenPage = srcSlotIndex / player.INVENTORY_PAGE_SIZE
  462. localSlotPos = srcSlotIndex - (itemInvenPage * player.INVENTORY_PAGE_SIZE)
  463. self.lockedItems[destSlotIndex] = (itemInvenPage, localSlotPos)
  464. if itemInvenPage == self.wndInventory.GetInventoryPageIndex():
  465. self.wndInventory.wndItem.SetCantMouseEventSlot(localSlotPos)
  466.  
  467. def RefreshLockedSlot(self):
  468. if self.wndInventory:
  469. for privatePos, (itemInvenPage, itemSlotPos) in self.lockedItems.items():
  470. if self.wndInventory.GetInventoryPageIndex() == itemInvenPage:
  471. self.wndInventory.wndItem.SetCantMouseEventSlot(itemSlotPos)
  472.  
  473. self.wndInventory.wndItem.RefreshSlot()
  474.  
  475. def BindInterface(self, interface):
  476. self.interface = interface
  477.  
  478. def OnTop(self):
  479. if self.interface:
  480. self.interface.SetOnTopWindow(player.ON_TOP_WND_PRIVATE_SHOP)
  481. self.interface.RefreshMarkInventoryBag()
  482.  
  483. def SetInven(self, wndInventory):
  484. from _weakref import proxy
  485. self.wndInventory = proxy(wndInventory)
Advertisement
Add Comment
Please, Sign In to add comment