DarkWraith.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. using S = ServerPackets;
  5. namespace Server.MirObjects.Monsters
  6. {
  7. public class DarkWraith : MonsterObject
  8. {
  9. private const byte AttackRange = 4;
  10. public long LineAttackTime;
  11. protected internal DarkWraith(MonsterInfo info)
  12. : base(info)
  13. {
  14. }
  15. protected override bool InAttackRange()
  16. {
  17. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  18. }
  19. protected bool InRangeAttackRange()
  20. {
  21. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  22. }
  23. protected override void ProcessTarget()
  24. {
  25. if (Target == null || Dead) return;
  26. if (!InAttackRange())
  27. {
  28. if (CanAttack)
  29. {
  30. if (Envir.Random.Next(3) == 0)
  31. LineAttack(4);
  32. }
  33. if (CurrentLocation == Target.CurrentLocation)
  34. {
  35. MirDirection direction = (MirDirection)Envir.Random.Next(8);
  36. int rotation = Envir.Random.Next(2) == 0 ? 1 : -1;
  37. for (int d = 0; d < 8; d++)
  38. {
  39. if (Walk(direction)) break;
  40. direction = Functions.ShiftDirection(direction, rotation);
  41. }
  42. }
  43. else
  44. MoveTo(Target.CurrentLocation);
  45. }
  46. if (!CanAttack) return;
  47. if (Envir.Random.Next(3) > 0)
  48. {
  49. if (InAttackRange())
  50. Attack();
  51. }
  52. else LineAttack(4);
  53. if (Envir.Time < ShockTime)
  54. {
  55. Target = null;
  56. return;
  57. }
  58. }
  59. protected override void Attack()
  60. {
  61. if (!Target.IsAttackTarget(this))
  62. {
  63. Target = null;
  64. return;
  65. }
  66. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  67. if (damage == 0) return;
  68. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  69. List<MapObject> targets = FindAllTargets(1, CurrentLocation);
  70. if (targets.Count > 1 && Envir.Random.Next(2) > 0)
  71. {
  72. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  73. for (int i = 0; i < targets.Count; i++)
  74. {
  75. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 600, targets[i], damage, DefenceType.AC);
  76. ActionList.Add(action);
  77. }
  78. }
  79. else
  80. {
  81. base.Attack();
  82. }
  83. ActionTime = Envir.Time + 500;
  84. AttackTime = Envir.Time + AttackSpeed;
  85. ShockTime = 0;
  86. }
  87. private void LineAttack(int distance)
  88. {
  89. if (!Target.IsAttackTarget(this))
  90. {
  91. Target = null;
  92. return;
  93. }
  94. if (LineAttackTime > Envir.Time) return;
  95. ShockTime = 0;
  96. ActionTime = Envir.Time + 500;
  97. AttackTime = Envir.Time + AttackSpeed + 500;
  98. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]) * 3;
  99. if (damage == 0) return;
  100. LineAttackTime = Envir.Time + 3000 + Envir.Random.Next(5) * 1000;
  101. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  102. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 2 });
  103. for (int i = 1; i <= distance; i++)
  104. {
  105. Point target = Functions.PointMove(CurrentLocation, Direction, i);
  106. if (target == Target.CurrentLocation)
  107. {
  108. Target.Attacked(this, damage, DefenceType.ACAgility);
  109. }
  110. else
  111. {
  112. if (!CurrentMap.ValidPoint(target)) continue;
  113. Cell cell = CurrentMap.GetCell(target);
  114. if (cell.Objects == null) continue;
  115. for (int o = 0; o < cell.Objects.Count; o++)
  116. {
  117. MapObject ob = cell.Objects[o];
  118. if (ob.Race == ObjectType.Monster || ob.Race == ObjectType.Player)
  119. {
  120. if (!ob.IsAttackTarget(this)) continue;
  121. ob.Attacked(this, damage, DefenceType.AC);
  122. }
  123. else continue;
  124. break;
  125. }
  126. }
  127. }
  128. }
  129. }
  130. }