AnomicFoundry.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 hellbound.AnomicFoundry;
  20. import java.util.Map;
  21. import javolution.util.FastMap;
  22. import com.l2jserver.gameserver.ai.CtrlIntention;
  23. import com.l2jserver.gameserver.datatables.SpawnTable;
  24. import com.l2jserver.gameserver.instancemanager.HellboundManager;
  25. import com.l2jserver.gameserver.model.L2Spawn;
  26. import com.l2jserver.gameserver.model.Location;
  27. import com.l2jserver.gameserver.model.actor.L2Attackable;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.quest.Quest;
  32. import com.l2jserver.gameserver.model.skills.Skill;
  33. import com.l2jserver.gameserver.network.NpcStringId;
  34. import com.l2jserver.gameserver.network.clientpackets.Say2;
  35. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  36. /**
  37. * @author GKR
  38. */
  39. public class AnomicFoundry extends Quest
  40. {
  41. private static int LABORER = 22396;
  42. private static int FOREMAN = 22397;
  43. private static int LESSER_EVIL = 22398;
  44. private static int GREATER_EVIL = 22399;
  45. // npcId, x, y, z, heading, max count
  46. private static int[][] SPAWNS =
  47. {
  48. {
  49. LESSER_EVIL,
  50. 27883,
  51. 248613,
  52. -3209,
  53. -13248,
  54. 5
  55. },
  56. {
  57. LESSER_EVIL,
  58. 26142,
  59. 246442,
  60. -3216,
  61. 7064,
  62. 5
  63. },
  64. {
  65. LESSER_EVIL,
  66. 27335,
  67. 246217,
  68. -3668,
  69. -7992,
  70. 5
  71. },
  72. {
  73. LESSER_EVIL,
  74. 28486,
  75. 245913,
  76. -3698,
  77. 0,
  78. 10
  79. },
  80. {
  81. GREATER_EVIL,
  82. 28684,
  83. 244118,
  84. -3700,
  85. -22560,
  86. 10
  87. }
  88. };
  89. private int respawnTime = 60000;
  90. private final int respawnMin = 20000;
  91. private final int respawnMax = 300000;
  92. private final int[] _spawned =
  93. {
  94. 0,
  95. 0,
  96. 0,
  97. 0,
  98. 0
  99. };
  100. private final Map<Integer, Integer> _atkIndex = new FastMap<>();
  101. public AnomicFoundry(int questId, String name, String descr)
  102. {
  103. super(questId, name, descr);
  104. addAggroRangeEnterId(LABORER);
  105. addAttackId(LABORER);
  106. addKillId(LABORER);
  107. addKillId(LESSER_EVIL);
  108. addKillId(GREATER_EVIL);
  109. addSpawnId(LABORER);
  110. addSpawnId(LESSER_EVIL);
  111. addSpawnId(GREATER_EVIL);
  112. startQuestTimer("make_spawn_1", respawnTime, null, null);
  113. }
  114. @Override
  115. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  116. {
  117. if (event.equalsIgnoreCase("make_spawn_1"))
  118. {
  119. if (HellboundManager.getInstance().getLevel() >= 10)
  120. {
  121. int idx = getRandom(3);
  122. if (_spawned[idx] < SPAWNS[idx][5])
  123. {
  124. addSpawn(SPAWNS[idx][0], SPAWNS[idx][1], SPAWNS[idx][2], SPAWNS[idx][3], SPAWNS[idx][4], false, 0, false);
  125. respawnTime += 10000;
  126. }
  127. startQuestTimer("make_spawn_1", respawnTime, null, null);
  128. }
  129. }
  130. else if (event.equalsIgnoreCase("make_spawn_2"))
  131. {
  132. if (_spawned[4] < SPAWNS[4][5])
  133. {
  134. addSpawn(SPAWNS[4][0], SPAWNS[4][1], SPAWNS[4][2], SPAWNS[4][3], SPAWNS[4][4], false, 0, false);
  135. }
  136. }
  137. else if (event.equalsIgnoreCase("return_laborer"))
  138. {
  139. if ((npc != null) && !npc.isDead())
  140. {
  141. ((L2Attackable) npc).returnHome();
  142. }
  143. }
  144. else if (event.equalsIgnoreCase("reset_respawn_time"))
  145. {
  146. respawnTime = 60000;
  147. }
  148. return null;
  149. }
  150. @Override
  151. public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isSummon)
  152. {
  153. if (getRandom(10000) < 2000)
  154. {
  155. requestHelp(npc, player, 500, FOREMAN);
  156. requestHelp(npc, player, 500, LESSER_EVIL);
  157. requestHelp(npc, player, 500, GREATER_EVIL);
  158. }
  159. return super.onAggroRangeEnter(npc, player, isSummon);
  160. }
  161. @Override
  162. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon, Skill skill)
  163. {
  164. int atkIndex = _atkIndex.containsKey(npc.getObjectId()) ? _atkIndex.get(npc.getObjectId()) : 0;
  165. if (atkIndex == 0)
  166. {
  167. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.ENEMY_INVASION_HURRY_UP));
  168. cancelQuestTimer("return_laborer", npc, null);
  169. startQuestTimer("return_laborer", 60000, npc, null);
  170. if (respawnTime > respawnMin)
  171. {
  172. respawnTime -= 5000;
  173. }
  174. else if ((respawnTime <= respawnMin) && (getQuestTimer("reset_respawn_time", null, null) == null))
  175. {
  176. startQuestTimer("reset_respawn_time", 600000, null, null);
  177. }
  178. }
  179. if (getRandom(10000) < 2000)
  180. {
  181. atkIndex++;
  182. _atkIndex.put(npc.getObjectId(), atkIndex);
  183. requestHelp(npc, attacker, 1000 * atkIndex, FOREMAN);
  184. requestHelp(npc, attacker, 1000 * atkIndex, LESSER_EVIL);
  185. requestHelp(npc, attacker, 1000 * atkIndex, GREATER_EVIL);
  186. if (getRandom(10) < 1)
  187. {
  188. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location((npc.getX() + getRandom(-800, 800)), (npc.getY() + getRandom(-800, 800)), npc.getZ(), npc.getHeading()));
  189. }
  190. }
  191. return super.onAttack(npc, attacker, damage, isSummon, skill);
  192. }
  193. @Override
  194. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  195. {
  196. if (getSpawnGroup(npc) >= 0)
  197. {
  198. _spawned[getSpawnGroup(npc)]--;
  199. SpawnTable.getInstance().deleteSpawn(npc.getSpawn(), false);
  200. }
  201. else if (npc.getId() == LABORER)
  202. {
  203. if (getRandom(10000) < 8000)
  204. {
  205. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.PROCESS_SHOULDNT_BE_DELAYED_BECAUSE_OF_ME));
  206. if (respawnTime < respawnMax)
  207. {
  208. respawnTime += 10000;
  209. }
  210. else if ((respawnTime >= respawnMax) && (getQuestTimer("reset_respawn_time", null, null) == null))
  211. {
  212. startQuestTimer("reset_respawn_time", 600000, null, null);
  213. }
  214. }
  215. _atkIndex.remove(npc.getObjectId());
  216. }
  217. return super.onKill(npc, killer, isSummon);
  218. }
  219. @Override
  220. public final String onSpawn(L2Npc npc)
  221. {
  222. if (!npc.isTeleporting())
  223. {
  224. SpawnTable.getInstance().addNewSpawn(npc.getSpawn(), false);
  225. if (getSpawnGroup(npc) >= 0)
  226. {
  227. _spawned[getSpawnGroup(npc)]++;
  228. }
  229. if (npc.getId() == LABORER)
  230. {
  231. npc.setIsNoRndWalk(true);
  232. }
  233. }
  234. else
  235. {
  236. if ((getSpawnGroup(npc) >= 0) && (getSpawnGroup(npc) <= 2))
  237. {
  238. _spawned[getSpawnGroup(npc)]--;
  239. SpawnTable.getInstance().deleteSpawn(npc.getSpawn(), false);
  240. npc.scheduleDespawn(100);
  241. if (_spawned[3] < SPAWNS[3][5])
  242. {
  243. addSpawn(SPAWNS[3][0], SPAWNS[3][1], SPAWNS[3][2], SPAWNS[3][3], SPAWNS[3][4], false, 0, false);
  244. }
  245. }
  246. else if (getSpawnGroup(npc) == 3)
  247. {
  248. // Announcements.getInstance().announceToAll("Greater spawn is added");
  249. startQuestTimer("make_spawn_2", respawnTime * 2, null, null);
  250. _spawned[3]--;
  251. SpawnTable.getInstance().deleteSpawn(npc.getSpawn(), false);
  252. npc.scheduleDespawn(100);
  253. }
  254. }
  255. return super.onSpawn(npc);
  256. }
  257. private static int getSpawnGroup(L2Npc npc)
  258. {
  259. final int coordX = npc.getSpawn().getX();
  260. final int coordY = npc.getSpawn().getY();
  261. final int npcId = npc.getId();
  262. for (int i = 0; i < 5; i++)
  263. {
  264. if ((SPAWNS[i][0] == npcId) && (SPAWNS[i][1] == coordX) && (SPAWNS[i][2] == coordY))
  265. {
  266. return i;
  267. }
  268. }
  269. return -1;
  270. }
  271. // Zoey76: TODO: This should be done with onFactionCall(..)
  272. private static void requestHelp(L2Npc requester, L2PcInstance agressor, int range, int helperId)
  273. {
  274. for (L2Spawn spawn : SpawnTable.getInstance().getSpawns(helperId))
  275. {
  276. final L2MonsterInstance monster = (L2MonsterInstance) spawn.getLastSpawn();
  277. if ((monster != null) && (agressor != null) && !monster.isDead() && monster.isInsideRadius(requester, range, true, false) && !agressor.isDead())
  278. {
  279. monster.addDamageHate(agressor, 0, 1000);
  280. }
  281. }
  282. }
  283. public static void main(String[] args)
  284. {
  285. new AnomicFoundry(-1, AnomicFoundry.class.getSimpleName(), "hellbound");
  286. }
  287. }