TrollKing.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using Server.MirDatabase;
  2. using S = ServerPackets;
  3. namespace Server.MirObjects.Monsters
  4. {
  5. public class TrollKing : MonsterObject
  6. {
  7. public long FearTime;
  8. public byte AttackRange = 7;
  9. protected internal TrollKing(MonsterInfo info)
  10. : base(info)
  11. {
  12. }
  13. protected override bool InAttackRange()
  14. {
  15. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  16. }
  17. protected override void Attack()
  18. {
  19. if (!Target.IsAttackTarget(this))
  20. {
  21. Target = null;
  22. return;
  23. }
  24. ShockTime = 0;
  25. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  26. if (Functions.InRange(CurrentLocation, Target.CurrentLocation, 3))
  27. {
  28. if (Envir.Random.Next(2) == 0 || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 2))
  29. {
  30. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 0 });
  31. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  32. if (damage == 0) return;
  33. List<MapObject> targets = FindAllTargets(3, CurrentLocation, false);
  34. if (targets.Count == 0) return;
  35. for (int i = 0; i < targets.Count; i++)
  36. {
  37. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, targets[i], damage, DefenceType.MACAgility);
  38. ActionList.Add(action);
  39. }
  40. }
  41. else
  42. {
  43. WalkAway();
  44. }
  45. }
  46. else
  47. {
  48. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 1 });
  49. List<MapObject> targets = FindAllTargets(3, Target.CurrentLocation, false);
  50. if (targets.Count == 0) return;
  51. for (int i = 0; i < targets.Count; i++)
  52. {
  53. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  54. if (damage == 0) continue;
  55. int delay = Functions.MaxDistance(CurrentLocation, targets[i].CurrentLocation) * 50 + 500; //50 MS per Step
  56. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, targets[i], damage, DefenceType.ACAgility);
  57. ActionList.Add(action);
  58. }
  59. }
  60. ActionTime = Envir.Time + 500;
  61. AttackTime = Envir.Time + AttackSpeed;
  62. }
  63. protected override void CompleteAttack(IList<object> data)
  64. {
  65. MapObject target = (MapObject)data[0];
  66. int damage = (int)data[1];
  67. DefenceType defence = (DefenceType)data[2];
  68. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  69. target.Attacked(this, damage, defence);
  70. }
  71. protected override void CompleteRangeAttack(IList<object> data)
  72. {
  73. MapObject target = (MapObject)data[0];
  74. int damage = (int)data[1];
  75. DefenceType defence = (DefenceType)data[2];
  76. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  77. target.Attacked(this, damage, defence);
  78. if (target.Attacked(this, damage, DefenceType.MACAgility) <= 0) return;
  79. PoisonTarget(target, 1, Envir.Random.Next(Stats[Stat.MaxMC]), PoisonType.Dazed, 1000);
  80. }
  81. protected override void ProcessTarget()
  82. {
  83. if (Target == null || !CanAttack) return;
  84. if (InAttackRange() && Envir.Time < FearTime)
  85. {
  86. Attack();
  87. return;
  88. }
  89. FearTime = Envir.Time + 5000;
  90. if (Envir.Time < ShockTime)
  91. {
  92. Target = null;
  93. return;
  94. }
  95. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  96. if (dist >= AttackRange)
  97. MoveTo(Target.CurrentLocation);
  98. else
  99. {
  100. WalkAway();
  101. }
  102. }
  103. private void WalkAway()
  104. {
  105. if (Target == null || !CanAttack) return;
  106. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  107. if (Walk(dir)) return;
  108. switch (Envir.Random.Next(2)) //No favour
  109. {
  110. case 0:
  111. for (int i = 0; i < 7; i++)
  112. {
  113. dir = Functions.NextDir(dir);
  114. if (Walk(dir))
  115. return;
  116. }
  117. break;
  118. default:
  119. for (int i = 0; i < 7; i++)
  120. {
  121. dir = Functions.PreviousDir(dir);
  122. if (Walk(dir))
  123. return;
  124. }
  125. break;
  126. }
  127. }
  128. }
  129. }