SpittingToad.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class SpittingToad : MonsterObject
  7. {
  8. public bool Summoned;
  9. public long AliveTime;
  10. public long deadTime;
  11. protected internal SpittingToad(MonsterInfo info) : base(info)
  12. {
  13. ActionTime = Envir.Time + 1000;
  14. }
  15. public override string Name
  16. {
  17. get { return Master == null ? Info.GameName : (Dead ? Info.GameName : string.Format("{0}({1})", Info.GameName, Master.Name)); }
  18. set { throw new NotSupportedException(); }
  19. }
  20. public override void Process()
  21. {
  22. if (!Dead && Summoned)
  23. {
  24. if (Master != null)
  25. {
  26. bool selfDestruct = false;
  27. if (FindObject(Master.ObjectID, 15) == null) selfDestruct = true;
  28. if (Summoned && Envir.Time > AliveTime) selfDestruct = true;
  29. if (selfDestruct && Master != null) Die();
  30. }
  31. }
  32. base.Process();
  33. }
  34. public override void Process(DelayedAction action)
  35. {
  36. switch (action.Type)
  37. {
  38. case DelayedType.Damage:
  39. CompleteAttack(action.Params);
  40. break;
  41. case DelayedType.RangeDamage:
  42. CompleteRangeAttack(action.Params);
  43. break;
  44. case DelayedType.Recall:
  45. PetRecall((MapObject)action.Params[0]);
  46. break;
  47. }
  48. }
  49. public void PetRecall(MapObject target)
  50. {
  51. if (target == null) return;
  52. if (Master == null) return;
  53. Teleport(Master.CurrentMap, target.CurrentLocation);
  54. }
  55. protected override void ProcessAI()
  56. {
  57. //ProcessSearch
  58. if (Envir.Time < SearchTime) return;
  59. SearchTime = Envir.Time + SearchDelay;
  60. if (Target == null) FindTarget();
  61. //ProcessTarget
  62. if (Target == null || !CanAttack) return;
  63. if (InAttackRange())
  64. {
  65. Attack();
  66. if (Target.Dead) FindTarget();
  67. return;
  68. }
  69. else FindTarget();//Target out of range find new
  70. if (Envir.Time < ShockTime)
  71. {
  72. Target = null;
  73. return;
  74. }
  75. }
  76. protected override bool InAttackRange()
  77. {
  78. if (Target.CurrentMap != CurrentMap) return false;
  79. if (Target.CurrentLocation == CurrentLocation) return false;
  80. int x = Math.Abs(Target.CurrentLocation.X - CurrentLocation.X);
  81. int y = Math.Abs(Target.CurrentLocation.Y - CurrentLocation.Y);
  82. if (x > 12 || y > 12) return false;
  83. return (x <= 12 && y <= 12) || (x == y || x % 2 == y % 2);
  84. }
  85. protected override void Attack()
  86. {
  87. if (!Target.IsAttackTarget(this))
  88. {
  89. Target = null;
  90. return;
  91. }
  92. ShockTime = 0;
  93. ActionTime = Envir.Time + 300;
  94. AttackTime = Envir.Time + AttackSpeed;
  95. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  96. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  97. Turn(Direction);
  98. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  99. AttackTime = Envir.Time + AttackSpeed + 500;
  100. if (damage == 0) return;
  101. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  102. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MAC);
  103. ActionList.Add(action);
  104. }
  105. public override void Spawned()
  106. {
  107. base.Spawned();
  108. Summoned = true;
  109. }
  110. public override Packet GetInfo()
  111. {
  112. var packet = (S.ObjectMonster)base.GetInfo();
  113. packet.Image = Monster.SpittingToad;
  114. packet.Extra = Summoned;
  115. return packet;
  116. }
  117. }
  118. }