hfwhite

uitarget.py metin2

Oct 4th, 2024
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 27.00 KB | Gaming | 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.                 self.itemScrollBar = None ## fix scrollbar
  131.  
  132.                 self.SetSize(self.BOARD_WIDTH, 0)
  133.  
  134.             def __del__(self):
  135.                 ui.ThinBoard.__del__(self)
  136.  
  137.             def __UpdatePosition(self, targetBoard):
  138.                 self.SetPosition(targetBoard.GetLeft() + (targetBoard.GetWidth() - self.GetWidth()) / 2, targetBoard.GetBottom() - 17)
  139.  
  140.             def Open(self, targetBoard, race):
  141.                 self.__LoadInformation(race)
  142.  
  143.                 self.SetSize(self.BOARD_WIDTH, self.yPos + 10)
  144.                 self.__UpdatePosition(targetBoard)
  145.  
  146.                 self.Show()
  147.  
  148.             def Refresh(self):
  149.                 self.__LoadInformation(self.race)
  150.                 self.SetSize(self.BOARD_WIDTH, self.yPos + 10)
  151.  
  152.             def Close(self):
  153.                 self.itemTooltip.HideToolTip()
  154.                 self.Hide()
  155.  
  156.             def __LoadInformation(self, race):
  157.                 self.yPos = 7
  158.                 self.children = []
  159.                 self.race = race
  160.                 self.stoneImg = None
  161.                 self.stoneVnum = None
  162.                 self.nextStoneIconChange = 0
  163.                 self.itemScrollBar = None ## fix scrollbar
  164.  
  165.                 self.__LoadInformation_Default(race)
  166.                 self.__LoadInformation_Race(race)
  167.                 self.__LoadInformation_Drops(race)
  168.  
  169.             def __LoadInformation_Default_GetHitRate(self, race):
  170.                 attacker_dx = nonplayer.GetMonsterDX(race)
  171.                 attacker_level = nonplayer.GetMonsterLevel(race)
  172.  
  173.                 self_dx = player.GetStatus(player.DX)
  174.                 self_level = player.GetStatus(player.LEVEL)
  175.  
  176.                 iARSrc = min(90, (attacker_dx * 4 + attacker_level * 2) / 6)
  177.                 iERSrc = min(90, (self_dx * 4 + self_level * 2) / 6)
  178.  
  179.                 fAR = (float(iARSrc) + 210.0) / 300.0
  180.                 fER = (float(iERSrc) * 2 + 5) / (float(iERSrc) + 95) * 3.0 / 10.0
  181.  
  182.                 return fAR - fER
  183.  
  184.             def __LoadInformation_Default(self, race):
  185.                 self.AppendSeperator()
  186.                 self.AppendTextLine(localeInfo.TARGET_INFO_MAX_HP % str(nonplayer.GetMonsterMaxHP(race)))
  187.  
  188.                 # calc att damage
  189.                 monsterLevel = nonplayer.GetMonsterLevel(race)
  190.                 fHitRate = self.__LoadInformation_Default_GetHitRate(race)
  191.                 iDamMin, iDamMax = nonplayer.GetMonsterDamage(race)
  192.                 iDamMin = int((iDamMin + nonplayer.GetMonsterST(race)) * 2 * fHitRate) + monsterLevel * 2
  193.                 iDamMax = int((iDamMax + nonplayer.GetMonsterST(race)) * 2 * fHitRate) + monsterLevel * 2
  194.                 iDef = player.GetStatus(player.DEF_GRADE) * (100 + player.GetStatus(player.DEF_BONUS)) / 100
  195.                 fDamMulti = nonplayer.GetMonsterDamageMultiply(race)
  196.                 iDamMin = int(max(0, iDamMin - iDef) * fDamMulti)
  197.                 iDamMax = int(max(0, iDamMax - iDef) * fDamMulti)
  198.                 if iDamMin < 1:
  199.                     iDamMin = 1
  200.                 if iDamMax < 5:
  201.                     iDamMax = 5
  202.                 self.AppendTextLine(localeInfo.TARGET_INFO_DAMAGE % (str(iDamMin), str(iDamMax)))
  203.  
  204.                 idx = min(len(self.EXP_BASE_LVDELTA) - 1, max(0, (monsterLevel + 15) - player.GetStatus(player.LEVEL)))
  205.                 iExp = nonplayer.GetMonsterExp(race) * self.EXP_BASE_LVDELTA[idx] / 100
  206.                 self.AppendTextLine(localeInfo.TARGET_INFO_EXP % str(iExp))
  207.  
  208.             def __LoadInformation_Race(self, race):
  209.                 dwRaceFlag = nonplayer.GetMonsterRaceFlag(race)
  210.                 self.AppendSeperator()
  211.  
  212.                 mainrace = ""
  213.                 subrace = ""
  214.                 for i in xrange(17):
  215.                     curFlag = 1 << i
  216.                     if HAS_FLAG(dwRaceFlag, curFlag):
  217.                         if self.RACE_FLAG_TO_NAME.has_key(curFlag):
  218.                             mainrace += self.RACE_FLAG_TO_NAME[curFlag] + ", "
  219.                         elif self.SUB_RACE_FLAG_TO_NAME.has_key(curFlag):
  220.                             subrace += self.SUB_RACE_FLAG_TO_NAME[curFlag] + ", "
  221.                 if nonplayer.IsMonsterStone(race):
  222.                     mainrace += localeInfo.TARGET_INFO_RACE_METIN + ", "
  223.                 if mainrace == "":
  224.                     mainrace = localeInfo.TARGET_INFO_NO_RACE
  225.                 else:
  226.                     mainrace = mainrace[:-2]
  227.                 if subrace == "":
  228.                     subrace = localeInfo.TARGET_INFO_NO_RACE
  229.                 else:
  230.                     subrace = subrace[:-2]
  231.  
  232.                 self.AppendTextLine(localeInfo.TARGET_INFO_MAINRACE % mainrace)
  233.                 self.AppendTextLine(localeInfo.TARGET_INFO_SUBRACE % subrace)
  234.  
  235.             def __LoadInformation_Drops(self, race):
  236.                 self.AppendSeperator()
  237.  
  238.                 if race in constInfo.MONSTER_INFO_DATA:
  239.                     if len(constInfo.MONSTER_INFO_DATA[race]["items"]) == 0:
  240.                         self.AppendTextLine(localeInfo.TARGET_INFO_NO_ITEM_TEXT)
  241.                     else:
  242.                         itemListBox = ui.ListBoxExNew(32 + 5, self.MAX_ITEM_COUNT)
  243.                         itemListBox.SetSize(self.GetWidth() - 15 * 2 - ui.ScrollBar.SCROLLBAR_WIDTH, (32 + 5) * self.MAX_ITEM_COUNT)
  244.                         height = 0
  245.                         for curItem in constInfo.MONSTER_INFO_DATA[race]["items"]:
  246.                             if curItem.has_key("vnum_list"):
  247.                                 height += self.AppendItem(itemListBox, curItem["vnum_list"], curItem["count"])
  248.                             else:
  249.                                 height += self.AppendItem(itemListBox, curItem["vnum"], curItem["count"])
  250.                         if height < itemListBox.GetHeight():
  251.                             itemListBox.SetSize(itemListBox.GetWidth(), height)
  252.                         self.AppendWindow(itemListBox, 15)
  253.                         itemListBox.SetBasePos(0)
  254.  
  255.                         if len(constInfo.MONSTER_INFO_DATA[race]["items"]) > itemListBox.GetViewItemCount():
  256.                             itemScrollBar = ui.ScrollBar()
  257.                             itemScrollBar.SetParent(self)
  258.                             itemScrollBar.SetPosition(itemListBox.GetRight(), itemListBox.GetTop())
  259.                             itemScrollBar.SetScrollBarSize(32 * self.MAX_ITEM_COUNT + 5 * (self.MAX_ITEM_COUNT - 1))
  260.                             itemScrollBar.SetMiddleBarSize(float(self.MAX_ITEM_COUNT) / float(height / (32 + 5)))
  261.                             itemScrollBar.Show()
  262.                             itemListBox.SetScrollBar(itemScrollBar)
  263.                             self.itemScrollBar = itemScrollBar ## fix scrollbar
  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.  
  400.     def __init__(self):
  401.         ui.ThinBoard.__init__(self)
  402.  
  403.         name = ui.TextLine()
  404.         name.SetParent(self)
  405.         name.SetDefaultFontName()
  406.         name.SetOutline()
  407.         name.Show()
  408.  
  409.         hpGauge = ui.Gauge()
  410.         hpGauge.SetParent(self)
  411.         hpGauge.MakeGauge(130, "red")
  412.         hpGauge.Hide()
  413.  
  414.         closeButton = ui.Button()
  415.         closeButton.SetParent(self)
  416.         closeButton.SetUpVisual("d:/ymir work/ui/public/close_button_01.sub")
  417.         closeButton.SetOverVisual("d:/ymir work/ui/public/close_button_02.sub")
  418.         closeButton.SetDownVisual("d:/ymir work/ui/public/close_button_03.sub")
  419.         closeButton.SetPosition(30, 13)
  420.  
  421.         if localeInfo.IsARABIC():
  422.             hpGauge.SetPosition(55, 17)
  423.             hpGauge.SetWindowHorizontalAlignLeft()
  424.             closeButton.SetWindowHorizontalAlignLeft()
  425.         else:
  426.             hpGauge.SetPosition(175, 17)
  427.             hpGauge.SetWindowHorizontalAlignRight()
  428.             closeButton.SetWindowHorizontalAlignRight()
  429.  
  430.         if app.ENABLE_SEND_TARGET_INFO:
  431.             infoButton = ui.Button()
  432.             infoButton.SetParent(self)
  433.             infoButton.SetUpVisual("d:/ymir work/ui/pattern/q_mark_01.tga")
  434.             infoButton.SetOverVisual("d:/ymir work/ui/pattern/q_mark_02.tga")
  435.             infoButton.SetDownVisual("d:/ymir work/ui/pattern/q_mark_01.tga")
  436.             infoButton.SetEvent(ui.__mem_func__(self.OnPressedInfoButton))
  437.             infoButton.Hide()
  438.  
  439.             infoBoard = self.InfoBoard()
  440.             infoBoard.Hide()
  441.             infoButton.showWnd = infoBoard
  442.  
  443.         closeButton.SetEvent(ui.__mem_func__(self.OnPressedCloseButton))
  444.         closeButton.Show()
  445.  
  446.         self.buttonDict = {}
  447.         self.showingButtonList = []
  448.         for buttonName in self.BUTTON_NAME_LIST:
  449.             button = ui.Button()
  450.             button.SetParent(self)
  451.  
  452.             if localeInfo.IsARABIC():
  453.                 button.SetUpVisual("d:/ymir work/ui/public/Small_Button_01.sub")
  454.                 button.SetOverVisual("d:/ymir work/ui/public/Small_Button_02.sub")
  455.                 button.SetDownVisual("d:/ymir work/ui/public/Small_Button_03.sub")
  456.             else:
  457.                 button.SetUpVisual("d:/ymir work/ui/public/small_thin_button_01.sub")
  458.                 button.SetOverVisual("d:/ymir work/ui/public/small_thin_button_02.sub")
  459.                 button.SetDownVisual("d:/ymir work/ui/public/small_thin_button_03.sub")
  460.  
  461.             button.SetWindowHorizontalAlignCenter()
  462.             button.SetText(buttonName)
  463.             button.Hide()
  464.             self.buttonDict[buttonName] = button
  465.             self.showingButtonList.append(button)
  466.  
  467.         self.buttonDict[localeInfo.TARGET_BUTTON_WHISPER].SetEvent(ui.__mem_func__(self.OnWhisper))
  468.         self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE].SetEvent(ui.__mem_func__(self.OnExchange))
  469.         self.buttonDict[localeInfo.TARGET_BUTTON_FIGHT].SetEvent(ui.__mem_func__(self.OnPVP))
  470.         self.buttonDict[localeInfo.TARGET_BUTTON_ACCEPT_FIGHT].SetEvent(ui.__mem_func__(self.OnPVP))
  471.         self.buttonDict[localeInfo.TARGET_BUTTON_AVENGE].SetEvent(ui.__mem_func__(self.OnPVP))
  472.         self.buttonDict[localeInfo.TARGET_BUTTON_FRIEND].SetEvent(ui.__mem_func__(self.OnAppendToMessenger))
  473.         self.buttonDict[localeInfo.TARGET_BUTTON_FRIEND].SetEvent(ui.__mem_func__(self.OnAppendToMessenger))
  474.         self.buttonDict[localeInfo.TARGET_BUTTON_INVITE_PARTY].SetEvent(ui.__mem_func__(self.OnPartyInvite))
  475.         self.buttonDict[localeInfo.TARGET_BUTTON_LEAVE_PARTY].SetEvent(ui.__mem_func__(self.OnPartyExit))
  476.         self.buttonDict[localeInfo.TARGET_BUTTON_EXCLUDE].SetEvent(ui.__mem_func__(self.OnPartyRemove))
  477.  
  478.         self.buttonDict[localeInfo.TARGET_BUTTON_INVITE_GUILD].SAFE_SetEvent(self.__OnGuildAddMember)
  479.         self.buttonDict[localeInfo.TARGET_BUTTON_DISMOUNT].SAFE_SetEvent(self.__OnDismount)
  480.         self.buttonDict[localeInfo.TARGET_BUTTON_EXIT_OBSERVER].SAFE_SetEvent(self.__OnExitObserver)
  481.         self.buttonDict[localeInfo.TARGET_BUTTON_VIEW_EQUIPMENT].SAFE_SetEvent(self.__OnViewEquipment)
  482.         self.buttonDict[localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY].SAFE_SetEvent(self.__OnRequestParty)
  483.         self.buttonDict[localeInfo.TARGET_BUTTON_BUILDING_DESTROY].SAFE_SetEvent(self.__OnDestroyBuilding)
  484.         self.buttonDict[localeInfo.TARGET_BUTTON_EMOTION_ALLOW].SAFE_SetEvent(self.__OnEmotionAllow)
  485.  
  486.         self.buttonDict["VOTE_BLOCK_CHAT"].SetEvent(ui.__mem_func__(self.__OnVoteBlockChat))
  487.  
  488.         self.name = name
  489.         self.hpGauge = hpGauge
  490.         if app.ENABLE_SEND_TARGET_INFO:
  491.             self.infoButton = infoButton
  492.         if app.ENABLE_SEND_TARGET_INFO:
  493.             self.vnum = 0
  494.         self.closeButton = closeButton
  495.         self.nameString = 0
  496.         self.nameLength = 0
  497.         self.vid = 0
  498.         self.eventWhisper = None
  499.         self.isShowButton = False
  500.  
  501.         self.__Initialize()
  502.         self.ResetTargetBoard()
  503.  
  504.     def __del__(self):
  505.         ui.ThinBoard.__del__(self)
  506.  
  507.         print "===================================================== DESTROYED TARGET BOARD"
  508.  
  509.     def __Initialize(self):
  510.         self.nameString = ""
  511.         self.nameLength = 0
  512.         self.vid = 0
  513.         if app.ENABLE_SEND_TARGET_INFO:
  514.             self.vnum = 0
  515.         self.isShowButton = False
  516.  
  517.     def Destroy(self):
  518.         self.eventWhisper = None
  519.         if app.ENABLE_SEND_TARGET_INFO:
  520.             self.infoButton = None
  521.         self.closeButton = None
  522.         self.showingButtonList = None
  523.         self.buttonDict = None
  524.         self.name = None
  525.         self.hpGauge = None
  526.         self.__Initialize()
  527.     if app.ENABLE_SEND_TARGET_INFO:
  528.         def RefreshMonsterInfoBoard(self):
  529.             if not self.infoButton.showWnd.IsShow():
  530.                 return
  531.  
  532.             self.infoButton.showWnd.Refresh()
  533.  
  534.         def OnPressedInfoButton(self):
  535.             net.SendTargetInfoLoad(player.GetTargetVID())
  536.             if self.infoButton.showWnd.IsShow():
  537.                 self.infoButton.showWnd.Close()
  538.             elif self.vnum != 0:
  539.                 self.infoButton.showWnd.Open(self, self.vnum)
  540.  
  541.     def OnPressedCloseButton(self):
  542.         player.ClearTarget()
  543.         self.Close()
  544.  
  545.     def Close(self):
  546.         self.__Initialize()
  547.         if app.ENABLE_SEND_TARGET_INFO:
  548.             self.infoButton.showWnd.Close()
  549.         self.Hide()
  550.  
  551.     def Open(self, vid, name):
  552.         if vid:
  553.             if not constInfo.GET_VIEW_OTHER_EMPIRE_PLAYER_TARGET_BOARD():
  554.                 if not player.IsSameEmpire(vid):
  555.                     self.Hide()
  556.                     return
  557.  
  558.             if vid != self.GetTargetVID():
  559.                 self.ResetTargetBoard()
  560.                 self.SetTargetVID(vid)
  561.                 self.SetTargetName(name)
  562.  
  563.             if player.IsMainCharacterIndex(vid):
  564.                 self.__ShowMainCharacterMenu()
  565.             elif chr.INSTANCE_TYPE_BUILDING == chr.GetInstanceType(self.vid):
  566.                 self.Hide()
  567.             else:
  568.                 self.RefreshButton()
  569.                 self.Show()
  570.         else:
  571.             self.HideAllButton()
  572.             self.__ShowButton(localeInfo.TARGET_BUTTON_WHISPER)
  573.             self.__ShowButton("VOTE_BLOCK_CHAT")
  574.             self.__ArrangeButtonPosition()
  575.             self.SetTargetName(name)
  576.             self.Show()
  577.  
  578.     def Refresh(self):
  579.         if self.IsShow():
  580.             if self.IsShowButton():
  581.                 self.RefreshButton()
  582.  
  583.     def RefreshByVID(self, vid):
  584.         if vid == self.GetTargetVID():
  585.             self.Refresh()
  586.  
  587.     def RefreshByName(self, name):
  588.         if name == self.GetTargetName():
  589.             self.Refresh()
  590.  
  591.     def __ShowMainCharacterMenu(self):
  592.         canShow=0
  593.  
  594.         self.HideAllButton()
  595.  
  596.         if player.IsMountingHorse():
  597.             self.__ShowButton(localeInfo.TARGET_BUTTON_DISMOUNT)
  598.             canShow=1
  599.  
  600.         if player.IsObserverMode():
  601.             self.__ShowButton(localeInfo.TARGET_BUTTON_EXIT_OBSERVER)
  602.             canShow=1
  603.  
  604.         if canShow:
  605.             self.__ArrangeButtonPosition()
  606.             self.Show()
  607.         else:
  608.             self.Hide()
  609.  
  610.     def __ShowNameOnlyMenu(self):
  611.         self.HideAllButton()
  612.  
  613.     def SetWhisperEvent(self, event):
  614.         self.eventWhisper = event
  615.  
  616.     def UpdatePosition(self):
  617.         self.SetPosition(wndMgr.GetScreenWidth()/2 - self.GetWidth()/2, 10)
  618.  
  619.     def ResetTargetBoard(self):
  620.  
  621.         for btn in self.buttonDict.values():
  622.             btn.Hide()
  623.  
  624.         self.__Initialize()
  625.  
  626.         self.name.SetPosition(0, 13)
  627.         self.name.SetHorizontalAlignCenter()
  628.         self.name.SetWindowHorizontalAlignCenter()
  629.         self.hpGauge.Hide()
  630.         if app.ENABLE_SEND_TARGET_INFO:
  631.             self.infoButton.Hide()
  632.             self.infoButton.showWnd.Close()
  633.         self.SetSize(250, 40)
  634.  
  635.     def SetTargetVID(self, vid):
  636.         self.vid = vid
  637.         if app.ENABLE_SEND_TARGET_INFO:
  638.             self.vnum = 0
  639.  
  640.     def SetEnemyVID(self, vid):
  641.         self.SetTargetVID(vid)
  642.  
  643.         name = chr.GetNameByVID(vid)
  644.  
  645.         if app.ENABLE_SEND_TARGET_INFO:
  646.             vnum = nonplayer.GetRaceNumByVID(vid)
  647.  
  648.         level = nonplayer.GetLevelByVID(vid)
  649.         grade = nonplayer.GetGradeByVID(vid)
  650.  
  651.         nameFront = ""
  652.         if -1 != level:
  653.             nameFront += "Lv." + str(level) + " "
  654.         if self.GRADE_NAME.has_key(grade):
  655.             nameFront += "(" + self.GRADE_NAME[grade] + ") "
  656.  
  657.         self.SetTargetName(nameFront + name)
  658.  
  659.         if app.ENABLE_SEND_TARGET_INFO:
  660.             (textWidth, textHeight) = self.name.GetTextSize()
  661.  
  662.             self.infoButton.SetPosition(textWidth + 25, 12)
  663.             self.infoButton.SetWindowHorizontalAlignLeft()
  664.  
  665.             self.vnum = vnum
  666.             self.infoButton.Show()
  667.  
  668.     def GetTargetVID(self):
  669.         return self.vid
  670.  
  671.     def GetTargetName(self):
  672.         return self.nameString
  673.  
  674.     def SetTargetName(self, name):
  675.         self.nameString = name
  676.         self.nameLength = len(name)
  677.         self.name.SetText(name)
  678.  
  679.     def SetHP(self, hpPercentage):
  680.         if not self.hpGauge.IsShow():
  681.  
  682.             self.SetSize(200 + 7*self.nameLength, self.GetHeight())
  683.  
  684.             if localeInfo.IsARABIC():
  685.                 self.name.SetPosition( self.GetWidth()-23, 13)
  686.             else:
  687.                 self.name.SetPosition(23, 13)
  688.  
  689.             self.name.SetWindowHorizontalAlignLeft()
  690.             self.name.SetHorizontalAlignLeft()
  691.             self.hpGauge.Show()
  692.             self.UpdatePosition()
  693.  
  694.         self.hpGauge.SetPercentage(hpPercentage, 100)
  695.  
  696.     def ShowDefaultButton(self):
  697.  
  698.         self.isShowButton = True
  699.         self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_WHISPER])
  700.         self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE])
  701.         self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_FIGHT])
  702.         self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_EMOTION_ALLOW])
  703.         for button in self.showingButtonList:
  704.             button.Show()
  705.  
  706.     def HideAllButton(self):
  707.         self.isShowButton = False
  708.         for button in self.showingButtonList:
  709.             button.Hide()
  710.         self.showingButtonList = []
  711.  
  712.     def __ShowButton(self, name):
  713.  
  714.         if not self.buttonDict.has_key(name):
  715.             return
  716.  
  717.         self.buttonDict[name].Show()
  718.         self.showingButtonList.append(self.buttonDict[name])
  719.  
  720.     def __HideButton(self, name):
  721.  
  722.         if not self.buttonDict.has_key(name):
  723.             return
  724.  
  725.         button = self.buttonDict[name]
  726.         button.Hide()
  727.  
  728.         for btnInList in self.showingButtonList:
  729.             if btnInList == button:
  730.                 self.showingButtonList.remove(button)
  731.                 break
  732.  
  733.     def OnWhisper(self):
  734.         if None != self.eventWhisper:
  735.             self.eventWhisper(self.nameString)
  736.  
  737.     def OnExchange(self):
  738.         net.SendExchangeStartPacket(self.vid)
  739.  
  740.     def OnPVP(self):
  741.         net.SendChatPacket("/pvp %d" % (self.vid))
  742.  
  743.     def OnAppendToMessenger(self):
  744.         net.SendMessengerAddByVIDPacket(self.vid)
  745.  
  746.     def OnPartyInvite(self):
  747.         net.SendPartyInvitePacket(self.vid)
  748.  
  749.     def OnPartyExit(self):
  750.         net.SendPartyExitPacket()
  751.  
  752.     def OnPartyRemove(self):
  753.         net.SendPartyRemovePacketVID(self.vid)
  754.  
  755.     def __OnGuildAddMember(self):
  756.         net.SendGuildAddMemberPacket(self.vid)
  757.  
  758.     def __OnDismount(self):
  759.         net.SendChatPacket("/unmount")
  760.  
  761.     def __OnExitObserver(self):
  762.         net.SendChatPacket("/observer_exit")
  763.  
  764.     def __OnViewEquipment(self):
  765.         net.SendChatPacket("/view_equip " + str(self.vid))
  766.  
  767.     def __OnRequestParty(self):
  768.         net.SendChatPacket("/party_request " + str(self.vid))
  769.  
  770.     def __OnDestroyBuilding(self):
  771.         net.SendChatPacket("/build d %d" % (self.vid))
  772.  
  773.     def __OnEmotionAllow(self):
  774.         net.SendChatPacket("/emotion_allow %d" % (self.vid))
  775.  
  776.     def __OnVoteBlockChat(self):
  777.         cmd = "/vote_block_chat %s" % (self.nameString)
  778.         net.SendChatPacket(cmd)
  779.  
  780.     def OnPressEscapeKey(self):
  781.         self.OnPressedCloseButton()
  782.         return True
  783.  
  784.     def IsShowButton(self):
  785.         return self.isShowButton
  786.  
  787.     def RefreshButton(self):
  788.  
  789.         self.HideAllButton()
  790.  
  791.         if chr.INSTANCE_TYPE_BUILDING == chr.GetInstanceType(self.vid):
  792.             #self.__ShowButton(localeInfo.TARGET_BUTTON_BUILDING_DESTROY)
  793.             #self.__ArrangeButtonPosition()
  794.             return
  795.  
  796.         if player.IsPVPInstance(self.vid) or player.IsObserverMode():
  797.             # PVP_INFO_SIZE_BUG_FIX
  798.             self.SetSize(200 + 7*self.nameLength, 40)
  799.             self.UpdatePosition()
  800.             # END_OF_PVP_INFO_SIZE_BUG_FIX
  801.             return
  802.  
  803.         self.ShowDefaultButton()
  804.  
  805.         if guild.MainPlayerHasAuthority(guild.AUTH_ADD_MEMBER):
  806.             if not guild.IsMemberByName(self.nameString):
  807.                 if 0 == chr.GetGuildID(self.vid):
  808.                     self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_GUILD)
  809.  
  810.         if not messenger.IsFriendByName(self.nameString):
  811.             self.__ShowButton(localeInfo.TARGET_BUTTON_FRIEND)
  812.  
  813.         if player.IsPartyMember(self.vid):
  814.  
  815.             self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  816.  
  817.             if player.IsPartyLeader(self.vid):
  818.                 self.__ShowButton(localeInfo.TARGET_BUTTON_LEAVE_PARTY)
  819.             elif player.IsPartyLeader(player.GetMainCharacterIndex()):
  820.                 self.__ShowButton(localeInfo.TARGET_BUTTON_EXCLUDE)
  821.  
  822.         else:
  823.             if player.IsPartyMember(player.GetMainCharacterIndex()):
  824.                 if player.IsPartyLeader(player.GetMainCharacterIndex()):
  825.                     self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  826.             else:
  827.                 if chr.IsPartyMember(self.vid):
  828.                     self.__ShowButton(localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY)
  829.                 else:
  830.                     self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  831.  
  832.             if player.IsRevengeInstance(self.vid):
  833.                 self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  834.                 self.__ShowButton(localeInfo.TARGET_BUTTON_AVENGE)
  835.             elif player.IsChallengeInstance(self.vid):
  836.                 self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  837.                 self.__ShowButton(localeInfo.TARGET_BUTTON_ACCEPT_FIGHT)
  838.             elif player.IsCantFightInstance(self.vid):
  839.                 self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  840.  
  841.             if not player.IsSameEmpire(self.vid):
  842.                 self.__HideButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  843.                 self.__HideButton(localeInfo.TARGET_BUTTON_FRIEND)
  844.                 self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  845.  
  846.         distance = player.GetCharacterDistance(self.vid)
  847.         if distance > self.EXCHANGE_LIMIT_RANGE:
  848.             self.__HideButton(localeInfo.TARGET_BUTTON_EXCHANGE)
  849.             self.__ArrangeButtonPosition()
  850.  
  851.         self.__ArrangeButtonPosition()
  852.  
  853.     def __ArrangeButtonPosition(self):
  854.         showingButtonCount = len(self.showingButtonList)
  855.  
  856.         pos = -(showingButtonCount / 2) * 68
  857.         if 0 == showingButtonCount % 2:
  858.             pos += 34
  859.  
  860.         for button in self.showingButtonList:
  861.             button.SetPosition(pos, 33)
  862.             pos += 68
  863.  
  864.         self.SetSize(max(150, showingButtonCount * 75), 65)
  865.         self.UpdatePosition()
  866.  
  867.     def OnUpdate(self):
  868.         if self.isShowButton:
  869.  
  870.             exchangeButton = self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE]
  871.             distance = player.GetCharacterDistance(self.vid)
  872.  
  873.             if distance < 0:
  874.                 return
  875.  
  876.             if exchangeButton.IsShow():
  877.                 if distance > self.EXCHANGE_LIMIT_RANGE:
  878.                     self.RefreshButton()
  879.  
  880.             else:
  881.                 if distance < self.EXCHANGE_LIMIT_RANGE:
  882.                     self.RefreshButton()
  883.  
Advertisement
Add Comment
Please, Sign In to add comment