FrostTiger.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using Server.MirDatabase;
  2. using S = ServerPackets;
  3. namespace Server.MirObjects.Monsters
  4. {
  5. public class FrostTiger : MonsterObject
  6. {
  7. protected byte AttackRange = 6;
  8. public long SitDownTime;
  9. protected internal FrostTiger(MonsterInfo info)
  10. : base(info)
  11. {
  12. SitDownTime = NewSitDownTime();
  13. }
  14. private bool _sitting;
  15. public bool Sitting
  16. {
  17. get { return _sitting; }
  18. set
  19. {
  20. if (_sitting == value) return;
  21. _sitting = value;
  22. Hidden = value;
  23. CurrentMap.Broadcast(new S.ObjectSitDown { ObjectID = ObjectID, Location = CurrentLocation, Direction = Direction, Sitting = value }, CurrentLocation);
  24. }
  25. }
  26. protected override bool CanAttack
  27. {
  28. get
  29. {
  30. return !Sitting && base.CanAttack;
  31. }
  32. }
  33. protected override bool CanMove
  34. {
  35. get
  36. {
  37. return !Sitting && base.CanMove;
  38. }
  39. }
  40. public override bool Walk(MirDirection dir)
  41. {
  42. return !Sitting && base.Walk(dir);
  43. }
  44. protected override bool InAttackRange()
  45. {
  46. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  47. }
  48. protected long NewSitDownTime()
  49. {
  50. long newtime = Envir.Time + Envir.Random.Next(1000 * 60 * 2);
  51. return newtime < SitDownTime ? SitDownTime : newtime;
  52. }
  53. protected override void FindTarget() { }
  54. protected override void Attack()
  55. {
  56. if (!Target.IsAttackTarget(this))
  57. {
  58. Target = null;
  59. return;
  60. }
  61. ShockTime = 0;
  62. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  63. bool ranged = CurrentLocation == Target.CurrentLocation || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  64. ActionTime = Envir.Time + 300;
  65. AttackTime = Envir.Time + AttackSpeed;
  66. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  67. if (!ranged)
  68. {
  69. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  70. if (damage == 0) return;
  71. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, Target, damage, DefenceType.ACAgility);
  72. ActionList.Add(action);
  73. }
  74. else
  75. {
  76. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  77. AttackTime = Envir.Time + AttackSpeed + 500;
  78. if (damage == 0) return;
  79. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  80. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MAC);
  81. ActionList.Add(action);
  82. if (Envir.Random.Next(Settings.PoisonResistWeight) >= Target.Stats[Stat.PoisonResist])
  83. {
  84. if (Envir.Random.Next(8) == 0)
  85. {
  86. if (Info.Effect == 0)
  87. {
  88. Target.ApplyPoison(new Poison
  89. {
  90. Owner = this,
  91. Duration = 5,
  92. PType = PoisonType.Bleeding,
  93. TickSpeed = 1000,
  94. }, this);
  95. }
  96. else if (Info.Effect == 1)
  97. {
  98. Target.ApplyPoison(new Poison
  99. {
  100. Owner = this,
  101. Duration = 5,
  102. PType = PoisonType.Slow,
  103. TickSpeed = 1000,
  104. }, this);
  105. }
  106. }
  107. }
  108. }
  109. if (Target.Dead)
  110. FindTarget();
  111. }
  112. protected override void ProcessTarget()
  113. {
  114. if (Target == null) return;
  115. if (Sitting) Sitting = false;
  116. SitDownTime = NewSitDownTime();
  117. if (InAttackRange() && CanAttack)
  118. {
  119. Attack();
  120. return;
  121. }
  122. if (Envir.Time < ShockTime)
  123. {
  124. Target = null;
  125. return;
  126. }
  127. MoveTo(Target.CurrentLocation);
  128. }
  129. protected override void ProcessAI()
  130. {
  131. if (!Dead && !Sitting && Envir.Time > SitDownTime)
  132. {
  133. Sitting = true;
  134. }
  135. base.ProcessAI();
  136. }
  137. public override Packet GetInfo()
  138. {
  139. var packet = (S.ObjectMonster)base.GetInfo();
  140. packet.Extra = Sitting;
  141. return packet;
  142. }
  143. }
  144. }