SepHighTaoist.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. using System.Drawing;
  2. using System.Linq;
  3. using Server.MirDatabase;
  4. using Server.MirEnvir;
  5. using S = ServerPackets;
  6. namespace Server.MirObjects.Monsters
  7. {
  8. public class SepHighTaoist : MonsterObject
  9. {
  10. public long FearTime, DecreaseMPTime, SummonTime;
  11. public byte AttackRange = 5;
  12. public bool Summoned;
  13. protected internal SepHighTaoist(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.MinDC], Stats[Stat.MaxDC]);
  32. if (damage == 0) return;
  33. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  34. DelayedAction action;
  35. int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
  36. if (!Target.PoisonList.Any(x => x.PType == PoisonType.Green) && !Target.PoisonList.Any(x => x.PType == PoisonType.Red))
  37. {
  38. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.Poisoning, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  39. int power = GetAttackPower(Stats[Stat.MinSC], Stats[Stat.MaxSC]);
  40. Target.ApplyPoison(new Poison
  41. {
  42. Duration = power + ((Envir.Random.Next(0, 3) + 1) * 7),
  43. Owner = this,
  44. PType = PoisonType.Green,
  45. TickSpeed = 2000,
  46. Value = power / 15 + 4
  47. }, this);
  48. return;
  49. }
  50. else if (Target.PoisonList.Any(x => x.PType == PoisonType.Green) && !Target.PoisonList.Any(x => x.PType == PoisonType.Red))
  51. {
  52. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.Poisoning, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  53. int power = GetAttackPower(Stats[Stat.MinSC], Stats[Stat.MaxSC]);
  54. Target.ApplyPoison(new Poison
  55. {
  56. Duration = power + ((Envir.Random.Next(0, 3) + 1) * 7),
  57. Owner = this,
  58. PType = PoisonType.Red,
  59. TickSpeed = 2000,
  60. }, this);
  61. return;
  62. }
  63. else if (!Target.PoisonList.Any(x => x.PType == PoisonType.Green) && Target.PoisonList.Any(x => x.PType == PoisonType.Red))
  64. {
  65. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.Poisoning, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  66. int power = GetAttackPower(Stats[Stat.MinSC], Stats[Stat.MaxSC]);
  67. Target.ApplyPoison(new Poison
  68. {
  69. Duration = power + ((Envir.Random.Next(0, 3) + 1) * 7),
  70. Owner = this,
  71. PType = PoisonType.Green,
  72. TickSpeed = 2000,
  73. }, this);
  74. return;
  75. }
  76. if (!Target.Buffs.Any(e => e.Type == BuffType.Curse) && Envir.Random.Next(8) == 0)
  77. {
  78. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.Curse, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  79. PoisonTarget(Target, 1, 5, PoisonType.Slow, 1000);
  80. return;
  81. }
  82. if (PercentHealth <= 90 && Envir.Random.Next(8) == 0)
  83. {
  84. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.MassHealing, TargetID = ObjectID, Target = CurrentLocation, Cast = true, Level = 3 });
  85. TriangleAttack(damage, 2, 1, 800);
  86. return;
  87. }
  88. if (Pets.Count < 1)
  89. {
  90. MonsterObject monster;
  91. MonsterInfo info = Envir.GetMonsterInfo(Settings.ShinsuName);
  92. if (info == null) return;
  93. monster = MonsterObject.GetMonster(info);
  94. monster.PetLevel = 3;
  95. monster.Master = this;
  96. monster.MaxPetLevel = 7;
  97. monster.Direction = Direction;
  98. monster.ActionTime = Envir.Time + 1000;
  99. monster.Target = Target;
  100. Pets.Add(monster);
  101. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.SummonShinsu, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  102. action = new DelayedAction(DelayedType.Spawn, Envir.Time + 1000, monster, Front);
  103. CurrentMap.ActionList.Add(action);
  104. return;
  105. }
  106. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.SoulFireBall, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  107. HalfmoonAttack(damage);
  108. if (Target.Dead)
  109. FindTarget();
  110. }
  111. protected override void ProcessTarget()
  112. {
  113. if (Target == null || !CanAttack) return;
  114. if (!InAttackRange())
  115. {
  116. if (CurrentLocation == Target.CurrentLocation)
  117. {
  118. MirDirection direction = (MirDirection)Envir.Random.Next(8);
  119. int rotation = Envir.Random.Next(2) == 0 ? 1 : -1;
  120. for (int d = 0; d < 8; d++)
  121. {
  122. if (Walk(direction)) break;
  123. direction = Functions.ShiftDirection(direction, rotation);
  124. }
  125. }
  126. else
  127. MoveTo(Target.CurrentLocation);
  128. }
  129. if (!CanAttack) return;
  130. if (InAttackRange() && Envir.Time < FearTime)
  131. {
  132. Attack();
  133. return;
  134. }
  135. FearTime = Envir.Time + 5000;
  136. if (Envir.Time < ShockTime)
  137. {
  138. Target = null;
  139. return;
  140. }
  141. int dist = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation);
  142. if (dist < AttackRange)
  143. {
  144. MirDirection dir = Functions.DirectionFromPoint(Target.CurrentLocation, CurrentLocation);
  145. if (Walk(dir)) return;
  146. switch (Envir.Random.Next(2)) //No favour
  147. {
  148. case 0:
  149. for (int i = 0; i < 7; i++)
  150. {
  151. dir = Functions.NextDir(dir);
  152. if (Walk(dir))
  153. return;
  154. }
  155. break;
  156. default:
  157. for (int i = 0; i < 7; i++)
  158. {
  159. dir = Functions.PreviousDir(dir);
  160. if (Walk(dir))
  161. return;
  162. }
  163. break;
  164. }
  165. }
  166. }
  167. public bool Walk(MirDirection dir, bool br = false)
  168. {
  169. if (!CanMove) return false;
  170. var temploc = Functions.PointMove(CurrentLocation, dir, 1);
  171. if (!CurrentMap.ValidPoint(temploc)) return false;
  172. var cell = CurrentMap.GetCell(temploc);
  173. if (cell.Objects != null)
  174. for (int i = 0; i < cell.Objects.Count; i++)
  175. {
  176. MapObject ob = cell.Objects[i];
  177. if (!ob.Blocking) continue;
  178. return false;
  179. }
  180. Point location = Functions.PointMove(CurrentLocation, dir, 2);
  181. if (!CurrentMap.ValidPoint(location)) return false;
  182. cell = CurrentMap.GetCell(location);
  183. bool isBreak = br;
  184. if (cell.Objects != null)
  185. for (int i = 0; i < cell.Objects.Count; i++)
  186. {
  187. MapObject ob = cell.Objects[i];
  188. if (!ob.Blocking) continue;
  189. isBreak = true;
  190. break;
  191. }
  192. if (isBreak)
  193. {
  194. location = Functions.PointMove(CurrentLocation, dir, 1);
  195. if (!CurrentMap.ValidPoint(location)) return false;
  196. cell = CurrentMap.GetCell(location);
  197. if (cell.Objects != null)
  198. for (int i = 0; i < cell.Objects.Count; i++)
  199. {
  200. MapObject ob = cell.Objects[i];
  201. if (!ob.Blocking) continue;
  202. return false;
  203. }
  204. }
  205. CurrentMap.GetCell(CurrentLocation).Remove(this);
  206. Direction = dir;
  207. RemoveObjects(dir, 1);
  208. CurrentLocation = location;
  209. CurrentMap.GetCell(CurrentLocation).Add(this);
  210. AddObjects(dir, 1);
  211. if (Hidden)
  212. {
  213. Hidden = false;
  214. for (int i = 0; i < Buffs.Count; i++)
  215. {
  216. if (Buffs[i].Type != BuffType.Hiding) continue;
  217. Buffs[i].ExpireTime = 0;
  218. break;
  219. }
  220. }
  221. CellTime = Envir.Time + 500;
  222. ActionTime = Envir.Time + 300;
  223. MoveTime = Envir.Time + MoveSpeed;
  224. if (MoveTime > AttackTime)
  225. AttackTime = MoveTime;
  226. InSafeZone = CurrentMap.GetSafeZone(CurrentLocation) != null;
  227. if (isBreak)
  228. Broadcast(new S.ObjectWalk { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  229. else
  230. Broadcast(new S.ObjectRun { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  231. cell = CurrentMap.GetCell(CurrentLocation);
  232. for (int i = 0; i < cell.Objects.Count; i++)
  233. {
  234. if (cell.Objects[i].Race != ObjectType.Spell) continue;
  235. SpellObject ob = (SpellObject)cell.Objects[i];
  236. ob.ProcessSpell(this);
  237. //break;
  238. }
  239. return true;
  240. }
  241. public override void Die()
  242. {
  243. if (Dead) return;
  244. HP = 0;
  245. Dead = true;
  246. //DeadTime = Envir.Time + DeadDelay;
  247. DeadTime = 0;
  248. Broadcast(new S.ObjectDied { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = (byte)(Master != null ? 1 : 0) });
  249. if (EXPOwner != null && Master == null && EXPOwner.Race == ObjectType.Player) EXPOwner.WinExp(Experience, Level);
  250. if (Respawn != null)
  251. Respawn.Count--;
  252. if (Master == null)
  253. Drop();
  254. Master = null;
  255. PoisonList.Clear();
  256. Envir.MonsterCount--;
  257. if (CurrentMap != null)
  258. CurrentMap.MonsterCount--;
  259. }
  260. public override Packet GetInfo()
  261. {
  262. PlayerObject master = null;
  263. short weapon = -1;
  264. short armour = 0;
  265. byte wing = 0;
  266. if (Master != null && Master is PlayerObject) master = (PlayerObject)Master;
  267. if (master != null)
  268. {
  269. weapon = master.Looks_Weapon;
  270. armour = master.Looks_Armour;
  271. wing = master.Looks_Wings;
  272. }
  273. return new S.ObjectPlayer
  274. {
  275. ObjectID = ObjectID,
  276. Name = master != null ? master.Name : Name,
  277. NameColour = NameColour,
  278. Class = MirClass.Taoist,
  279. Gender = master != null ? master.Gender : Envir.Random.Next(1, 2) == 1 ? MirGender.Male : MirGender.Female,
  280. Location = CurrentLocation,
  281. Direction = Direction,
  282. Hair = master != null ? master.Hair : (byte)Envir.Random.Next(0, 5),
  283. Weapon = 53,
  284. Armour = 33,
  285. Light = master != null ? master.Light : Light,
  286. Poison = CurrentPoison,
  287. Dead = Dead,
  288. Hidden = Hidden,
  289. Effect = SpellEffect.None,
  290. WingEffect = wing,
  291. Extra = Summoned,
  292. TransformType = -1,
  293. };
  294. }
  295. }
  296. }