PowerBead.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 PowerBead : MonsterObject
  8. {
  9. public bool Summoned;
  10. protected internal PowerBead(MonsterInfo info)
  11. : base(info)
  12. {
  13. }
  14. protected override bool CanMove
  15. {
  16. get { return false; }
  17. }
  18. public override void Turn(MirDirection dir) { }
  19. public override void Spawned()
  20. {
  21. base.Spawned();
  22. Summoned = true;
  23. }
  24. protected override void ProcessSearch()
  25. {
  26. if (Envir.Time < SearchTime) return;
  27. if (Master != null && (Master.PMode == PetMode.MoveOnly || Master.PMode == PetMode.None || Master.PMode == PetMode.FocusMasterTarget)) return;
  28. SearchTime = Envir.Time + SearchDelay;
  29. if (Info.Effect == 0)
  30. {
  31. var targets = FindAllTargets(Info.ViewRange, CurrentLocation);
  32. if (targets.Count > 0)
  33. {
  34. Target = targets[Envir.Random.Next(targets.Count)];
  35. }
  36. }
  37. else if (Info.Effect == 1 || Info.Effect == 2)
  38. {
  39. if (Owner == null)
  40. {
  41. var friends = FindAllFriends(Info.ViewRange, CurrentLocation, true, false);
  42. if (friends.Count > 0)
  43. {
  44. Target = friends[Envir.Random.Next(friends.Count)];
  45. }
  46. }
  47. else
  48. {
  49. Target = Owner;
  50. }
  51. }
  52. }
  53. protected override void ProcessTarget()
  54. {
  55. if (Target == null || !CanAttack) return;
  56. if (Info.Effect == 0 && !Target.IsAttackTarget(this))
  57. {
  58. return;
  59. }
  60. else if ((Info.Effect == 1 || Info.Effect == 2) && !Target.IsFriendlyTarget(this))
  61. {
  62. return;
  63. }
  64. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 0 });
  65. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 300, Target);
  66. ActionList.Add(action);
  67. ActionTime = Envir.Time + 300;
  68. AttackTime = Envir.Time + AttackSpeed;
  69. ShockTime = 0;
  70. }
  71. protected override void CompleteRangeAttack(IList<object> data)
  72. {
  73. MapObject target = (MapObject)data[0];
  74. if (target == null || target.CurrentMap != CurrentMap || target.Node == null) return;
  75. if (Info.Effect == 0)
  76. {
  77. if (target.IsAttackTarget(this))
  78. {
  79. var damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  80. if (damage == 0) return;
  81. target.Attacked(this, damage, DefenceType.MACAgility);
  82. }
  83. }
  84. else if (Info.Effect == 1)
  85. {
  86. if (target.IsFriendlyTarget(this))
  87. {
  88. for (int i = 0; i < target.Buffs.Count; i++)
  89. {
  90. var buff = target.Buffs[i];
  91. if (!buff.Properties.HasFlag(BuffProperty.Debuff)) continue;
  92. target.RemoveBuff(buff.Type);
  93. }
  94. if (target.PoisonList.Count == 0) return;
  95. if (target.PoisonList.Any(x => x.PType == PoisonType.DelayedExplosion))
  96. {
  97. target.ExplosionInflictedTime = 0;
  98. target.ExplosionInflictedStage = 0;
  99. target.Broadcast(new S.RemoveDelayedExplosion { ObjectID = target.ObjectID });
  100. }
  101. target.PoisonList.Clear();
  102. target.OperateTime = 0;
  103. }
  104. }
  105. else if (Info.Effect == 2)
  106. {
  107. if (target.IsFriendlyTarget(this))
  108. {
  109. var protect = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  110. if (protect == 0) return;
  111. target.AddBuff(BuffType.PowerBeadBuff, this, Info.AttackSpeed, new Stats { [Stat.MaxAC] = protect, [Stat.MaxMAC] = protect });
  112. target.OperateTime = 0;
  113. }
  114. }
  115. }
  116. public override Packet GetInfo()
  117. {
  118. var packet = (S.ObjectMonster)base.GetInfo();
  119. packet.Extra = Summoned;
  120. return packet;
  121. }
  122. public static bool SpawnRandom(MonsterObject owner, Point spawn)
  123. {
  124. var beads = Envir.MonsterInfoList.Where(x => x.AI == 149).ToList();
  125. if (beads.Count > 0)
  126. {
  127. var randomBead = beads[Envir.Random.Next(beads.Count)];
  128. var mob = GetMonster(Envir.GetMonsterInfo(randomBead.Name));
  129. if (mob.Spawn(owner.CurrentMap, spawn))
  130. {
  131. owner.SlaveList.Add(mob);
  132. return true;
  133. }
  134. }
  135. return false;
  136. }
  137. }
  138. }