StoneTrap.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Threading;
  6. using Server.MirDatabase;
  7. using Server.MirEnvir;
  8. using S = ServerPackets;
  9. namespace Server.MirObjects.Monsters
  10. {
  11. public class StoneTrap : MonsterObject
  12. {
  13. public bool Summoned;
  14. public long DieTime;
  15. protected internal StoneTrap(MonsterInfo info) : base(info)
  16. {
  17. Direction = MirDirection.Up;
  18. }
  19. public override string Name
  20. {
  21. get { return Master == null ? Info.GameName : (Dead ? Info.GameName : string.Format("{0}({1})", Info.GameName, Master.Name)); }
  22. set { throw new NotSupportedException(); }
  23. }
  24. protected override void ProcessRegen() { }
  25. protected override void Attack() { }
  26. protected override void ProcessAI()
  27. {
  28. for (int d = 0; d <= Info.ViewRange; d++)
  29. {
  30. for (int y = CurrentLocation.Y - d; y <= CurrentLocation.Y + d; y++)
  31. {
  32. if (y < 0) continue;
  33. if (y >= CurrentMap.Height) break;
  34. for (int x = CurrentLocation.X - d; x <= CurrentLocation.X + d; x += Math.Abs(y - CurrentLocation.Y) == d ? 1 : d * 2)
  35. {
  36. if (x < 0) continue;
  37. if (x >= CurrentMap.Width) break;
  38. Cell cell = CurrentMap.GetCell(x, y);
  39. if (!cell.Valid || cell.Objects == null) continue;
  40. for (int i = 0; i < cell.Objects.Count; i++)
  41. {
  42. MapObject ob = cell.Objects[i];
  43. if (ob == this)
  44. {
  45. continue;
  46. }
  47. switch (ob.Race)
  48. {
  49. case ObjectType.Monster:
  50. case ObjectType.Hero:
  51. MonsterInfo mInfo = Envir.GetMonsterInfo(ob.Name);
  52. if (mInfo == null)
  53. {
  54. continue;
  55. }
  56. MonsterObject monster = MonsterObject.GetMonster(mInfo);
  57. if (!monster.Dead)
  58. {
  59. if (monster.Master == null ||
  60. (monster.Master != null &&
  61. monster.IsAttackTarget(this.Master)))
  62. {
  63. if (Target != null &&
  64. Target is StoneTrap &&
  65. Target != this)
  66. {
  67. continue;
  68. }
  69. monster.Target = this;
  70. }
  71. }
  72. break;
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79. public override void Turn(MirDirection dir)
  80. {
  81. }
  82. public override bool Walk(MirDirection dir)
  83. {
  84. return false;
  85. }
  86. public override void Spawned()
  87. {
  88. base.Spawned();
  89. Summoned = true;
  90. }
  91. public override void Process()
  92. {
  93. if (!Dead &&
  94. Master != null)
  95. {
  96. if (Master.CurrentMap != CurrentMap ||
  97. Envir.Time > DieTime ||
  98. !Functions.InRange(Master.CurrentLocation, CurrentLocation, 15))
  99. {
  100. Die();
  101. }
  102. else
  103. {
  104. FindTarget();
  105. }
  106. }
  107. base.Process();
  108. }
  109. public override int Struck(int damage, DefenceType type = DefenceType.ACAgility)
  110. {
  111. return 0;
  112. }
  113. public override Packet GetInfo()
  114. {
  115. var packet = (S.ObjectMonster)base.GetInfo();
  116. packet.Image = Monster.StoningSpider;
  117. packet.Extra = Summoned;
  118. return packet;
  119. }
  120. }
  121. }