Armadillo.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 Armadillo : DigOutZombie
  8. {
  9. protected bool _runAway;
  10. protected internal Armadillo(MonsterInfo info)
  11. : base(info)
  12. {
  13. }
  14. protected override void SpawnDigOutEffect()
  15. {
  16. if (Visible && Envir.Time > DigOutTime + 500 && !DoneDigOut)
  17. {
  18. SpellObject ob = new SpellObject
  19. {
  20. Spell = Spell.DigOutArmadillo,
  21. Value = 1,
  22. ExpireTime = Envir.Time + (5 * 60 * 1000),
  23. TickSpeed = 2000,
  24. Caster = null,
  25. CurrentLocation = DigOutLocation,
  26. CurrentMap = this.CurrentMap,
  27. Direction = DigOutDirection
  28. };
  29. CurrentMap.AddObject(ob);
  30. ob.Spawned();
  31. DoneDigOut = true;
  32. }
  33. }
  34. public override int Attacked(HumanObject attacker, int damage, DefenceType type = DefenceType.ACAgility, bool damageWeapon = true)
  35. {
  36. if (_runAway && Envir.Random.Next(4) == 0)
  37. {
  38. _runAway = false;
  39. }
  40. return base.Attacked(attacker, damage, type, damageWeapon);
  41. }
  42. public override int Attacked(MonsterObject attacker, int damage, DefenceType type = DefenceType.ACAgility)
  43. {
  44. if (_runAway && Envir.Random.Next(4) == 0)
  45. {
  46. _runAway = false;
  47. }
  48. return base.Attacked(attacker, damage, type);
  49. }
  50. protected override void Attack()
  51. {
  52. if (!Target.IsAttackTarget(this))
  53. {
  54. Target = null;
  55. return;
  56. }
  57. ShockTime = 0;
  58. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  59. ActionTime = Envir.Time + 300;
  60. AttackTime = Envir.Time + AttackSpeed;
  61. switch (Envir.Random.Next(0, 6))
  62. {
  63. case 0:
  64. {
  65. Retreat();
  66. }
  67. break;
  68. case 1:
  69. {
  70. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  71. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  72. if (damage == 0) return;
  73. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 400, Target, damage / 2, DefenceType.ACAgility);
  74. ActionList.Add(action);
  75. damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  76. if (damage == 0) return;
  77. action = new DelayedAction(DelayedType.Damage, Envir.Time + 600, Target, damage / 2, DefenceType.ACAgility);
  78. ActionList.Add(action);
  79. damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  80. if (damage == 0) return;
  81. action = new DelayedAction(DelayedType.Damage, Envir.Time + 800, Target, damage / 2, DefenceType.ACAgility);
  82. ActionList.Add(action);
  83. }
  84. break;
  85. default:
  86. {
  87. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  88. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  89. if (damage == 0) return;
  90. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 400, Target, damage, DefenceType.ACAgility);
  91. ActionList.Add(action);
  92. }
  93. break;
  94. }
  95. }
  96. protected void Retreat()
  97. {
  98. MirDirection jumpDir = Functions.ReverseDirection(Direction);
  99. Point location = new Point();
  100. for (int i = 0; i < 2; i++)
  101. {
  102. location = Functions.PointMove(CurrentLocation, jumpDir, 1);
  103. if (!CurrentMap.ValidPoint(location)) return;
  104. }
  105. for (int i = 0; i < 2; i++)
  106. {
  107. location = Functions.PointMove(CurrentLocation, jumpDir, 1);
  108. CurrentMap.GetCell(CurrentLocation).Remove(this);
  109. RemoveObjects(jumpDir, 1);
  110. CurrentLocation = location;
  111. CurrentMap.GetCell(CurrentLocation).Add(this);
  112. AddObjects(jumpDir, 1);
  113. }
  114. Broadcast(new S.ObjectBackStep { ObjectID = ObjectID, Direction = Direction, Location = location, Distance = 2 });
  115. int damage = Stats[Stat.MaxDC];
  116. if (damage == 0) return;
  117. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 900, Target, damage, DefenceType.AC);
  118. ActionList.Add(action);
  119. }
  120. protected override void CompleteRangeAttack(IList<object> data)
  121. {
  122. MapObject target = (MapObject)data[0];
  123. int damage = (int)data[1];
  124. DefenceType defence = (DefenceType)data[2];
  125. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  126. var targets = FindAllTargets(2, CurrentLocation);
  127. for (int i = 0; i < targets.Count; i++)
  128. {
  129. if (targets[i].Attacked(this, damage, defence) <= 0)
  130. {
  131. _runAway = true;
  132. };
  133. }
  134. }
  135. protected override void ProcessTarget()
  136. {
  137. if (_runAway)
  138. {
  139. if (!CanMove || Target == null) return;
  140. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  141. if (Walk(dir)) return;
  142. switch (Envir.Random.Next(2)) //No favour
  143. {
  144. case 0:
  145. for (int i = 0; i < 7; i++)
  146. {
  147. dir = Functions.NextDir(dir);
  148. if (Walk(dir))
  149. return;
  150. }
  151. break;
  152. default:
  153. for (int i = 0; i < 7; i++)
  154. {
  155. dir = Functions.PreviousDir(dir);
  156. if (Walk(dir))
  157. return;
  158. }
  159. break;
  160. }
  161. }
  162. else base.ProcessTarget();
  163. }
  164. }
  165. }