Advertisement
Ulthar

uitarget

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