AnomicFoundry.java 8.0 KB

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