{
L2PcInstance player = (L2PcInstance) activeChar;
// If in Monster Derby Track
if(player.isInsideZone(L2Character.ZONE_MONSTERTRACK))
return new Location(12661, 181687, -3560);
Castle castle = null;
Fort fort = 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());
}
// If teleport to fort
if(teleportWhere == TeleportWhereType.Fortress)
{
fort = FortManager.getInstance().getFortByOwner(player.getClan());
}
// Check if player is on castle&fortress ground
if(castle == null)
{
castle = CastleManager.getInstance().getCastle(player);
}
if(fort == null)
{
fort = FortManager.getInstance().getFort(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());
}
flags = null;
}
}
else if(fort != null && fort.getFortId() > 0)
{
// teleporting to castle or fortress
// is on caslte with siege and player's clan is defender
if(teleportWhere == TeleportWhereType.Fortress || teleportWhere == TeleportWhereType.Fortress && fort.getSiege().getIsInProgress() && fort.getSiege().getDefenderClan(player.getClan()) != null)
{
coord = fort.getZone().getSpawn();
return new Location(coord[0], coord[1], coord[2]);
}
if(teleportWhere == TeleportWhereType.SiegeFlag && fort.getSiege().getIsInProgress())
{
// check if player's clan is attacker
List<L2NpcInstance> flags = fort.getSiege().getFlag(player.getClan());
if(flags != null && !flags.isEmpty())
{
// spawn to flag
L2NpcInstance flag = flags.get(0);
return new Location(flag.getX(), flag.getY(), flag.getZ());
}
flags = null;
}
}
}
castle = null;
fort = null;
// 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]);
}
L2ChaoticZone chaotic = ChaoticManager.getInstance().getChaotic(player);
if(chaotic != null)
{
coord = chaotic.getSpawnLoc();
return new Location(coord[0], coord[1], coord[2]);
}
L2EventZone event = EventZoneManager.getInstance().getEventZone(player);
if(event != null)
{
coord = event.getSpawnLoc();
return new Location(coord[0], coord[1], coord[2]);
}
L2KamalokaZone kama = KamalokaZoneManager.getInstance().getKamaZone(player);
if(kama != null)
{
coord = kama.getSpawnLoc();
return new Location(coord[0], coord[1], coord[2]);
}
L2DmZone dm = DmManager.getInstance().getChaotic(player);
if(dm != null)
{
coord = dm.getSpawnLoc();
return new Location(coord[0], coord[1], coord[2]);
}
}
// Get the nearest town
L2TownZone local_zone = null;
if(activeChar!=null && (local_zone = TownManager.getInstance().getClosestTown(activeChar))!=null)
{
coord = local_zone.getSpawnLoc();
return new Location(coord[0], coord[1], coord[2]);
}
local_zone = TownManager.getInstance().getTown(9); //giran
coord = local_zone.getSpawnLoc();
return new Location(coord[0], coord[1], coord[2]);
}