FortressOfResistance.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (C) 2004-2015 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.FortressOfResistance;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import java.util.Map.Entry;
  23. import com.l2jserver.gameserver.cache.HtmCache;
  24. import com.l2jserver.gameserver.data.sql.impl.ClanTable;
  25. import com.l2jserver.gameserver.model.L2Clan;
  26. import com.l2jserver.gameserver.model.L2Spawn;
  27. import com.l2jserver.gameserver.model.Location;
  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.serverpackets.NpcHtmlMessage;
  32. import com.l2jserver.gameserver.util.Util;
  33. /**
  34. * Fortress of Resistance clan hall siege Script.
  35. * @author BiggBoss
  36. */
  37. public final class FortressOfResistance extends ClanHallSiegeEngine
  38. {
  39. private final int MESSENGER = 35382;
  40. private final int BLOODY_LORD_NURKA = 35375;
  41. private final Location[] NURKA_COORDS =
  42. {
  43. new Location(45109, 112124, -1900), // 30%
  44. new Location(47653, 110816, -2110), // 40%
  45. new Location(47247, 109396, -2000)
  46. // 30%
  47. };
  48. private L2Spawn _nurka;
  49. private final Map<Integer, Long> _damageToNurka = new HashMap<>();
  50. private NpcHtmlMessage _messengerMsg;
  51. private FortressOfResistance()
  52. {
  53. super(FortressOfResistance.class.getSimpleName(), "conquerablehalls", FORTRESS_RESSISTANCE);
  54. addFirstTalkId(MESSENGER);
  55. addKillId(BLOODY_LORD_NURKA);
  56. addAttackId(BLOODY_LORD_NURKA);
  57. buildMessengerMessage();
  58. try
  59. {
  60. _nurka = new L2Spawn(BLOODY_LORD_NURKA);
  61. _nurka.setAmount(1);
  62. _nurka.setRespawnDelay(10800);
  63. // @formatter:off
  64. // int chance = getRandom(100) + 1;
  65. // if (chance <= 30)
  66. // {
  67. // coords = NURKA_COORDS[0];
  68. // }
  69. // else if ((chance > 30) && (chance <= 70))
  70. // {
  71. // coords = NURKA_COORDS[1];
  72. // }
  73. // else
  74. // {
  75. // coords = NURKA_COORDS[2];
  76. // }
  77. // @formatter:on
  78. _nurka.setLocation(NURKA_COORDS[0]);
  79. }
  80. catch (Exception e)
  81. {
  82. _log.warning(getName() + ": Couldnt set the Bloody Lord Nurka spawn");
  83. e.printStackTrace();
  84. }
  85. }
  86. private final void buildMessengerMessage()
  87. {
  88. String html = HtmCache.getInstance().getHtm(null, "data/scripts/conquerablehalls/FortressOfResistance/partisan_ordery_brakel001.htm");
  89. if (html != null)
  90. {
  91. // FIXME: We don't have an object id to put in here :(
  92. _messengerMsg = new NpcHtmlMessage();
  93. _messengerMsg.setHtml(html);
  94. _messengerMsg.replace("%nextSiege%", Util.formatDate(_hall.getSiegeDate().getTime(), "yyyy-MM-dd HH:mm:ss"));
  95. }
  96. }
  97. @Override
  98. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  99. {
  100. player.sendPacket(_messengerMsg);
  101. return null;
  102. }
  103. @Override
  104. public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isSummon)
  105. {
  106. if (!_hall.isInSiege())
  107. {
  108. return null;
  109. }
  110. int clanId = player.getClanId();
  111. if (clanId > 0)
  112. {
  113. long clanDmg = (_damageToNurka.containsKey(clanId)) ? _damageToNurka.get(clanId) + damage : damage;
  114. _damageToNurka.put(clanId, clanDmg);
  115. }
  116. return null;
  117. }
  118. @Override
  119. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  120. {
  121. if (!_hall.isInSiege())
  122. {
  123. return null;
  124. }
  125. _missionAccomplished = true;
  126. synchronized (this)
  127. {
  128. npc.getSpawn().stopRespawn();
  129. npc.deleteMe();
  130. cancelSiegeTask();
  131. endSiege();
  132. }
  133. return null;
  134. }
  135. @Override
  136. public L2Clan getWinner()
  137. {
  138. int winnerId = 0;
  139. long counter = 0;
  140. for (Entry<Integer, Long> e : _damageToNurka.entrySet())
  141. {
  142. long dam = e.getValue();
  143. if (dam > counter)
  144. {
  145. winnerId = e.getKey();
  146. counter = dam;
  147. }
  148. }
  149. return ClanTable.getInstance().getClan(winnerId);
  150. }
  151. @Override
  152. public void onSiegeStarts()
  153. {
  154. _nurka.init();
  155. }
  156. @Override
  157. public void onSiegeEnds()
  158. {
  159. buildMessengerMessage();
  160. }
  161. public static void main(String[] args)
  162. {
  163. new FortressOfResistance();
  164. }
  165. }