SepWizard.cs 10 KB

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