コード例 #1
0
ファイル: Kamaloka.java プロジェクト: auras2010/project-nmsx
  /** 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
  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();
    }
  }