FortressOfResistance.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.warn("{}: Couldnt set the Bloody Lord Nurka spawn!", getName(), e);
  83. }
  84. }
  85. private final void buildMessengerMessage()
  86. {
  87. String html = HtmCache.getInstance().getHtm(null, "data/scripts/conquerablehalls/FortressOfResistance/partisan_ordery_brakel001.htm");
  88. if (html != null)
  89. {
  90. // FIXME: We don't have an object id to put in here :(
  91. _messengerMsg = new NpcHtmlMessage();
  92. _messengerMsg.setHtml(html);
  93. _messengerMsg.replace("%nextSiege%", Util.formatDate(_hall.getSiegeDate().getTime(), "yyyy-MM-dd HH:mm:ss"));
  94. }
  95. }
  96. @Override
  97. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  98. {
  99. player.sendPacket(_messengerMsg);
  100. return null;
  101. }
  102. @Override
  103. public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isSummon)
  104. {
  105. if (!_hall.isInSiege())
  106. {
  107. return null;
  108. }
  109. int clanId = player.getClanId();
  110. if (clanId > 0)
  111. {
  112. long clanDmg = (_damageToNurka.containsKey(clanId)) ? _damageToNurka.get(clanId) + damage : damage;
  113. _damageToNurka.put(clanId, clanDmg);
  114. }
  115. return null;
  116. }
  117. @Override
  118. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  119. {
  120. if (!_hall.isInSiege())
  121. {
  122. return null;
  123. }
  124. _missionAccomplished = true;
  125. synchronized (this)
  126. {
  127. npc.getSpawn().stopRespawn();
  128. npc.deleteMe();
  129. cancelSiegeTask();
  130. endSiege();
  131. }
  132. return null;
  133. }
  134. @Override
  135. public L2Clan getWinner()
  136. {
  137. int winnerId = 0;
  138. long counter = 0;
  139. for (Entry<Integer, Long> e : _damageToNurka.entrySet())
  140. {
  141. long dam = e.getValue();
  142. if (dam > counter)
  143. {
  144. winnerId = e.getKey();
  145. counter = dam;
  146. }
  147. }
  148. return ClanTable.getInstance().getClan(winnerId);
  149. }
  150. @Override
  151. public void onSiegeStarts()
  152. {
  153. _nurka.init();
  154. }
  155. @Override
  156. public void onSiegeEnds()
  157. {
  158. buildMessengerMessage();
  159. }
  160. public static void main(String[] args)
  161. {
  162. new FortressOfResistance();
  163. }
  164. }