예제 #1
0
  /** Talk with captains and using of the escape teleporter */
  @Override
  public final String onTalk(L2Npc npc, L2PcInstance player) {
    QuestState st = player.getQuestState(qn);
    if (st == null) newQuestState(player);
    final int npcId = npc.getNpcId();

    if (npcId == TELEPORTER) {
      final L2Party party = player.getParty();
      // only party leader can talk with escape teleporter
      if (party != null && party.isLeader(player)) {
        final InstanceWorld world = InstanceManager.getInstance().getWorld(npc.getInstanceId());
        if (world instanceof KamaWorld) {
          // party members must be in the instance
          if (world.allowed.contains(player.getObjectId())) {
            Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);

            // teleports entire party away
            for (L2PcInstance partyMember : party.getPartyMembers())
              if (partyMember != null && partyMember.getInstanceId() == world.instanceId)
                teleportPlayer(partyMember, inst.getSpawnLoc(), 0);
          }
        }
      }
    } else return npcId + ".htm";

    return "";
  }
예제 #2
0
  /**
   * Handling enter of the players into kamaloka
   *
   * @param player party leader
   * @param index (0-18) kamaloka index in arrays
   */
  private final synchronized void enterInstance(L2PcInstance player, int index) {
    int templateId;
    try {
      templateId = INSTANCE_IDS[index];
    } catch (ArrayIndexOutOfBoundsException e) {
      throw e;
    }

    // check for existing instances for this player
    InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
    // player already in the instance
    if (world != null) {
      // but not in kamaloka
      if (!(world instanceof KamaWorld) || world.templateId != templateId) {
        player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
        return;
      }
      // check for level difference again on reenter
      if (Math.abs(player.getLevel() - LEVEL[((KamaWorld) world).index]) > MAX_LEVEL_DIFFERENCE) {
        SystemMessage sm =
            SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
        sm.addPcName(player);
        player.sendPacket(sm);
        return;
      }
      // check what instance still exist
      Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
      if (inst != null) {
        removeBuffs(player);
        teleportPlayer(player, TELEPORTS[index], world.instanceId);
      }
      return;
    }
    // Creating new kamaloka instance
    else {
      if (!checkConditions(player, index)) return;

      // Creating dynamic instance without template
      final int instanceId = InstanceManager.getInstance().createDynamicInstance(null);
      final Instance inst = InstanceManager.getInstance().getInstance(instanceId);
      // set name for the kamaloka
      inst.setName(InstanceManager.getInstance().getInstanceIdName(templateId));
      // set return location
      final int[] returnLoc = {player.getX(), player.getY(), player.getZ()};
      inst.setSpawnLoc(returnLoc);
      // disable summon friend into instance
      inst.setAllowSummon(false);
      // set duration and empty destroy time
      inst.setDuration(DURATION[index] * 60000);
      inst.setEmptyDestroyTime(EMPTY_DESTROY_TIME * 60000);

      // Creating new instanceWorld, using our instanceId and templateId
      world = new KamaWorld();
      world.instanceId = instanceId;
      world.templateId = templateId;
      // set index for easy access to the arrays
      ((KamaWorld) world).index = index;
      InstanceManager.getInstance().addWorld(world);
      world.status = 0;
      // spawn npcs
      spawnKama((KamaWorld) world);

      // and finally teleport party into instance
      final L2Party party = player.getParty();
      for (L2PcInstance partyMember : party.getPartyMembers()) {
        if (partyMember.getQuestState(qn) == null) newQuestState(partyMember);
        world.allowed.add(partyMember.getObjectId());

        removeBuffs(partyMember);
        teleportPlayer(partyMember, TELEPORTS[index], instanceId);
      }
      return;
    }
  }
예제 #3
0
  /**
   * Check if party with player as leader allowed to enter
   *
   * @param player party leader
   * @param index (0-18) index of the kamaloka in arrays
   * @return true if party allowed to enter
   */
  private static final boolean checkConditions(L2PcInstance player, int index) {
    final L2Party party = player.getParty();
    // player must be in party
    if (party == null) {
      player.sendPacket(SystemMessageId.NOT_IN_PARTY_CANT_ENTER);
      return false;
    }
    // ...and be party leader
    if (party.getLeader() != player) {
      player.sendPacket(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER);
      return false;
    }
    // party must not exceed max size for selected instance
    if (party.getMemberCount() > MAX_PARTY_SIZE[index]) {
      player.sendPacket(SystemMessageId.PARTY_EXCEEDED_THE_LIMIT_CANT_ENTER);
      return false;
    }

    // get level of the instance
    final int level = LEVEL[index];
    // and client name
    final String instanceName =
        InstanceManager.getInstance().getInstanceIdName(INSTANCE_IDS[index]);

    Map<Integer, Long> instanceTimes;
    // for each party member
    for (L2PcInstance partyMember : party.getPartyMembers()) {
      // player level must be in range
      if (Math.abs(partyMember.getLevel() - level) > MAX_LEVEL_DIFFERENCE) {
        SystemMessage sm =
            SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
        sm.addPcName(partyMember);
        player.sendPacket(sm);
        return false;
      }
      // player must be near party leader
      if (!partyMember.isInsideRadius(player, 1000, true, true)) {
        SystemMessage sm =
            SystemMessage.getSystemMessage(
                SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
        sm.addPcName(partyMember);
        player.sendPacket(sm);
        return false;
      }
      // get instances reenter times for player
      instanceTimes = InstanceManager.getInstance().getAllInstanceTimes(partyMember.getObjectId());
      if (instanceTimes != null) {
        for (int id : instanceTimes.keySet()) {
          // find instance with same name (kamaloka or labyrinth)
          // TODO: Zoey76: Don't use instance name, use other system.
          if (!instanceName.equals(InstanceManager.getInstance().getInstanceIdName(id))) continue;
          // if found instance still can't be reentered - exit
          if (System.currentTimeMillis() < instanceTimes.get(id)) {
            SystemMessage sm =
                SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
            sm.addPcName(partyMember);
            player.sendPacket(sm);
            return false;
          }
        }
      }
    }
    return true;
  }