CannibalTentacles.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 CannibalTentacles : MonsterObject
  8. {
  9. protected internal CannibalTentacles(MonsterInfo info)
  10. : base(info)
  11. {
  12. }
  13. protected override bool InAttackRange()
  14. {
  15. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, Info.ViewRange);
  16. }
  17. protected override void Attack()
  18. {
  19. if (!Target.IsAttackTarget(this))
  20. {
  21. Target = null;
  22. return;
  23. }
  24. ShockTime = 0;
  25. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  26. bool ranged = CurrentLocation == Target.CurrentLocation || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  27. ActionTime = Envir.Time + 300;
  28. AttackTime = Envir.Time + AttackSpeed;
  29. if (!ranged)
  30. {
  31. if (Envir.Random.Next(5) > 0)
  32. {
  33. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  34. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  35. if (damage == 0) return;
  36. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, Target, damage, DefenceType.AC, false);
  37. ActionList.Add(action);
  38. }
  39. else
  40. {
  41. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  42. HalfmoonAttack(500);
  43. }
  44. }
  45. else
  46. {
  47. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 0 });
  48. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  49. if (damage == 0) return;
  50. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  51. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MACAgility);
  52. ActionList.Add(action);
  53. }
  54. }
  55. protected override void HalfmoonAttack(int damage, int delay = 500, DefenceType defenceType = DefenceType.ACAgility)
  56. {
  57. MirDirection dir = Functions.PreviousDir(Direction);
  58. for (int i = 0; i < 4; i++)
  59. {
  60. Point target = Functions.PointMove(CurrentLocation, dir, 1);
  61. dir = Functions.NextDir(dir);
  62. if (!CurrentMap.ValidPoint(target)) continue;
  63. Cell cell = CurrentMap.GetCell(target);
  64. if (cell.Objects == null) continue;
  65. for (int o = 0; o < cell.Objects.Count; o++)
  66. {
  67. MapObject ob = cell.Objects[o];
  68. if (ob.Race != ObjectType.Player && ob.Race != ObjectType.Monster) continue;
  69. if (!ob.IsAttackTarget(this)) continue;
  70. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + delay, ob, damage, defenceType, true);
  71. ActionList.Add(action);
  72. break;
  73. }
  74. }
  75. }
  76. protected override void CompleteAttack(IList<object> data)
  77. {
  78. MapObject target = (MapObject)data[0];
  79. int damage = (int)data[1];
  80. DefenceType defence = (DefenceType)data[2];
  81. bool poison = (bool)data[3];
  82. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  83. if (poison && target.Attacked(this, damage, defence) > 0)
  84. {
  85. PoisonTarget(target, 1, 5, PoisonType.Green, 1000);
  86. }
  87. }
  88. protected override void ProcessTarget()
  89. {
  90. if (Target == null) return;
  91. if (InAttackRange() && CanAttack)
  92. {
  93. Attack();
  94. return;
  95. }
  96. if (Envir.Time < ShockTime)
  97. {
  98. Target = null;
  99. return;
  100. }
  101. MoveTo(Target.CurrentLocation);
  102. }
  103. }
  104. }