HellKeeper.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. class HellKeeper : MonsterObject
  7. {
  8. protected override bool CanMove { get { return false; } }
  9. protected override bool CanRegen { get { return false; } }
  10. protected internal HellKeeper(MonsterInfo info) : base(info)
  11. {
  12. Direction = MirDirection.Up;
  13. }
  14. protected override bool InAttackRange()
  15. {
  16. if (Target.CurrentMap != CurrentMap) return false;
  17. return Target.CurrentLocation != CurrentLocation && Functions.InRange(CurrentLocation, Target.CurrentLocation, Info.ViewRange);
  18. }
  19. public override void Turn(MirDirection dir)
  20. {
  21. }
  22. public override bool Walk(MirDirection dir) { return false; }
  23. public override int Attacked(MonsterObject attacker, int damage, DefenceType type = DefenceType.ACAgility)
  24. {
  25. int armour = 0;
  26. switch (type)
  27. {
  28. case DefenceType.ACAgility:
  29. if (Envir.Random.Next(Stats[Stat.Agility] + 1) > attacker.Stats[Stat.Accuracy]) return 0;
  30. armour = GetAttackPower(Stats[Stat.MinAC], Stats[Stat.MaxAC]);
  31. break;
  32. case DefenceType.AC:
  33. armour = GetAttackPower(Stats[Stat.MinAC], Stats[Stat.MaxAC]);
  34. break;
  35. case DefenceType.MACAgility:
  36. if (Envir.Random.Next(Stats[Stat.Agility] + 1) > attacker.Stats[Stat.Accuracy]) return 0;
  37. armour = GetAttackPower(Stats[Stat.MinMAC], Stats[Stat.MaxMAC]);
  38. break;
  39. case DefenceType.MAC:
  40. armour = GetAttackPower(Stats[Stat.MinMAC], Stats[Stat.MaxMAC]);
  41. break;
  42. case DefenceType.Agility:
  43. if (Envir.Random.Next(Stats[Stat.Agility] + 1) > attacker.Stats[Stat.Accuracy]) return 0;
  44. break;
  45. }
  46. if (armour >= damage) return 0;
  47. ShockTime = 0;
  48. for (int i = PoisonList.Count - 1; i >= 0; i--)
  49. {
  50. if (PoisonList[i].PType != PoisonType.LRParalysis) continue;
  51. PoisonList.RemoveAt(i);
  52. OperateTime = 0;
  53. }
  54. if (attacker.Info.AI == 6)
  55. EXPOwner = null;
  56. else if (attacker.Master != null)
  57. {
  58. if (EXPOwner == null || EXPOwner.Dead)
  59. EXPOwner = attacker.Master switch
  60. {
  61. HeroObject hero => hero.Owner,
  62. _ => attacker.Master
  63. };
  64. if (EXPOwner == attacker.Master)
  65. EXPOwnerTime = Envir.Time + EXPOwnerDelay;
  66. }
  67. Broadcast(new S.ObjectStruck { ObjectID = ObjectID, AttackerID = attacker.ObjectID, Direction = Direction, Location = CurrentLocation });
  68. ChangeHP(armour - damage);
  69. return 1;
  70. }
  71. public override int Attacked(HumanObject attacker, int damage, DefenceType type = DefenceType.ACAgility, bool damageWeapon = true)
  72. {
  73. int armour = 0;
  74. switch (type)
  75. {
  76. case DefenceType.ACAgility:
  77. if (Envir.Random.Next(Stats[Stat.Agility] + 1) > attacker.Stats[Stat.Accuracy]) return 0;
  78. armour = GetAttackPower(Stats[Stat.MinAC], Stats[Stat.MaxAC]);
  79. break;
  80. case DefenceType.AC:
  81. armour = GetAttackPower(Stats[Stat.MinAC], Stats[Stat.MaxAC]);
  82. break;
  83. case DefenceType.MACAgility:
  84. if (Envir.Random.Next(Stats[Stat.Agility] + 1) > attacker.Stats[Stat.Accuracy]) return 0;
  85. armour = GetAttackPower(Stats[Stat.MinMAC], Stats[Stat.MaxMAC]);
  86. break;
  87. case DefenceType.MAC:
  88. armour = GetAttackPower(Stats[Stat.MinMAC], Stats[Stat.MaxMAC]);
  89. break;
  90. case DefenceType.Agility:
  91. if (Envir.Random.Next(Stats[Stat.Agility] + 1) > attacker.Stats[Stat.Accuracy]) return 0;
  92. break;
  93. }
  94. if (armour >= damage) return 0;
  95. if (damageWeapon)
  96. attacker.DamageWeapon();
  97. ShockTime = 0;
  98. for (int i = PoisonList.Count - 1; i >= 0; i--)
  99. {
  100. if (PoisonList[i].PType != PoisonType.LRParalysis) continue;
  101. PoisonList.RemoveAt(i);
  102. OperateTime = 0;
  103. }
  104. if (Master != null && Master != attacker)
  105. if (Envir.Time > Master.BrownTime && Master.PKPoints < 200)
  106. attacker.BrownTime = Envir.Time + Settings.Minute;
  107. if (EXPOwner == null || EXPOwner.Dead)
  108. EXPOwner = GetAttacker(attacker);
  109. if (EXPOwner == attacker)
  110. EXPOwnerTime = Envir.Time + EXPOwnerDelay;
  111. Broadcast(new S.ObjectStruck { ObjectID = ObjectID, AttackerID = attacker.ObjectID, Direction = Direction, Location = CurrentLocation });
  112. attacker.GatherElement();
  113. ChangeHP(armour - damage);
  114. return 1;
  115. }
  116. public override void ApplyPoison(Poison p, MapObject Caster = null, bool NoResist = false, bool ignoreDefence = true)
  117. {
  118. }
  119. protected override void ProcessTarget()
  120. {
  121. if (!CanAttack) return;
  122. Attack();
  123. ShockTime = 0;
  124. ActionTime = Envir.Time + 300;
  125. AttackTime = Envir.Time + AttackSpeed;
  126. }
  127. protected override void Attack()
  128. {
  129. byte attacktype1 = (byte)(Envir.Random.Next(3) > 0 ? 0 : 1);
  130. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = attacktype1 });
  131. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, attacktype1);
  132. ActionList.Add(action);
  133. }
  134. protected override void CompleteAttack(IList<object> data)
  135. {
  136. byte attackType = (byte)data[0];
  137. List<MapObject> targets = FindAllTargets(Info.ViewRange, CurrentLocation);
  138. if (targets.Count == 0) return;
  139. for (int i = 0; i < targets.Count; i++)
  140. {
  141. Target = targets[i];
  142. if (attackType == 0)
  143. {
  144. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  145. if (damage == 0) continue;
  146. Target.Attacked(this, damage);
  147. }
  148. else
  149. {
  150. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  151. if (damage == 0) continue;
  152. if (Target.Attacked(this, damage, DefenceType.MACAgility) <= 0) continue;
  153. PoisonTarget(Target, 10, damage, PoisonType.Dazed, 1000);
  154. }
  155. }
  156. }
  157. }
  158. }