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