SepAssassin.cs 8.4 KB

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