Advertisement
Guest User

uitarget.py

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