HeroObject.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Client.MirControls;
  2. using Client.MirScenes.Dialogs;
  3. using S = ServerPackets;
  4. namespace Client.MirObjects
  5. {
  6. public class HeroObject : PlayerObject
  7. {
  8. public override ObjectType Race
  9. {
  10. get { return ObjectType.Hero; }
  11. }
  12. public string OwnerName;
  13. public MirLabel OwnerLabel;
  14. public override bool ShouldDrawHealth()
  15. {
  16. if (GroupDialog.GroupList.Contains(OwnerName) || OwnerName == User.Name)
  17. {
  18. return true;
  19. }
  20. else
  21. {
  22. return false;
  23. }
  24. }
  25. public HeroObject(uint objectID) : base(objectID)
  26. {
  27. }
  28. public void Load(S.ObjectHero info)
  29. {
  30. Load((S.ObjectPlayer)info);
  31. OwnerName = info.OwnerName;
  32. if (info.ObjectID == Hero?.ObjectID)
  33. Hero.CurrentLocation = info.Location;
  34. }
  35. public override void CreateLabel()
  36. {
  37. base.CreateLabel();
  38. OwnerLabel = null;
  39. string ownerText = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.OwnerHero), OwnerName);
  40. for (int i = 0; i < LabelList.Count; i++)
  41. {
  42. if (LabelList[i].Text != ownerText || LabelList[i].ForeColour != NameColour) continue;
  43. OwnerLabel = LabelList[i];
  44. break;
  45. }
  46. if (OwnerLabel != null && !OwnerLabel.IsDisposed) return;
  47. OwnerLabel = new MirLabel
  48. {
  49. AutoSize = true,
  50. BackColour = Color.Transparent,
  51. ForeColour = NameColour,
  52. OutLine = true,
  53. OutLineColour = Color.Black,
  54. Text = ownerText,
  55. };
  56. OwnerLabel.Disposing += (o, e) => LabelList.Remove(OwnerLabel);
  57. LabelList.Add(OwnerLabel);
  58. }
  59. public override void DrawName()
  60. {
  61. CreateLabel();
  62. if (NameLabel == null || OwnerLabel == null) return;
  63. NameLabel.Location = new Point(DisplayRectangle.X + (50 - NameLabel.Size.Width) / 2, DisplayRectangle.Y - (42 - NameLabel.Size.Height / 2) + (Dead ? 35 : 8));
  64. NameLabel.Draw();
  65. OwnerLabel.Location = new Point(DisplayRectangle.X + (50 - OwnerLabel.Size.Width) / 2, NameLabel.Location.Y + NameLabel.Size.Height - 1);
  66. OwnerLabel.Draw();
  67. }
  68. }
  69. }