{
L2PcInstance player = ((L2PcInstance)activeChar);
// If in Monster Derby Track
if (player.isInsideZone(L2Character.ZONE_MONSTERTRACK))
return new Location(12661, 181687, -3560);
Castle castle = null;
ClanHall clanhall = null;
if (player.getClan() != null)
{
// If teleport to clan hall
if (teleportWhere == TeleportWhereType.ClanHall)
{
clanhall = ClanHallManager.getInstance().getClanHallByOwner(player.getClan());
if (clanhall != null)
{
L2ClanHallZone zone = clanhall.getZone();
if (zone != null)
{
return zone.getSpawn();
}
}
}
// If teleport to castle
if (teleportWhere == TeleportWhereType.Castle) castle = CastleManager.getInstance().getCastleByOwner(player.getClan());
// Check if player is on castle ground
if (castle == null) castle = CastleManager.getInstance().getCastle(player);
if (castle != null && castle.getCastleId() > 0)
{
// If Teleporting to castle or
// If is on caslte with siege and player's clan is defender
if (teleportWhere == TeleportWhereType.Castle || (teleportWhere == TeleportWhereType.Castle && castle.getSiege().getIsInProgress() && castle.getSiege().getDefenderClan(player.getClan()) != null))
{
coord = castle.getZone().getSpawn();
return new Location(coord[0], coord[1], coord[2]);
}
if (teleportWhere == TeleportWhereType.SiegeFlag && castle.getSiege().getIsInProgress())
{
// Check if player's clan is attacker
List<L2NpcInstance> flags = castle.getSiege().getFlag(player.getClan());
if (flags != null && !flags.isEmpty())
{
// Spawn to flag - Need more work to get player to the nearest flag
L2NpcInstance flag = flags.get(0);
return new Location(flag.getX(), flag.getY(), flag.getZ());
}
}
}
}
// teleport RED PK 5+ to Floran Village
if(player.getPkKills() > 5 && player.getKarma() > 1) return new Location(17817, 170079, -3530);
//Karma player land out of city
if(player.getKarma() > 1)
{
int closest = getMapRegion(activeChar.getX(), activeChar.getY());
if(closest >= 0 && closest < _pointsWithKarmas.length)
return new Location(_pointsWithKarmas[closest][0], _pointsWithKarmas[closest][1], _pointsWithKarmas[closest][2]);
return new Location(17817, 170079, -3530);
}
// Checking if in arena
L2ArenaZone arena = ArenaManager.getInstance().getArena(player);
if (arena != null)
{
coord = arena.getSpawnLoc();
return new Location(coord[0], coord[1], coord[2]);
}
}
// Get the nearest town
// TODO: Micht: Maybe we should add some checks to prevent exception here.
coord = TownManager.getInstance().getClosestTown(activeChar).getSpawnLoc();
return new Location(coord[0], coord[1], coord[2]);
}