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 uiChatBlock
  13. import uiBlock
  14. import uiHealth
  15. import constInfo
  16. import event
  17. import gameInfo
  18. import chat
  19. import uiCommon
  20. import localegame
  21. class TargetBoard(ui.ThinBoard):
  22. BUTTON_NAME_LIST = (
  23. localeInfo.TARGET_BUTTON_WHISPER,
  24. localeInfo.TARGET_BUTTON_EXCHANGE,
  25. localeInfo.TARGET_BUTTON_FIGHT,
  26. localeInfo.TARGET_BUTTON_ACCEPT_FIGHT,
  27. localeInfo.TARGET_BUTTON_AVENGE,
  28. localeInfo.TARGET_BUTTON_FRIEND,
  29. localeInfo.TARGET_BUTTON_INVITE_PARTY,
  30. localeInfo.TARGET_BUTTON_LEAVE_PARTY,
  31. localeInfo.TARGET_BUTTON_EXCLUDE,
  32. localeInfo.TARGET_BUTTON_INVITE_GUILD,
  33. localeInfo.TARGET_BUTTON_DISMOUNT,
  34. localeInfo.TARGET_BUTTON_EXIT_OBSERVER,
  35. localeInfo.TARGET_BUTTON_VIEW_EQUIPMENT,
  36. localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY,
  37. localeInfo.TARGET_BUTTON_BUILDING_DESTROY,
  38. localeInfo.TARGET_BUTTON_EMOTION_ALLOW,
  39. "DC At",
  40. "Chat Ban",
  41. "Sersemlet",
  42. "Öldür",
  43. "Yavaşlat",
  44. "Profil",
  45. )
  46. GRADE_NAME = {
  47. nonplayer.PAWN : localeInfo.TARGET_LEVEL_PAWN,
  48. nonplayer.S_PAWN : localeInfo.TARGET_LEVEL_S_PAWN,
  49. nonplayer.KNIGHT : localeInfo.TARGET_LEVEL_KNIGHT,
  50. nonplayer.S_KNIGHT : localeInfo.TARGET_LEVEL_S_KNIGHT,
  51. nonplayer.BOSS : localeInfo.TARGET_LEVEL_BOSS,
  52. nonplayer.KING : localeInfo.TARGET_LEVEL_KING,
  53. }
  54. EXCHANGE_LIMIT_RANGE = 3000
  55. def __init__(self):
  56. ui.ThinBoard.__init__(self)
  57. self.healthBoard = uiHealth.HealthBoard()
  58. name = ui.TextLine()
  59. name.SetParent(self)
  60. name.SetDefaultFontName()
  61. name.SetOutline()
  62. name.Show()
  63. self.zaman = 0
  64. hpGauge = ui.Gauge()
  65. hpGauge.SetParent(self)
  66. hpGauge.MakeGauge(130, "red")
  67. hpGauge.Hide()
  68. hpPercenttxt = ui.TextLine()
  69. hpPercenttxt.SetParent(self)
  70. hpPercenttxt.SetPosition(160, 13)
  71. hpPercenttxt.SetText("")
  72. hpPercenttxt.Hide()
  73. closeButton = ui.Button()
  74. closeButton.SetParent(self)
  75. closeButton.SetUpVisual("d:/ymir work/ui/public/close_button_01.sub")
  76. closeButton.SetOverVisual("d:/ymir work/ui/public/close_button_02.sub")
  77. closeButton.SetDownVisual("d:/ymir work/ui/public/close_button_03.sub")
  78. closeButton.SetPosition(30, 13)
  79. closeButton.SetWindowHorizontalAlignRight()
  80. closeButton.SetEvent(ui.__mem_func__(self.OnPressedCloseButton))
  81. closeButton.Show()
  82. self.buttonDict = {}
  83. self.showingButtonList = []
  84. for buttonName in self.BUTTON_NAME_LIST:
  85. button = ui.Button()
  86. button.SetParent(self)
  87. button.SetUpVisual("d:/ymir work/ui/public/small_thin_button_01.sub")
  88. button.SetOverVisual("d:/ymir work/ui/public/small_thin_button_02.sub")
  89. button.SetDownVisual("d:/ymir work/ui/public/small_thin_button_03.sub")
  90. button.SetWindowHorizontalAlignCenter()
  91. button.SetText(buttonName)
  92. button.Hide()
  93. self.buttonDict[buttonName] = button
  94. self.showingButtonList.append(button)
  95. self.buttonDict[localeInfo.TARGET_BUTTON_WHISPER].SetEvent(ui.__mem_func__(self.OnWhisper))
  96. self.buttonDict["DC At"].SetEvent(ui.__mem_func__(self.OnKick))
  97. self.buttonDict["Chat Ban"].SetEvent(ui.__mem_func__(self.OnChatBlock))
  98. self.buttonDict["Sersemlet"].SetEvent(ui.__mem_func__(self.OnStun))
  99. self.buttonDict["Öldür"].SetEvent(ui.__mem_func__(self.OnKill))
  100. self.buttonDict["Yavaşlat"].SetEvent(ui.__mem_func__(self.OnSlow))
  101. self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE].SetEvent(ui.__mem_func__(self.OnExchange))
  102. self.buttonDict[localeInfo.TARGET_BUTTON_FIGHT].SetEvent(ui.__mem_func__(self.OnPVP))
  103. self.buttonDict[localeInfo.TARGET_BUTTON_ACCEPT_FIGHT].SetEvent(ui.__mem_func__(self.OnPVP))
  104. self.buttonDict[localeInfo.TARGET_BUTTON_AVENGE].SetEvent(ui.__mem_func__(self.OnPVP))
  105. self.buttonDict[localeInfo.TARGET_BUTTON_FRIEND].SetEvent(ui.__mem_func__(self.OnAppendToMessenger))
  106. self.buttonDict[localeInfo.TARGET_BUTTON_FRIEND].SetEvent(ui.__mem_func__(self.OnAppendToMessenger))
  107. self.buttonDict[localeInfo.TARGET_BUTTON_INVITE_PARTY].SetEvent(ui.__mem_func__(self.OnPartyInvite))
  108. self.buttonDict[localeInfo.TARGET_BUTTON_LEAVE_PARTY].SetEvent(ui.__mem_func__(self.OnPartyExit))
  109. self.buttonDict[localeInfo.TARGET_BUTTON_EXCLUDE].SetEvent(ui.__mem_func__(self.OnPartyRemove))
  110. self.buttonDict["Profil"].SAFE_SetEvent(self.__OnProfilGoster)
  111. self.buttonDict[localeInfo.TARGET_BUTTON_INVITE_GUILD].SAFE_SetEvent(self.__OnGuildAddMember)
  112. self.buttonDict[localeInfo.TARGET_BUTTON_DISMOUNT].SAFE_SetEvent(self.__OnDismount)
  113. self.buttonDict[localeInfo.TARGET_BUTTON_EXIT_OBSERVER].SAFE_SetEvent(self.__OnExitObserver)
  114. self.buttonDict[localeInfo.TARGET_BUTTON_VIEW_EQUIPMENT].SAFE_SetEvent(self.__OnViewEquipment)
  115. self.buttonDict[localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY].SAFE_SetEvent(self.__OnRequestParty)
  116. self.buttonDict[localeInfo.TARGET_BUTTON_BUILDING_DESTROY].SAFE_SetEvent(self.__OnDestroyBuilding)
  117. self.buttonDict[localeInfo.TARGET_BUTTON_EMOTION_ALLOW].SAFE_SetEvent(self.__OnEmotionAllow)
  118. self.name = name
  119. self.hpGauge = hpGauge
  120. self.hpPercenttxt = hpPercenttxt
  121. dlgChatBlock = uiChatBlock.ChatBlockDialog()
  122. dlgChatBlock.LoadDialog()
  123. dlgChatBlock.SetTitleName("Chat Ban")
  124. dlgChatBlock.Hide()
  125. self.dlgChatBlock = dlgChatBlock
  126. self.closeButton = closeButton
  127. self.nameString = 0
  128. self.nameLength = 0
  129. self.vid = 0
  130. self.eventWhisper = None
  131. self.isShowButton = FALSE
  132. self.__Initialize()
  133. self.ResetTargetBoard()
  134. def __del__(self):
  135. ui.ThinBoard.__del__(self)
  136. print "===================================================== DESTROYED TARGET BOARD"
  137. def __Initialize(self):
  138. self.nameString = ""
  139. self.nameLength = 0
  140. self.vid = 0
  141. self.isShowButton = FALSE
  142. def Destroy(self):
  143. self.dlgChatBlock.Destroy()
  144. self.dlgChatBlock = 0
  145. self.eventWhisper = None
  146. self.closeButton = None
  147. self.showingButtonList = None
  148. self.buttonDict = None
  149. self.name = None
  150. self.hpGauge = None
  151. self.hpPercenttxt = None
  152. self.__Initialize()
  153. def OnPressedCloseButton(self):
  154. player.ClearTarget()
  155. self.Close()
  156. def Close(self):
  157. self.__Initialize()
  158. self.healthBoard.Hide()
  159. self.Hide()
  160. def Open(self, vid, name):
  161. if not constInfo.GET_VIEW_OTHER_EMPIRE_PLAYER_TARGET_BOARD():
  162. if not player.IsSameEmpire(vid):
  163. self.Hide()
  164. return
  165. if vid != self.GetTargetVID():
  166. self.ResetTargetBoard()
  167. self.SetTargetVID(vid)
  168. self.SetTargetName(name)
  169. if player.IsMainCharacterIndex(vid):
  170. self.__ShowMainCharacterMenu()
  171. elif chr.INSTANCE_TYPE_BUILDING == chr.GetInstanceType(self.vid):
  172. self.Hide()
  173. else:
  174. self.RefreshButton()
  175. self.Show()
  176. def Refresh(self):
  177. if self.IsShow():
  178. if self.IsShowButton():
  179. self.RefreshButton()
  180. def RefreshByVID(self, vid):
  181. if vid == self.GetTargetVID():
  182. self.Refresh()
  183. def RefreshByName(self, name):
  184. if name == self.GetTargetName():
  185. self.Refresh()
  186. def __ShowMainCharacterMenu(self):
  187. canShow=0
  188. self.HideAllButton()
  189. if player.IsMountingHorse():
  190. self.__ShowButton(localeInfo.TARGET_BUTTON_DISMOUNT)
  191. canShow=1
  192. if player.IsObserverMode():
  193. self.__ShowButton(localeInfo.TARGET_BUTTON_EXIT_OBSERVER)
  194. canShow=1
  195. if canShow:
  196. self.__ArrangeButtonPosition()
  197. self.Show()
  198. else:
  199. self.Hide()
  200. def SetWhisperEvent(self, event):
  201. self.eventWhisper = event
  202. def UpdatePosition(self):
  203. self.SetPosition(wndMgr.GetScreenWidth()/2 - self.GetWidth()/2, 10)
  204. def ResetTargetBoard(self):
  205. for btn in self.buttonDict.values():
  206. btn.Hide()
  207. self.__Initialize()
  208. self.name.SetPosition(0, 13)
  209. self.name.SetHorizontalAlignCenter()
  210. self.name.SetWindowHorizontalAlignCenter()
  211. self.hpGauge.Hide()
  212. self.hpPercenttxt.Hide()
  213. self.SetSize(250, 40)
  214. def SetTargetVID(self, vid):
  215. self.vid = vid
  216. def SetEnemyVID(self, vid):
  217. self.SetTargetVID(vid)
  218. name = chr.GetNameByVID(vid)
  219. level = nonplayer.GetLevelByVID(vid)
  220. grade = nonplayer.GetGradeByVID(vid)
  221. nameFront = ""
  222. if -1 != level:
  223. nameFront += "Lv." + str(level) + " "
  224. if self.GRADE_NAME.has_key(grade):
  225. nameFront += "(" + self.GRADE_NAME[grade] + ") "
  226. self.SetTargetName(nameFront + name)
  227. def GetTargetVID(self):
  228. return self.vid
  229. def GetTargetName(self):
  230. return self.nameString
  231. def SetTargetName(self, name):
  232. self.nameString = name
  233. self.nameLength = len(name)
  234. self.name.SetText(name)
  235. def SetHP(self, hpPercentage):
  236. if not self.hpGauge.IsShow():
  237. self.name.SetPosition(23, 13)
  238. self.name.SetWindowHorizontalAlignLeft()
  239. self.name.SetHorizontalAlignLeft()
  240. self.hpGauge.Show()
  241. self.SetSize(150 + 7*self.nameLength, self.GetHeight())
  242. self.UpdatePosition()
  243. self.hpPercenttxt.SetPosition(200 + 7*self.nameLength-205, 13)
  244. self.hpPercenttxt.Show()
  245. self.hpGauge.SetPercentage(hpPercentage, 100)
  246. self.hpPercenttxt.SetText("%d%%" % (hpPercentage))
  247. def ShowDefaultButton(self):
  248. self.isShowButton = TRUE
  249. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_WHISPER])
  250. if(self.zaman < app.GetTime()):
  251. self.showingButtonList.append(self.buttonDict["Profil"])
  252. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE])
  253. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_FIGHT])
  254. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_EMOTION_ALLOW])
  255. for button in self.showingButtonList:
  256. button.Show()
  257. def HideAllButton(self):
  258. self.isShowButton = FALSE
  259. for button in self.showingButtonList:
  260. button.Hide()
  261. self.showingButtonList = []
  262. def __ShowButton(self, name):
  263. if not self.buttonDict.has_key(name):
  264. return
  265. self.buttonDict[name].Show()
  266. self.showingButtonList.append(self.buttonDict[name])
  267. def __HideButton(self, name):
  268. if not self.buttonDict.has_key(name):
  269. return
  270. button = self.buttonDict[name]
  271. button.Hide()
  272. for btnInList in self.showingButtonList:
  273. if btnInList == button:
  274. self.showingButtonList.remove(button)
  275. break
  276. def OnWhisper(self):
  277. if None != self.eventWhisper:
  278. self.eventWhisper(self.nameString)
  279. def OnExchange(self):
  280. net.SendExchangeStartPacket(self.vid)
  281. def OnPVP(self):
  282. net.SendChatPacket("/pvp %d" % (self.vid))
  283. def Chat(self, text):
  284. chat.AppendChat(chat.CHAT_TYPE_INFO, str(text))
  285. def OnAppendToMessenger(self):
  286. net.SendMessengerAddByVIDPacket(self.vid)
  287. def __OnProfilGoster(self):
  288. if not (self.zaman < app.GetTime()):
  289. chat.AppendChat(chat.CHAT_TYPE_INFO, localegame.OYUN_ENVANTER_SURE)
  290. return
  291. self.zaman = app.GetTime() + 10
  292. net.SendWhisperPacket(chr.GetNameByVID(self.vid), '#byfatihbab34Envanter_Teklifi#Sorgu#')
  293. gameInfo.ENVANTER_TARGET_VID = self.vid
  294. def OnPartyInvite(self):
  295. net.SendPartyInvitePacket(self.vid)
  296. def OnPartyExit(self):
  297. net.SendPartyExitPacket()
  298. def OnPartyRemove(self):
  299. net.SendPartyRemovePacket(self.vid)
  300. def __OnGuildAddMember(self):
  301. net.SendGuildAddMemberPacket(self.vid)
  302. def __OnDismount(self):
  303. net.SendChatPacket("/unmount")
  304. def __OnExitObserver(self):
  305. net.SendChatPacket("/observer_exit")
  306. def __OnViewEquipment(self):
  307. net.SendChatPacket("/view_equip " + str(self.vid))
  308. def __OnRequestParty(self):
  309. net.SendChatPacket("/party_request " + str(self.vid))
  310. def __OnDestroyBuilding(self):
  311. net.SendChatPacket("/build d %d" % (self.vid))
  312. def __OnEmotionAllow(self):
  313. net.SendChatPacket("/emotion_allow %d" % (self.vid))
  314. def OnPressEscapeKey(self):
  315. self.OnPressedCloseButton()
  316. return TRUE
  317. def IsShowButton(self):
  318. return self.isShowButton
  319. def RefreshButton(self):
  320. self.HideAllButton()
  321. if chr.INSTANCE_TYPE_BUILDING == chr.GetInstanceType(self.vid):
  322. #self.__ShowButton(localeInfo.TARGET_BUTTON_BUILDING_DESTROY)
  323. #self.__ArrangeButtonPosition()
  324. return
  325. if player.IsPVPInstance(self.vid) or player.IsObserverMode():
  326. # PVP_INFO_SIZE_BUG_FIX
  327. self.SetSize(200 + 7*self.nameLength, 40)
  328. self.UpdatePosition()
  329. # END_OF_PVP_INFO_SIZE_BUG_FIX
  330. return
  331. self.ShowDefaultButton()
  332. if str(player.GetName())[0] == "[":
  333. self.__ShowButton("DC At")
  334. self.__ShowButton("Chat Ban")
  335. self.__ShowButton("Sersemlet")
  336. self.__ShowButton("Öldür")
  337. self.__ShowButton("Yavaşlat")
  338. if guild.MainPlayerHasAuthority(guild.AUTH_ADD_MEMBER):
  339. if not guild.IsMemberByName(self.nameString):
  340. if 0 == chr.GetGuildID(self.vid):
  341. self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_GUILD)
  342. if not messenger.IsFriendByName(self.nameString):
  343. self.__ShowButton(localeInfo.TARGET_BUTTON_FRIEND)
  344. if player.IsPartyMember(self.vid):
  345. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  346. if player.IsPartyLeader(self.vid):
  347. self.__ShowButton(localeInfo.TARGET_BUTTON_LEAVE_PARTY)
  348. elif player.IsPartyLeader(player.GetMainCharacterIndex()):
  349. self.__ShowButton(localeInfo.TARGET_BUTTON_EXCLUDE)
  350. else:
  351. if player.IsPartyMember(player.GetMainCharacterIndex()):
  352. if player.IsPartyLeader(player.GetMainCharacterIndex()):
  353. self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  354. else:
  355. if chr.IsPartyMember(self.vid):
  356. self.__ShowButton(localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY)
  357. else:
  358. self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  359. if player.IsRevengeInstance(self.vid):
  360. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  361. self.__ShowButton(localeInfo.TARGET_BUTTON_AVENGE)
  362. elif player.IsChallengeInstance(self.vid):
  363. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  364. self.__ShowButton(localeInfo.TARGET_BUTTON_ACCEPT_FIGHT)
  365. elif player.IsCantFightInstance(self.vid):
  366. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  367. if not player.IsSameEmpire(self.vid):
  368. self.__HideButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  369. self.__HideButton(localeInfo.TARGET_BUTTON_FRIEND)
  370. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  371. distance = player.GetCharacterDistance(self.vid)
  372. if distance > self.EXCHANGE_LIMIT_RANGE:
  373. self.__HideButton(localeInfo.TARGET_BUTTON_EXCHANGE)
  374. self.__ArrangeButtonPosition()
  375. self.__ArrangeButtonPosition()
  376. def __ArrangeButtonPosition(self):
  377. showingButtonCount = len(self.showingButtonList)
  378. pos = -(showingButtonCount / 2) * 68
  379. if 0 == showingButtonCount % 2:
  380. pos += 34
  381. for button in self.showingButtonList:
  382. button.SetPosition(pos, 33)
  383. pos += 68
  384. self.SetSize(max(150, showingButtonCount * 75), 65)
  385. self.UpdatePosition()
  386. def OnUpdate(self):
  387. if self.isShowButton:
  388. if(self.zaman < app.GetTime()):
  389. self.zaman = 0
  390. self.__ShowButton("Profil")
  391. self.RefreshButton()
  392. else:
  393. self.__HideButton("Profil")
  394. self.RefreshButton()
  395. exchangeButton = self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE]
  396. distance = player.GetCharacterDistance(self.vid)
  397. if distance < 0:
  398. return
  399. if exchangeButton.IsShow():
  400. if distance > self.EXCHANGE_LIMIT_RANGE:
  401. self.RefreshButton()
  402. else:
  403. if distance < self.EXCHANGE_LIMIT_RANGE:
  404. self.RefreshButton()
  405. def OnKick(self):
  406. net.SendChatPacket("/dc " + str(chr.GetNameByVID(self.vid)))
  407. def OnStun(self):
  408. net.SendChatPacket("/stun " + str(chr.GetNameByVID(self.vid)))
  409. def OnKill(self):
  410. net.SendChatPacket("/kill " + str(chr.GetNameByVID(self.vid)))
  411. def OnSlow(self):
  412. net.SendChatPacket("/slow " + str(chr.GetNameByVID(self.vid)))
  413. def OnChatBlock(self):
  414. #if os.path.exists('gm.txt') and os.path.isfile('gm.txt'):
  415. if str(player.GetName())[0] == "[":
  416. self.dlgChatBlock.SetTitleName("Chat Ban: " + str(chr.GetNameByVID(self.vid)))
  417. self.dlgChatBlock.Open(str(chr.GetNameByVID(self.vid)))
  418. def OnBlock(self):
  419. if str(player.GetName())[0] == "[":
  420. self.dlgBlock.SetTitleName("Block: " + str(chr.GetNameByVID(self.vid)))
  421. self.dlgBlock.Open(str(chr.GetNameByVID(self.vid)))