ZumaMonster.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. using S = ServerPackets;
  5. namespace Server.MirObjects.Monsters
  6. {
  7. public class ZumaMonster : MonsterObject
  8. {
  9. public bool Stoned = true;
  10. public bool AvoidFireWall = true;
  11. protected override bool CanMove
  12. {
  13. get
  14. {
  15. return base.CanMove && !Stoned;
  16. }
  17. }
  18. protected override bool CanAttack
  19. {
  20. get
  21. {
  22. return base.CanAttack && !Stoned;
  23. }
  24. }
  25. protected internal ZumaMonster(MonsterInfo info) : base(info)
  26. {
  27. }
  28. public override int Pushed(MapObject pusher, MirDirection dir, int distance)
  29. {
  30. return Stoned ? 0 : base.Pushed(pusher, dir, distance);
  31. }
  32. public override void ApplyPoison(Poison p, MapObject Caster = null, bool NoResist = false, bool ignoreDefence = true)
  33. {
  34. if (Stoned) return;
  35. base.ApplyPoison(p, Caster, NoResist, ignoreDefence);
  36. }
  37. public override Buff AddBuff(BuffType type, MapObject owner, int duration, Stats stats, bool refreshStats = true, bool updateOnly = false, params int[] values)
  38. {
  39. if (Stoned) return null;
  40. return base.AddBuff(type, owner, duration, stats, refreshStats, updateOnly, values);
  41. }
  42. public override bool IsFriendlyTarget(HumanObject ally)
  43. {
  44. if (Stoned) return false;
  45. return base.IsFriendlyTarget(ally);
  46. }
  47. protected override void ProcessAI()
  48. {
  49. if (!Dead && Envir.Time > ActionTime)
  50. {
  51. bool stoned = !FindNearby(2);
  52. if (Stoned && !stoned)
  53. {
  54. Wake();
  55. WakeAll(14);
  56. }
  57. }
  58. base.ProcessAI();
  59. }
  60. public void Wake()
  61. {
  62. if (!Stoned) return;
  63. Stoned = false;
  64. Broadcast(new S.ObjectShow { ObjectID = ObjectID });
  65. ActionTime = Envir.Time + 1000;
  66. }
  67. public void WakeAll(int dist)
  68. {
  69. for (int y = CurrentLocation.Y - dist; y <= CurrentLocation.Y + dist; y++)
  70. {
  71. if (y < 0) continue;
  72. if (y >= CurrentMap.Height) break;
  73. for (int x = CurrentLocation.X - dist; x <= CurrentLocation.X + dist; x++)
  74. {
  75. if (x < 0) continue;
  76. if (x >= CurrentMap.Width) break;
  77. Cell cell = CurrentMap.GetCell(x, y);
  78. if (!cell.Valid || cell.Objects == null) continue;
  79. for (int i = 0; i < cell.Objects.Count; i++)
  80. {
  81. ZumaMonster target = cell.Objects[i] as ZumaMonster;
  82. if (target == null || !target.Stoned) continue;
  83. target.Wake();
  84. target.Target = Target;
  85. }
  86. }
  87. }
  88. }
  89. public override bool IsAttackTarget(MonsterObject attacker)
  90. {
  91. return !Stoned && base.IsAttackTarget(attacker);
  92. }
  93. public override bool IsAttackTarget(HumanObject attacker)
  94. {
  95. return !Stoned && base.IsAttackTarget(attacker);
  96. }
  97. public override bool Walk(MirDirection dir)
  98. {
  99. if (!CanMove) return false;
  100. Point location = Functions.PointMove(CurrentLocation, dir, 1);
  101. if (!CurrentMap.ValidPoint(location)) return false;
  102. Cell cell = CurrentMap.GetCell(location);
  103. if (cell.Objects != null)
  104. for (int i = 0; i < cell.Objects.Count; i++)
  105. {
  106. MapObject ob = cell.Objects[i];
  107. if (AvoidFireWall && ob.Race == ObjectType.Spell)
  108. if (((SpellObject)ob).Spell == Spell.FireWall) return false;
  109. if (!ob.Blocking) continue;
  110. return false;
  111. }
  112. CurrentMap.GetCell(CurrentLocation).Remove(this);
  113. Direction = dir;
  114. RemoveObjects(dir, 1);
  115. CurrentLocation = location;
  116. CurrentMap.GetCell(CurrentLocation).Add(this);
  117. AddObjects(dir, 1);
  118. if (Hidden)
  119. {
  120. RemoveBuff(BuffType.Hiding);
  121. }
  122. CellTime = Envir.Time + 500;
  123. ActionTime = Envir.Time + 300;
  124. MoveTime = Envir.Time + MoveSpeed;
  125. if (MoveTime > AttackTime)
  126. AttackTime = MoveTime;
  127. InSafeZone = CurrentMap.GetSafeZone(CurrentLocation) != null;
  128. Broadcast(new S.ObjectWalk { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  129. cell = CurrentMap.GetCell(CurrentLocation);
  130. for (int i = 0; i < cell.Objects.Count; i++)
  131. {
  132. if (cell.Objects[i].Race != ObjectType.Spell) continue;
  133. SpellObject ob = (SpellObject)cell.Objects[i];
  134. ob.ProcessSpell(this);
  135. //break;
  136. }
  137. return true;
  138. }
  139. public override Packet GetInfo()
  140. {
  141. var packet = (S.ObjectMonster)base.GetInfo();
  142. packet.Extra = Stoned;
  143. return packet;
  144. }
  145. }
  146. }