Guest User

Untitled

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