Пример #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
  /**
   * 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);
    }
  }
Пример #3
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;
    }
  }
Пример #4
0
  public Location getTeleToLocation(L2Character activeChar, TeleportWhereType teleportWhere) {
    int[] coord;

    if (activeChar instanceof L2PcInstance) {
      L2PcInstance player = ((L2PcInstance) activeChar);

      Castle castle = null;
      Fort fort = null;
      ClanHall clanhall = null;

      if (player.getClan() != null
          && !player.isFlyingMounted()
          && !player.isFlying()) // flying players in gracia cant use teleports to aden continent
      {
        // If teleport to clan hall
        if (teleportWhere == TeleportWhereType.ClanHall) {
          clanhall = ClanHallManager.getInstance().getAbstractHallByOwner(player.getClan());
          if (clanhall != null) {
            L2ClanHallZone zone = clanhall.getZone();
            if (zone != null && !player.isFlyingMounted()) {
              if (player.getKarma() > 0) return zone.getChaoticSpawnLoc();
              return zone.getSpawnLoc();
            }
          }
        }

        // If teleport to castle
        if (teleportWhere == TeleportWhereType.Castle) {
          castle = CastleManager.getInstance().getCastleByOwner(player.getClan());
          // Otherwise check if player is on castle or fortress ground
          // and player's clan is defender
          if (castle == null) {
            castle = CastleManager.getInstance().getCastle(player);
            if (!(castle != null
                && castle.getSiege().getIsInProgress()
                && castle.getSiege().getDefenderClan(player.getClan()) != null)) castle = null;
          }

          if (castle != null && castle.getCastleId() > 0) {
            if (player.getKarma() > 0) return castle.getCastleZone().getChaoticSpawnLoc();
            return castle.getCastleZone().getSpawnLoc();
          }
        }

        // If teleport to fortress
        if (teleportWhere == TeleportWhereType.Fortress) {
          fort = FortManager.getInstance().getFortByOwner(player.getClan());
          // Otherwise check if player is on castle or fortress ground
          // and player's clan is defender
          if (fort == null) {
            fort = FortManager.getInstance().getFort(player);
            if (!(fort != null
                && fort.getSiege().getIsInProgress()
                && fort.getOwnerClan() == player.getClan())) fort = null;
          }

          if (fort != null && fort.getFortId() > 0) {
            if (player.getKarma() > 0) return fort.getFortZone().getChaoticSpawnLoc();
            return fort.getFortZone().getSpawnLoc();
          }
        }

        // If teleport to SiegeHQ
        if (teleportWhere == TeleportWhereType.SiegeFlag) {
          castle = CastleManager.getInstance().getCastle(player);
          fort = FortManager.getInstance().getFort(player);
          clanhall =
              ClanHallManager.getInstance()
                  .getNearbyAbstractHall(activeChar.getX(), activeChar.getY(), 10000);
          L2SiegeFlagInstance tw_flag =
              TerritoryWarManager.getInstance().getFlagForClan(player.getClan());
          if (tw_flag != null) return new Location(tw_flag.getX(), tw_flag.getY(), tw_flag.getZ());
          else if (castle != null) {
            if (castle.getSiege().getIsInProgress()) {
              // Check if player's clan is attacker
              List<L2Npc> flags = castle.getSiege().getFlag(player.getClan());
              if (flags != null && !flags.isEmpty()) {
                // Spawn to flag - Need more work to get player to the nearest flag
                L2Npc flag = flags.get(0);
                return new Location(flag.getX(), flag.getY(), flag.getZ());
              }
            }

          } else if (fort != null) {
            if (fort.getSiege().getIsInProgress()) {
              // Check if player's clan is attacker
              List<L2Npc> flags = fort.getSiege().getFlag(player.getClan());
              if (flags != null && !flags.isEmpty()) {
                // Spawn to flag - Need more work to get player to the nearest flag
                L2Npc flag = flags.get(0);
                return new Location(flag.getX(), flag.getY(), flag.getZ());
              }
            }
          } else if (clanhall != null && clanhall.isSiegableHall()) {
            SiegableHall sHall = (SiegableHall) clanhall;
            List<L2Npc> flags = sHall.getSiege().getFlag(player.getClan());
            if (flags != null && !flags.isEmpty()) {
              L2Npc flag = flags.get(0);
              return new Location(flag.getX(), flag.getY(), flag.getZ());
            }
          }
        }
      }

      if (teleportWhere == TeleportWhereType.Castle_banish) {
        castle = CastleManager.getInstance().getCastle(player);
        if (castle != null) return castle.getCastleZone().getBanishSpawnLoc();
      } else if (teleportWhere == TeleportWhereType.Fortress_banish) {
        fort = FortManager.getInstance().getFort(activeChar);
        if (fort != null) return fort.getFortZone().getBanishSpawnLoc();
      } else if (teleportWhere == TeleportWhereType.ClanHall_banish) {
        clanhall = ClanHallManager.getInstance().getClanHall(activeChar);
        if (clanhall != null) return clanhall.getZone().getBanishSpawnLoc();
      }

      // Karma player land out of city
      if (player.getKarma() > 0) {
        try {
          L2RespawnZone zone = ZoneManager.getInstance().getZone(player, L2RespawnZone.class);
          if (zone != null)
            return getRestartRegion(activeChar, zone.getRespawnPoint((L2PcInstance) activeChar))
                .getChaoticSpawnLoc();
          return getMapRegion(activeChar).getChaoticSpawnLoc();
        } catch (Exception e) {
          if (player.isFlyingMounted()) // prevent flying players to teleport outside of gracia
          return _regions.get("union_base_of_kserth").getChaoticSpawnLoc();
          return _regions.get("talking_island_town").getChaoticSpawnLoc();
        }
      }

      // Checking if needed to be respawned in "far" town from the castle;
      castle = CastleManager.getInstance().getCastle(player);
      if (castle != null) {
        if (castle.getSiege().getIsInProgress()) {
          // Check if player's clan is participating
          if ((castle.getSiege().checkIsDefender(player.getClan())
                  || castle.getSiege().checkIsAttacker(player.getClan()))
              && SevenSigns.getInstance().getSealOwner(SevenSigns.SEAL_STRIFE)
                  == SevenSigns.CABAL_DAWN) return castle.getCastleZone().getOtherSpawnLoc();
        }
      }

      // Checking if in an instance
      if (player.getInstanceId() > 0) {
        Instance inst = InstanceManager.getInstance().getInstance(player.getInstanceId());
        if (inst != null) {
          coord = inst.getSpawnLoc();
          if (coord[0] != 0 && coord[1] != 0 && coord[2] != 0)
            return new Location(coord[0], coord[1], coord[2]);
        }
      }
    }

    // Get the nearest town
    try {
      L2RespawnZone zone = ZoneManager.getInstance().getZone(activeChar, L2RespawnZone.class);
      if (zone != null)
        return getRestartRegion(activeChar, zone.getRespawnPoint((L2PcInstance) activeChar))
            .getSpawnLoc();
      return getMapRegion(activeChar).getSpawnLoc();
    } catch (Exception e) {
      // port to the Talking Island if no closest town found
      if (Config.DEBUG)
        _log.log(
            Level.WARNING,
            "Not defined respawn point for coords loc X="
                + activeChar.getX()
                + " Y="
                + activeChar.getY()
                + " Z="
                + activeChar.getZ());
      return _regions.get("talking_island_town").getSpawnLoc();
    }
  }