SepHighWizard.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using System.Collections.Generic;
  2. using System.Drawing;
  3. using Server.MirDatabase;
  4. using Server.MirEnvir;
  5. using S = ServerPackets;
  6. namespace Server.MirObjects.Monsters
  7. {
  8. public class SepHighWizard : MonsterObject
  9. {
  10. public long FearTime, DecreaseMPTime, RepulsionTime;
  11. public byte AttackRange = 5;
  12. public bool Summoned;
  13. protected internal SepHighWizard(MonsterInfo info)
  14. : base(info)
  15. {
  16. }
  17. protected override bool InAttackRange()
  18. {
  19. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, Info.ViewRange);
  20. }
  21. protected override void Attack()
  22. {
  23. if (!Target.IsAttackTarget(this))
  24. {
  25. Target = null;
  26. return;
  27. }
  28. ShockTime = 0;
  29. ActionTime = Envir.Time + 300;
  30. AttackTime = Envir.Time + AttackSpeed;
  31. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  32. if (damage == 0) return;
  33. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  34. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  35. List<MapObject> targets = FindAllTargets(1, CurrentLocation, false);
  36. if (targets.Count > 0 && Envir.Time > RepulsionTime)
  37. {
  38. for (int i = 0; i < targets.Count; i++)
  39. {
  40. if (targets[i].IsAttackTarget(this) && targets[i].Level < Level)
  41. targets[i].Pushed(this, Functions.DirectionFromPoint(targets[i].CurrentLocation, targets[i].Back), 4);
  42. }
  43. RepulsionTime = Envir.Time + Settings.Second * Envir.Random.Next(10, 30);
  44. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.Repulsion, Cast = true, Level = 3 });
  45. return;
  46. }
  47. if (Functions.InRange(CurrentLocation, Target.CurrentLocation, 2) && Envir.Random.Next(3) == 0)
  48. {
  49. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.FlameField, TargetID = Target.ObjectID, Target = Target.CurrentLocation });
  50. ProjectileAttack(damage);
  51. return;
  52. }
  53. if (Envir.Random.Next(3) == 0)
  54. {
  55. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.FireBang, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  56. ProjectileAttack(damage);
  57. return;
  58. }
  59. if (PercentHealth <= 80 && Envir.Random.Next(4) == 0)
  60. {
  61. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.Vampirism, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  62. ProjectileAttack(damage);
  63. return;
  64. }
  65. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.GreatFireBall, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  66. SinglePushAttack(damage);
  67. if (Target.Dead)
  68. FindTarget();
  69. }
  70. protected override void ProcessTarget()
  71. {
  72. if (Target == null || !CanAttack) return;
  73. if (!InAttackRange())
  74. {
  75. if (CurrentLocation == Target.CurrentLocation)
  76. {
  77. MirDirection direction = (MirDirection)Envir.Random.Next(8);
  78. int rotation = Envir.Random.Next(2) == 0 ? 1 : -1;
  79. for (int d = 0; d < 8; d++)
  80. {
  81. if (Walk(direction)) break;
  82. direction = Functions.ShiftDirection(direction, rotation);
  83. }
  84. }
  85. else
  86. MoveTo(Target.CurrentLocation);
  87. }
  88. if (!CanAttack) return;
  89. if (InAttackRange() && Envir.Time < FearTime)
  90. {
  91. Attack();
  92. return;
  93. }
  94. FearTime = Envir.Time + 5000;
  95. if (Envir.Time < ShockTime)
  96. {
  97. Target = null;
  98. return;
  99. }
  100. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  101. if (dist < AttackRange)
  102. {
  103. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  104. if (Walk(dir)) return;
  105. switch (Envir.Random.Next(2)) //No favour
  106. {
  107. case 0:
  108. for (int i = 0; i < 7; i++)
  109. {
  110. dir = Functions.NextDir(dir);
  111. if (Walk(dir))
  112. return;
  113. }
  114. break;
  115. default:
  116. for (int i = 0; i < 7; i++)
  117. {
  118. dir = Functions.PreviousDir(dir);
  119. if (Walk(dir))
  120. return;
  121. }
  122. break;
  123. }
  124. }
  125. }
  126. public bool Walk(MirDirection dir, bool br = false)
  127. {
  128. if (!CanMove) return false;
  129. var temploc = Functions.PointMove(CurrentLocation, dir, 1);
  130. if (!CurrentMap.ValidPoint(temploc)) return false;
  131. var cell = CurrentMap.GetCell(temploc);
  132. if (cell.Objects != null)
  133. for (int i = 0; i < cell.Objects.Count; i++)
  134. {
  135. MapObject ob = cell.Objects[i];
  136. if (!ob.Blocking) continue;
  137. return false;
  138. }
  139. Point location = Functions.PointMove(CurrentLocation, dir, 2);
  140. if (!CurrentMap.ValidPoint(location)) return false;
  141. cell = CurrentMap.GetCell(location);
  142. bool isBreak = br;
  143. if (cell.Objects != null)
  144. for (int i = 0; i < cell.Objects.Count; i++)
  145. {
  146. MapObject ob = cell.Objects[i];
  147. if (!ob.Blocking) continue;
  148. isBreak = true;
  149. break;
  150. }
  151. if (isBreak)
  152. {
  153. location = Functions.PointMove(CurrentLocation, dir, 1);
  154. if (!CurrentMap.ValidPoint(location)) return false;
  155. cell = CurrentMap.GetCell(location);
  156. if (cell.Objects != null)
  157. for (int i = 0; i < cell.Objects.Count; i++)
  158. {
  159. MapObject ob = cell.Objects[i];
  160. if (!ob.Blocking) continue;
  161. return false;
  162. }
  163. }
  164. CurrentMap.GetCell(CurrentLocation).Remove(this);
  165. Direction = dir;
  166. RemoveObjects(dir, 1);
  167. CurrentLocation = location;
  168. CurrentMap.GetCell(CurrentLocation).Add(this);
  169. AddObjects(dir, 1);
  170. if (Hidden)
  171. {
  172. Hidden = false;
  173. for (int i = 0; i < Buffs.Count; i++)
  174. {
  175. if (Buffs[i].Type != BuffType.Hiding) continue;
  176. Buffs[i].ExpireTime = 0;
  177. break;
  178. }
  179. }
  180. CellTime = Envir.Time + 500;
  181. ActionTime = Envir.Time + 300;
  182. MoveTime = Envir.Time + MoveSpeed;
  183. if (MoveTime > AttackTime)
  184. AttackTime = MoveTime;
  185. InSafeZone = CurrentMap.GetSafeZone(CurrentLocation) != null;
  186. if (isBreak)
  187. Broadcast(new S.ObjectWalk { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  188. else
  189. Broadcast(new S.ObjectRun { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  190. cell = CurrentMap.GetCell(CurrentLocation);
  191. for (int i = 0; i < cell.Objects.Count; i++)
  192. {
  193. if (cell.Objects[i].Race != ObjectType.Spell) continue;
  194. SpellObject ob = (SpellObject)cell.Objects[i];
  195. ob.ProcessSpell(this);
  196. //break;
  197. }
  198. return true;
  199. }
  200. public override void Die()
  201. {
  202. if (Dead) return;
  203. HP = 0;
  204. Dead = true;
  205. DeadTime = 0;
  206. Broadcast(new S.ObjectDied { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = (byte)(Master != null ? 1 : 0) });
  207. if (EXPOwner != null && Master == null && EXPOwner.Race == ObjectType.Player) EXPOwner.WinExp(Experience, Level);
  208. if (Respawn != null)
  209. Respawn.Count--;
  210. if (Master == null)
  211. Drop();
  212. Master = null;
  213. PoisonList.Clear();
  214. Envir.MonsterCount--;
  215. if (CurrentMap != null)
  216. CurrentMap.MonsterCount--;
  217. }
  218. public override Packet GetInfo()
  219. {
  220. PlayerObject master = null;
  221. short weapon = -1;
  222. short armour = 0;
  223. byte wing = 0;
  224. if (Master != null && Master is PlayerObject) master = (PlayerObject)Master;
  225. if (master != null)
  226. {
  227. weapon = master.Looks_Weapon;
  228. armour = master.Looks_Armour;
  229. wing = master.Looks_Wings;
  230. }
  231. return new S.ObjectPlayer
  232. {
  233. ObjectID = ObjectID,
  234. Name = master != null ? master.Name : Name,
  235. NameColour = NameColour,
  236. Class = MirClass.Wizard,
  237. Gender = master != null ? master.Gender : Envir.Random.Next(2) == 0 ? MirGender.Male : MirGender.Female,
  238. Location = CurrentLocation,
  239. Direction = Direction,
  240. Hair = master != null ? master.Hair : (byte)Envir.Random.Next(0, 5),
  241. Weapon = 54,
  242. Armour = 32,
  243. Light = master != null ? master.Light : Light,
  244. Poison = CurrentPoison,
  245. Dead = Dead,
  246. Hidden = Hidden,
  247. Effect = SpellEffect.None,
  248. WingEffect = wing,
  249. Extra = Summoned,
  250. TransformType = -1,
  251. };
  252. }
  253. }
  254. }