TaoistHero.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using Server.MirDatabase;
  2. namespace Server.MirObjects
  3. {
  4. public class TaoistHero : HeroObject
  5. {
  6. public TaoistHero(CharacterInfo info, PlayerObject owner) : base(info, owner) { }
  7. protected override bool InAttackRange()
  8. {
  9. if (Target.CurrentMap != CurrentMap) return false;
  10. if (HasRangedSpell && CanCast)
  11. return TargetDistance <= ViewRange;
  12. return Target.CurrentLocation != CurrentLocation && Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  13. }
  14. protected override void ProcessFriend()
  15. {
  16. if (!CanCast) return;
  17. UserMagic magic;
  18. List<MapObject> TargetList = new List<MapObject>()
  19. {
  20. this,
  21. Owner
  22. };
  23. for (int i = 0; i < TargetList.Count; i++)
  24. {
  25. MapObject target = TargetList[i];
  26. if (target.Dead) continue;
  27. MirDirection direction = Functions.DirectionFromPoint(CurrentLocation, target.CurrentLocation);
  28. if (target.Buffs.Any(b => b.Properties.HasFlag(BuffProperty.Debuff)) || target.PoisonList.Count > 0)
  29. {
  30. magic = GetMagic(Spell.Purification);
  31. if (CanUseMagic(magic))
  32. {
  33. BeginMagic(magic.Spell, direction, target.ObjectID, target.CurrentLocation);
  34. return;
  35. }
  36. }
  37. if (target.PercentHealth < 90)
  38. {
  39. magic = GetMagic(Spell.MassHealing);
  40. if (CanUseMagic(magic))
  41. {
  42. BeginMagic(magic.Spell, direction, target.ObjectID, target.CurrentLocation);
  43. return;
  44. }
  45. magic = GetMagic(Spell.Healing);
  46. if (CanUseMagic(magic))
  47. {
  48. BeginMagic(magic.Spell, direction, target.ObjectID, target.CurrentLocation);
  49. return;
  50. }
  51. }
  52. UserItem item = GetAmulet(1);
  53. if (Target != null)
  54. {
  55. magic = GetMagic(Spell.SoulShield);
  56. if (CanUseMagic(magic) && item != null && !target.HasBuff(BuffType.SoulShield))
  57. {
  58. BeginMagic(magic.Spell, direction, target.ObjectID, target.CurrentLocation);
  59. return;
  60. }
  61. magic = GetMagic(Spell.BlessedArmour);
  62. if (CanUseMagic(magic) && item != null && !target.HasBuff(BuffType.BlessedArmour))
  63. {
  64. BeginMagic(magic.Spell, direction, target.ObjectID, target.CurrentLocation);
  65. return;
  66. }
  67. magic = GetMagic(Spell.UltimateEnhancer);
  68. if (CanUseMagic(magic) && item != null && !target.HasBuff(BuffType.UltimateEnhancer))
  69. {
  70. BeginMagic(magic.Spell, direction, target.ObjectID, target.CurrentLocation);
  71. return;
  72. }
  73. }
  74. }
  75. magic = GetMagic(Spell.None);
  76. {
  77. return;
  78. }
  79. }
  80. protected override void ProcessAttack()
  81. {
  82. if (Target == null || Target.Dead) return;
  83. TargetDistance = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  84. if (!CanCast) return;
  85. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  86. UserMagic magic;
  87. UserItem amuletItem = GetAmulet(1);
  88. UserItem poisonItem = GetPoison(1);
  89. if (InAttackRange())
  90. {
  91. magic = GetMagic(Spell.Poisoning);
  92. if (CanUseMagic(magic) && poisonItem != null)
  93. {
  94. if ((poisonItem.Info.Shape == 1 && !Target.PoisonList.Any(p => p.PType == PoisonType.Green)) || (poisonItem.Info.Shape == 2 && !Target.PoisonList.Any(p => p.PType == PoisonType.Red)))
  95. {
  96. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  97. return;
  98. }
  99. }
  100. magic = GetMagic(Spell.Curse);
  101. if (CanUseMagic(magic) && !Target.HasBuff(BuffType.Curse) && amuletItem != null)
  102. {
  103. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  104. return;
  105. }
  106. if (Target.AutoRev == false && Envir.Time > Target.RevTime)
  107. {
  108. magic = GetMagic(Spell.Revelation);
  109. if (CanUseMagic(magic) && amuletItem != null)
  110. {
  111. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  112. return;
  113. }
  114. }
  115. magic = GetMagic(Spell.SoulFireBall);
  116. if (CanUseMagic(magic) && amuletItem != null)
  117. {
  118. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  119. return;
  120. }
  121. magic = GetMagic(Spell.None);
  122. {
  123. return;
  124. }
  125. }
  126. magic = GetMagic(Spell.None);
  127. {
  128. return;
  129. }
  130. }
  131. protected override void ProcessTarget()
  132. {
  133. if (Target != null && Owner.PMode == PetMode.FocusMasterTarget && !Target.IsAttackTarget(Owner))
  134. {
  135. Target = null;
  136. return;
  137. }
  138. if (CanMove && ((!CanCast || NextMagicSpell == Spell.None) && Owner.Info.HeroBehaviour == HeroBehaviour.CounterAttack))
  139. {
  140. MoveTo(Owner.Back);
  141. return;
  142. }
  143. if (CanCast && NextMagicSpell != Spell.None)
  144. {
  145. if (Target != Owner && !CanAttack) return;
  146. Magic(NextMagicSpell, NextMagicDirection, NextMagicTargetID, NextMagicLocation);
  147. NextMagicSpell = Spell.None;
  148. }
  149. if (Target == null || !CanAttack) return;
  150. if (CanAttack && (!HasRangedSpell && InAttackRange() || NextMagicSpell == Spell.None && Owner.Info.HeroBehaviour == HeroBehaviour.Attack && TargetDistance == 1))
  151. {
  152. Attack();
  153. if (Target != null && Target.Dead)
  154. {
  155. FindTarget();
  156. }
  157. return;
  158. }
  159. if (CanMove && (!HasRangedSpell || NextMagicSpell == Spell.None && Owner.Info.HeroBehaviour == HeroBehaviour.Attack && TargetDistance > 1))
  160. MoveTo(Target.CurrentLocation);
  161. }
  162. private bool HasRangedSpell => Info.Magics.Select(x => x.Spell).Intersect(Globals.RangedSpells).Any();
  163. }
  164. }