DevastatedCastle.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package conquerablehalls.DevastatedCastle;
  16. import java.util.HashMap;
  17. import java.util.Map;
  18. import java.util.Map.Entry;
  19. import com.l2jserver.gameserver.ai.CtrlIntention;
  20. import com.l2jserver.gameserver.datatables.ClanTable;
  21. import com.l2jserver.gameserver.datatables.NpcTable;
  22. import com.l2jserver.gameserver.datatables.SkillTable;
  23. import com.l2jserver.gameserver.model.L2Clan;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.entity.clanhall.ClanHallSiegeEngine;
  27. import com.l2jserver.gameserver.network.clientpackets.Say2;
  28. /**
  29. * Devastated Castle clan hall siege script.
  30. * @author BiggBoss
  31. */
  32. public final class DevastatedCastle extends ClanHallSiegeEngine
  33. {
  34. private static final String qn = "DevastatedCastle";
  35. private static final int GUSTAV = 35410;
  36. private static final int MIKHAIL = 35409;
  37. private static final int DIETRICH = 35408;
  38. private static final double GUSTAV_TRIGGER_HP = NpcTable.getInstance().getTemplate(GUSTAV).getBaseHpMax() / 12;
  39. private static Map<Integer, Integer> _damageToGustav = new HashMap<>();
  40. public DevastatedCastle(int questId, String name, String descr, int hallId)
  41. {
  42. super(questId, name, descr, hallId);
  43. addKillId(GUSTAV);
  44. addSpawnId(MIKHAIL);
  45. addSpawnId(DIETRICH);
  46. addAttackId(GUSTAV);
  47. }
  48. @Override
  49. public String onSpawn(L2Npc npc)
  50. {
  51. if(npc.getNpcId() == MIKHAIL)
  52. broadcastNpcSay(npc, Say2.SHOUT, 1000276);
  53. else if(npc.getNpcId() == DIETRICH)
  54. broadcastNpcSay(npc, Say2.SHOUT, 1000277);
  55. return null;
  56. }
  57. @Override
  58. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  59. {
  60. if(!_hall.isInSiege())
  61. return null;
  62. synchronized(this)
  63. {
  64. final L2Clan clan = attacker.getClan();
  65. if(clan != null && checkIsAttacker(clan))
  66. {
  67. final int id = clan.getClanId();
  68. if(_damageToGustav.containsKey(id))
  69. {
  70. int newDamage = _damageToGustav.get(id);
  71. newDamage += damage;
  72. _damageToGustav.put(id, newDamage);
  73. }
  74. else
  75. _damageToGustav.put(id, damage);
  76. }
  77. if(npc.getCurrentHp() < GUSTAV_TRIGGER_HP
  78. && npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_CAST)
  79. {
  80. broadcastNpcSay(npc, Say2.ALL, 1000278);
  81. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, SkillTable.getInstance().getInfo(4235, 1), npc);
  82. }
  83. }
  84. return super.onAttack(npc, attacker, damage, isPet);
  85. }
  86. @Override
  87. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  88. {
  89. if(!_hall.isInSiege())
  90. return null;
  91. _missionAccomplished = true;
  92. if(npc.getNpcId() == GUSTAV)
  93. {
  94. synchronized(this)
  95. {
  96. cancelSiegeTask();
  97. endSiege();
  98. }
  99. }
  100. return super.onKill(npc, killer, isPet);
  101. }
  102. @Override
  103. public L2Clan getWinner()
  104. {
  105. int counter = 0;
  106. int damagest = 0;
  107. for(Entry<Integer, Integer> e : _damageToGustav.entrySet())
  108. {
  109. final int damage = e.getValue();
  110. if(damage > counter)
  111. {
  112. counter = damage;
  113. damagest = e.getKey();
  114. }
  115. }
  116. return ClanTable.getInstance().getClan(damagest);
  117. }
  118. public static void main(String[] args)
  119. {
  120. new DevastatedCastle(-1, qn, "conquerablehalls", DEVASTATED_CASTLE);
  121. }
  122. }