HellLord.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 HellLord : MonsterObject
  8. {
  9. protected override bool CanMove { get { return false; } }
  10. protected override bool CanRegen { get { return false; } }
  11. private byte _stage = 0;
  12. private bool _begin = false;
  13. private bool _raged = false;
  14. private long _rageDelay = Settings.Minute * 2;
  15. private long _rageTime;
  16. private int _bombChance = 3;
  17. private int _bombSpreadMin = 5;
  18. private int _bombSpreadMax = 20;
  19. private int _quakeSpreadMin = 5;
  20. private int _quakeSpreadMax = 15;
  21. private int _quakeCount = 5;
  22. protected internal HellLord(MonsterInfo info) : base(info)
  23. {
  24. Direction = MirDirection.Up;
  25. _begin = true;
  26. }
  27. protected override bool InAttackRange()
  28. {
  29. if (Target.CurrentMap != CurrentMap) return false;
  30. return true;
  31. }
  32. public override void Turn(MirDirection dir)
  33. {
  34. }
  35. public override bool Walk(MirDirection dir) { return false; }
  36. public override int Attacked(MonsterObject attacker, int damage, DefenceType type = DefenceType.ACAgility)
  37. {
  38. if (_stage >= 4)
  39. {
  40. return base.Attacked(attacker, damage, type);
  41. }
  42. return 0;
  43. }
  44. public override int Attacked(HumanObject attacker, int damage, DefenceType type = DefenceType.ACAgility, bool damageWeapon = true)
  45. {
  46. if (_stage >= 4)
  47. {
  48. return base.Attacked(attacker, damage, type, damageWeapon);
  49. }
  50. return 0;
  51. }
  52. public override void ApplyPoison(Poison p, MapObject Caster = null, bool NoResist = false, bool ignoreDefence = true)
  53. {
  54. }
  55. public override void Process()
  56. {
  57. if(CurrentMap.Players.Count == 0 && _stage > 0)
  58. {
  59. _stage = 0;
  60. _begin = true;
  61. }
  62. base.Process();
  63. }
  64. protected override void ProcessTarget()
  65. {
  66. if (CurrentMap.Players.Count == 0) return;
  67. if (!CanAttack) return;
  68. if (_raged && _rageTime < Envir.Time && _stage < 4 || _begin)
  69. {
  70. if (_begin)
  71. {
  72. _begin = false;
  73. }
  74. _raged = false;
  75. SpawnKnight();
  76. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  77. }
  78. if (Envir.Random.Next(_bombChance) == 0 || _raged)
  79. {
  80. SpawnBomb();
  81. }
  82. SpawnQuakes();
  83. ActionTime = Envir.Time + 600;
  84. AttackTime = Envir.Time + AttackSpeed;
  85. }
  86. protected override void Attack() { }
  87. private void SpawnQuakes()
  88. {
  89. int count = Envir.Random.Next(1, _raged ? _quakeCount * 2 : _quakeCount);
  90. int distance = Envir.Random.Next(_quakeSpreadMin, _quakeSpreadMax);
  91. for (int j = 0; j < CurrentMap.Players.Count; j++)
  92. {
  93. Point playerLocation = CurrentMap.Players[j].CurrentLocation;
  94. for (int i = 0; i < count; i++)
  95. {
  96. Point location = new Point(playerLocation.X + Envir.Random.Next(-distance, distance + 1),
  97. playerLocation.Y + Envir.Random.Next(-distance, distance + 1));
  98. if(Envir.Random.Next(10) == 0)
  99. {
  100. location = playerLocation;
  101. }
  102. if (!CurrentMap.ValidPoint(location)) continue;
  103. var start = Envir.Random.Next(5000);
  104. var spellObj = new SpellObject
  105. {
  106. Spell = Envir.Random.Next(2) == 0 ? Spell.MapQuake1 : Spell.MapQuake2,
  107. Value = Envir.Random.Next(Envir.Random.Next(Stats[Stat.MinDC], Stats[Stat.MaxDC])),
  108. ExpireTime = Envir.Time + 2000 + start,
  109. TickSpeed = 500,
  110. Caster = null,
  111. CurrentLocation = location,
  112. CurrentMap = CurrentMap,
  113. Direction = MirDirection.Up
  114. };
  115. DelayedAction action = new DelayedAction(DelayedType.Spawn, Envir.Time + start, spellObj);
  116. CurrentMap.ActionList.Add(action);
  117. }
  118. }
  119. }
  120. private void SpawnBomb()
  121. {
  122. int distance = Envir.Random.Next(_bombSpreadMin, _bombSpreadMax);
  123. for (int j = 0; j < CurrentMap.Players.Count; j++)
  124. {
  125. Point playerLocation = CurrentMap.Players[j].CurrentLocation;
  126. Point location = new Point(playerLocation.X + Envir.Random.Next(-distance, distance + 1),
  127. playerLocation.Y + Envir.Random.Next(-distance, distance + 1));
  128. MonsterObject mob = null;
  129. switch (Envir.Random.Next(3))
  130. {
  131. case 0:
  132. mob = GetMonster(Envir.GetMonsterInfo(Settings.HellBomb1));
  133. break;
  134. case 1:
  135. mob = GetMonster(Envir.GetMonsterInfo(Settings.HellBomb2));
  136. break;
  137. case 2:
  138. mob = GetMonster(Envir.GetMonsterInfo(Settings.HellBomb3));
  139. break;
  140. }
  141. if (mob == null) return;
  142. mob.Spawn(CurrentMap, location);
  143. }
  144. }
  145. private void SpawnKnight()
  146. {
  147. MonsterObject mob = null;
  148. switch (_stage)
  149. {
  150. case 0:
  151. mob = GetMonster(Envir.GetMonsterInfo(Settings.HellKnight1));
  152. break;
  153. case 1:
  154. mob = GetMonster(Envir.GetMonsterInfo(Settings.HellKnight2));
  155. break;
  156. case 2:
  157. mob = GetMonster(Envir.GetMonsterInfo(Settings.HellKnight3));
  158. break;
  159. case 3:
  160. mob = GetMonster(Envir.GetMonsterInfo(Settings.HellKnight4));
  161. break;
  162. }
  163. if (mob == null || !(mob is HellKnight)) return;
  164. HellKnight knight = (HellKnight)mob;
  165. knight.Owner = this;
  166. knight.Lord = this;
  167. Point front = Functions.PointMove(CurrentLocation, MirDirection.DownLeft, 12);
  168. for (int i = 0; i < 50; i++)
  169. {
  170. Point location = new Point(front.X + Envir.Random.Next(-10, 10),
  171. front.Y + Envir.Random.Next(-10, 10));
  172. if (CurrentMap.ValidPoint(location))
  173. {
  174. DelayedAction action = new DelayedAction(DelayedType.Spawn, Envir.Time + 500, knight, location);
  175. CurrentMap.ActionList.Add(action);
  176. break;
  177. }
  178. }
  179. }
  180. public void KnightKilled()
  181. {
  182. _rageTime = Envir.Time + _rageDelay;
  183. _raged = true;
  184. _stage += 1;
  185. Broadcast(GetInfo());
  186. }
  187. public override Packet GetInfo()
  188. {
  189. var packet = (S.ObjectMonster)base.GetInfo();
  190. packet.ExtraByte = _stage;
  191. return packet;
  192. }
  193. }
  194. }