FlyingStatue.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. /// <summary>
  7. /// Attack1 - Green Poison attack
  8. /// Attack2 - Purple Poison attack
  9. /// AttackRange1 - Ice Tornado (big range)
  10. /// AttackRange2 - Blizzard (big range)
  11. /// </summary>
  12. public class FlyingStatue : MonsterObject
  13. {
  14. public long _BlizzardCooldown;
  15. protected internal FlyingStatue(MonsterInfo info)
  16. : base(info)
  17. {
  18. }
  19. protected override bool InAttackRange()
  20. {
  21. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, Info.ViewRange);
  22. }
  23. protected override void Attack()
  24. {
  25. if (!Target.IsAttackTarget(this))
  26. {
  27. Target = null;
  28. return;
  29. }
  30. ShockTime = 0;
  31. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  32. bool ranged = CurrentLocation == Target.CurrentLocation || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  33. ActionTime = Envir.Time + 600;
  34. AttackTime = Envir.Time + AttackSpeed;
  35. if (!ranged)
  36. {
  37. if (Envir.Random.Next(6) != 0)
  38. {
  39. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 0 });
  40. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  41. if (damage == 0) return;
  42. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 1100, Target, damage, DefenceType.MACAgility);
  43. ActionList.Add(action);
  44. }
  45. else
  46. {
  47. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  48. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  49. if (damage == 0) return;
  50. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 1100, Target, damage, DefenceType.MACAgility);
  51. ActionList.Add(action);
  52. }
  53. }
  54. else
  55. {
  56. SpawnIceTornado();
  57. }
  58. }
  59. private void SpawnIceTornado()
  60. {
  61. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 0 });
  62. List<MapObject> targets = FindAllTargets(Info.ViewRange, CurrentLocation);
  63. var count = targets.Count;
  64. if (count == 0) return;
  65. var target = targets[Envir.Random.Next(count)];
  66. var location = target.CurrentLocation;
  67. for (int y = location.Y - 1; y <= location.Y + 1; y++)
  68. {
  69. if (y < 0) continue;
  70. if (y >= CurrentMap.Height) break;
  71. for (int x = location.X - 1; x <= location.X + 1; x++)
  72. {
  73. if (x < 0) continue;
  74. if (x >= CurrentMap.Width) break;
  75. if (x == CurrentLocation.X && y == CurrentLocation.Y) continue;
  76. var cell = CurrentMap.GetCell(x, y);
  77. if (!cell.Valid) continue;
  78. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  79. var start = 500;
  80. SpellObject ob = new SpellObject
  81. {
  82. Spell = Spell.FlyingStatueIceTornado,
  83. Value = damage,
  84. ExpireTime = Envir.Time + 1500 + start,
  85. TickSpeed = 3000,
  86. CurrentLocation = new Point(x, y),
  87. CastLocation = location,
  88. Show = location.X == x && location.Y == y,
  89. CurrentMap = CurrentMap,
  90. Caster = this
  91. };
  92. DelayedAction action = new DelayedAction(DelayedType.Spawn, Envir.Time + start, ob);
  93. CurrentMap.ActionList.Add(action);
  94. }
  95. }
  96. }
  97. public override void Spawned()
  98. {
  99. base.Spawned();
  100. }
  101. protected override void ProcessTarget()
  102. {
  103. if (Target == null) return;
  104. if (InAttackRange() && CanAttack)
  105. {
  106. Attack();
  107. return;
  108. }
  109. if (Envir.Time < ShockTime)
  110. {
  111. Target = null;
  112. return;
  113. }
  114. var hpPercent = (HP * 100) / Stats[Stat.HP];
  115. bool halfHealth = hpPercent <= 50;
  116. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  117. if (dist >= Info.ViewRange || !halfHealth)
  118. MoveTo(Target.CurrentLocation);
  119. else
  120. {
  121. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  122. if (Walk(dir)) return;
  123. switch (Envir.Random.Next(2)) //No favour
  124. {
  125. case 0:
  126. for (int i = 0; i < 7; i++)
  127. {
  128. dir = Functions.NextDir(dir);
  129. if (Walk(dir))
  130. return;
  131. }
  132. break;
  133. default:
  134. for (int i = 0; i < 7; i++)
  135. {
  136. dir = Functions.PreviousDir(dir);
  137. if (Walk(dir))
  138. return;
  139. }
  140. break;
  141. }
  142. }
  143. }
  144. }
  145. }