ItemObject.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using Client.MirGraphics;
  2. using Client.MirScenes;
  3. using S = ServerPackets;
  4. using System.Text.RegularExpressions;
  5. namespace Client.MirObjects
  6. {
  7. public class ItemObject : MapObject
  8. {
  9. public override ObjectType Race{
  10. get { return ObjectType.Item; }
  11. }
  12. public override bool Blocking
  13. {
  14. get { return false; }
  15. }
  16. public Size Size;
  17. public ItemObject(uint objectID) : base(objectID)
  18. {
  19. }
  20. public void Load(S.ObjectItem info)
  21. {
  22. Name = info.Name;
  23. NameColour = info.NameColour;
  24. BodyLibrary = Libraries.FloorItems;
  25. CurrentLocation = info.Location;
  26. MapLocation = info.Location;
  27. GameScene.Scene.MapControl.AddObject(this);
  28. DrawFrame = info.Image;
  29. Size = BodyLibrary.GetTrueSize(DrawFrame);
  30. DrawY = CurrentLocation.Y;
  31. }
  32. public void Load(S.ObjectGold info)
  33. {
  34. Name = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.GoldAmount), info.Gold);
  35. BodyLibrary = Libraries.FloorItems;
  36. CurrentLocation = info.Location;
  37. MapLocation = info.Location;
  38. GameScene.Scene.MapControl.AddObject(this);
  39. if (info.Gold < 100)
  40. DrawFrame = 112;
  41. else if (info.Gold < 200)
  42. DrawFrame = 113;
  43. else if (info.Gold < 500)
  44. DrawFrame = 114;
  45. else if (info.Gold < 1000)
  46. DrawFrame = 115;
  47. else
  48. DrawFrame = 116;
  49. Size = BodyLibrary.GetTrueSize(DrawFrame);
  50. DrawY = CurrentLocation.Y;
  51. }
  52. public override void Draw()
  53. {
  54. if (BodyLibrary != null)
  55. BodyLibrary.Draw(DrawFrame, DrawLocation, DrawColour);
  56. }
  57. public override void Process()
  58. {
  59. DrawLocation = new Point((CurrentLocation.X - User.Movement.X + MapControl.OffSetX) * MapControl.CellWidth, (CurrentLocation.Y - User.Movement.Y + MapControl.OffSetY) * MapControl.CellHeight);
  60. DrawLocation.Offset((MapControl.CellWidth - Size.Width) / 2, (MapControl.CellHeight - Size.Height) / 2);
  61. DrawLocation.Offset(User.OffSetMove);
  62. DrawLocation.Offset(GlobalDisplayLocationOffset);
  63. FinalDrawLocation = DrawLocation;
  64. DisplayRectangle = new Rectangle(DrawLocation, Size);
  65. }
  66. public override bool MouseOver(Point p)
  67. {
  68. return MapControl.MapLocation == CurrentLocation;
  69. // return DisplayRectangle.Contains(p);
  70. }
  71. public override void DrawName()
  72. {
  73. CreateLabel(Color.Transparent, false, true);
  74. if (NameLabel == null) return;
  75. NameLabel.Location = new Point(
  76. DisplayRectangle.X + (DisplayRectangle.Width - NameLabel.Size.Width) / 2,
  77. DisplayRectangle.Y + (DisplayRectangle.Height - NameLabel.Size.Height) / 2 - 20);
  78. NameLabel.Draw();
  79. }
  80. public override void DrawBehindEffects(bool effectsEnabled)
  81. {
  82. }
  83. public override void DrawEffects(bool effectsEnabled)
  84. {
  85. }
  86. public void DrawName(int y)
  87. {
  88. CreateLabel(Color.FromArgb(100, 0, 24, 48), true, false);
  89. NameLabel.Location = new Point(
  90. DisplayRectangle.X + (DisplayRectangle.Width - NameLabel.Size.Width) / 2,
  91. DisplayRectangle.Y + y + (DisplayRectangle.Height - NameLabel.Size.Height) / 2 - 20);
  92. NameLabel.Draw();
  93. }
  94. private void CreateLabel(Color backColour, bool border, bool outline)
  95. {
  96. NameLabel = null;
  97. for (int i = 0; i < LabelList.Count; i++)
  98. {
  99. if (LabelList[i].Text != Name || LabelList[i].Border != border || LabelList[i].BackColour != backColour || LabelList[i].ForeColour != NameColour || LabelList[i].OutLine != outline) continue;
  100. NameLabel = LabelList[i];
  101. break;
  102. }
  103. if (NameLabel != null && !NameLabel.IsDisposed) return;
  104. NameLabel = new MirControls.MirLabel
  105. {
  106. AutoSize = true,
  107. BorderColour = Color.Black,
  108. BackColour = backColour,
  109. ForeColour = NameColour,
  110. OutLine = outline,
  111. Border = border,
  112. Text = Name,//Regex.Replace(Name, @"\d+$", string.Empty),//In fact, the item names passed from the server no longer have numeric suffixes, as they are redundant and affect performance.
  113. };
  114. LabelList.Add(NameLabel);
  115. }
  116. }
  117. }