AncientBringer.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 AncientBringer : MonsterObject
  8. {
  9. protected virtual byte AttackRange
  10. {
  11. get
  12. {
  13. return 12;
  14. }
  15. }
  16. protected internal AncientBringer(MonsterInfo info)
  17. : base(info)
  18. {
  19. }
  20. protected override bool InAttackRange()
  21. {
  22. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  23. }
  24. protected override void Attack()
  25. {
  26. if (!Target.IsAttackTarget(this))
  27. {
  28. Target = null;
  29. return;
  30. }
  31. ActionTime = Envir.Time + 300;
  32. AttackTime = Envir.Time + AttackSpeed;
  33. ShockTime = 0;
  34. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  35. bool ranged = CurrentLocation == Target.CurrentLocation || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 2);
  36. if (!ranged)
  37. {
  38. if (Envir.Random.Next(5) > 0)
  39. {
  40. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  41. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  42. PoisonLineAttack(2, damage, DefenceType.ACAgility);
  43. }
  44. else
  45. {
  46. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  47. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC] * 2);
  48. PoisonLineAttack(2, damage, DefenceType.ACAgility, true);
  49. }
  50. }
  51. else
  52. {
  53. if (Envir.Random.Next(10) > 0)
  54. {
  55. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  56. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  57. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  58. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.ACAgility, (byte)4);
  59. ActionList.Add(action);
  60. }
  61. else
  62. {
  63. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 1 });
  64. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC] * 2);
  65. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.ACAgility, (byte)5);
  66. ActionList.Add(action);
  67. if (damage > 0)
  68. {
  69. SpawnSlaves();
  70. }
  71. }
  72. }
  73. }
  74. protected override void CompleteRangeAttack(IList<object> data)
  75. {
  76. MapObject target = (MapObject)data[0];
  77. int damage = (int)data[1];
  78. DefenceType defence = (DefenceType)data[2];
  79. byte range = (byte)data[3];
  80. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  81. var targets = FindAllTargets(range, target.CurrentLocation);
  82. for (int i = 0; i < targets.Count; i++)
  83. {
  84. targets[i].Attacked(this, damage, defence);
  85. }
  86. }
  87. protected override void CompleteAttack(IList<object> data)
  88. {
  89. MapObject target = (MapObject)data[0];
  90. int damage = (int)data[1];
  91. DefenceType defence = (DefenceType)data[2];
  92. bool poison = (bool)data[3];
  93. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  94. var finalDamage = target.Attacked(this, damage, defence);
  95. if (finalDamage > 0 && poison)
  96. {
  97. PoisonTarget(target, 5, 5, PoisonType.Paralysis, 2000);
  98. }
  99. }
  100. protected void PoisonLineAttack(int distance, int additionalDelay = 500, DefenceType defenceType = DefenceType.ACAgility, bool poison = false)
  101. {
  102. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  103. if (damage == 0) return;
  104. for (int i = 1; i <= distance; i++)
  105. {
  106. Point target = Functions.PointMove(CurrentLocation, Direction, i);
  107. if (!CurrentMap.ValidPoint(target)) continue;
  108. Cell cell = CurrentMap.GetCell(target);
  109. if (cell.Objects == null) continue;
  110. for (int o = 0; o < cell.Objects.Count; o++)
  111. {
  112. MapObject ob = cell.Objects[o];
  113. if (ob.Race == ObjectType.Monster || ob.Race == ObjectType.Player)
  114. {
  115. if (!ob.IsAttackTarget(this)) continue;
  116. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, ob, damage, defenceType, poison);
  117. ActionList.Add(action);
  118. }
  119. }
  120. }
  121. }
  122. private void SpawnSlaves()
  123. {
  124. int count = Math.Min(6, 40 - SlaveList.Count);
  125. ActionTime = Envir.Time + 300;
  126. AttackTime = Envir.Time + AttackSpeed;
  127. for (int i = 0; i < count; i++)
  128. {
  129. MonsterObject mob = GetMonster(Envir.GetMonsterInfo(Settings.AncientBatName));
  130. if (mob == null) continue;
  131. if (!mob.Spawn(CurrentMap, Target.CurrentLocation))
  132. mob.Spawn(CurrentMap, Target.CurrentLocation);
  133. mob.Target = Target;
  134. mob.ActionTime = Envir.Time + 2000;
  135. SlaveList.Add(mob);
  136. }
  137. }
  138. protected override void ProcessTarget()
  139. {
  140. if (Target == null) return;
  141. if (InAttackRange() && CanAttack)
  142. {
  143. Attack();
  144. return;
  145. }
  146. if (Envir.Time < ShockTime)
  147. {
  148. Target = null;
  149. return;
  150. }
  151. MoveTo(Target.CurrentLocation);
  152. }
  153. }
  154. }