Advertisement
tedlol

error

Aug 28th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.49 KB | None | 0 0
  1. package instances.IceQueenKegor;
  2.  
  3. import java.util.List;
  4.  
  5. import javolution.util.FastList;
  6.  
  7. import ai.npc.AbstractNpcAI;
  8.  
  9. import com.l2jserver.gameserver.ai.CtrlIntention;
  10. import com.l2jserver.gameserver.datatables.SkillTable;
  11. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  12. import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
  13. import com.l2jserver.gameserver.model.L2CharPosition;
  14. import com.l2jserver.gameserver.model.Location;
  15. import com.l2jserver.gameserver.model.actor.L2Attackable;
  16. import com.l2jserver.gameserver.model.actor.L2Npc;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.model.entity.Instance;
  19. import com.l2jserver.gameserver.model.quest.Quest;
  20. import com.l2jserver.gameserver.model.quest.QuestState;
  21. import com.l2jserver.gameserver.model.quest.State;
  22. import com.l2jserver.gameserver.model.skills.L2Skill;
  23. import com.l2jserver.gameserver.network.NpcStringId;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.clientpackets.Say2;
  26. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. import com.l2jserver.gameserver.util.Util;
  29.  
  30. public class IceQueen_Kegor extends AbstractNpcAI
  31. {
  32. private class KegorWorld extends InstanceWorld
  33. {
  34. public long[] storeTime = {0,0};
  35. public boolean underAttack = false;
  36. public L2Npc KEGOR = null;
  37. public List<L2Attackable> liveMobs;
  38.  
  39. public KegorWorld()
  40. {
  41.  
  42. }
  43. }
  44.  
  45. private static final int INSTANCEID = 138;
  46.  
  47. private static final int KROON = 32653;
  48. private static final int TAROON = 32654;
  49. private static final int KEGOR_IN_CAVE = 18846;
  50. private static final int MONSTER = 22766;
  51.  
  52. private static final int ANTIDOTE = 15514;
  53.  
  54. private static final int BUFF = 6286;
  55.  
  56. private static final int[][] MOB_SPAWNS = {
  57. { 185216, -184112, -3308, -15396 },
  58. { 185456, -184240, -3308, -19668 },
  59. { 185712, -184384, -3308, -26696 },
  60. { 185920, -184544, -3308, -32544 },
  61. { 185664, -184720, -3308, 27892 },
  62. };
  63.  
  64. private static final int[] ENTRY_POINT = { 186852, -173492, -3763 };
  65.  
  66. private class teleCoord {int instanceId; int x; int y; int z;}
  67.  
  68. private void teleportplayer(L2PcInstance player, teleCoord teleto)
  69. {
  70. player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  71. player.setInstanceId(teleto.instanceId);
  72. player.teleToLocation(teleto.x, teleto.y, teleto.z);
  73. return;
  74. }
  75.  
  76. private boolean checkConditions(L2PcInstance player)
  77. {
  78. if (player.getLevel() < 82 || player.getLevel() > 85)
  79. {
  80. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
  81. sm.addPcName(player);
  82. player.sendPacket(sm);
  83. return false;
  84. }
  85.  
  86. return true;
  87. }
  88.  
  89. protected void exitInstance(L2PcInstance player, teleCoord tele)
  90. {
  91. player.setInstanceId(0);
  92. player.teleToLocation(tele.x, tele.y, tele.z);
  93. }
  94.  
  95. protected int enterInstance(L2PcInstance player, String template, teleCoord teleto)
  96. {
  97. int instanceId = 0;
  98. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  99. //existing instance
  100. if (world != null)
  101. {
  102. //this instance
  103. if (!(world instanceof KegorWorld))
  104. {
  105. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
  106. return 0;
  107. }
  108.  
  109. teleto.instanceId = world.instanceId;
  110. teleportplayer(player,teleto);
  111. return instanceId;
  112. }
  113. //New instance
  114. if (!checkConditions(player))
  115. return 0;
  116.  
  117. instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  118. final Instance inst = InstanceManager.getInstance().getInstance(instanceId);
  119. inst.setSpawnLoc(new Location(player));
  120. world = new KegorWorld();
  121. world.instanceId = instanceId;
  122. world.templateId = INSTANCEID;
  123. world.status = 0;
  124.  
  125. ((KegorWorld)world).storeTime[0] = System.currentTimeMillis();
  126. InstanceManager.getInstance().addWorld(world);
  127. _log.info("KegorWorld started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  128. teleto.instanceId = instanceId;
  129. teleportplayer(player,teleto);
  130. world.allowed.add(player.getObjectId());
  131. return instanceId;
  132. }
  133.  
  134. @Override
  135. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  136. {
  137. if (npc.getNpcId() == KEGOR_IN_CAVE)
  138. {
  139. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  140. if (tmpworld != null && tmpworld instanceof KegorWorld);
  141. {
  142. KegorWorld world = (KegorWorld) tmpworld;
  143.  
  144. if (event.equalsIgnoreCase("spawn"))
  145. {
  146. world.liveMobs = new FastList<L2Attackable>();
  147. for(int[] spawn : MOB_SPAWNS)
  148. {
  149. L2Attackable spawnedMob = (L2Attackable) addSpawn(MONSTER, spawn[0], spawn[1], spawn[2], spawn[3], false, 0, false, world.instanceId);
  150. world.liveMobs.add(spawnedMob);
  151. }
  152. }
  153.  
  154. else if (event.equalsIgnoreCase("buff"))
  155. {
  156. //schedule mob attack
  157. if (world != null && world.liveMobs != null && !world.liveMobs.isEmpty())
  158. {
  159. for (L2Attackable monster : world.liveMobs)
  160. {
  161. if (monster.getKnownList().knowsObject(npc))
  162. {
  163. monster.addDamageHate(npc, 0, 999);
  164. monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, npc, null);
  165. }
  166. else
  167. monster.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(npc.getX(), npc.getY(), npc.getZ(), 0));
  168. }
  169.  
  170. //buff player
  171. if (npc.getKnownList().getKnownPlayers().size() == 1)
  172. {
  173. L2Skill buff = SkillTable.getInstance().getInfo(BUFF,1);
  174. if (buff != null)
  175. {
  176. for (L2PcInstance pl : npc.getKnownList().getKnownPlayers().values())
  177. {
  178. if (Util.checkIfInRange(buff.getCastRange(), npc, pl, false))
  179. {
  180. npc.setTarget(pl);
  181. npc.doCast(buff);
  182. }
  183. }
  184. }
  185. }
  186. startQuestTimer("buff", 30000, npc,player);
  187. }
  188. }
  189.  
  190. //Throws exception when L2NpcInstance is converted into L2Attackable
  191. /*
  192. else if (event.equalsIgnoreCase("attack_mobs"))
  193. {
  194. if (_liveMobs != null && !_liveMobs.isEmpty())
  195. {
  196. int idx = Rnd.get(_liveMobs.size());
  197.  
  198. if (npc.getKnownList().knowsObject(_liveMobs.get(idx)))
  199. {
  200. ((L2Attackable)npc).addDamageHate(_liveMobs.get(idx), 0, 999);
  201. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, _liveMobs.get(idx));
  202. }
  203.  
  204. startQuestTimer("attack_mobs", 10000, KEGOR, player);
  205. }
  206. }
  207. */
  208.  
  209. }
  210. }
  211.  
  212. return null;
  213. }
  214.  
  215. @Override
  216. public String onTalk ( L2Npc npc, L2PcInstance player)
  217. {
  218. int npcId = npc.getNpcId();
  219. String htmltext = getNoQuestMsg(player);
  220.  
  221. QuestState hostQuest = player.getQuestState("Q10284_AcquisitionOfDivineSword");
  222.  
  223. if (hostQuest == null)
  224. {
  225. System.out.println("null host quest");
  226. return htmltext;
  227. }
  228.  
  229. if (npcId == KROON || npcId == TAROON)
  230. {
  231. teleCoord tele = new teleCoord();
  232. tele.x = ENTRY_POINT[0];
  233. tele.y = ENTRY_POINT[1];
  234. tele.z = ENTRY_POINT[2];
  235.  
  236. htmltext = npcId == KROON ? "32653-07.htm" : "32654-07.htm";
  237. if (enterInstance(player, "IceQueen_Kegor.xml", tele) > 0)
  238. {
  239. htmltext = "";
  240. if (hostQuest.getInt("progress") == 2 && hostQuest.getQuestItemsCount(ANTIDOTE) == 0)
  241. {
  242. hostQuest.giveItems(ANTIDOTE, 1);
  243. hostQuest.playSound("ItemSound.quest_middle");
  244. hostQuest.set("cond", "4");
  245. }
  246. }
  247. }
  248.  
  249. else if (npc.getNpcId() == KEGOR_IN_CAVE)
  250. {
  251. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(player.getInstanceId());
  252. if (tmpworld != null && tmpworld instanceof KegorWorld);
  253. {
  254. KegorWorld world = (KegorWorld) tmpworld;
  255. if (hostQuest.getInt("progress") == 2 && hostQuest.getQuestItemsCount(ANTIDOTE) > 0 && !world.underAttack)
  256. {
  257. hostQuest.takeItems(ANTIDOTE, hostQuest.getQuestItemsCount(ANTIDOTE));
  258. hostQuest.playSound("ItemSound.quest_middle");
  259. hostQuest.set("cond", "5");
  260. htmltext = "18846-01.htm";
  261. world.underAttack = true;
  262. npc.setIsInvul(false);
  263. npc.setIsMortal(true);
  264. startQuestTimer("spawn", 3000, npc,player);
  265. startQuestTimer("buff", 3500, npc,player);
  266. }
  267.  
  268. else if (hostQuest.getState() == State.COMPLETED)
  269. {
  270. world.allowed.remove(world.allowed.indexOf(player.getObjectId()));
  271. final Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
  272. teleCoord tele = new teleCoord();
  273. tele.instanceId = 0;
  274. tele.x = inst.getSpawnLoc()[0];
  275. tele.y = inst.getSpawnLoc()[1];
  276. tele.z = inst.getSpawnLoc()[2];
  277. exitInstance(player,tele);
  278. htmltext = "";
  279. }
  280. }
  281. }
  282.  
  283. return htmltext;
  284. }
  285.  
  286. @Override
  287. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  288. {
  289. QuestState hostQuest = player.getQuestState("Q10284_AcquisitionOfDivineSword");
  290. if (hostQuest == null)
  291. return null;
  292.  
  293. if (npc.getNpcId() == KEGOR_IN_CAVE)
  294. {
  295. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(player.getInstanceId());
  296. if (tmpworld != null && tmpworld instanceof KegorWorld);
  297. {
  298. KegorWorld world = (KegorWorld) tmpworld;
  299.  
  300. if (world.KEGOR == null)
  301. world.KEGOR = npc;
  302.  
  303. if (hostQuest.getState() != State.STARTED)
  304. return "18846-04.htm";
  305.  
  306. if (!world.underAttack && hostQuest.getInt("progress") == 2)
  307. return "18846-00.htm";
  308.  
  309. else if (hostQuest.getInt("progress") == 3)
  310. {
  311. hostQuest.giveItems(57, 296425);
  312. hostQuest.addExpAndSp(921805, 82230);
  313. hostQuest.playSound("ItemSound.quest_finish");
  314. hostQuest.exitQuest(false);
  315. return "18846-03.htm";
  316. }
  317.  
  318. else
  319. return "18846-02.htm";
  320. }
  321. }
  322.  
  323. return null;
  324. }
  325.  
  326. @Override
  327. public final String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
  328. {
  329. QuestState hostQuest = player.getQuestState("Q10284_AcquisitionOfDivineSword");
  330. if (hostQuest == null || hostQuest.getState() != State.STARTED)
  331. return null;
  332.  
  333. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  334. if (tmpworld != null && tmpworld instanceof KegorWorld);
  335. {
  336. KegorWorld world = (KegorWorld) tmpworld;
  337.  
  338. if (npc.getNpcId() == MONSTER)
  339. {
  340. if (world.liveMobs != null)
  341. {
  342. world.liveMobs.remove(npc);
  343. if (world.liveMobs.isEmpty() && world.KEGOR != null && !world.KEGOR.isDead() && hostQuest.getInt("progress") == 2)
  344. {
  345. world.underAttack = false;
  346. world.liveMobs = null;
  347. cancelQuestTimer("buff", world.KEGOR, null);
  348. world.KEGOR.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, player, null);
  349. NpcSay cs = new NpcSay(world.KEGOR.getObjectId(), Say2.ALL, world.KEGOR.getNpcId(), NpcStringId.I_CAN_FINALLY_TAKE_A_BREATHER_BY_THE_WAY_WHO_ARE_YOU_HMM_I_THINK_I_KNOW_WHO_SENT_YOU);
  350. world.KEGOR.broadcastPacket(cs);
  351. hostQuest.set("progress", "3");
  352. hostQuest.set("cond", "6");
  353. hostQuest.playSound("ItemSound.quest_middle");
  354.  
  355. // destroy instance after 3 min
  356. Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
  357. inst.setDuration(3 * 60000);
  358. inst.setEmptyDestroyTime(0);
  359. }
  360. }
  361.  
  362. else if (npc.getNpcId() == KEGOR_IN_CAVE)
  363. {
  364. world.KEGOR = null;
  365. NpcSay cs = new NpcSay(npc.getObjectId(), Say2.ALL, npc.getNpcId(), NpcStringId.HOW_COULD_I_FALL_IN_A_PLACE_LIKE_THIS);
  366. npc.broadcastPacket(cs);
  367.  
  368. // destroy instance after 1 min
  369. Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
  370. inst.setDuration(60000);
  371. inst.setEmptyDestroyTime(0);
  372. }
  373. }
  374. }
  375.  
  376. return null;
  377. }
  378.  
  379. @Override
  380. public final String onSpawn(L2Npc npc)
  381. {
  382.  
  383. //Doesn't work now. NPC doesn't wish to attack Monster
  384. /*
  385. else if (npcId == _mob && KEGOR != null)
  386. {
  387. if (getQuestTimer("attack_mobs", KEGOR, null) == null)
  388. startQuestTimer("attack_mobs", 10000, KEGOR, null);
  389. }
  390. */
  391. return super.onSpawn(npc);
  392. }
  393.  
  394. public IceQueen_Kegor(String name, String descr)
  395. {
  396. super(name, descr);
  397. addFirstTalkId(KEGOR_IN_CAVE);
  398. addStartNpc(KROON);
  399. addStartNpc(TAROON);
  400. addTalkId(KROON);
  401. addTalkId(TAROON);
  402. addTalkId(KEGOR_IN_CAVE);
  403. addKillId(KEGOR_IN_CAVE);
  404. addKillId(MONSTER);
  405. addSpawnId(KEGOR_IN_CAVE);
  406. addSpawnId(MONSTER);
  407.  
  408. }
  409.  
  410. public static void main(String[] args)
  411. {
  412. new IceQueen_Kegor(IceQueen_Kegor.class.getSimpleName(),"instances");
  413. }
  414. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement