DevastatedCastle.java 4.4 KB

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