Advertisement
torres1801

uitarget.py

Aug 13th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.91 KB | None | 0 0
  1. import app
  2. import ui
  3. import player
  4. import net
  5. import wndMgr
  6. import messenger
  7. import guild
  8. import chr
  9. import nonplayer
  10. import localeInfo
  11. import constInfo
  12. import uiToolTip
  13. import item
  14. if app.ENABLE_SEND_TARGET_INFO:
  15. def HAS_FLAG(value, flag):
  16. return (value & flag) == flag
  17. class TargetBoard(ui.ThinBoard):
  18. if app.ENABLE_SEND_TARGET_INFO:
  19. class InfoBoard(ui.ThinBoard):
  20. class ItemListBoxItem(ui.ListBoxExNew.Item):
  21. def __init__(self, width):
  22. ui.ListBoxExNew.Item.__init__(self)
  23.  
  24. image = ui.ExpandedImageBox()
  25. image.SetParent(self)
  26. image.Show()
  27. self.image = image
  28.  
  29. nameLine = ui.TextLine()
  30. nameLine.SetParent(self)
  31. nameLine.SetPosition(32 + 5, 0)
  32. nameLine.Show()
  33. self.nameLine = nameLine
  34.  
  35. self.SetSize(width, 32 + 5)
  36.  
  37. def LoadImage(self, image, name = None):
  38. self.image.LoadImage(image)
  39. self.SetSize(self.GetWidth(), self.image.GetHeight() + 5 * (self.image.GetHeight() / 32))
  40. if name != None:
  41. self.SetText(name)
  42.  
  43. def SetText(self, text):
  44. self.nameLine.SetText(text)
  45.  
  46. def RefreshHeight(self):
  47. ui.ListBoxExNew.Item.RefreshHeight(self)
  48. self.image.SetRenderingRect(0.0, 0.0 - float(self.removeTop) / float(self.GetHeight()), 0.0, 0.0 - float(self.removeBottom) / float(self.GetHeight()))
  49. self.image.SetPosition(0, - self.removeTop)
  50.  
  51. MAX_ITEM_COUNT = 5
  52.  
  53. EXP_BASE_LVDELTA = [
  54. 1, # -15 0
  55. 5, # -14 1
  56. 10, # -13 2
  57. 20, # -12 3
  58. 30, # -11 4
  59. 50, # -10 5
  60. 70, # -9 6
  61. 80, # -8 7
  62. 85, # -7 8
  63. 90, # -6 9
  64. 92, # -5 10
  65. 94, # -4 11
  66. 96, # -3 12
  67. 98, # -2 13
  68. 100, # -1 14
  69. 100, # 0 15
  70. 105, # 1 16
  71. 110, # 2 17
  72. 115, # 3 18
  73. 120, # 4 19
  74. 125, # 5 20
  75. 130, # 6 21
  76. 135, # 7 22
  77. 140, # 8 23
  78. 145, # 9 24
  79. 150, # 10 25
  80. 155, # 11 26
  81. 160, # 12 27
  82. 165, # 13 28
  83. 170, # 14 29
  84. 180, # 15 30
  85. ]
  86.  
  87. RACE_FLAG_TO_NAME = {
  88. 1 << 0 : localeInfo.TARGET_INFO_RACE_ANIMAL,
  89. 1 << 1 : localeInfo.TARGET_INFO_RACE_UNDEAD,
  90. 1 << 2 : localeInfo.TARGET_INFO_RACE_DEVIL,
  91. 1 << 3 : localeInfo.TARGET_INFO_RACE_HUMAN,
  92. 1 << 4 : localeInfo.TARGET_INFO_RACE_ORC,
  93. 1 << 5 : localeInfo.TARGET_INFO_RACE_MILGYO,
  94. }
  95.  
  96. SUB_RACE_FLAG_TO_NAME = {
  97. 1 << 11 : localeInfo.TARGET_INFO_RACE_ELEC,
  98. 1 << 12 : localeInfo.TARGET_INFO_RACE_FIRE,
  99. 1 << 13 : localeInfo.TARGET_INFO_RACE_ICE,
  100. 1 << 14 : localeInfo.TARGET_INFO_RACE_WIND,
  101. 1 << 15 : localeInfo.TARGET_INFO_RACE_EARTH,
  102. 1 << 16 : localeInfo.TARGET_INFO_RACE_DARK,
  103. }
  104.  
  105. STONE_START_VNUM = 28030
  106. STONE_LAST_VNUM = 28042
  107.  
  108. BOARD_WIDTH = 250
  109.  
  110. def __init__(self):
  111. ui.ThinBoard.__init__(self)
  112.  
  113. self.HideCorners(self.LT)
  114. self.HideCorners(self.RT)
  115. self.HideLine(self.T)
  116.  
  117. self.race = 0
  118. self.hasItems = False
  119.  
  120. self.itemTooltip = uiToolTip.ItemToolTip()
  121. self.itemTooltip.HideToolTip()
  122.  
  123. self.stoneImg = None
  124. self.stoneVnum = None
  125. self.lastStoneVnum = 0
  126. self.nextStoneIconChange = 0
  127.  
  128. self.SetSize(self.BOARD_WIDTH, 0)
  129.  
  130. def __del__(self):
  131. ui.ThinBoard.__del__(self)
  132.  
  133. def __UpdatePosition(self, targetBoard):
  134. self.SetPosition(targetBoard.GetLeft() + (targetBoard.GetWidth() - self.GetWidth()) / 2, targetBoard.GetBottom() - 17)
  135.  
  136. def Open(self, targetBoard, race):
  137. self.__LoadInformation(race)
  138.  
  139. self.SetSize(self.BOARD_WIDTH, self.yPos + 10)
  140. self.__UpdatePosition(targetBoard)
  141.  
  142. self.Show()
  143.  
  144. def Refresh(self):
  145. self.__LoadInformation(self.race)
  146. self.SetSize(self.BOARD_WIDTH, self.yPos + 10)
  147.  
  148. def Close(self):
  149. self.itemTooltip.HideToolTip()
  150. self.Hide()
  151.  
  152. def __LoadInformation(self, race):
  153. self.yPos = 7
  154. self.children = []
  155. self.race = race
  156. self.stoneImg = None
  157. self.stoneVnum = None
  158. self.nextStoneIconChange = 0
  159.  
  160. self.__LoadInformation_Default(race)
  161. self.__LoadInformation_Race(race)
  162. self.__LoadInformation_Drops(race)
  163.  
  164. def __LoadInformation_Default_GetHitRate(self, race):
  165. attacker_dx = nonplayer.GetMonsterDX(race)
  166. attacker_level = nonplayer.GetMonsterLevel(race)
  167.  
  168. self_dx = player.GetStatus(player.DX)
  169. self_level = player.GetStatus(player.LEVEL)
  170.  
  171. iARSrc = min(90, (attacker_dx * 4 + attacker_level * 2) / 6)
  172. iERSrc = min(90, (self_dx * 4 + self_level * 2) / 6)
  173.  
  174. fAR = (float(iARSrc) + 210.0) / 300.0
  175. fER = (float(iERSrc) * 2 + 5) / (float(iERSrc) + 95) * 3.0 / 10.0
  176.  
  177. return fAR - fER
  178.  
  179. def __LoadInformation_Default(self, race):
  180. self.AppendSeperator()
  181. self.AppendTextLine(localeInfo.TARGET_INFO_MAX_HP % str(nonplayer.GetMonsterMaxHP(race)))
  182.  
  183. # calc att damage
  184. monsterLevel = nonplayer.GetMonsterLevel(race)
  185. fHitRate = self.__LoadInformation_Default_GetHitRate(race)
  186. iDamMin, iDamMax = nonplayer.GetMonsterDamage(race)
  187. iDamMin = int((iDamMin + nonplayer.GetMonsterST(race)) * 2 * fHitRate) + monsterLevel * 2
  188. iDamMax = int((iDamMax + nonplayer.GetMonsterST(race)) * 2 * fHitRate) + monsterLevel * 2
  189. iDef = player.GetStatus(player.DEF_GRADE) * (100 + player.GetStatus(player.DEF_BONUS)) / 100
  190. fDamMulti = nonplayer.GetMonsterDamageMultiply(race)
  191. iDamMin = int(max(0, iDamMin - iDef) * fDamMulti)
  192. iDamMax = int(max(0, iDamMax - iDef) * fDamMulti)
  193. if iDamMin < 1:
  194. iDamMin = 1
  195. if iDamMax < 5:
  196. iDamMax = 5
  197. self.AppendTextLine(localeInfo.TARGET_INFO_DAMAGE % (str(iDamMin), str(iDamMax)))
  198.  
  199. idx = min(len(self.EXP_BASE_LVDELTA) - 1, max(0, (monsterLevel + 15) - player.GetStatus(player.LEVEL)))
  200. iExp = nonplayer.GetMonsterExp(race) * self.EXP_BASE_LVDELTA[idx] / 100
  201. self.AppendTextLine(localeInfo.TARGET_INFO_EXP % str(iExp))
  202.  
  203. def __LoadInformation_Race(self, race):
  204. dwRaceFlag = nonplayer.GetMonsterRaceFlag(race)
  205. self.AppendSeperator()
  206.  
  207. mainrace = ""
  208. subrace = ""
  209. for i in xrange(17):
  210. curFlag = 1 << i
  211. if HAS_FLAG(dwRaceFlag, curFlag):
  212. if self.RACE_FLAG_TO_NAME.has_key(curFlag):
  213. mainrace += self.RACE_FLAG_TO_NAME[curFlag] + ", "
  214. elif self.SUB_RACE_FLAG_TO_NAME.has_key(curFlag):
  215. subrace += self.SUB_RACE_FLAG_TO_NAME[curFlag] + ", "
  216. if nonplayer.IsMonsterStone(race):
  217. mainrace += localeInfo.TARGET_INFO_RACE_METIN + ", "
  218. if mainrace == "":
  219. mainrace = localeInfo.TARGET_INFO_NO_RACE
  220. else:
  221. mainrace = mainrace[:-2]
  222. if subrace == "":
  223. subrace = localeInfo.TARGET_INFO_NO_RACE
  224. else:
  225. subrace = subrace[:-2]
  226.  
  227. self.AppendTextLine(localeInfo.TARGET_INFO_MAINRACE % mainrace)
  228. self.AppendTextLine(localeInfo.TARGET_INFO_SUBRACE % subrace)
  229.  
  230. def __LoadInformation_Drops(self, race):
  231. self.AppendSeperator()
  232.  
  233. if race in constInfo.MONSTER_INFO_DATA:
  234. if len(constInfo.MONSTER_INFO_DATA[race]["items"]) == 0:
  235. self.AppendTextLine(localeInfo.TARGET_INFO_NO_ITEM_TEXT)
  236. else:
  237. itemListBox = ui.ListBoxExNew(32 + 5, self.MAX_ITEM_COUNT)
  238. itemListBox.SetSize(self.GetWidth() - 15 * 2 - ui.ScrollBar.SCROLLBAR_WIDTH, (32 + 5) * self.MAX_ITEM_COUNT)
  239. height = 0
  240. for curItem in constInfo.MONSTER_INFO_DATA[race]["items"]:
  241. if curItem.has_key("vnum_list"):
  242. height += self.AppendItem(itemListBox, curItem["vnum_list"], curItem["count"])
  243. else:
  244. height += self.AppendItem(itemListBox, curItem["vnum"], curItem["count"])
  245. if height < itemListBox.GetHeight():
  246. itemListBox.SetSize(itemListBox.GetWidth(), height)
  247. self.AppendWindow(itemListBox, 15)
  248. itemListBox.SetBasePos(0)
  249.  
  250. if len(constInfo.MONSTER_INFO_DATA[race]["items"]) > itemListBox.GetViewItemCount():
  251. itemScrollBar = ui.ScrollBar()
  252. itemScrollBar.SetParent(self)
  253. itemScrollBar.SetPosition(itemListBox.GetRight(), itemListBox.GetTop())
  254. itemScrollBar.SetScrollBarSize(32 * self.MAX_ITEM_COUNT + 5 * (self.MAX_ITEM_COUNT - 1))
  255. itemScrollBar.SetMiddleBarSize(float(self.MAX_ITEM_COUNT) / float(height / (32 + 5)))
  256. itemScrollBar.Show()
  257. itemListBox.SetScrollBar(itemScrollBar)
  258. else:
  259. self.AppendTextLine(localeInfo.TARGET_INFO_NO_ITEM_TEXT)
  260.  
  261. def AppendTextLine(self, text):
  262. textLine = ui.TextLine()
  263. textLine.SetParent(self)
  264. textLine.SetWindowHorizontalAlignCenter()
  265. textLine.SetHorizontalAlignCenter()
  266. textLine.SetText(text)
  267. textLine.SetPosition(0, self.yPos)
  268. textLine.Show()
  269.  
  270. self.children.append(textLine)
  271. self.yPos += 17
  272.  
  273. def AppendSeperator(self):
  274. img = ui.ImageBox()
  275. img.LoadImage("d:/ymir work/ui/seperator.tga")
  276. self.AppendWindow(img)
  277. img.SetPosition(img.GetLeft(), img.GetTop() - 15)
  278. self.yPos -= 15
  279.  
  280. def AppendItem(self, listBox, vnums, count):
  281. if type(vnums) == int:
  282. vnum = vnums
  283. else:
  284. vnum = vnums[0]
  285.  
  286. item.SelectItem(vnum)
  287. itemName = item.GetItemName()
  288. if type(vnums) != int and len(vnums) > 1:
  289. vnums = sorted(vnums)
  290. realName = itemName[:itemName.find("+")]
  291. if item.GetItemType() == item.ITEM_TYPE_METIN:
  292. realName = localeInfo.TARGET_INFO_STONE_NAME
  293. itemName = realName + "+0 - +4"
  294. else:
  295. itemName = realName + "+" + str(vnums[0] % 10) + " - +" + str(vnums[len(vnums) - 1] % 10)
  296. vnum = vnums[len(vnums) - 1]
  297.  
  298. myItem = self.ItemListBoxItem(listBox.GetWidth())
  299. myItem.LoadImage(item.GetIconImageFileName())
  300. if count <= 1:
  301. myItem.SetText(itemName)
  302. else:
  303. myItem.SetText("%dx %s" % (count, itemName))
  304. myItem.SAFE_SetOverInEvent(self.OnShowItemTooltip, vnum)
  305. myItem.SAFE_SetOverOutEvent(self.OnHideItemTooltip)
  306. listBox.AppendItem(myItem)
  307.  
  308. if item.GetItemType() == item.ITEM_TYPE_METIN:
  309. self.stoneImg = myItem
  310. self.stoneVnum = vnums
  311. self.lastStoneVnum = self.STONE_LAST_VNUM + vnums[len(vnums) - 1] % 1000 / 100 * 100
  312.  
  313. return myItem.GetHeight()
  314.  
  315. def OnShowItemTooltip(self, vnum):
  316. item.SelectItem(vnum)
  317. if item.GetItemType() == item.ITEM_TYPE_METIN:
  318. self.itemTooltip.isStone = True
  319. self.itemTooltip.isBook = False
  320. self.itemTooltip.isBook2 = False
  321. self.itemTooltip.SetItemToolTip(self.lastStoneVnum)
  322. else:
  323. self.itemTooltip.isStone = False
  324. self.itemTooltip.isBook = True
  325. self.itemTooltip.isBook2 = True
  326. self.itemTooltip.SetItemToolTip(vnum)
  327.  
  328. def OnHideItemTooltip(self):
  329. self.itemTooltip.HideToolTip()
  330.  
  331. def AppendWindow(self, wnd, x = 0, width = 0, height = 0):
  332. if width == 0:
  333. width = wnd.GetWidth()
  334. if height == 0:
  335. height = wnd.GetHeight()
  336.  
  337. wnd.SetParent(self)
  338. if x == 0:
  339. wnd.SetPosition((self.GetWidth() - width) / 2, self.yPos)
  340. else:
  341. wnd.SetPosition(x, self.yPos)
  342. wnd.Show()
  343.  
  344. self.children.append(wnd)
  345. self.yPos += height + 5
  346.  
  347. def OnUpdate(self):
  348. if self.stoneImg != None and self.stoneVnum != None and app.GetTime() >= self.nextStoneIconChange:
  349. nextImg = self.lastStoneVnum + 1
  350. if nextImg % 100 > self.STONE_LAST_VNUM % 100:
  351. nextImg -= (self.STONE_LAST_VNUM - self.STONE_START_VNUM) + 1
  352. self.lastStoneVnum = nextImg
  353. self.nextStoneIconChange = app.GetTime() + 2.5
  354.  
  355. item.SelectItem(nextImg)
  356. itemName = item.GetItemName()
  357. realName = itemName[:itemName.find("+")]
  358. realName = realName + "+0 - +4"
  359. self.stoneImg.LoadImage(item.GetIconImageFileName(), realName)
  360.  
  361. if self.itemTooltip.IsShow() and self.itemTooltip.isStone:
  362. self.itemTooltip.SetItemToolTip(nextImg)
  363.  
  364. BUTTON_NAME_LIST = (
  365. localeInfo.TARGET_BUTTON_WHISPER,
  366. localeInfo.TARGET_BUTTON_EXCHANGE,
  367. localeInfo.TARGET_BUTTON_FIGHT,
  368. localeInfo.TARGET_BUTTON_ACCEPT_FIGHT,
  369. localeInfo.TARGET_BUTTON_AVENGE,
  370. localeInfo.TARGET_BUTTON_FRIEND,
  371. localeInfo.TARGET_BUTTON_INVITE_PARTY,
  372. localeInfo.TARGET_BUTTON_LEAVE_PARTY,
  373. localeInfo.TARGET_BUTTON_EXCLUDE,
  374. localeInfo.TARGET_BUTTON_INVITE_GUILD,
  375. localeInfo.TARGET_BUTTON_DISMOUNT,
  376. localeInfo.TARGET_BUTTON_EXIT_OBSERVER,
  377. ##localeInfo.TARGET_BUTTON_VIEW_EQUIPMENT,
  378. localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY,
  379. localeInfo.TARGET_BUTTON_BUILDING_DESTROY,
  380. localeInfo.TARGET_BUTTON_EMOTION_ALLOW,
  381. "VOTE_BLOCK_CHAT",
  382. )
  383.  
  384. GRADE_NAME = {
  385. nonplayer.PAWN : localeInfo.TARGET_LEVEL_PAWN,
  386. nonplayer.S_PAWN : localeInfo.TARGET_LEVEL_S_PAWN,
  387. nonplayer.KNIGHT : localeInfo.TARGET_LEVEL_KNIGHT,
  388. nonplayer.S_KNIGHT : localeInfo.TARGET_LEVEL_S_KNIGHT,
  389. nonplayer.BOSS : localeInfo.TARGET_LEVEL_BOSS,
  390. nonplayer.KING : localeInfo.TARGET_LEVEL_KING,
  391. }
  392. EXCHANGE_LIMIT_RANGE = 3000
  393.  
  394. def __init__(self):
  395. ui.ThinBoard.__init__(self)
  396.  
  397. name = ui.TextLine()
  398. name.SetParent(self)
  399. name.SetDefaultFontName()
  400. name.SetOutline()
  401. name.Show()
  402.  
  403. hpGauge = ui.Gauge()
  404. hpGauge.SetParent(self)
  405. hpGauge.MakeGauge(130, "red")
  406. hpGauge.Hide()
  407.  
  408. if app.ENABLE_VIEW_TARGET_DECIMAL_HP:
  409. hpDecimal = ui.TextLine()
  410. hpDecimal.SetParent(hpGauge)
  411. hpDecimal.SetDefaultFontName()
  412. hpDecimal.SetPosition(5, 5)
  413. hpDecimal.SetOutline()
  414. hpDecimal.Hide()
  415.  
  416. closeButton = ui.Button()
  417. closeButton.SetParent(self)
  418. closeButton.SetUpVisual("d:/ymir work/ui/public/close_button_01.sub")
  419. closeButton.SetOverVisual("d:/ymir work/ui/public/close_button_02.sub")
  420. closeButton.SetDownVisual("d:/ymir work/ui/public/close_button_03.sub")
  421. closeButton.SetPosition(30, 13)
  422.  
  423. if localeInfo.IsARABIC():
  424. hpGauge.SetPosition(55, 17)
  425. hpGauge.SetWindowHorizontalAlignLeft()
  426. closeButton.SetWindowHorizontalAlignLeft()
  427. else:
  428. hpGauge.SetPosition(175, 17)
  429. hpGauge.SetWindowHorizontalAlignRight()
  430. closeButton.SetWindowHorizontalAlignRight()
  431. if app.ENABLE_SEND_TARGET_INFO:
  432. infoButton = ui.Button()
  433. infoButton.SetParent(self)
  434. infoButton.SetUpVisual("d:/ymir work/ui/pattern/q_mark_01.tga")
  435. infoButton.SetOverVisual("d:/ymir work/ui/pattern/q_mark_02.tga")
  436. infoButton.SetDownVisual("d:/ymir work/ui/pattern/q_mark_01.tga")
  437. infoButton.SetEvent(ui.__mem_func__(self.OnPressedInfoButton))
  438. infoButton.Hide()
  439.  
  440. infoBoard = self.InfoBoard()
  441. infoBoard.Hide()
  442. infoButton.showWnd = infoBoard
  443.  
  444. closeButton.SetEvent(ui.__mem_func__(self.OnPressedCloseButton))
  445. closeButton.Show()
  446.  
  447. self.buttonDict = {}
  448. self.showingButtonList = []
  449. for buttonName in self.BUTTON_NAME_LIST:
  450. button = ui.Button()
  451. button.SetParent(self)
  452.  
  453. if localeInfo.IsARABIC():
  454. button.SetUpVisual("d:/ymir work/ui/public/Small_Button_01.sub")
  455. button.SetOverVisual("d:/ymir work/ui/public/Small_Button_02.sub")
  456. button.SetDownVisual("d:/ymir work/ui/public/Small_Button_03.sub")
  457. else:
  458. button.SetUpVisual("d:/ymir work/ui/public/small_thin_button_01.sub")
  459. button.SetOverVisual("d:/ymir work/ui/public/small_thin_button_02.sub")
  460. button.SetDownVisual("d:/ymir work/ui/public/small_thin_button_03.sub")
  461.  
  462. button.SetWindowHorizontalAlignCenter()
  463. button.SetText(buttonName)
  464. button.Hide()
  465. self.buttonDict[buttonName] = button
  466. self.showingButtonList.append(button)
  467.  
  468. self.buttonDict[localeInfo.TARGET_BUTTON_WHISPER].SetEvent(ui.__mem_func__(self.OnWhisper))
  469. self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE].SetEvent(ui.__mem_func__(self.OnExchange))
  470. self.buttonDict[localeInfo.TARGET_BUTTON_FIGHT].SetEvent(ui.__mem_func__(self.OnPVP))
  471. self.buttonDict[localeInfo.TARGET_BUTTON_ACCEPT_FIGHT].SetEvent(ui.__mem_func__(self.OnPVP))
  472. self.buttonDict[localeInfo.TARGET_BUTTON_AVENGE].SetEvent(ui.__mem_func__(self.OnPVP))
  473. self.buttonDict[localeInfo.TARGET_BUTTON_FRIEND].SetEvent(ui.__mem_func__(self.OnAppendToMessenger))
  474. self.buttonDict[localeInfo.TARGET_BUTTON_FRIEND].SetEvent(ui.__mem_func__(self.OnAppendToMessenger))
  475. self.buttonDict[localeInfo.TARGET_BUTTON_INVITE_PARTY].SetEvent(ui.__mem_func__(self.OnPartyInvite))
  476. self.buttonDict[localeInfo.TARGET_BUTTON_LEAVE_PARTY].SetEvent(ui.__mem_func__(self.OnPartyExit))
  477. self.buttonDict[localeInfo.TARGET_BUTTON_EXCLUDE].SetEvent(ui.__mem_func__(self.OnPartyRemove))
  478.  
  479. self.buttonDict[localeInfo.TARGET_BUTTON_INVITE_GUILD].SAFE_SetEvent(self.__OnGuildAddMember)
  480. self.buttonDict[localeInfo.TARGET_BUTTON_DISMOUNT].SAFE_SetEvent(self.__OnDismount)
  481. self.buttonDict[localeInfo.TARGET_BUTTON_EXIT_OBSERVER].SAFE_SetEvent(self.__OnExitObserver)
  482. ##self.buttonDict[localeInfo.TARGET_BUTTON_VIEW_EQUIPMENT].SAFE_SetEvent(self.__OnViewEquipment)
  483. self.buttonDict[localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY].SAFE_SetEvent(self.__OnRequestParty)
  484. self.buttonDict[localeInfo.TARGET_BUTTON_BUILDING_DESTROY].SAFE_SetEvent(self.__OnDestroyBuilding)
  485. self.buttonDict[localeInfo.TARGET_BUTTON_EMOTION_ALLOW].SAFE_SetEvent(self.__OnEmotionAllow)
  486.  
  487. self.buttonDict["VOTE_BLOCK_CHAT"].SetEvent(ui.__mem_func__(self.__OnVoteBlockChat))
  488.  
  489. self.name = name
  490. self.hpGauge = hpGauge
  491. if app.ENABLE_SEND_TARGET_INFO:
  492. self.infoButton = infoButton
  493. if app.ENABLE_SEND_TARGET_INFO:
  494. self.vnum = 0
  495. if app.ENABLE_VIEW_TARGET_DECIMAL_HP:
  496. self.hpDecimal = hpDecimal
  497. self.closeButton = closeButton
  498. self.nameString = 0
  499. self.nameLength = 0
  500. self.vid = 0
  501. self.eventWhisper = None
  502. self.isShowButton = False
  503.  
  504. self.__Initialize()
  505. self.ResetTargetBoard()
  506.  
  507. def __del__(self):
  508. ui.ThinBoard.__del__(self)
  509.  
  510. print "===================================================== DESTROYED TARGET BOARD"
  511.  
  512. def __Initialize(self):
  513. self.nameString = ""
  514. self.nameLength = 0
  515. self.vid = 0
  516. if app.ENABLE_SEND_TARGET_INFO:
  517. self.vnum = 0
  518. self.isShowButton = False
  519.  
  520. def Destroy(self):
  521. self.eventWhisper = None
  522. if app.ENABLE_SEND_TARGET_INFO:
  523. self.infoButton = None
  524. self.closeButton = None
  525. self.showingButtonList = None
  526. self.buttonDict = None
  527. self.name = None
  528. self.hpGauge = None
  529. if app.ENABLE_VIEW_TARGET_DECIMAL_HP:
  530. self.hpDecimal = None
  531. self.__Initialize()
  532. if app.ENABLE_SEND_TARGET_INFO:
  533. def RefreshMonsterInfoBoard(self):
  534. if not self.infoButton.showWnd.IsShow():
  535. return
  536.  
  537. self.infoButton.showWnd.Refresh()
  538.  
  539. def OnPressedInfoButton(self):
  540. net.SendTargetInfoLoad(player.GetTargetVID())
  541. if self.infoButton.showWnd.IsShow():
  542. self.infoButton.showWnd.Close()
  543. elif self.vnum != 0:
  544. self.infoButton.showWnd.Open(self, self.vnum)
  545.  
  546. def OnPressedCloseButton(self):
  547. player.ClearTarget()
  548. self.Close()
  549.  
  550. def Close(self):
  551. self.__Initialize()
  552. if app.ENABLE_SEND_TARGET_INFO:
  553. self.infoButton.showWnd.Close()
  554. self.Hide()
  555.  
  556. def Open(self, vid, name):
  557. if vid:
  558. if not constInfo.GET_VIEW_OTHER_EMPIRE_PLAYER_TARGET_BOARD():
  559. if not player.IsSameEmpire(vid):
  560. self.Hide()
  561. return
  562.  
  563. if vid != self.GetTargetVID():
  564. self.ResetTargetBoard()
  565. self.SetTargetVID(vid)
  566. self.SetTargetName(name)
  567.  
  568. if player.IsMainCharacterIndex(vid):
  569. self.__ShowMainCharacterMenu()
  570. elif chr.INSTANCE_TYPE_BUILDING == chr.GetInstanceType(self.vid):
  571. self.Hide()
  572. else:
  573. self.RefreshButton()
  574. self.Show()
  575. else:
  576. self.HideAllButton()
  577. self.__ShowButton(localeInfo.TARGET_BUTTON_WHISPER)
  578. self.__ShowButton("VOTE_BLOCK_CHAT")
  579. self.__ArrangeButtonPosition()
  580. self.SetTargetName(name)
  581. self.Show()
  582.  
  583. def Refresh(self):
  584. if self.IsShow():
  585. if self.IsShowButton():
  586. self.RefreshButton()
  587.  
  588. def RefreshByVID(self, vid):
  589. if vid == self.GetTargetVID():
  590. self.Refresh()
  591.  
  592. def RefreshByName(self, name):
  593. if name == self.GetTargetName():
  594. self.Refresh()
  595.  
  596. def __ShowMainCharacterMenu(self):
  597. canShow=0
  598.  
  599. self.HideAllButton()
  600.  
  601. if player.IsMountingHorse():
  602. self.__ShowButton(localeInfo.TARGET_BUTTON_DISMOUNT)
  603. canShow=1
  604.  
  605. if player.IsObserverMode():
  606. self.__ShowButton(localeInfo.TARGET_BUTTON_EXIT_OBSERVER)
  607. canShow=1
  608.  
  609. if canShow:
  610. self.__ArrangeButtonPosition()
  611. self.Show()
  612. else:
  613. self.Hide()
  614.  
  615. def __ShowNameOnlyMenu(self):
  616. self.HideAllButton()
  617.  
  618. def SetWhisperEvent(self, event):
  619. self.eventWhisper = event
  620.  
  621. def UpdatePosition(self):
  622. if app.TOURNAMENT_PVP_SYSTEM:
  623. if player.IsTournamentMap():
  624. self.SetPosition(wndMgr.GetScreenWidth()/2 - self.GetWidth()/2, 114)
  625. else:
  626. self.SetPosition(wndMgr.GetScreenWidth()/2 - self.GetWidth()/2, 10)
  627. else:
  628. self.SetPosition(wndMgr.GetScreenWidth()/2 - self.GetWidth()/2, 10)
  629.  
  630. def ResetTargetBoard(self):
  631.  
  632. for btn in self.buttonDict.values():
  633. btn.Hide()
  634.  
  635. self.__Initialize()
  636.  
  637. self.name.SetPosition(0, 13)
  638. self.name.SetHorizontalAlignCenter()
  639. self.name.SetWindowHorizontalAlignCenter()
  640. self.hpGauge.Hide()
  641. if app.ENABLE_SEND_TARGET_INFO:
  642. self.infoButton.Hide()
  643. self.infoButton.showWnd.Close()
  644. if app.ENABLE_VIEW_TARGET_DECIMAL_HP:
  645. self.hpDecimal.Hide()
  646. self.SetSize(250, 40)
  647.  
  648. def SetTargetVID(self, vid):
  649. self.vid = vid
  650. if app.ENABLE_SEND_TARGET_INFO:
  651. self.vnum = 0
  652.  
  653. def SetEnemyVID(self, vid):
  654. self.SetTargetVID(vid)
  655.  
  656. name = chr.GetNameByVID(vid)
  657. if app.ENABLE_SEND_TARGET_INFO:
  658. vnum = nonplayer.GetRaceNumByVID(vid)
  659. level = nonplayer.GetLevelByVID(vid)
  660. grade = nonplayer.GetGradeByVID(vid)
  661.  
  662. nameFront = ""
  663. if -1 != level:
  664. nameFront += "Lv." + str(level) + " "
  665. if self.GRADE_NAME.has_key(grade):
  666. nameFront += "(" + self.GRADE_NAME[grade] + ") "
  667.  
  668. self.SetTargetName(nameFront + name)
  669. if app.ENABLE_SEND_TARGET_INFO:
  670. (textWidth, textHeight) = self.name.GetTextSize()
  671.  
  672. self.infoButton.SetPosition(textWidth + 25, 12)
  673. self.infoButton.SetWindowHorizontalAlignLeft()
  674.  
  675. self.vnum = vnum
  676. self.infoButton.Show()
  677.  
  678. def GetTargetVID(self):
  679. return self.vid
  680.  
  681. def GetTargetName(self):
  682. return self.nameString
  683.  
  684. def SetTargetName(self, name):
  685. self.nameString = name
  686. self.nameLength = len(name)
  687. self.name.SetText(name)
  688.  
  689. if app.ENABLE_VIEW_TARGET_DECIMAL_HP:
  690. def SetHP(self, hpPercentage, iMinHP, iMaxHP):
  691. if not self.hpGauge.IsShow():
  692. if app.ENABLE_VIEW_TARGET_PLAYER_HP:
  693. showingButtonCount = len(self.showingButtonList)
  694. if showingButtonCount > 0:
  695. if chr.GetInstanceType(self.vid) == chr.INSTANCE_TYPE_PLAYER:
  696. self.SetSize(max(120 + 75 * 3, showingButtonCount * 75), self.GetHeight())
  697. else:
  698. self.SetSize(200 + 7*self.nameLength, self.GetHeight())
  699. else:
  700. self.SetSize(200 + 7*self.nameLength, self.GetHeight())
  701. else:
  702. self.SetSize(200 + 7*self.nameLength, self.GetHeight())
  703.  
  704. if localeInfo.IsARABIC():
  705. self.name.SetPosition( self.GetWidth()-23, 13)
  706. else:
  707. self.name.SetPosition(23, 13)
  708.  
  709. self.name.SetWindowHorizontalAlignLeft()
  710. self.name.SetHorizontalAlignLeft()
  711. self.hpGauge.Show()
  712. self.UpdatePosition()
  713.  
  714. self.hpGauge.SetPercentage(hpPercentage, 100)
  715. if app.ENABLE_VIEW_TARGET_DECIMAL_HP:
  716. iMinHPText = '.'.join([i - 3 < 0 and str(iMinHP)[:i] or str(iMinHP)[i-3:i] for i in range(len(str(iMinHP)) % 3, len(str(iMinHP))+1, 3) if i])
  717. iMaxHPText = '.'.join([i - 3 < 0 and str(iMaxHP)[:i] or str(iMaxHP)[i-3:i] for i in range(len(str(iMaxHP)) % 3, len(str(iMaxHP))+1, 3) if i])
  718. self.hpDecimal.SetText(str(iMinHPText) + "/" + str(iMaxHPText))
  719. (textWidth, textHeight)=self.hpDecimal.GetTextSize()
  720. if localeInfo.IsARABIC():
  721. self.hpDecimal.SetPosition(120 / 2 + textWidth / 2, -13)
  722. else:
  723. self.hpDecimal.SetPosition(130 / 2 - textWidth / 2, -13)
  724.  
  725. self.hpDecimal.Show()
  726. else:
  727. def SetHP(self, hpPercentage):
  728. if not self.hpGauge.IsShow():
  729. if app.ENABLE_VIEW_TARGET_PLAYER_HP:
  730. showingButtonCount = len(self.showingButtonList)
  731. if showingButtonCount > 0:
  732. if chr.GetInstanceType(self.GetTargetVID) != chr.INSTANCE_TYPE_PLAYER:
  733. if showingButtonCount != 1:
  734. self.SetSize(max(150, showingButtonCount * 75), self.GetHeight())
  735. else:
  736. self.SetSize(max(150, 2 * 75), self.GetHeight())
  737. else:
  738. self.SetSize(200 + 7*self.nameLength, self.GetHeight())
  739. else:
  740. self.SetSize(200 + 7*self.nameLength, self.GetHeight())
  741. else:
  742. self.SetSize(200 + 7*self.nameLength, self.GetHeight())
  743.  
  744. if localeInfo.IsARABIC():
  745. self.name.SetPosition( self.GetWidth()-23, 13)
  746. else:
  747. self.name.SetPosition(23, 13)
  748.  
  749. self.name.SetWindowHorizontalAlignLeft()
  750. self.name.SetHorizontalAlignLeft()
  751. self.hpGauge.Show()
  752. self.UpdatePosition()
  753.  
  754. def ShowDefaultButton(self):
  755.  
  756. self.isShowButton = True
  757. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_WHISPER])
  758. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE])
  759. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_FIGHT])
  760. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_EMOTION_ALLOW])
  761. for button in self.showingButtonList:
  762. button.Show()
  763.  
  764. def HideAllButton(self):
  765. self.isShowButton = False
  766. for button in self.showingButtonList:
  767. button.Hide()
  768. self.showingButtonList = []
  769.  
  770. def __ShowButton(self, name):
  771.  
  772. if not self.buttonDict.has_key(name):
  773. return
  774.  
  775. self.buttonDict[name].Show()
  776. self.showingButtonList.append(self.buttonDict[name])
  777.  
  778. def __HideButton(self, name):
  779.  
  780. if not self.buttonDict.has_key(name):
  781. return
  782.  
  783. button = self.buttonDict[name]
  784. button.Hide()
  785.  
  786. for btnInList in self.showingButtonList:
  787. if btnInList == button:
  788. self.showingButtonList.remove(button)
  789. break
  790.  
  791. def OnWhisper(self):
  792. if None != self.eventWhisper:
  793. self.eventWhisper(self.nameString)
  794.  
  795. def OnExchange(self):
  796. net.SendExchangeStartPacket(self.vid)
  797.  
  798. def OnPVP(self):
  799. if app.ENABLE_PVP_ADVANCED:
  800. net.SendChatPacket("/pvp_advanced %d" % (self.vid))
  801. else:
  802. net.SendChatPacket("/pvp %d" % (self.vid))
  803.  
  804. def OnAppendToMessenger(self):
  805. net.SendMessengerAddByVIDPacket(self.vid)
  806.  
  807. def OnPartyInvite(self):
  808. net.SendPartyInvitePacket(self.vid)
  809.  
  810. def OnPartyExit(self):
  811. net.SendPartyExitPacket()
  812.  
  813. def OnPartyRemove(self):
  814. net.SendPartyRemovePacketVID(self.vid)
  815.  
  816. def __OnGuildAddMember(self):
  817. net.SendGuildAddMemberPacket(self.vid)
  818.  
  819. def __OnDismount(self):
  820. net.SendChatPacket("/unmount")
  821.  
  822. def __OnExitObserver(self):
  823. net.SendChatPacket("/observer_exit")
  824.  
  825. def __OnViewEquipment(self):
  826. net.SendChatPacket("/view_equip " + str(self.vid))
  827.  
  828. def __OnRequestParty(self):
  829. net.SendChatPacket("/party_request " + str(self.vid))
  830.  
  831. def __OnDestroyBuilding(self):
  832. net.SendChatPacket("/build d %d" % (self.vid))
  833.  
  834. def __OnEmotionAllow(self):
  835. net.SendChatPacket("/emotion_allow %d" % (self.vid))
  836.  
  837. def __OnVoteBlockChat(self):
  838. cmd = "/vote_block_chat %s" % (self.nameString)
  839. net.SendChatPacket(cmd)
  840.  
  841. def OnPressEscapeKey(self):
  842. self.OnPressedCloseButton()
  843. return True
  844.  
  845. def IsShowButton(self):
  846. return self.isShowButton
  847.  
  848. def RefreshButton(self):
  849.  
  850. self.HideAllButton()
  851.  
  852. if chr.INSTANCE_TYPE_BUILDING == chr.GetInstanceType(self.vid):
  853. #self.__ShowButton(localeInfo.TARGET_BUTTON_BUILDING_DESTROY)
  854. #self.__ArrangeButtonPosition()
  855. return
  856.  
  857. if player.IsPVPInstance(self.vid) or player.IsObserverMode():
  858. # PVP_INFO_SIZE_BUG_FIX
  859. self.SetSize(200 + 7*self.nameLength, 40)
  860. self.UpdatePosition()
  861. # END_OF_PVP_INFO_SIZE_BUG_FIX
  862. return
  863.  
  864. self.ShowDefaultButton()
  865.  
  866. if guild.MainPlayerHasAuthority(guild.AUTH_ADD_MEMBER):
  867. if not guild.IsMemberByName(self.nameString):
  868. if 0 == chr.GetGuildID(self.vid):
  869. self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_GUILD)
  870.  
  871. if not messenger.IsFriendByName(self.nameString):
  872. self.__ShowButton(localeInfo.TARGET_BUTTON_FRIEND)
  873.  
  874. if player.IsPartyMember(self.vid):
  875.  
  876. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  877.  
  878. if player.IsPartyLeader(self.vid):
  879. self.__ShowButton(localeInfo.TARGET_BUTTON_LEAVE_PARTY)
  880. elif player.IsPartyLeader(player.GetMainCharacterIndex()):
  881. self.__ShowButton(localeInfo.TARGET_BUTTON_EXCLUDE)
  882.  
  883. else:
  884. if player.IsPartyMember(player.GetMainCharacterIndex()):
  885. if player.IsPartyLeader(player.GetMainCharacterIndex()):
  886. self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  887. else:
  888. if chr.IsPartyMember(self.vid):
  889. self.__ShowButton(localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY)
  890. else:
  891. self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  892.  
  893. if player.IsRevengeInstance(self.vid):
  894. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  895. self.__ShowButton(localeInfo.TARGET_BUTTON_AVENGE)
  896. elif player.IsChallengeInstance(self.vid):
  897. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  898. self.__ShowButton(localeInfo.TARGET_BUTTON_ACCEPT_FIGHT)
  899. elif player.IsCantFightInstance(self.vid):
  900. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  901.  
  902. if not player.IsSameEmpire(self.vid):
  903. self.__HideButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  904. self.__HideButton(localeInfo.TARGET_BUTTON_FRIEND)
  905. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  906.  
  907. distance = player.GetCharacterDistance(self.vid)
  908. if distance > self.EXCHANGE_LIMIT_RANGE:
  909. self.__HideButton(localeInfo.TARGET_BUTTON_EXCHANGE)
  910. self.__ArrangeButtonPosition()
  911.  
  912. self.__ArrangeButtonPosition()
  913.  
  914. def __ArrangeButtonPosition(self):
  915. showingButtonCount = len(self.showingButtonList)
  916. pos = -(showingButtonCount / 2) * 68
  917. if 0 == showingButtonCount % 2:
  918. pos += 34
  919.  
  920. for button in self.showingButtonList:
  921. button.SetPosition(pos, 33)
  922. pos += 68
  923.  
  924. if app.ENABLE_VIEW_TARGET_PLAYER_HP:
  925. if showingButtonCount <= 2:
  926. self.SetSize(max(150 + 125, showingButtonCount * 75), 65)
  927. else:
  928. self.SetSize(max(150, showingButtonCount * 75), 65)
  929. else:
  930. self.SetSize(max(150, showingButtonCount * 75), 65)
  931.  
  932. self.UpdatePosition()
  933.  
  934. def OnUpdate(self):
  935. if self.isShowButton:
  936.  
  937. exchangeButton = self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE]
  938. distance = player.GetCharacterDistance(self.vid)
  939.  
  940. if distance < 0:
  941. return
  942.  
  943. if exchangeButton.IsShow():
  944. if distance > self.EXCHANGE_LIMIT_RANGE:
  945. self.RefreshButton()
  946.  
  947. else:
  948. if distance < self.EXCHANGE_LIMIT_RANGE:
  949. self.RefreshButton()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement