TrapRock.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public class TrapRock : MonsterObject
  7. {
  8. public bool Visible, ChildRock, FirstAttack;
  9. public long VisibleTime;
  10. public byte SpawnCorner;
  11. public TrapRock ParentRock;
  12. public Point TargetLocation;
  13. protected override bool CanAttack
  14. {
  15. get
  16. {
  17. return Visible && base.CanAttack;
  18. }
  19. }
  20. protected override bool CanMove { get { return false; } }
  21. public override bool Blocking
  22. {
  23. get
  24. {
  25. return Visible && base.Blocking;
  26. }
  27. }
  28. protected internal TrapRock(MonsterInfo info)
  29. : base(info)
  30. {
  31. Visible = false;
  32. VisibleTime = Envir.Time + 2000;
  33. FirstAttack = true;
  34. }
  35. public override MapObject Target
  36. {
  37. get { return _target; }
  38. set
  39. {
  40. if (_target != null && value != null) return;
  41. if (_target != null && value == null) _target.InTrapRock = false;
  42. _target = value;
  43. if (Visible && value == null) Die();
  44. }
  45. }
  46. protected override void ProcessAI()
  47. {
  48. if (Dead) return;
  49. if (Envir.Time > VisibleTime)
  50. {
  51. VisibleTime = Envir.Time + 2000;
  52. bool visible = Target != null;
  53. if (!Visible && visible && !Target.Dead && !Target.InTrapRock)
  54. {
  55. SpawnCorner = (byte)(Envir.Random.Next(4) * 2);
  56. if (Teleport(CurrentMap, Functions.PointMove(Target.CurrentLocation, (MirDirection)SpawnCorner, 1), false))
  57. {
  58. ActionTime = Envir.Time + 1000;
  59. Show();
  60. return;
  61. }
  62. }
  63. if (Visible && (Target.Dead || Target.CurrentLocation != TargetLocation))
  64. {
  65. Die();
  66. return;
  67. }
  68. }
  69. base.ProcessAI();
  70. }
  71. protected override void Attack()
  72. {
  73. if (!Target.IsAttackTarget(this))
  74. {
  75. Target = null;
  76. return;
  77. }
  78. if (!ChildRock)
  79. {
  80. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
  81. }
  82. else Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  83. ActionTime = Envir.Time + 300;
  84. AttackTime = Envir.Time + AttackSpeed;
  85. if (Envir.Random.Next(8) == 0 && !ChildRock)
  86. {
  87. Target.ApplyPoison(new Poison { PType = PoisonType.Paralysis, Duration = 3, TickSpeed = 1000 }, this, true);
  88. }
  89. if (Target.Dead)
  90. Die();
  91. }
  92. public override void Die()
  93. {
  94. if (!ChildRock)
  95. {
  96. if (Target != null)
  97. {
  98. if (CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, 1))
  99. Target.InTrapRock = false;
  100. }
  101. if (Info.HasDieScript && (Envir.MonsterNPC != null))
  102. {
  103. Envir.MonsterNPC.Call(this,string.Format("[@_DIE({0})]", Info.Index));
  104. }
  105. for (int i = SlaveList.Count - 1; i >= 0; i--)
  106. if (!SlaveList[i].Dead || SlaveList[i].Node != null)
  107. {
  108. SlaveList[i].Die();
  109. SlaveList.RemoveAt(i);
  110. }
  111. }
  112. base.Die();
  113. }
  114. public override int Attacked(MonsterObject attacker, int damage, DefenceType type = DefenceType.ACAgility)
  115. {
  116. if (ChildRock) ParentRock.FirstAttack = false;
  117. if (!ChildRock && FirstAttack == true)
  118. {
  119. Die();
  120. return 0;
  121. }
  122. return base.Attacked(attacker, damage, type);
  123. }
  124. public override int Attacked(HumanObject attacker, int damage, DefenceType type = DefenceType.ACAgility, bool damageWeapon = true)
  125. {
  126. if (ChildRock) ParentRock.FirstAttack = false;
  127. if (!ChildRock && FirstAttack == true)
  128. {
  129. Die();
  130. return 0;
  131. }
  132. return base.Attacked(attacker, damage, type, damageWeapon);
  133. }
  134. public override int Struck(int damage, DefenceType type = DefenceType.ACAgility)
  135. {
  136. return 0;
  137. }
  138. public override void ChangeHP(int amount)
  139. {
  140. if (ChildRock) return;
  141. base.ChangeHP(amount);
  142. }
  143. public override void Turn(MirDirection dir)
  144. {
  145. }
  146. public override bool Walk(MirDirection dir) { return false; }
  147. protected override void ProcessRoam() { }
  148. public override Packet GetInfo()
  149. {
  150. if (!Visible) return null;
  151. return base.GetInfo();
  152. }
  153. public void Show()
  154. {
  155. TargetLocation = Target.CurrentLocation;
  156. Visible = true;
  157. CellTime = ChildRock ? ParentRock.CellTime : Envir.Time + 500;
  158. Broadcast(GetInfo());
  159. Broadcast(new S.ObjectShow { ObjectID = ObjectID });
  160. if (!ChildRock)
  161. {
  162. Target.ApplyPoison(new Poison { PType = PoisonType.Paralysis, Duration = 3, TickSpeed = 1000 },this, true);
  163. Target.InTrapRock = true;
  164. for (byte i = 0; i <= 6; i += 2)
  165. {
  166. if (i == SpawnCorner) continue;
  167. var mob = GetMonster(Envir.GetMonsterInfo(Name));
  168. if (mob == null) return;
  169. var childmob = (TrapRock)mob;
  170. if (childmob.Spawn(CurrentMap, Functions.PointMove(Target.CurrentLocation, (MirDirection)i, 1)))
  171. {
  172. if (Target != null) childmob.Target = Target;
  173. childmob.ChildRock = true;
  174. childmob.ParentRock = this;
  175. SlaveList.Add(childmob);
  176. childmob.Show();
  177. childmob.ActionTime = this.ActionTime;
  178. childmob.AttackTime = this.AttackTime;
  179. }
  180. else continue;
  181. }
  182. }
  183. }
  184. }
  185. }