GreatFoxSpirit.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class GreatFoxSpirit : MonsterObject
  7. {
  8. private byte _stage;
  9. private long RecallTime;
  10. private byte AttackRange = 7;
  11. protected override bool CanMove { get { return false; } }
  12. protected internal GreatFoxSpirit(MonsterInfo info)
  13. : base(info)
  14. {
  15. }
  16. protected override bool InAttackRange()
  17. {
  18. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  19. }
  20. protected override void ProcessAI()
  21. {
  22. if (Dead) return;
  23. if (Stats[Stat.HP] >= 4)
  24. {
  25. byte stage = (byte)(4 - (HP / (Stats[Stat.HP] / 4)));
  26. if (stage > _stage)
  27. {
  28. _stage = stage;
  29. Broadcast(GetInfo());
  30. }
  31. }
  32. base.ProcessAI();
  33. }
  34. public override void Turn(MirDirection dir)
  35. {
  36. }
  37. public override bool Walk(MirDirection dir) { return false; }
  38. protected override void ProcessRoam() { }
  39. protected override void ProcessTarget()
  40. {
  41. if (Target == null) return;
  42. //remark: does this mean nobody gets teleported if the main target is standing closeby + does it mean it always try's to teleport the person with lowest x/y coords?)
  43. if (Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) > 3 && Envir.Random.Next(10) == 0 && Envir.Time >= RecallTime)
  44. {
  45. RecallTime = Envir.Time + 10000;
  46. List<MapObject> targets = FindAllTargets(30, CurrentLocation);
  47. if (targets.Count != 0 && Envir.Random.Next(4) > 0)
  48. {
  49. for (int i = 0; i < targets.Count; i++)
  50. {
  51. if (Functions.MaxDistance(CurrentLocation, targets[i].CurrentLocation) > 3)
  52. {
  53. if (Envir.Random.Next(Settings.MagicResistWeight) < targets[i].Stats[Stat.MagicResist]) continue;
  54. if (!targets[i].Teleport(CurrentMap, Functions.PointMove(CurrentLocation, (MirDirection)((byte)Envir.Random.Next(7)), 1)))
  55. targets[i].Teleport(CurrentMap, CurrentLocation);
  56. return;
  57. }
  58. }
  59. }
  60. }
  61. if (InAttackRange() && CanAttack)
  62. {
  63. Attack();
  64. if (Target.Dead)
  65. FindTarget();
  66. return;
  67. }
  68. if (Envir.Time < ShockTime)
  69. {
  70. Target = null;
  71. return;
  72. }
  73. }
  74. protected override void Attack()
  75. {
  76. if (!Target.IsAttackTarget(this))
  77. {
  78. Target = null;
  79. return;
  80. }
  81. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  82. if (damage == 0) return;
  83. ShockTime = 0;
  84. ActionTime = Envir.Time + 300;
  85. AttackTime = Envir.Time + AttackSpeed;
  86. bool ranged = CurrentLocation == Target.CurrentLocation || Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) > 2;
  87. List<MapObject> targets = FindAllTargets(ranged ? AttackRange : 2, CurrentLocation);
  88. if (targets.Count == 0) return;
  89. if (ranged) Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  90. else Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  91. for (int i = 0; i < targets.Count; i++)
  92. {
  93. Target = targets[i];
  94. if (ranged) Broadcast(new S.ObjectEffect { ObjectID = Target.ObjectID, Effect = SpellEffect.GreatFoxSpirit });
  95. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, Target, damage, DefenceType.MAC);
  96. ActionList.Add(action);
  97. }
  98. }
  99. protected override void CompleteAttack(IList<object> data)
  100. {
  101. MapObject target = (MapObject)data[0];
  102. int damage = (int)data[1];
  103. DefenceType defence = (DefenceType)data[2];
  104. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  105. if (target.Attacked(this, damage, defence) <= 0) return;
  106. PoisonTarget(target, 5, 15, PoisonType.Slow, 1000);
  107. PoisonTarget(target, 5, 5, PoisonType.Paralysis, 1000);
  108. }
  109. public override void Die()
  110. {
  111. if (Dead) return;
  112. ChangeGuardianState(false);
  113. base.Die();
  114. }
  115. public override void Spawned()
  116. {
  117. base.Spawned();
  118. ChangeGuardianState(true);
  119. }
  120. private void ChangeGuardianState(bool Active)
  121. {
  122. int ExpectedDistance = 20;
  123. for (int y = CurrentLocation.Y - ExpectedDistance; y <= CurrentLocation.Y + ExpectedDistance; y++)
  124. {
  125. if (y < 0) continue;
  126. if (y >= CurrentMap.Height) break;
  127. for (int x = CurrentLocation.X - ExpectedDistance; x <= CurrentLocation.X + ExpectedDistance; x++)
  128. {
  129. if (x < 0) continue;
  130. if (x >= CurrentMap.Width) break;
  131. Cell cell = CurrentMap.GetCell(x, y);
  132. if (!cell.Valid || cell.Objects == null) continue;
  133. for (int i = 0; i < cell.Objects.Count; i++)
  134. {
  135. GuardianRock target = cell.Objects[i] as GuardianRock;
  136. if (target == null) continue;
  137. target.Active = Active;
  138. }
  139. }
  140. }
  141. }
  142. public override Packet GetInfo()
  143. {
  144. var packet = (S.ObjectMonster)base.GetInfo();
  145. packet.ExtraByte = _stage;
  146. return packet;
  147. }
  148. }
  149. }