private void openDoor(QuestState st, L2PcInstance player, int doorId) { st.unset("correct"); final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(player.getInstanceId()); if (tmpworld instanceof NornilsWorld) { openDoor(doorId, tmpworld.getInstanceId()); } }
@Override public final String onKill(L2Npc npc, L2PcInstance player, boolean isSummon) { final QuestState st = getQuestState(player, false); if (st == null) { return null; } for (int _gk[] : _gatekeepers) { if (npc.getId() == _gk[0]) { // Drop key npc.dropItem(player, _gk[1], 1); // Check if gatekeeper should open bridge, and open it if (_gk[2] > 0) { final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(player.getInstanceId()); if (tmpworld instanceof NornilsWorld) { openDoor(_gk[2], tmpworld.getInstanceId()); } } } if (npc.getId() == 18355) { spawn2(npc); } } return super.onKill(npc, player, isSummon); }
private void exitInstance(L2PcInstance player) { final InstanceWorld inst = InstanceManager.getInstance().getWorld(player.getInstanceId()); if (inst instanceof NornilsWorld) { final NornilsWorld world = ((NornilsWorld) inst); world.removeAllowed(player.getObjectId()); teleportPlayer(player, EXIT_PPL, 0); } }
private static L2DoorInstance getDoor(int doorId) { L2DoorInstance door = null; if (_TvTEventInstance <= 0) { door = DoorData.getInstance().getDoor(doorId); } else { final Instance inst = InstanceManager.getInstance().getInstance(_TvTEventInstance); if (inst != null) { door = inst.getDoor(doorId); } } return door; }
private void spawn4(L2Character cha) { final InstanceWorld inst = InstanceManager.getInstance().getWorld(cha.getInstanceId()); if (inst instanceof NornilsWorld) { final NornilsWorld world = ((NornilsWorld) inst); if (!world.spawned_4) { world.spawned_4 = true; for (int mob[] : _group_4) { addSpawn(mob[0], mob[1], mob[2], mob[3], mob[4], false, 0, false, world.getInstanceId()); } } } }
private void spawn2(L2Npc npc) { final InstanceWorld inst = InstanceManager.getInstance().getWorld(npc.getInstanceId()); if (inst instanceof NornilsWorld) { final NornilsWorld world = ((NornilsWorld) inst); if (!world.spawned_2) { world.spawned_2 = true; for (int mob[] : _group_2) { addSpawn(mob[0], mob[1], mob[2], mob[3], mob[4], false, 0, false, world.getInstanceId()); } } } }
@Override public String onEnterZone(L2Character character, L2ZoneType zone) { if ((character instanceof L2PcInstance) && !character.isDead() && !character.isTeleporting() && ((L2PcInstance) character).isOnline()) { final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(character.getInstanceId()); if (tmpworld instanceof NornilsWorld) { for (int _auto[] : _auto_gates) { if (zone.getId() == _auto[0]) { openDoor(_auto[1], tmpworld.getInstanceId()); } if (zone.getId() == 20111) { spawn3(character); } else if (zone.getId() == 20112) { spawn4(character); } } } } return super.onEnterZone(character, zone); }
private final synchronized String enterInstance(L2Npc npc, L2PcInstance player) { InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player); if (world != null) { if (!(world instanceof NornilsWorld) || (world.getTemplateId() != TEMPLATE_ID)) { player.sendPacket( SystemMessageId .YOU_HAVE_ENTERED_ANOTHER_INSTANT_ZONE_THEREFORE_YOU_CANNOT_ENTER_CORRESPONDING_DUNGEON); return null; } // check for level difference again on reenter if ((player.getLevel() > INSTANCE_LVL_MAX) || (player.getLevel() < INSTANCE_LVL_MIN)) { final SystemMessage sm = SystemMessage.getSystemMessage( SystemMessageId.C1_S_LEVEL_DOES_NOT_CORRESPOND_TO_THE_REQUIREMENTS_FOR_ENTRY); sm.addPcName(player); player.sendPacket(sm); return null; } // check what instance still exist final Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId()); if (inst != null) { teleportPlayer(player, SPAWN_PPL, world.getInstanceId()); } return null; } // Creating new instance final String result = checkConditions(npc, player); if (!(result.equalsIgnoreCase("ok"))) { return result; } final int instanceId = InstanceManager.getInstance().createDynamicInstance("NornilsGarden.xml"); final Instance inst = InstanceManager.getInstance().getInstance(instanceId); inst.setName(InstanceManager.getInstance().getInstanceIdName(TEMPLATE_ID)); inst.setExitLoc(new Location(player)); inst.setAllowSummon(false); inst.setDuration(DURATION_TIME * 60000); inst.setEmptyDestroyTime(EMPTY_DESTROY_TIME * 60000); world = new NornilsWorld(); world.setInstanceId(instanceId); world.setTemplateId(TEMPLATE_ID); InstanceManager.getInstance().addWorld(world); _log.info( "Nornils Garden: started, Instance: " + instanceId + " created by player: " + player.getName()); prepareInstance((NornilsWorld) world); // and finally teleport party into instance final L2Party party = player.getParty(); if (party != null) { for (L2PcInstance partyMember : party.getMembers()) { world.addAllowed(partyMember.getObjectId()); teleportPlayer(partyMember, SPAWN_PPL, instanceId); } } return null; }
/** * Starts the TvTEvent fight<br> * 1. Set state EventState.STARTING<br> * 2. Close doors specified in configs<br> * 3. Abort if not enough participants(return false)<br> * 4. Set state EventState.STARTED<br> * 5. Teleport all participants to team spot<br> * <br> * * @return boolean: true if success, otherwise false<br> */ public static boolean startFight() { // Set state to STARTING setState(EventState.STARTING); // Randomize and balance team distribution final Map<Integer, L2PcInstance> allParticipants = new HashMap<>(); allParticipants.putAll(_teams[0].getParticipatedPlayers()); allParticipants.putAll(_teams[1].getParticipatedPlayers()); _teams[0].cleanMe(); _teams[1].cleanMe(); L2PcInstance player; Iterator<L2PcInstance> iter; if (needParticipationFee()) { iter = allParticipants.values().iterator(); while (iter.hasNext()) { player = iter.next(); if (!hasParticipationFee(player)) { iter.remove(); } } } final int balance[] = {0, 0}; int priority = 0, highestLevelPlayerId; L2PcInstance highestLevelPlayer; // TODO: allParticipants should be sorted by level instead of using highestLevelPcInstanceOf for // every fetch while (!allParticipants.isEmpty()) { // Priority team gets one player highestLevelPlayerId = highestLevelPcInstanceOf(allParticipants); highestLevelPlayer = allParticipants.get(highestLevelPlayerId); allParticipants.remove(highestLevelPlayerId); _teams[priority].addPlayer(highestLevelPlayer); balance[priority] += highestLevelPlayer.getLevel(); // Exiting if no more players if (allParticipants.isEmpty()) { break; } // The other team gets one player // TODO: Code not dry priority = 1 - priority; highestLevelPlayerId = highestLevelPcInstanceOf(allParticipants); highestLevelPlayer = allParticipants.get(highestLevelPlayerId); allParticipants.remove(highestLevelPlayerId); _teams[priority].addPlayer(highestLevelPlayer); balance[priority] += highestLevelPlayer.getLevel(); // Recalculating priority priority = balance[0] > balance[1] ? 1 : 0; } // Check for enought participants if ((_teams[0].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS) || (_teams[1].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS)) { // Set state INACTIVE setState(EventState.INACTIVE); // Cleanup of teams _teams[0].cleanMe(); _teams[1].cleanMe(); // Unspawn the event NPC unSpawnNpc(); AntiFeedManager.getInstance().clear(AntiFeedManager.TVT_ID); return false; } if (needParticipationFee()) { iter = _teams[0].getParticipatedPlayers().values().iterator(); while (iter.hasNext()) { player = iter.next(); if (!payParticipationFee(player)) { iter.remove(); } } iter = _teams[1].getParticipatedPlayers().values().iterator(); while (iter.hasNext()) { player = iter.next(); if (!payParticipationFee(player)) { iter.remove(); } } } if (Config.TVT_EVENT_IN_INSTANCE) { try { _TvTEventInstance = InstanceManager.getInstance().createDynamicInstance(Config.TVT_EVENT_INSTANCE_FILE); InstanceManager.getInstance().getInstance(_TvTEventInstance).setAllowSummon(false); InstanceManager.getInstance().getInstance(_TvTEventInstance).setPvPInstance(true); InstanceManager.getInstance() .getInstance(_TvTEventInstance) .setEmptyDestroyTime((Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY * 1000) + 60000L); } catch (Exception e) { _TvTEventInstance = 0; _log.log( Level.WARNING, "TvTEventEngine[TvTEvent.createDynamicInstance]: exception: " + e.getMessage(), e); } } // Opens all doors specified in configs for tvt openDoors(Config.TVT_DOORS_IDS_TO_OPEN); // Closes all doors specified in configs for tvt closeDoors(Config.TVT_DOORS_IDS_TO_CLOSE); // Set state STARTED setState(EventState.STARTED); // Iterate over all teams for (TvTEventTeam team : _teams) { // Iterate over all participated player instances in this team for (L2PcInstance playerInstance : team.getParticipatedPlayers().values()) { if (playerInstance != null) { // Disable player revival. playerInstance.setCanRevive(false); // Teleporter implements Runnable and starts itself new TvTEventTeleporter(playerInstance, team.getCoordinates(), false, false); } } } // Notify to scripts. EventDispatcher.getInstance().notifyEventAsync(new OnTvTEventStart()); return true; }