HoodedSummoner.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using Server.MirDatabase;
  2. using S = ServerPackets;
  3. namespace Server.MirObjects.Monsters
  4. {
  5. public class HoodedSummoner : MonsterObject
  6. {
  7. public long SlaveSpawnTime;
  8. public long FearTime;
  9. public bool slaves1 = false;
  10. public bool slaves2 = false;
  11. protected internal HoodedSummoner(MonsterInfo info)
  12. : base(info)
  13. {
  14. }
  15. protected override bool InAttackRange()
  16. {
  17. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, Info.ViewRange);
  18. }
  19. protected override void Attack()
  20. {
  21. if (!Target.IsAttackTarget(this))
  22. {
  23. Target = null;
  24. return;
  25. }
  26. ShockTime = 0;
  27. ActionTime = Envir.Time + 300;
  28. AttackTime = Envir.Time + AttackSpeed;
  29. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  30. switch (Envir.Random.Next(6))
  31. {
  32. case 0:
  33. case 1:
  34. case 2:
  35. case 3:
  36. {
  37. RangedAttack();
  38. }
  39. break;
  40. case 4:
  41. {
  42. if (Envir.Time > SlaveSpawnTime)
  43. {
  44. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 0 });
  45. slaves1 = true;
  46. SpawnSlaves();
  47. // Timer added so if many of these mobs are around it doesn't overwhelm players too quickly with scrolls.
  48. SlaveSpawnTime = Envir.Time + (Settings.Second * 15);
  49. }
  50. else
  51. {
  52. RangedAttack();
  53. }
  54. }
  55. break;
  56. case 5:
  57. {
  58. if (Envir.Time > SlaveSpawnTime)
  59. {
  60. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  61. slaves2 = true;
  62. SpawnSlaves();
  63. // Timer added so if many of these mobs are around it doesn't overwhelm players too quickly with scrolls.
  64. SlaveSpawnTime = Envir.Time + (Settings.Second * 15);
  65. }
  66. else
  67. {
  68. RangedAttack();
  69. }
  70. }
  71. break;
  72. default:
  73. {
  74. RangedAttack();
  75. }
  76. break;
  77. }
  78. slaves1 = false;
  79. slaves2 = false;
  80. }
  81. private void RangedAttack()
  82. {
  83. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 0 });
  84. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  85. if (damage == 0) return;
  86. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.MAC);
  87. ActionList.Add(action);
  88. }
  89. private void SpawnSlaves()
  90. {
  91. int count = Math.Min(1, 4 - SlaveList.Count);
  92. for (int i = 0; i < count; i++)
  93. {
  94. MonsterObject mob = null;
  95. if (slaves1 == true)
  96. {
  97. switch (Envir.Random.Next(2))
  98. {
  99. case 0:
  100. mob = GetMonster(Envir.GetMonsterInfo(Settings.ScrollMob1));
  101. break;
  102. case 1:
  103. mob = GetMonster(Envir.GetMonsterInfo(Settings.ScrollMob2));
  104. break;
  105. }
  106. }
  107. if (slaves2 == true)
  108. {
  109. switch (Envir.Random.Next(2))
  110. {
  111. case 0:
  112. mob = GetMonster(Envir.GetMonsterInfo(Settings.ScrollMob3));
  113. break;
  114. case 1:
  115. mob = GetMonster(Envir.GetMonsterInfo(Settings.ScrollMob4));
  116. break;
  117. }
  118. }
  119. if (mob == null) continue;
  120. if (!mob.Spawn(CurrentMap, Front))
  121. mob.Spawn(CurrentMap, Target.CurrentLocation);
  122. mob.ActionTime = Envir.Time + 2000;
  123. SlaveList.Add(mob);
  124. }
  125. }
  126. protected override void ProcessTarget()
  127. {
  128. if (Target == null || !CanAttack) return;
  129. if (InAttackRange() && Envir.Time < FearTime)
  130. {
  131. Attack();
  132. return;
  133. }
  134. FearTime = Envir.Time + 5000;
  135. if (Envir.Time < ShockTime)
  136. {
  137. Target = null;
  138. return;
  139. }
  140. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  141. if (dist >= Info.ViewRange)
  142. MoveTo(Target.CurrentLocation);
  143. else
  144. {
  145. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  146. if (Walk(dir)) return;
  147. switch (Envir.Random.Next(2)) //No favour
  148. {
  149. case 0:
  150. for (int i = 0; i < 7; i++)
  151. {
  152. dir = Functions.NextDir(dir);
  153. if (Walk(dir))
  154. return;
  155. }
  156. break;
  157. default:
  158. for (int i = 0; i < 7; i++)
  159. {
  160. dir = Functions.PreviousDir(dir);
  161. if (Walk(dir))
  162. return;
  163. }
  164. break;
  165. }
  166. }
  167. }
  168. }
  169. }