Guest User

Untitled

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