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