SepWarrior.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. using S = ServerPackets;
  5. namespace Server.MirObjects.Monsters
  6. {
  7. public class SepWarrior : MonsterObject
  8. {
  9. public long FearTime, DecreaseMPTime;
  10. public byte AttackRange = 1;
  11. public bool Summoned;
  12. protected internal SepWarrior(MonsterInfo info)
  13. : base(info)
  14. {
  15. }
  16. protected override bool InAttackRange()
  17. {
  18. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  19. }
  20. protected override void ProcessTarget()
  21. {
  22. if (Target == null) return;
  23. if (!InAttackRange())
  24. {
  25. if (CurrentLocation == Target.CurrentLocation)
  26. {
  27. MirDirection direction = (MirDirection)Envir.Random.Next(8);
  28. int rotation = Envir.Random.Next(2) == 0 ? 1 : -1;
  29. for (int d = 0; d < 8; d++)
  30. {
  31. if (Walk(direction)) break;
  32. direction = Functions.ShiftDirection(direction, rotation);
  33. }
  34. }
  35. else
  36. MoveTo(Target.CurrentLocation);
  37. }
  38. if (!CanAttack) return;
  39. if (InAttackRange())
  40. {
  41. Attack();
  42. }
  43. }
  44. protected override void Attack()
  45. {
  46. if (!Target.IsAttackTarget(this))
  47. {
  48. Target = null;
  49. return;
  50. }
  51. ShockTime = 0;
  52. ActionTime = Envir.Time + 300;
  53. AttackTime = Envir.Time + AttackSpeed;
  54. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  55. if (damage == 0) return;
  56. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  57. if (Envir.Random.Next(3) == 0)
  58. {
  59. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Spell = Spell.TwinDrakeBlade });
  60. Target.Attacked(this, (int)(damage * 0.8), DefenceType.ACAgility);
  61. ProjectileAttack((int)(damage * 0.8),DefenceType.ACAgility);
  62. 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))
  63. {
  64. Target.ApplyPoison(new Poison { PType = PoisonType.Stun, Duration = 5, TickSpeed = 1000 }, this);
  65. Target.Broadcast(new S.ObjectEffect { ObjectID = Target.ObjectID, Effect = SpellEffect.TwinDrakeBlade });
  66. }
  67. }
  68. else
  69. base.Attack();
  70. }
  71. public bool Walk(MirDirection dir, bool br = false)
  72. {
  73. if (!CanMove) return false;
  74. var temploc = Functions.PointMove(CurrentLocation, dir, 1);
  75. if (!CurrentMap.ValidPoint(temploc)) return false;
  76. var cell = CurrentMap.GetCell(temploc);
  77. if (cell.Objects != null)
  78. for (int i = 0; i < cell.Objects.Count; i++)
  79. {
  80. MapObject ob = cell.Objects[i];
  81. if (!ob.Blocking) continue;
  82. return false;
  83. }
  84. Point location = Functions.PointMove(CurrentLocation, dir, 2);
  85. if (!CurrentMap.ValidPoint(location)) return false;
  86. cell = CurrentMap.GetCell(location);
  87. bool isBreak = br;
  88. if (cell.Objects != null)
  89. for (int i = 0; i < cell.Objects.Count; i++)
  90. {
  91. MapObject ob = cell.Objects[i];
  92. if (!ob.Blocking) continue;
  93. isBreak = true;
  94. break;
  95. }
  96. if (isBreak)
  97. {
  98. location = Functions.PointMove(CurrentLocation, dir, 1);
  99. if (!CurrentMap.ValidPoint(location)) return false;
  100. cell = CurrentMap.GetCell(location);
  101. if (cell.Objects != null)
  102. for (int i = 0; i < cell.Objects.Count; i++)
  103. {
  104. MapObject ob = cell.Objects[i];
  105. if (!ob.Blocking) continue;
  106. return false;
  107. }
  108. }
  109. CurrentMap.GetCell(CurrentLocation).Remove(this);
  110. Direction = dir;
  111. RemoveObjects(dir, 1);
  112. CurrentLocation = location;
  113. CurrentMap.GetCell(CurrentLocation).Add(this);
  114. AddObjects(dir, 1);
  115. if (Hidden)
  116. {
  117. Hidden = false;
  118. for (int i = 0; i < Buffs.Count; i++)
  119. {
  120. if (Buffs[i].Type != BuffType.Hiding) continue;
  121. Buffs[i].ExpireTime = 0;
  122. break;
  123. }
  124. }
  125. CellTime = Envir.Time + 500;
  126. ActionTime = Envir.Time + 300;
  127. MoveTime = Envir.Time + MoveSpeed;
  128. if (MoveTime > AttackTime)
  129. AttackTime = MoveTime;
  130. InSafeZone = CurrentMap.GetSafeZone(CurrentLocation) != null;
  131. if (isBreak)
  132. Broadcast(new S.ObjectWalk { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  133. else
  134. Broadcast(new S.ObjectRun { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  135. cell = CurrentMap.GetCell(CurrentLocation);
  136. for (int i = 0; i < cell.Objects.Count; i++)
  137. {
  138. if (cell.Objects[i].Race != ObjectType.Spell) continue;
  139. SpellObject ob = (SpellObject)cell.Objects[i];
  140. ob.ProcessSpell(this);
  141. //break;
  142. }
  143. return true;
  144. }
  145. public override void Die()
  146. {
  147. if (Dead) return;
  148. HP = 0;
  149. Dead = true;
  150. //DeadTime = Envir.Time + DeadDelay;
  151. DeadTime = 0;
  152. Broadcast(new S.ObjectDied { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = (byte)(Master != null ? 1 : 0) });
  153. if (EXPOwner != null && Master == null && EXPOwner.Race == ObjectType.Player)
  154. EXPOwner.WinExp(Experience, Level);
  155. if (Respawn != null)
  156. Respawn.Count--;
  157. if (Master == null)
  158. Drop();
  159. Master = null;
  160. PoisonList.Clear();
  161. Envir.MonsterCount--;
  162. if (CurrentMap != null)
  163. CurrentMap.MonsterCount--;
  164. }
  165. public override Packet GetInfo()
  166. {
  167. PlayerObject master = null;
  168. short weapon = -1;
  169. short armour = 0;
  170. byte wing = 0;
  171. if (Master != null && Master is PlayerObject) master = (PlayerObject)Master;
  172. if (master != null)
  173. {
  174. weapon = master.Looks_Weapon;
  175. armour = master.Looks_Armour;
  176. wing = master.Looks_Wings;
  177. }
  178. return new S.ObjectPlayer
  179. {
  180. ObjectID = ObjectID,
  181. Name = master != null ? master.Name : Name,
  182. NameColour = NameColour,
  183. Class = MirClass.Warrior,
  184. Gender = master != null ? master.Gender : Envir.Random.Next(2) == 0 ? MirGender.Male : MirGender.Female,
  185. Location = CurrentLocation,
  186. Direction = Direction,
  187. Hair = master != null ? master.Hair : (byte)Envir.Random.Next(0, 5),
  188. Weapon = 29,
  189. Armour = 6,
  190. Light = master != null ? master.Light : Light,
  191. Poison = CurrentPoison,
  192. Dead = Dead,
  193. Hidden = Hidden,
  194. Effect = SpellEffect.None,
  195. WingEffect = wing,
  196. Extra = Summoned,
  197. TransformType = -1,
  198. };
  199. }
  200. }
  201. }