TucsonEgg.cs 6.9 KB

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