DevastatedCastle.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 gnu.trove.map.hash.TIntIntHashMap;
  17. import com.l2jserver.gameserver.ai.CtrlIntention;
  18. import com.l2jserver.gameserver.datatables.ClanTable;
  19. import com.l2jserver.gameserver.datatables.NpcTable;
  20. import com.l2jserver.gameserver.datatables.SkillTable;
  21. import com.l2jserver.gameserver.model.L2Clan;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.entity.clanhall.ClanHallSiegeEngine;
  25. import com.l2jserver.gameserver.network.clientpackets.Say2;
  26. /**
  27. * Devastated Castle clan hall siege script.
  28. * @author BiggBoss
  29. */
  30. public final class DevastatedCastle extends ClanHallSiegeEngine
  31. {
  32. private static final String qn = "DevastatedCastle";
  33. private static final int GUSTAV = 35410;
  34. private static final int MIKHAIL = 35409;
  35. private static final int DIETRICH = 35408;
  36. private static final double GUSTAV_TRIGGER_HP = NpcTable.getInstance().getTemplate(GUSTAV).getBaseHpMax() / 12;
  37. private static TIntIntHashMap _damageToGustav = new TIntIntHashMap();
  38. public DevastatedCastle(int questId, String name, String descr, int hallId)
  39. {
  40. super(questId, name, descr, hallId);
  41. addKillId(GUSTAV);
  42. addSpawnId(MIKHAIL);
  43. addSpawnId(DIETRICH);
  44. addAttackId(GUSTAV);
  45. }
  46. @Override
  47. public String onSpawn(L2Npc npc)
  48. {
  49. if(npc.getNpcId() == MIKHAIL)
  50. broadcastNpcSay(npc, Say2.SHOUT, 1000276);
  51. else if(npc.getNpcId() == DIETRICH)
  52. broadcastNpcSay(npc, Say2.SHOUT, 1000277);
  53. return null;
  54. }
  55. @Override
  56. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  57. {
  58. if(!_hall.isInSiege())
  59. return null;
  60. synchronized(this)
  61. {
  62. final L2Clan clan = attacker.getClan();
  63. if(clan != null && checkIsAttacker(clan))
  64. {
  65. final int id = clan.getClanId();
  66. if(_damageToGustav.containsKey(id))
  67. {
  68. int newDamage = _damageToGustav.get(id);
  69. newDamage += damage;
  70. _damageToGustav.put(id, newDamage);
  71. }
  72. else
  73. _damageToGustav.put(id, damage);
  74. }
  75. if(npc.getCurrentHp() < GUSTAV_TRIGGER_HP
  76. && npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_CAST)
  77. {
  78. broadcastNpcSay(npc, Say2.ALL, 1000278);
  79. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, SkillTable.getInstance().getInfo(4235, 1), npc);
  80. }
  81. }
  82. return super.onAttack(npc, attacker, damage, isPet);
  83. }
  84. @Override
  85. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  86. {
  87. if(!_hall.isInSiege())
  88. return null;
  89. _missionAccomplished = true;
  90. if(npc.getNpcId() == GUSTAV)
  91. {
  92. synchronized(this)
  93. {
  94. cancelSiegeTask();
  95. endSiege();
  96. }
  97. }
  98. return super.onKill(npc, killer, isPet);
  99. }
  100. @Override
  101. public L2Clan getWinner()
  102. {
  103. double counter = 0;
  104. int damagest = 0;
  105. for(int clan : _damageToGustav.keys())
  106. {
  107. final double damage = _damageToGustav.get(clan);
  108. if(damage > counter)
  109. {
  110. counter = damage;
  111. damagest = clan;
  112. }
  113. }
  114. L2Clan winner = ClanTable.getInstance().getClan(damagest);
  115. return winner;
  116. }
  117. public static void main(String[] args)
  118. {
  119. new DevastatedCastle(-1, qn, "conquerablehalls", DEVASTATED_CASTLE);
  120. }
  121. }