DevastatedCastle.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2004-2014 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.NpcData;
  26. import com.l2jserver.gameserver.datatables.SkillData;
  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 int GUSTAV = 35410;
  40. private static final int MIKHAIL = 35409;
  41. private static final int DIETRICH = 35408;
  42. private static final double GUSTAV_TRIGGER_HP = NpcData.getInstance().getTemplate(GUSTAV).getBaseHpMax() / 12;
  43. private static Map<Integer, Integer> _damageToGustav = new HashMap<>();
  44. private DevastatedCastle()
  45. {
  46. super(DevastatedCastle.class.getSimpleName(), "conquerablehalls", DEVASTATED_CASTLE);
  47. addKillId(GUSTAV);
  48. addSpawnId(MIKHAIL);
  49. addSpawnId(DIETRICH);
  50. addAttackId(GUSTAV);
  51. }
  52. @Override
  53. public String onSpawn(L2Npc npc)
  54. {
  55. if (npc.getId() == MIKHAIL)
  56. {
  57. broadcastNpcSay(npc, Say2.NPC_SHOUT, NpcStringId.GLORY_TO_ADEN_THE_KINGDOM_OF_THE_LION_GLORY_TO_SIR_GUSTAV_OUR_IMMORTAL_LORD);
  58. }
  59. else if (npc.getId() == DIETRICH)
  60. {
  61. broadcastNpcSay(npc, Say2.NPC_SHOUT, NpcStringId.SOLDIERS_OF_GUSTAV_GO_FORTH_AND_DESTROY_THE_INVADERS);
  62. }
  63. return null;
  64. }
  65. @Override
  66. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  67. {
  68. if (!_hall.isInSiege())
  69. {
  70. return null;
  71. }
  72. synchronized (this)
  73. {
  74. final L2Clan clan = attacker.getClan();
  75. if ((clan != null) && checkIsAttacker(clan))
  76. {
  77. final int id = clan.getId();
  78. if (_damageToGustav.containsKey(id))
  79. {
  80. int newDamage = _damageToGustav.get(id);
  81. newDamage += damage;
  82. _damageToGustav.put(id, newDamage);
  83. }
  84. else
  85. {
  86. _damageToGustav.put(id, damage);
  87. }
  88. }
  89. if ((npc.getCurrentHp() < GUSTAV_TRIGGER_HP) && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_CAST))
  90. {
  91. broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.THIS_IS_UNBELIEVABLE_HAVE_I_REALLY_BEEN_DEFEATED_I_SHALL_RETURN_AND_TAKE_YOUR_HEAD);
  92. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, SkillData.getInstance().getSkill(4235, 1), npc);
  93. }
  94. }
  95. return super.onAttack(npc, attacker, damage, isSummon);
  96. }
  97. @Override
  98. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  99. {
  100. if (!_hall.isInSiege())
  101. {
  102. return null;
  103. }
  104. _missionAccomplished = true;
  105. if (npc.getId() == GUSTAV)
  106. {
  107. synchronized (this)
  108. {
  109. cancelSiegeTask();
  110. endSiege();
  111. }
  112. }
  113. return super.onKill(npc, killer, isSummon);
  114. }
  115. @Override
  116. public L2Clan getWinner()
  117. {
  118. int counter = 0;
  119. int damagest = 0;
  120. for (Entry<Integer, Integer> e : _damageToGustav.entrySet())
  121. {
  122. final int damage = e.getValue();
  123. if (damage > counter)
  124. {
  125. counter = damage;
  126. damagest = e.getKey();
  127. }
  128. }
  129. return ClanTable.getInstance().getClan(damagest);
  130. }
  131. public static void main(String[] args)
  132. {
  133. new DevastatedCastle();
  134. }
  135. }