WizardHero.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using Server.MirDatabase;
  2. namespace Server.MirObjects
  3. {
  4. public class WizardHero : HeroObject
  5. {
  6. public WizardHero(CharacterInfo info, PlayerObject owner) : base(info, owner) { }
  7. public int SurroundedCount;
  8. public int TargetSurroundedCount;
  9. protected override bool InAttackRange()
  10. {
  11. if (Target.CurrentMap != CurrentMap) return false;
  12. if (HasRangedSpell && CanCast)
  13. return TargetDistance <= ViewRange;
  14. return Target.CurrentLocation != CurrentLocation && Functions.InRange(CurrentLocation, Target.CurrentLocation, 1);
  15. }
  16. protected override void ProcessFriend()
  17. {
  18. if (!CanCast) return;
  19. if (Target != null)
  20. {
  21. UserMagic magic = GetMagic(Spell.MagicShield);
  22. if (CanUseMagic(magic) && !HasBuff(BuffType.MagicShield))
  23. {
  24. BeginMagic(magic.Spell, Direction, ObjectID, CurrentLocation);
  25. return;
  26. }
  27. magic = GetMagic(Spell.MagicBooster);
  28. if (CanUseMagic(magic) && !HasBuff(BuffType.MagicBooster))
  29. {
  30. BeginMagic(magic.Spell, Direction, ObjectID, CurrentLocation);
  31. return;
  32. }
  33. }
  34. }
  35. protected override void ProcessAttack()
  36. {
  37. if (!CanCast || Target == null || Target.Dead) return;
  38. TargetDistance = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  39. SurroundedCount = FindAllTargets(2, CurrentLocation).Count;
  40. TargetSurroundedCount = FindAllTargets(1, Target.CurrentLocation).Count;
  41. if (!HasRangedSpell) return;
  42. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  43. UserMagic magic;
  44. if (InAttackRange())
  45. {
  46. if (TargetDistance == 1)
  47. {
  48. if (Target.Level < Level)
  49. {
  50. magic = GetMagic(Spell.Repulsion);
  51. if (CanUseMagic(magic))
  52. {
  53. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  54. return;
  55. }
  56. }
  57. }
  58. if (TargetDistance < 3 && SurroundedCount > 1)
  59. {
  60. magic = GetMagic(Spell.FlameField);
  61. if (CanUseMagic(magic))
  62. {
  63. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  64. return;
  65. }
  66. magic = GetMagic(Spell.ThunderStorm);
  67. if (CanUseMagic(magic))
  68. {
  69. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  70. return;
  71. }
  72. }
  73. if (TargetSurroundedCount > 1)
  74. {
  75. magic = GetMagic(Spell.IceStorm);
  76. if (CanUseMagic(magic))
  77. {
  78. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  79. return;
  80. }
  81. magic = GetMagic(Spell.FireBang);
  82. if (CanUseMagic(magic))
  83. {
  84. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  85. return;
  86. }
  87. }
  88. if (Target.Undead == true && Target.Level < Level)
  89. {
  90. magic = GetMagic(Spell.TurnUndead);
  91. if (CanUseMagic(magic))
  92. {
  93. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  94. return;
  95. }
  96. }
  97. magic = GetMagic(Spell.FlameDisruptor);
  98. if (CanUseMagic(magic))
  99. {
  100. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  101. return;
  102. }
  103. magic = GetMagic(Spell.Vampirism);
  104. if (CanUseMagic(magic))
  105. {
  106. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  107. return;
  108. }
  109. magic = GetMagic(Spell.FrostCrunch);
  110. if (CanUseMagic(magic))
  111. {
  112. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  113. return;
  114. }
  115. magic = GetMagic(Spell.ThunderBolt);
  116. if (CanUseMagic(magic))
  117. {
  118. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  119. return;
  120. }
  121. magic = GetMagic(Spell.GreatFireBall);
  122. if (CanUseMagic(magic))
  123. {
  124. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  125. return;
  126. }
  127. magic = GetMagic(Spell.FireBall);
  128. if (CanUseMagic(magic))
  129. {
  130. BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation);
  131. return;
  132. }
  133. magic = GetMagic(Spell.None);
  134. {
  135. return;
  136. }
  137. }
  138. magic = GetMagic(Spell.None);
  139. {
  140. return;
  141. }
  142. }
  143. protected override void ProcessTarget()
  144. {
  145. if (Target != null && Owner.PMode == PetMode.FocusMasterTarget && !Target.IsAttackTarget(Owner))
  146. {
  147. Target = null;
  148. return;
  149. }
  150. if (CanMove && ((!CanCast || NextMagicSpell == Spell.None) && Owner.Info.HeroBehaviour == HeroBehaviour.CounterAttack))
  151. {
  152. MoveTo(Owner.Back);
  153. return;
  154. }
  155. if (Target == null || !CanAttack) return;
  156. if (CanCast && NextMagicSpell != Spell.None)
  157. {
  158. Magic(NextMagicSpell, NextMagicDirection, NextMagicTargetID, NextMagicLocation);
  159. NextMagicSpell = Spell.None;
  160. }
  161. if (CanAttack && (!HasRangedSpell && InAttackRange() || NextMagicSpell == Spell.None && Owner.Info.HeroBehaviour == HeroBehaviour.Attack && TargetDistance == 1))
  162. {
  163. Attack();
  164. if (Target != null && Target.Dead)
  165. {
  166. FindTarget();
  167. }
  168. return;
  169. }
  170. if (CanMove && (!HasRangedSpell || NextMagicSpell == Spell.None && Owner.Info.HeroBehaviour == HeroBehaviour.Attack && TargetDistance > 1))
  171. MoveTo(Target.CurrentLocation);
  172. }
  173. private bool HasRangedSpell => Info.Magics.Select(x => x.Spell).Intersect(Globals.RangedSpells).Any();
  174. }
  175. }