AnomicFoundry.java 8.9 KB

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