SepHighWarrior.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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 SepHighWarrior : MonsterObject
  9. {
  10. public long FearTime, DecreaseMPTime;
  11. public byte AttackRange = 1;
  12. public bool Summoned;
  13. protected internal SepHighWarrior(MonsterInfo info)
  14. : base(info)
  15. {
  16. }
  17. protected override bool InAttackRange()
  18. {
  19. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  20. }
  21. protected override void ProcessTarget()
  22. {
  23. if (Target == null) return;
  24. if (!InAttackRange())
  25. {
  26. if (CurrentLocation == Target.CurrentLocation)
  27. {
  28. MirDirection direction = (MirDirection)Envir.Random.Next(8);
  29. int rotation = Envir.Random.Next(2) == 0 ? 1 : -1;
  30. for (int d = 0; d < 8; d++)
  31. {
  32. if (Walk(direction)) break;
  33. direction = Functions.ShiftDirection(direction, rotation);
  34. }
  35. }
  36. else
  37. MoveTo(Target.CurrentLocation);
  38. }
  39. if (!CanAttack) return;
  40. if (InAttackRange())
  41. {
  42. Attack();
  43. }
  44. }
  45. protected override void Attack()
  46. {
  47. if (!Target.IsAttackTarget(this))
  48. {
  49. Target = null;
  50. return;
  51. }
  52. ShockTime = 0;
  53. ActionTime = Envir.Time + 500;
  54. AttackTime = Envir.Time + AttackSpeed;
  55. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  56. if (damage == 0) return;
  57. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  58. switch (Envir.Random.Next(5))
  59. {
  60. case 0:
  61. TwinDrakeBlade();
  62. break;
  63. case 1:
  64. CrossHalfMoon();
  65. break;
  66. case 2:
  67. BladeAvalanche();
  68. break;
  69. default:
  70. base.Attack();
  71. break;
  72. }
  73. }
  74. public void TwinDrakeBlade()
  75. {
  76. if (Target == null) return;
  77. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  78. if (damage == 0) return;
  79. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.TwinDrakeBlade });
  80. Target.Attacked(this, (int)(damage * 0.8), DefenceType.AC);
  81. ProjectileAttack((int)(damage * 0.8), DefenceType.ACAgility);
  82. if (((Target.Race != ObjectType.Player || Settings.PvpCanResistPoison) && (Envir.Random.Next(Settings.PoisonAttackWeight) >= Target.Stats[Stat.PoisonResist])) && (Target.Level <= Level + 8 && Envir.Random.Next(20) <= 5))
  83. {
  84. Target.ApplyPoison(new Poison { PType = PoisonType.Stun, Duration = 5, TickSpeed = 1000 }, this);
  85. Target.Broadcast(new S.ObjectEffect { ObjectID = Target.ObjectID, Effect = SpellEffect.TwinDrakeBlade });
  86. }
  87. }
  88. public void CrossHalfMoon()
  89. {
  90. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  91. if (damage == 0) return;
  92. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.CrossHalfMoon });
  93. List<MapObject> targets = FindAllTargets(1, CurrentLocation, false);
  94. if (targets.Count == 0) return;
  95. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  96. for (int i = 0; i < targets.Count; i++)
  97. {
  98. HalfmoonAttack(damage);
  99. }
  100. }
  101. public void BladeAvalanche()
  102. {
  103. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  104. if (damage == 0) return;
  105. Broadcast(new S.ObjectMagic { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.BladeAvalanche, TargetID = Target.ObjectID, Target = Target.CurrentLocation, Cast = true, Level = 3 });
  106. int col = 3;
  107. int row = 3;
  108. Point[] loc = new Point[col];
  109. loc[0] = Functions.PointMove(CurrentLocation, Functions.PreviousDir(Direction), 1);
  110. loc[1] = Functions.PointMove(CurrentLocation, Direction, 1);
  111. loc[2] = Functions.PointMove(CurrentLocation, Functions.NextDir(Direction), 1);
  112. for (int i = 0; i < col; i++)
  113. {
  114. Point startPoint = loc[i];
  115. for (int j = 0; j < row; j++)
  116. {
  117. Point hitPoint = Functions.PointMove(startPoint, Direction, j);
  118. if (!CurrentMap.ValidPoint(hitPoint)) continue;
  119. Cell cell = CurrentMap.GetCell(hitPoint);
  120. if (cell.Objects == null) continue;
  121. for (int k = 0; k < cell.Objects.Count; k++)
  122. {
  123. MapObject target = cell.Objects[k];
  124. switch (target.Race)
  125. {
  126. case ObjectType.Monster:
  127. case ObjectType.Player:
  128. case ObjectType.Hero:
  129. //Only targets
  130. if (target.IsAttackTarget(this))
  131. {
  132. target.Attacked(this, j <= 1 ? damage : (int)(damage * 0.6), DefenceType.MAC);
  133. }
  134. break;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. public bool Walk(MirDirection dir, bool br = false)
  141. {
  142. if (!CanMove) return false;
  143. var temploc = Functions.PointMove(CurrentLocation, dir, 1);
  144. if (!CurrentMap.ValidPoint(temploc)) return false;
  145. var cell = CurrentMap.GetCell(temploc);
  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. Point location = Functions.PointMove(CurrentLocation, dir, 2);
  154. if (!CurrentMap.ValidPoint(location)) return false;
  155. cell = CurrentMap.GetCell(location);
  156. bool isBreak = br;
  157. if (cell.Objects != null)
  158. for (int i = 0; i < cell.Objects.Count; i++)
  159. {
  160. MapObject ob = cell.Objects[i];
  161. if (!ob.Blocking) continue;
  162. isBreak = true;
  163. break;
  164. }
  165. if (isBreak)
  166. {
  167. location = Functions.PointMove(CurrentLocation, dir, 1);
  168. if (!CurrentMap.ValidPoint(location)) return false;
  169. cell = CurrentMap.GetCell(location);
  170. if (cell.Objects != null)
  171. for (int i = 0; i < cell.Objects.Count; i++)
  172. {
  173. MapObject ob = cell.Objects[i];
  174. if (!ob.Blocking) continue;
  175. return false;
  176. }
  177. }
  178. CurrentMap.GetCell(CurrentLocation).Remove(this);
  179. Direction = dir;
  180. RemoveObjects(dir, 1);
  181. CurrentLocation = location;
  182. CurrentMap.GetCell(CurrentLocation).Add(this);
  183. AddObjects(dir, 1);
  184. if (Hidden)
  185. {
  186. Hidden = false;
  187. for (int i = 0; i < Buffs.Count; i++)
  188. {
  189. if (Buffs[i].Type != BuffType.Hiding) continue;
  190. Buffs[i].ExpireTime = 0;
  191. break;
  192. }
  193. }
  194. CellTime = Envir.Time + 500;
  195. ActionTime = Envir.Time + 300;
  196. MoveTime = Envir.Time + MoveSpeed;
  197. if (MoveTime > AttackTime)
  198. AttackTime = MoveTime;
  199. InSafeZone = CurrentMap.GetSafeZone(CurrentLocation) != null;
  200. if (isBreak)
  201. Broadcast(new S.ObjectWalk { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  202. else
  203. Broadcast(new S.ObjectRun { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  204. cell = CurrentMap.GetCell(CurrentLocation);
  205. for (int i = 0; i < cell.Objects.Count; i++)
  206. {
  207. if (cell.Objects[i].Race != ObjectType.Spell) continue;
  208. SpellObject ob = (SpellObject)cell.Objects[i];
  209. ob.ProcessSpell(this);
  210. //break;
  211. }
  212. return true;
  213. }
  214. public override void Die()
  215. {
  216. if (Dead) return;
  217. HP = 0;
  218. Dead = true;
  219. //DeadTime = Envir.Time + DeadDelay;
  220. DeadTime = 0;
  221. Broadcast(new S.ObjectDied { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = (byte)(Master != null ? 1 : 0) });
  222. if (EXPOwner != null && Master == null && EXPOwner.Race == ObjectType.Player) EXPOwner.WinExp(Experience, Level);
  223. if (Respawn != null)
  224. Respawn.Count--;
  225. if (Master == null)
  226. Drop();
  227. Master = null;
  228. PoisonList.Clear();
  229. Envir.MonsterCount--;
  230. if (CurrentMap != null)
  231. CurrentMap.MonsterCount--;
  232. }
  233. public override Packet GetInfo()
  234. {
  235. PlayerObject master = null;
  236. short weapon = -1;
  237. short armour = 0;
  238. byte wing = 0;
  239. if (Master != null && Master is PlayerObject) master = (PlayerObject)Master;
  240. if (master != null)
  241. {
  242. weapon = master.Looks_Weapon;
  243. armour = master.Looks_Armour;
  244. wing = master.Looks_Wings;
  245. }
  246. return new S.ObjectPlayer
  247. {
  248. ObjectID = ObjectID,
  249. Name = master != null ? master.Name : Name,
  250. NameColour = NameColour,
  251. Class = MirClass.Warrior,
  252. Gender = master != null ? master.Gender : Envir.Random.Next(2) == 0 ? MirGender.Male : MirGender.Female,
  253. Location = CurrentLocation,
  254. Direction = Direction,
  255. Hair = master != null ? master.Hair : (byte)Envir.Random.Next(0, 5),
  256. Weapon = 52,
  257. Armour = 31,
  258. Light = master != null ? master.Light : Light,
  259. Poison = CurrentPoison,
  260. Dead = Dead,
  261. Hidden = Hidden,
  262. Effect = SpellEffect.None,
  263. WingEffect = wing,
  264. Extra = Summoned,
  265. TransformType = -1,
  266. };
  267. }
  268. }
  269. }