Advertisement
Guest User

Untitled

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