FloatingRock.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. using S = ServerPackets;
  5. using Shared.Extensions;
  6. namespace Server.MirObjects.Monsters
  7. {
  8. public class FloatingRock : MonsterObject
  9. {
  10. protected override bool CanMove { get { return false; } }
  11. protected internal FloatingRock(MonsterInfo info)
  12. : base(info)
  13. {
  14. }
  15. public override bool Walk(MirDirection dir) { return false; }
  16. protected override void ProcessRoam() { }
  17. protected override bool InAttackRange()
  18. {
  19. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, Info.ViewRange);
  20. }
  21. protected override void ProcessTarget()
  22. {
  23. if (!CanAttack) return;
  24. ActionTime = Envir.Time + 300;
  25. AttackTime = Envir.Time + AttackSpeed;
  26. var targets = FindAllNearby(Info.ViewRange, CurrentLocation, true);
  27. targets.Shuffle();
  28. if (targets.Count == 0) return;
  29. for (int i = 0; i < targets.Count; i++)
  30. {
  31. if (targets[i].Race != ObjectType.Monster) continue;
  32. var target = (MonsterObject)targets[i];
  33. if (target.Info.AI == Info.AI) continue;
  34. var mob = GetMonster(Envir.GetMonsterInfo(target.Info.Name));
  35. mob.PetLevel = target.PetLevel;
  36. mob.ActionTime = Envir.Time + 1000;
  37. if (Envir.Random.Next(3) == 0)
  38. {
  39. var attempts = 4;
  40. var distance = 5;
  41. for (int j = 0; j < attempts; j++)
  42. {
  43. var location = new Point(CurrentLocation.X + Envir.Random.Next(-distance, distance + 1),
  44. CurrentLocation.Y + Envir.Random.Next(-distance, distance + 1));
  45. if (location == CurrentLocation) continue;
  46. if (mob.Spawn(CurrentMap, location))
  47. {
  48. Direction = Functions.DirectionFromPoint(CurrentLocation, target.CurrentLocation);
  49. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = mob.ObjectID });
  50. SlaveList.Add(mob);
  51. break;
  52. }
  53. }
  54. }
  55. break;
  56. }
  57. }
  58. public override void Die()
  59. {
  60. //Kill Minions
  61. for (int i = SlaveList.Count - 1; i >= 0; i--)
  62. {
  63. if (!SlaveList[i].Dead && SlaveList[i].Node != null)
  64. {
  65. SlaveList[i].Die();
  66. }
  67. }
  68. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  69. List<MapObject> targets = FindAllTargets(3, CurrentLocation, false);
  70. for (int i = 0; i < targets.Count; i++)
  71. {
  72. DelayedAction action = new DelayedAction(DelayedType.Die, Envir.Time + 300, targets[i], damage, DefenceType.AC);
  73. ActionList.Add(action);
  74. }
  75. base.Die();
  76. }
  77. protected override void CompleteDeath(IList<object> data)
  78. {
  79. MapObject target = (MapObject)data[0];
  80. int damage = (int)data[1];
  81. DefenceType defence = (DefenceType)data[2];
  82. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  83. target.Attacked(this, damage, defence);
  84. }
  85. }
  86. }