Esempio n. 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 "";
  }
Esempio n. 2
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);
    }
  }
Esempio n. 3
0
  @Override
  public final String onKill(L2Npc npc, L2PcInstance player, boolean isPet) {
    final InstanceWorld tmpWorld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
    if (tmpWorld instanceof KamaWorld) {
      final KamaWorld world = (KamaWorld) tmpWorld;
      final int objectId = npc.getObjectId();

      // first room was spawned ?
      if (world.firstRoom != null) {
        // is shaman killed ?
        if (world.shaman != 0 && world.shaman == objectId) {
          world.shaman = 0;
          // stop respawn of the minions
          for (L2Spawn spawn : world.firstRoom) {
            if (spawn != null) spawn.stopRespawn();
          }
          world.firstRoom.clear();
          world.firstRoom = null;

          if (world.boss != null) {
            final int skillId = FIRST_ROOM[world.index][2];
            final int skillLvl = FIRST_ROOM[world.index][3];
            if (skillId != 0 && skillLvl != 0) {
              final L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLvl);
              if (skill != null) skill.getEffects(world.boss, world.boss);
            }
          }

          return super.onKill(npc, player, isPet);
        }
      }

      // second room was spawned ?
      if (world.secondRoom != null) {
        boolean all = true;
        // check for all mobs in the second room
        for (int i = 0; i < world.secondRoom.size(); i++) {
          // found killed now mob
          if (world.secondRoom.get(i) == objectId) world.secondRoom.set(i, 0);
          // found alive mob
          else if (world.secondRoom.get(i) != 0) all = false;
        }
        // all mobs killed ?
        if (all) {
          world.secondRoom.clear();
          world.secondRoom = null;

          if (world.boss != null) {
            final int skillId = SECOND_ROOM[world.index][1];
            final int skillLvl = SECOND_ROOM[world.index][2];
            if (skillId != 0 && skillLvl != 0) {
              final L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLvl);
              if (skill != null) skill.getEffects(world.boss, world.boss);
            }
          }

          return super.onKill(npc, player, isPet);
        }
      }

      // miniboss spawned ?
      if (world.miniBoss != 0 && world.miniBoss == objectId) {
        world.miniBoss = 0;

        if (world.boss != null) {
          final int skillId = MINIBOSS[world.index][4];
          final int skillLvl = MINIBOSS[world.index][5];
          if (skillId != 0 && skillLvl != 0) {
            final L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLvl);
            if (skill != null) skill.getEffects(world.boss, world.boss);
          }
        }

        return super.onKill(npc, player, isPet);
      }

      // boss was killed, finish instance
      if (world.boss != null && world.boss == npc) {
        world.boss = null;
        finishInstance(world);
      }
    }
    return super.onKill(npc, player, isPet);
  }
Esempio n. 4
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;
    }
  }
Esempio n. 5
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;
  }