Пример #1
0
  /**
   * Called on instance finish and handles reenter time for instance
   *
   * @param world instanceWorld
   */
  private static final void finishInstance(InstanceWorld world) {
    if (world instanceof KamaWorld) {
      Calendar reenter = Calendar.getInstance();
      reenter.set(Calendar.MINUTE, RESET_MIN);
      // if time is >= RESET_HOUR - roll to the next day
      if (reenter.get(Calendar.HOUR_OF_DAY) >= RESET_HOUR) reenter.add(Calendar.DATE, 1);
      reenter.set(Calendar.HOUR_OF_DAY, RESET_HOUR);

      SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_S1_RESTRICTED);
      sm.addInstanceName(world.templateId);

      // set instance reenter time for all allowed players
      for (int objectId : world.allowed) {
        L2PcInstance obj = L2World.getInstance().getPlayer(objectId);
        if (obj != null && obj.isOnline()) {
          InstanceManager.getInstance()
              .setInstanceTime(objectId, world.templateId, reenter.getTimeInMillis());
          obj.sendPacket(sm);
        }
      }

      // destroy instance after EXIT_TIME
      Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
      inst.setDuration(EXIT_TIME * 60000);
      inst.setEmptyDestroyTime(0);
    }
  }
Пример #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;
    }
  }