VampireSpider.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 VampireSpider : MonsterObject
  8. {
  9. public bool Summoned;
  10. public long AliveTime;
  11. public long deadTime;
  12. protected internal VampireSpider(MonsterInfo info) : base(info)
  13. {
  14. ActionTime = Envir.Time + 1000;
  15. }
  16. public override string Name
  17. {
  18. get { return Master == null ? Info.GameName : (Dead ? Info.GameName : string.Format("{0}({1})", Info.GameName, Master.Name)); }
  19. set { throw new NotSupportedException(); }
  20. }
  21. public override void Process()
  22. {
  23. if (!Dead && Summoned)
  24. {
  25. if (Master != null)
  26. {
  27. bool selfDestruct = false;
  28. if (FindObject(Master.ObjectID, 15) == null) selfDestruct = true;
  29. if (Summoned && Envir.Time > AliveTime) selfDestruct = true;
  30. if (selfDestruct && Master != null) Die();
  31. }
  32. }
  33. base.Process();
  34. }
  35. public override void Process(DelayedAction action)
  36. {
  37. switch (action.Type)
  38. {
  39. case DelayedType.Damage:
  40. CompleteAttack(action.Params);
  41. break;
  42. case DelayedType.RangeDamage:
  43. CompleteRangeAttack(action.Params);
  44. break;
  45. case DelayedType.Recall:
  46. PetRecall((MapObject)action.Params[0]);
  47. break;
  48. }
  49. }
  50. public void PetRecall(MapObject target)
  51. {
  52. if (target == null) return;
  53. if (Master == null) return;
  54. Teleport(Master.CurrentMap, target.CurrentLocation);
  55. }
  56. protected override void ProcessAI()
  57. {
  58. if (Dead) return;
  59. ProcessSearch();
  60. //todo ProcessRoaming(); needs no master follow just target roaming
  61. ProcessTarget();
  62. }
  63. public override void Die()
  64. {
  65. base.Die();
  66. //Explosion
  67. for (int y = CurrentLocation.Y - 1; y <= CurrentLocation.Y + 1; y++)
  68. {
  69. if (y < 0) continue;
  70. if (y >= CurrentMap.Height) break;
  71. for (int x = CurrentLocation.X - 1; x <= CurrentLocation.X + 1; x++)
  72. {
  73. if (x < 0) continue;
  74. if (x >= CurrentMap.Width) break;
  75. Cell cell = CurrentMap.GetCell(x, y);
  76. if (!cell.Valid || cell.Objects == null) continue;
  77. for (int i = 0; i < cell.Objects.Count; i++)
  78. {
  79. MapObject target = cell.Objects[i];
  80. switch (target.Race)
  81. {
  82. case ObjectType.Monster:
  83. case ObjectType.Player:
  84. //Only targets
  85. if (!target.IsAttackTarget(this) || target.Dead) break;
  86. int value = target.Attacked(this,10*PetLevel,DefenceType.MACAgility);
  87. if (value <= 0) break;
  88. if (Master != null) MasterVampire(value, target);
  89. break;
  90. }
  91. }
  92. }
  93. }
  94. }
  95. protected override bool InAttackRange()
  96. {
  97. if (Target.CurrentMap != CurrentMap) return false;
  98. if (Target.CurrentLocation == CurrentLocation) return false;
  99. int x = Math.Abs(Target.CurrentLocation.X - CurrentLocation.X);
  100. int y = Math.Abs(Target.CurrentLocation.Y - CurrentLocation.Y);
  101. if (x > 1 || y > 1) return false;
  102. return (x <= 1 && y <= 1) || (x == y || x % 2 == y % 2);
  103. }
  104. protected override void Attack()
  105. {
  106. if (!Target.IsAttackTarget(this))
  107. {
  108. Target = null;
  109. return;
  110. }
  111. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  112. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  113. AttackLogic();
  114. ActionTime = Envir.Time + 300;
  115. AttackTime = Envir.Time + AttackSpeed;
  116. ShockTime = 0;
  117. if (Target.Dead) FindTarget();
  118. }
  119. private void AttackLogic()
  120. {
  121. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  122. if (damage == 0) return;
  123. Point target = Functions.PointMove(CurrentLocation, Direction, 1);
  124. int value;
  125. if (target == Target.CurrentLocation)
  126. {
  127. value = Target.Attacked(this, damage, DefenceType.MACAgility);
  128. if (value > 0 && Master != null) MasterVampire(value, Target);
  129. }
  130. else
  131. {
  132. if (!CurrentMap.ValidPoint(target)) return;
  133. Cell cell = CurrentMap.GetCell(target);
  134. if (cell.Objects == null) return;
  135. for (int o = 0; o < cell.Objects.Count; o++)
  136. {
  137. MapObject ob = cell.Objects[o];
  138. if (ob.Race == ObjectType.Monster || ob.Race == ObjectType.Player)
  139. {
  140. if (!ob.IsAttackTarget(this)) continue;
  141. value = ob.Attacked(this, damage, DefenceType.MACAgility);
  142. if (value > 0 && Master != null) MasterVampire(value, ob);
  143. }
  144. else continue;
  145. break;
  146. }
  147. }
  148. }
  149. private void MasterVampire(int value, MapObject ob)
  150. {
  151. if (Master == null) return;
  152. if (Master.VampAmount == 0) ((PlayerObject)Master).VampTime = Envir.Time + 1000;
  153. Master.VampAmount += (ushort)(value * (PetLevel + 1) * 0.25F);
  154. ob.Broadcast(new S.ObjectEffect { ObjectID = ob.ObjectID, Effect = SpellEffect.Bleeding, EffectType = 0 });
  155. }
  156. public override void Spawned()
  157. {
  158. base.Spawned();
  159. Summoned = true;
  160. }
  161. public override Packet GetInfo()
  162. {
  163. var packet = (S.ObjectMonster)base.GetInfo();
  164. packet.Image = Monster.VampireSpider;
  165. packet.Extra = Summoned;
  166. return packet;
  167. }
  168. }
  169. }