SnowYeti.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class SnowYeti : MonsterObject
  7. {
  8. private const byte AttackRange = 9;
  9. protected internal SnowYeti(MonsterInfo info)
  10. : base(info)
  11. {
  12. }
  13. protected override bool InAttackRange()
  14. {
  15. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  16. }
  17. protected bool InRangeAttackRange()
  18. {
  19. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  20. }
  21. protected override void ProcessTarget()
  22. {
  23. if (Target == null || Dead) return;
  24. if (!InAttackRange())
  25. {
  26. if (CanAttack)
  27. {
  28. if (Envir.Random.Next(5) == 0)
  29. RangeAttack();
  30. }
  31. if (CurrentLocation == Target.CurrentLocation)
  32. {
  33. MirDirection direction = (MirDirection)Envir.Random.Next(8);
  34. int rotation = Envir.Random.Next(2) == 0 ? 1 : -1;
  35. for (int d = 0; d < 8; d++)
  36. {
  37. if (Walk(direction)) break;
  38. direction = Functions.ShiftDirection(direction, rotation);
  39. }
  40. }
  41. else
  42. MoveTo(Target.CurrentLocation);
  43. }
  44. if (!CanAttack) return;
  45. if (Envir.Random.Next(5) > 0)
  46. {
  47. if (InAttackRange())
  48. Attack();
  49. }
  50. else RangeAttack();
  51. if (Envir.Time < ShockTime)
  52. {
  53. Target = null;
  54. return;
  55. }
  56. }
  57. protected override void Attack()
  58. {
  59. if (!Target.IsAttackTarget(this))
  60. {
  61. Target = null;
  62. return;
  63. }
  64. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  65. if (damage == 0) return;
  66. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  67. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  68. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.ACAgility);
  69. ActionList.Add(action);
  70. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  71. action = new DelayedAction(DelayedType.Damage, Envir.Time + 1500, Target, damage, DefenceType.ACAgility);
  72. ActionList.Add(action);
  73. ActionTime = Envir.Time + 1500;
  74. AttackTime = Envir.Time + AttackSpeed;
  75. ShockTime = 0;
  76. }
  77. public void RangeAttack()
  78. {
  79. if (!Target.IsAttackTarget(this))
  80. {
  81. Target = null;
  82. return;
  83. }
  84. ShockTime = 0;
  85. ActionTime = Envir.Time + 1000;
  86. AttackTime = Envir.Time + AttackSpeed + 1000;
  87. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  88. if (damage == 0) return;
  89. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  90. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  91. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  92. if (damage == 0) return;
  93. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MAC);
  94. ActionList.Add(action);
  95. }
  96. protected override void CompleteRangeAttack(IList<object> data)
  97. {
  98. MapObject target = (MapObject)data[0];
  99. int damage = (int)data[1];
  100. DefenceType defence = (DefenceType)data[2];
  101. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  102. if (target.Attacked(this, damage, DefenceType.MAC) > 0)
  103. {
  104. if (Envir.Random.Next(Settings.PoisonResistWeight) >= target.Stats[Stat.PoisonResist])
  105. {
  106. if (Envir.Random.Next(3) == 0)
  107. target.ApplyPoison(new Poison { PType = PoisonType.Frozen, Duration = 5, TickSpeed = 1000 }, this);
  108. }
  109. }
  110. }
  111. }
  112. }