CastleGate.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. public abstract class CastleGate : MonsterObject
  7. {
  8. public ConquestObject Conquest;
  9. public int GateIndex;
  10. public bool Closed;
  11. private long CloseTime;
  12. private bool AutoOpen = false;
  13. protected List<BlockingObject> BlockingObjects = new List<BlockingObject>();
  14. protected Point[] BlockArray;
  15. protected override bool CanAttack
  16. {
  17. get
  18. {
  19. return false;
  20. }
  21. }
  22. protected override bool CanMove { get { return false; } }
  23. public override bool Blocking
  24. {
  25. get
  26. {
  27. return Closed && base.Blocking;
  28. }
  29. }
  30. protected internal CastleGate(MonsterInfo info)
  31. : base(info)
  32. {
  33. Closed = true;
  34. }
  35. public override void Spawned()
  36. {
  37. base.Spawned();
  38. if (BlockArray == null) return;
  39. MonsterInfo bInfo = new MonsterInfo
  40. {
  41. Image = Monster.EvilMirBody,
  42. CanTame = false,
  43. CanPush = false,
  44. AutoRev = false
  45. };
  46. bInfo.Stats[Stat.HP] = this.Stats[Stat.HP];
  47. foreach (var block in BlockArray)
  48. {
  49. BlockingObject b = new BlockingObject(this, bInfo);
  50. BlockingObjects.Add(b);
  51. if (!b.Spawn(this.CurrentMap, new Point(this.CurrentLocation.X + block.X, this.CurrentLocation.Y + block.Y)))
  52. {
  53. MessageQueue.EnqueueDebugging(string.Format("{3} blocking mob not spawned at {0} {1}:{2}", CurrentMap.Info.FileName, block.X, block.Y, Info.Name));
  54. }
  55. }
  56. }
  57. protected override void ProcessAI()
  58. {
  59. base.ProcessAI();
  60. if(!Closed && CloseTime > 0 && CloseTime < Envir.Time)
  61. {
  62. CloseDoor();
  63. CloseTime = 0;
  64. }
  65. }
  66. protected override void ProcessSearch()
  67. {
  68. if (Envir.Time < SearchTime) return;
  69. SearchTime = Envir.Time + SearchDelay;
  70. if (Closed && AutoOpen)
  71. {
  72. var nearby = FindAllNearby(4, CurrentLocation);
  73. for (int i = 0; i < nearby.Count; i++)
  74. {
  75. if (nearby[i].Race != ObjectType.Player) continue;
  76. PlayerObject player = (PlayerObject)nearby[i];
  77. if (player.MyGuild == null || player.MyGuild.Conquest == null || player.MyGuild.Conquest != Conquest || player.WarZone) continue;
  78. OpenDoor();
  79. CloseTime = Envir.Time + (Settings.Second * 10);
  80. break;
  81. }
  82. }
  83. }
  84. public override void Turn(MirDirection dir) { }
  85. public override bool Walk(MirDirection dir) { return false; }
  86. public override bool IsAttackTarget(MonsterObject attacker)
  87. {
  88. if (attacker.Master != null && attacker.Master.Race == ObjectType.Player)
  89. {
  90. PlayerObject owner = (PlayerObject)attacker.Master;
  91. if (owner.MyGuild != null && owner.MyGuild.Conquest != null && owner.MyGuild.Conquest == Conquest) return false;
  92. }
  93. return Closed && base.IsAttackTarget(attacker);
  94. }
  95. public override bool IsAttackTarget(HumanObject attacker)
  96. {
  97. if (attacker.MyGuild != null && attacker.MyGuild.Conquest != null && attacker.MyGuild.Conquest == Conquest) return false;
  98. return Closed && base.IsAttackTarget(attacker);
  99. }
  100. protected override void ProcessRoam() { }
  101. public override Packet GetInfo()
  102. {
  103. return base.GetInfo();
  104. }
  105. public override void Die()
  106. {
  107. ActiveDoorWall(false);
  108. base.Die();
  109. }
  110. public override int Attacked(HumanObject attacker, int damage, DefenceType type = DefenceType.ACAgility, bool damageWeapon = true)
  111. {
  112. return base.Attacked(attacker, damage, type, damageWeapon);
  113. }
  114. protected abstract int GetDamageLevel();
  115. public abstract void OpenDoor();
  116. public abstract void CloseDoor();
  117. public abstract void RepairGate();
  118. protected virtual void ActiveDoorWall(bool closed)
  119. {
  120. foreach (var obj in BlockingObjects)
  121. {
  122. if (obj == null) continue;
  123. if (closed)
  124. obj.Show();
  125. else
  126. obj.Hide();
  127. }
  128. }
  129. }
  130. }