SnowWolfKing.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. //TODO - Teleport
  7. public class SnowWolfKing : MonsterObject
  8. {
  9. private bool _SpawnedSlaves;
  10. protected internal SnowWolfKing(MonsterInfo info)
  11. : base(info)
  12. {
  13. }
  14. public override int Attacked(HumanObject attacker, int damage, DefenceType type = DefenceType.ACAgility, bool damageWeapon = true)
  15. {
  16. int attackerDamage = base.Attacked(attacker, damage, type, damageWeapon);
  17. int ownDamage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  18. if (attackerDamage > ownDamage && Envir.Random.Next(2) == 0)
  19. {
  20. FindWeakerTarget();
  21. }
  22. return attackerDamage;
  23. }
  24. public override int Attacked(MonsterObject attacker, int damage, DefenceType type = DefenceType.ACAgility)
  25. {
  26. int attackerDamage = base.Attacked(attacker, damage, type);
  27. int ownDamage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  28. if (attackerDamage > ownDamage && Envir.Random.Next(10) == 0)
  29. {
  30. FindWeakerTarget();
  31. }
  32. return attackerDamage;
  33. }
  34. private void FindWeakerTarget()
  35. {
  36. List<MapObject> targets = FindAllTargets(Info.ViewRange, CurrentLocation);
  37. if (targets.Count < 2) return;
  38. var newTarget = Target;
  39. for (int i = 0; i < targets.Count; i++)
  40. {
  41. if (targets[i].Stats[Stat.MinDC] >= Target.Stats[Stat.MinDC]) continue;
  42. newTarget = targets[i];
  43. }
  44. if (newTarget != Target)
  45. {
  46. Target = newTarget;
  47. TeleportToTarget(Target);
  48. }
  49. }
  50. private bool TeleportToTarget(MapObject target)
  51. {
  52. Direction = Functions.DirectionFromPoint(CurrentLocation, target.CurrentLocation);
  53. var reverse = Functions.ReverseDirection(Direction);
  54. var point = Functions.PointMove(target.CurrentLocation, reverse, 1);
  55. if (point != CurrentLocation)
  56. {
  57. if (Teleport(CurrentMap, point, true, 11)) return true;
  58. }
  59. return false;
  60. }
  61. protected override void Attack()
  62. {
  63. if (!Target.IsAttackTarget(this))
  64. {
  65. Target = null;
  66. return;
  67. }
  68. ShockTime = 0;
  69. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  70. ActionTime = Envir.Time + 300;
  71. AttackTime = Envir.Time + AttackSpeed;
  72. if (Envir.Random.Next(3) > 0)
  73. {
  74. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 0 });
  75. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  76. if (damage == 0) return;
  77. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.ACAgility, false, false);
  78. ActionList.Add(action);
  79. }
  80. else
  81. {
  82. if (HealthPercent >= 60)
  83. {
  84. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  85. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  86. if (damage == 0) return;
  87. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.ACAgility, true, false);
  88. ActionList.Add(action);
  89. }
  90. else if (HealthPercent >= 30)
  91. {
  92. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 2 });
  93. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  94. if (damage == 0) return;
  95. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.ACAgility, false, true);
  96. ActionList.Add(action);
  97. }
  98. else
  99. {
  100. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 3 });
  101. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  102. if (damage == 0) return;
  103. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.ACAgility, false, false);
  104. ActionList.Add(action);
  105. }
  106. }
  107. if (HealthPercent < 70 && !_SpawnedSlaves)
  108. {
  109. SpawnSlaves();
  110. }
  111. }
  112. protected override void CompleteAttack(IList<object> data)
  113. {
  114. MapObject target = (MapObject)data[0];
  115. int damage = (int)data[1];
  116. DefenceType defence = (DefenceType)data[2];
  117. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  118. target.Attacked(this, damage, defence);
  119. }
  120. public override void Die()
  121. {
  122. ActionList.Add(new DelayedAction(DelayedType.Die, Envir.Time + 500));
  123. base.Die();
  124. }
  125. protected override void CompleteDeath(IList<object> data)
  126. {
  127. var targets = FindAllTargets(1, CurrentLocation, false);
  128. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  129. if (damage > 0)
  130. {
  131. for (int i = 0; i < targets.Count; i++)
  132. {
  133. targets[i].Attacked(this, damage, DefenceType.MAC);
  134. }
  135. }
  136. for (int i = 0; i < SlaveList.Count; i++)
  137. {
  138. var mob = SlaveList[i];
  139. if (EXPOwner != null)
  140. {
  141. if (EXPOwner.Pets.Count >= 6) break;
  142. mob.Master = EXPOwner;
  143. mob.BroadcastHealthChange();
  144. EXPOwner.Pets.Add(mob);
  145. mob.Target = null;
  146. mob.RageTime = 0;
  147. mob.ShockTime = 0;
  148. mob.OperateTime = 0;
  149. if (!Settings.PetSave)
  150. {
  151. mob.TameTime = Envir.Time + (Settings.Minute * 60);
  152. }
  153. mob.Broadcast(new S.ObjectName { ObjectID = mob.ObjectID, Name = mob.Name });
  154. }
  155. }
  156. SlaveList.Clear();
  157. }
  158. private void SpawnSlaves()
  159. {
  160. _SpawnedSlaves = true;
  161. ActionTime = Envir.Time + 300;
  162. AttackTime = Envir.Time + AttackSpeed;
  163. for (int i = 0; i < 3; i++)
  164. {
  165. MonsterObject mob = GetMonster(Envir.GetMonsterInfo(Settings.SnowWolfKingMob));
  166. if (mob == null) continue;
  167. if (!mob.Spawn(CurrentMap, Target.Back))
  168. mob.Spawn(CurrentMap, CurrentLocation);
  169. mob.Target = Target;
  170. mob.ActionTime = Envir.Time + 2000;
  171. SlaveList.Add(mob);
  172. }
  173. }
  174. }
  175. }