11-05-2010, 11:37 AM
Подскажите как сделать осаду 3 раза в неделю
Знаю что в ядре в
\gameserver\model\entity\Siege.java
Там есть метод:
Пробовал изменить дату в этом календаре не вышло
Дата ставилась на осаде левая
п.с может быть к ней его где то добавляется что то но я не нашел (
Как делал:
Сам скрипт:
Знаю что в ядре в
\gameserver\model\entity\Siege.java
Там есть метод:
setNextSiegeDate()
Код:
/** Set the date for the next siege. */
private void setNextSiegeDate()
{
Calendar siegeDate = getCastle().getSiegeDate();
if (siegeDate == null)
return;
while (siegeDate.getTimeInMillis() < Calendar.getInstance().getTimeInMillis())
{
// from CT2.3 Castle sieges are on Sunday, but if server admins
// allow to set day of the siege
// than sieges can occur on Saturdays as well
if (siegeDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY && !Config.CL_SET_SIEGE_TIME_LIST.contains("day"))
siegeDate.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
// set the next siege day to the next weekend
siegeDate.add(Calendar.DAY_OF_MONTH, 7);
if (!SevenSigns.getInstance().isDateInSealValidPeriod(siegeDate) && !Config.ALT_SIEGE_EVERY_WEEK)
siegeDate.add(Calendar.DAY_OF_MONTH, 7);
_isRegistrationOver = false; // Allow registration for next siege
}
}
Дата ставилась на осаде левая
п.с может быть к ней его где то добавляется что то но я не нашел (
Как делал:
setNextSiegeDate()
Код:
/** Set the date for the next siege. */
private void setNextSiegeDate()
{
Calendar siegeDate = getCastle().getSiegeDate();
if (siegeDate == null)
return;
while (siegeDate.getTimeInMillis() < Calendar.getInstance().getTimeInMillis())
{
// Осады ТОЛЬКО по Субботам!!!
if (siegeDate.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY)
siegeDate.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (siegeDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY && !Config.CL_SET_SIEGE_TIME_LIST.contains("day"))
siegeDate.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
siegeDate.set(Calendar.HOUR_OF_DAY, 20);
siegeDate.set(Calendar.MINUTE, 0);
siegeDate.set(Calendar.SECOND, 0);
// set the next siege day to the next weekend
siegeDate.add(Calendar.DAY_OF_MONTH, 7);
}
if (!SevenSigns.getInstance().isDateInSealValidPeriod(siegeDate) && !Config.ALT_SIEGE_EVERY_WEEK)
{
int data = 0;
Calendar Time = Calendar.getInstance();
if (Time.get(Calendar.DAY_OF_WEEK) == 1)
data = 2;
else if (Time.get(Calendar.DAY_OF_WEEK) == 2)
data = 1;
else if (Time.get(Calendar.DAY_OF_WEEK) == 3)
data = 2;
else if (Time.get(Calendar.DAY_OF_WEEK) == 4)
data = 1;
else if (Time.get(Calendar.DAY_OF_WEEK) == 5)
data = 3;
else if (Time.get(Calendar.DAY_OF_WEEK) == 6)
data = 2;
else if (Time.get(Calendar.DAY_OF_WEEK) == 7)
data = 1;
siegeDate.add(Calendar.DAY_OF_WEEK, data);
siegeDate.set(Calendar.HOUR_OF_DAY, 20);
siegeDate.set(Calendar.MINUTE, 0);
siegeDate.set(Calendar.SECOND, 0);
}
_isRegistrationOver = false; // Allow registration for next siege
}
Скрипт Siege.java
Код:
package ru.nproject.gameserver.model.entity;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import javolution.util.FastList;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import ru.nproject.Config;
import ru.nproject.L2DatabaseFactory;
import ru.nproject.gameserver.Announcements;
import ru.nproject.gameserver.SevenSigns;
import ru.nproject.gameserver.ThreadPoolManager;
import ru.nproject.gameserver.datatables.ClanTable;
import ru.nproject.gameserver.datatables.MapRegionTable;
import ru.nproject.gameserver.datatables.NpcTable;
import ru.nproject.gameserver.idfactory.IdFactory;
import ru.nproject.gameserver.instancemanager.MercTicketManager;
import ru.nproject.gameserver.instancemanager.SiegeGuardManager;
import ru.nproject.gameserver.instancemanager.SiegeManager;
import ru.nproject.gameserver.instancemanager.SiegeRewardManager;
import ru.nproject.gameserver.instancemanager.SiegeManager.SiegeSpawn;
import ru.nproject.gameserver.model.L2Clan;
import ru.nproject.gameserver.model.L2ClanMember;
import ru.nproject.gameserver.model.L2Object;
import ru.nproject.gameserver.model.L2SiegeClan;
import ru.nproject.gameserver.model.L2Spawn;
import ru.nproject.gameserver.model.L2SiegeClan.SiegeClanType;
import ru.nproject.gameserver.model.actor.L2Npc;
import ru.nproject.gameserver.model.actor.instance.L2ArtefactInstance;
import ru.nproject.gameserver.model.actor.instance.L2ControlTowerInstance;
import ru.nproject.gameserver.model.actor.instance.L2PcInstance;
import ru.nproject.gameserver.network.SystemMessageId;
import ru.nproject.gameserver.network.serverpackets.ExBrExtraUserInfo;
import ru.nproject.gameserver.network.serverpackets.RelationChanged;
import ru.nproject.gameserver.network.serverpackets.SiegeInfo;
import ru.nproject.gameserver.network.serverpackets.SystemMessage;
import ru.nproject.gameserver.network.serverpackets.UserInfo;
import ru.nproject.gameserver.templates.chars.L2NpcTemplate;
public class Siege
{
private static final Logger _log = LogManager.getLogger(Siege.class);
// typeId's
private static final byte OWNER = -1;
private static final byte DEFENDER = 0;
private static final byte ATTACKER = 1;
private static final byte DEFENDER_NOT_APPROWED = 2;
static enum TeleportWhoType
{
All, Attacker, DefenderNotOwner, Owner, Spectator
}
private int _controlTowerCount;
private int _controlTowerMaxCount;
private int _lastOwnerId;
class ScheduleEndSiegeTask implements Runnable
{
private Castle _castleInst;
protected ScheduleEndSiegeTask(Castle pCastle)
{
_castleInst = pCastle;
}
public void run()
{
if (!getIsInProgress())
return;
try
{
long timeRemaining = _siegeEndDate.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
if (timeRemaining > 3600000)
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_HOURS_UNTIL_SIEGE_CONCLUSION);
sm.addNumber(2);
announceToPlayer(sm, true);
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndSiegeTask(_castleInst), timeRemaining - 3600000); // Prepare task for 1 hr left.
}
else if ((timeRemaining <= 3600000) && (timeRemaining > 600000))
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_MINUTES_UNTIL_SIEGE_CONCLUSION);
sm.addNumber(Math.round(timeRemaining / 60000));
announceToPlayer(sm, true);
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndSiegeTask(_castleInst), timeRemaining - 600000); // Prepare
// task
// for
// 10
// minute left.
}
else if ((timeRemaining <= 600000) && (timeRemaining > 300000))
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_MINUTES_UNTIL_SIEGE_CONCLUSION);
sm.addNumber(Math.round(timeRemaining / 60000));
announceToPlayer(sm, true);
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndSiegeTask(_castleInst), timeRemaining - 300000); // Prepare
// task
// for 5
// minute left.
}
else if ((timeRemaining <= 300000) && (timeRemaining > 10000))
{
SystemMessage sm = new SystemMessage(SystemMessageId.S1_MINUTES_UNTIL_SIEGE_CONCLUSION);
sm.addNumber(Math.round(timeRemaining / 60000));
announceToPlayer(sm, true);
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndSiegeTask(_castleInst), timeRemaining - 10000); // Prepare
// task
// for
// 10
// seconds count down
}
else if ((timeRemaining <= 10000) && (timeRemaining > 0))
{
SystemMessage sm = new SystemMessage(SystemMessageId.CASTLE_SIEGE_S1_SECONDS_LEFT);
sm.addNumber(Math.round(timeRemaining / 1000));
announceToPlayer(sm, true);
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndSiegeTask(_castleInst), timeRemaining); // Prepare
// task
// for second
// count
// down
}
else
{
_castleInst.getSiege().endSiege();
}
}
catch (Exception e)
{
_log.error("", e);
}
}
}
class ScheduleStartSiegeTask implements Runnable
{
private Castle _castleInst;
protected ScheduleStartSiegeTask(Castle pCastle)
{
_castleInst = pCastle;
}
public void run()
{
_scheduledStartSiegeTask.cancel(false);
if (getIsInProgress())
return;
try
{
if (!getIsTimeRegistrationOver())
{
long regTimeRemaining = getTimeRegistrationOverDate().getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
if (regTimeRemaining > 0)
{
_scheduledStartSiegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleStartSiegeTask(_castleInst), regTimeRemaining);
return;
}
else
endTimeRegistration(true);
}
long timeRemaining = getSiegeDate().getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
if (timeRemaining > 86400000)
{
_scheduledStartSiegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleStartSiegeTask(_castleInst), timeRemaining - 86400000); // Prepare task for 24 before siege start to end registration
}
else if ((timeRemaining <= 86400000) && (timeRemaining > 13600000))
{
SystemMessage sm = new SystemMessage(SystemMessageId.REGISTRATION_TERM_FOR_S1_ENDED);
sm.addString(getCastle().getName());
Announcements.getInstance().announceToAll(sm);
_isRegistrationOver = true;
clearSiegeWaitingClan();
_scheduledStartSiegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleStartSiegeTask(_castleInst), timeRemaining - 13600000); // Prepare task for 1 hr left before siege start.z
}
else if ((timeRemaining <= 13600000) && (timeRemaining > 600000))
{
_scheduledStartSiegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleStartSiegeTask(_castleInst), timeRemaining - 600000); // Prepare task for 10 min left before siege start.
}
else if ((timeRemaining <= 600000) && (timeRemaining > 300000))
{
_scheduledStartSiegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleStartSiegeTask(_castleInst), timeRemaining - 300000); // Prepare task for 5 min left before siege start.
}
else if ((timeRemaining <= 300000) && (timeRemaining > 10000))
{
_scheduledStartSiegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleStartSiegeTask(_castleInst), timeRemaining - 10000); // Prepare task for 10 seconds left before siege start.
}
else if ((timeRemaining <= 10000) && (timeRemaining > 0))
{
_scheduledStartSiegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleStartSiegeTask(_castleInst), timeRemaining); // Prepare task for second count down
}
else
{
_castleInst.getSiege().startSiege();
}
}
catch (Exception e)
{
_log.error("", e);
}
}
}
private List<L2SiegeClan> _attackerClans = new FastList<L2SiegeClan>();
private List<L2SiegeClan> _defenderClans = new FastList<L2SiegeClan>();
private List<L2SiegeClan> _defenderWaitingClans = new FastList<L2SiegeClan>();
// Castle setting
private List<L2ControlTowerInstance> _controlTowers = new FastList<L2ControlTowerInstance>();
private List<L2ArtefactInstance> _artefacts = new FastList<L2ArtefactInstance>();
private Castle[] _castle;
private boolean _isInProgress = false;
private boolean _isNormalSide = true; // true = Atk is Atk, false = Atk is
// Def
protected boolean _isRegistrationOver = false;
protected Calendar _siegeEndDate;
private SiegeGuardManager _siegeGuardManager;
protected ScheduledFuture<?> _scheduledStartSiegeTask = null;
protected Siege(Castle[] castle)
{
_castle = castle;
_siegeGuardManager = new SiegeGuardManager(getCastle());
startAutoTask();
}
public void endSiege()
{
if (getIsInProgress())
{
SystemMessage sm = new SystemMessage(SystemMessageId.SIEGE_OF_S1_HAS_ENDED);
sm.addString(getCastle().getName());
Announcements.getInstance().announceToAll(sm);
if (getCastle().getOwnerId() > 0)
{
L2Clan clan = ClanTable.getInstance().getClan(getCastle().getOwnerId());
sm = new SystemMessage(SystemMessageId.CLAN_S1_VICTORIOUS_OVER_S2_S_SIEGE);
sm.addString(clan.getName());
sm.addString(getCastle().getName());
Announcements.getInstance().announceToAll(sm);
if (getCastle().getOwnerId() == _lastOwnerId)
{
clan.setHonoraryItems(clan.getHonoraryItems() + 1);
clan.updateClanInDB();
}
else
{
for (L2ClanMember member : clan.getMembers())
{
if (member != null)
{
L2PcInstance player = member.getPlayerInstance();
if(player != null && player.isNoble())
{
Hero.getInstance().setCastleTaken(player.getObjectId(), getCastle().getCastleId());
}
}
}
}
}
else
{
sm = new SystemMessage(SystemMessageId.SIEGE_S1_DRAW);
sm.addString(getCastle().getName());
Announcements.getInstance().announceToAll(sm);
}
if (_lastOwnerId > 0 && getCastle().getOwnerId() != _lastOwnerId)
{
L2Clan clan = ClanTable.getInstance().getClan(_lastOwnerId);
clan.setHonoraryItems(0);
clan.updateClanInDB();
}
getCastle().updateClansReputation();
removeFlags(); // Removes all flags. Note: Remove flag before
// teleporting players
teleportPlayer(Siege.TeleportWhoType.Attacker, MapRegionTable.TeleportWhereType.Town); // Teleport to the second closest town
teleportPlayer(Siege.TeleportWhoType.DefenderNotOwner, MapRegionTable.TeleportWhereType.Town); // Teleport to the second closest town
teleportPlayer(Siege.TeleportWhoType.Spectator, MapRegionTable.TeleportWhereType.Town); // Teleport to the second closest town
_isInProgress = false; // Flag so that siege instance can be started
updatePlayerSiegeStateFlags(true);
saveCastleSiege(); // Save castle specific data
clearSiegeClan(); // Clear siege clan from db
removeControlTower(); // Remove all control tower from this castle
removeArtefacts(); // Remove all artefacts from this castle
_siegeGuardManager.unspawnSiegeGuard(); // Remove all spawned siege guard from this castle
if (getCastle().getOwnerId() > 0)
_siegeGuardManager.removeMercs();
getCastle().spawnDoor(); // Respawn door to castle
getCastle().getZone().updateZoneStatusForCharactersInside();
// Siege Reward Manager
if(getCastle().getOwnerId() > 0)
SiegeRewardManager.getInstance().notifySiegeEnded(ClanTable.getInstance().getClan(getCastle().getOwnerId()), getCastle().getName());
}
}
private void removeDefender(L2SiegeClan sc)
{
if (sc != null)
getDefenderClans().remove(sc);
}
private void removeAttacker(L2SiegeClan sc)
{
if (sc != null)
getAttackerClans().remove(sc);
}
private void addDefender(L2SiegeClan sc, SiegeClanType type)
{
if (sc == null)
return;
sc.setType(type);
getDefenderClans().add(sc);
}
private void addAttacker(L2SiegeClan sc)
{
if (sc == null)
return;
sc.setType(SiegeClanType.ATTACKER);
getAttackerClans().add(sc);
}
/**
* When control of castle changed during siege<BR>
* <BR>
*/
protected void midVictory()
{
if (getIsInProgress()) // Siege still in progress
{
if (getCastle().getOwnerId() > 0)
_siegeGuardManager.removeMercs(); // Remove all merc entry from
// db
if (getDefenderClans().isEmpty() && // If defender doesn't exist (Pc
// vs Npc)
getAttackerClans().size() == 1 // Only 1 attacker
)
{
L2SiegeClan sc_newowner = getAttackerClan(getCastle().getOwnerId());
removeAttacker(sc_newowner);
addDefender(sc_newowner, SiegeClanType.OWNER);
endSiege();
return;
}
if (getCastle().getOwnerId() > 0)
{
int allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();
if (getDefenderClans().isEmpty()) // If defender doesn't exist (Pc vs Npc) and only an alliance attacks
{
// The player's clan is in an alliance
if (allyId != 0)
{
boolean allinsamealliance = true;
for (L2SiegeClan sc : getAttackerClans())
{
if (sc != null)
{
if (ClanTable.getInstance().getClan(sc.getClanId()).getAllyId() != allyId)
allinsamealliance = false;
}
}
if (allinsamealliance)
{
L2SiegeClan sc_newowner = getAttackerClan(getCastle().getOwnerId());
removeAttacker(sc_newowner);
addDefender(sc_newowner, SiegeClanType.OWNER);
endSiege();
return;
}
}
}
for (L2SiegeClan sc : getDefenderClans())
{
if (sc != null)
{
removeDefender(sc);
addAttacker(sc);
}
}
L2SiegeClan sc_newowner = getAttackerClan(getCastle().getOwnerId());
removeAttacker(sc_newowner);
addDefender(sc_newowner, SiegeClanType.OWNER);
// The player's clan is in an alliance
if (allyId != 0)
{
L2Clan[] clanList = ClanTable.getInstance().getClans();
for (L2Clan clan : clanList)
{
if (clan.getAllyId() == allyId)
{
L2SiegeClan sc = getAttackerClan(clan.getClanId());
if (sc != null)
{
removeAttacker(sc);
addDefender(sc, SiegeClanType.DEFENDER);
}
}
}
}
teleportPlayer(Siege.TeleportWhoType.Attacker, MapRegionTable.TeleportWhereType.SiegeFlag); // Teleport to the second closest town
teleportPlayer(Siege.TeleportWhoType.Spectator, MapRegionTable.TeleportWhereType.Town); // Teleport to the second closest town
removeDefenderFlags(); // Removes defenders' flags
getCastle().removeUpgrade(); // Remove all castle upgrade
getCastle().spawnDoor(true); // Respawn door to castle but make them weaker (50% hp)
removeControlTower(); // Remove all control tower from this castle
_controlTowerCount = 0;// Each new siege midvictory CT are completely respawned.
_controlTowerMaxCount = 0;
spawnControlTower(getCastle().getCastleId());
updatePlayerSiegeStateFlags(false);
}
}
}
/**
* When siege starts<BR>
* <BR>
*/
public void startSiege()
{
if (!getIsInProgress())
{
if (getCastle().getOwnerId() > 0)
_lastOwnerId = getCastle().getOwnerId();
if (getAttackerClans().isEmpty())
{
SystemMessage sm;
if (getCastle().getOwnerId() <= 0)
sm = new SystemMessage(SystemMessageId.SIEGE_OF_S1_HAS_BEEN_CANCELED_DUE_TO_LACK_OF_INTEREST);
else
sm = new SystemMessage(SystemMessageId.S1_SIEGE_WAS_CANCELED_BECAUSE_NO_CLANS_PARTICIPATED);
sm.addString(getCastle().getName());
Announcements.getInstance().announceToAll(sm);
saveCastleSiege();
if (_lastOwnerId > 0)
{
L2Clan clan = ClanTable.getInstance().getClan(_lastOwnerId);
clan.setHonoraryItems(clan.getHonoraryItems() + 1);
clan.updateClanInDB();
}
return;
}
_isNormalSide = true; // Atk is now atk
_isInProgress = true; // Flag so that same siege instance cannot be
// started again
loadSiegeClan(); // Load siege clan from db
updatePlayerSiegeStateFlags(false);
teleportPlayer(Siege.TeleportWhoType.Attacker, MapRegionTable.TeleportWhereType.Town); // Teleport
// to
// the
// closest town
// teleportPlayer(Siege.TeleportWhoType.Spectator,
// MapRegionTable.TeleportWhereType.Town); // Teleport to the second
// closest town
_controlTowerCount = 0;
_controlTowerMaxCount = 0;
spawnControlTower(getCastle().getCastleId()); // Spawn control tower
spawnArtefacts(getCastle().getCastleId()); // Spawn castle artefacts
getCastle().spawnDoor(); // Spawn door
spawnSiegeGuard(); // Spawn siege guard
MercTicketManager.getInstance().deleteTickets(getCastle().getCastleId()); // remove the
// tickets
// from the
// ground
getCastle().getZone().updateZoneStatusForCharactersInside();
// Schedule a task to prepare auto siege end
_siegeEndDate = Calendar.getInstance();
_siegeEndDate.add(Calendar.MINUTE, SiegeManager.getInstance().getSiegeLength());
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndSiegeTask(getCastle()), 1000); // Prepare
// auto end
// task
SystemMessage sm = new SystemMessage(SystemMessageId.SIEGE_OF_S1_HAS_STARTED);
sm.addString(getCastle().getName());
Announcements.getInstance().announceToAll(sm);
}
}
/**
* Announce to player.<BR>
* <BR>
*
* @param message
* The SystemMessage to send to player
* @param bothSides
* True - broadcast to both attackers and defenders. False - only to defenders.
*/
public void announceToPlayer(SystemMessage message, boolean bothSides)
{
for (L2SiegeClan siegeClans : getDefenderClans())
{
L2Clan clan = ClanTable.getInstance().getClan(siegeClans.getClanId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
if (member != null)
member.sendPacket(message);
}
}
if (bothSides)
{
for (L2SiegeClan siegeClans : getAttackerClans())
{
L2Clan clan = ClanTable.getInstance().getClan(siegeClans.getClanId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
if (member != null)
member.sendPacket(message);
}
}
}
}
private void updatePlayerSiegeStateFlags(boolean clear)
{
L2Clan clan;
for (L2SiegeClan siegeclan : getAttackerClans())
{
if (siegeclan == null)
continue;
clan = ClanTable.getInstance().getClan(siegeclan.getClanId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
if (member == null)
continue;
if (clear)
{
member.setSiegeState((byte) 0);
member.setIsInSiege(false);
member.stopFameTask();
}
else
{
member.setSiegeState((byte) 1);
if (checkIfInZone(member))
{
member.setIsInSiege(true);
member.startFameTask(Config.CASTLE_ZONE_FAME_TASK_FREQUENCY * 1000, Config.CASTLE_ZONE_FAME_AQUIRE_POINTS);
}
}
member.sendPacket(new UserInfo(member));
member.sendPacket(new ExBrExtraUserInfo(member));
// synchronized (member.getKnownList().getKnownPlayers())
{
for (L2PcInstance player : member.getKnownList().getKnownPlayers().values())
{
try
{
player.sendPacket(new RelationChanged(member, member.getRelation(player), member.isAutoAttackable(player)));
if (member.getPet() != null)
player.sendPacket(new RelationChanged(member.getPet(), member.getRelation(player), member.isAutoAttackable(player)));
}
catch (NullPointerException e)
{
}
}
}
}
}
for (L2SiegeClan siegeclan : getDefenderClans())
{
if (siegeclan == null)
continue;
clan = ClanTable.getInstance().getClan(siegeclan.getClanId());
for (L2PcInstance member : clan.getOnlineMembers(0))
{
if (member == null)
continue;
if (clear)
{
member.setSiegeState((byte) 0);
member.setIsInSiege(false);
member.stopFameTask();
}
else
{
member.setSiegeState((byte) 2);
if (checkIfInZone(member))
{
member.setIsInSiege(true);
member.startFameTask(Config.CASTLE_ZONE_FAME_TASK_FREQUENCY * 1000, Config.CASTLE_ZONE_FAME_AQUIRE_POINTS);
}
}
member.sendPacket(new UserInfo(member));
member.sendPacket(new ExBrExtraUserInfo(member));
// synchronized (member.getKnownList().getKnownPlayers())
{
for (L2PcInstance player : member.getKnownList().getKnownPlayers().values())
{
try
{
player.sendPacket(new RelationChanged(member, member.getRelation(player), member.isAutoAttackable(player)));
if (member.getPet() != null)
player.sendPacket(new RelationChanged(member.getPet(), member.getRelation(player), member.isAutoAttackable(player)));
}
catch (NullPointerException e)
{
}
}
}
}
}
}
/**
* Approve clan as defender for siege<BR>
* <BR>
*
* @param clanId
* The int of player's clan id
*/
public void approveSiegeDefenderClan(int clanId)
{
if (clanId <= 0)
return;
saveSiegeClan(ClanTable.getInstance().getClan(clanId), DEFENDER, true);
loadSiegeClan();
}
/** Return true if object is inside the zone */
private boolean checkIfInZone(L2Object object)
{
return checkIfInZone(object.getX(), object.getY(), object.getZ());
}
/** Return true if object is inside the zone */
public boolean checkIfInZone(int x, int y, int z)
{
return (getIsInProgress() && (getCastle().checkIfInZone(x, y, z))); // Castle
// zone
// during
// siege
}
/**
* Return true if clan is attacker<BR>
* <BR>
*
* @param clan
* The L2Clan of the player
*/
public boolean checkIsAttacker(L2Clan clan)
{
return (getAttackerClan(clan) != null);
}
/**
* Return true if clan is defender<BR>
* <BR>
*
* @param clan
* The L2Clan of the player
*/
public boolean checkIsDefender(L2Clan clan)
{
return (getDefenderClan(clan) != null);
}
/**
* Return true if clan is defender waiting approval<BR>
* <BR>
*
* @param clan
* The L2Clan of the player
*/
public boolean checkIsDefenderWaiting(L2Clan clan)
{
return (getDefenderWaitingClan(clan) != null);
}
/** Clear all registered siege clans from database for castle */
public void clearSiegeClan()
{
Connection con = null;
PreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("DELETE FROM siege_clans WHERE castle_id=?");
statement.setInt(1, getCastle().getCastleId());
statement.execute();
statement.close();
if (getCastle().getOwnerId() > 0)
{
statement = con.prepareStatement("DELETE FROM siege_clans WHERE clan_id=?");
statement.setInt(1, getCastle().getOwnerId());
statement.execute();
statement.close();
}
getAttackerClans().clear();
getDefenderClans().clear();
getDefenderWaitingClans().clear();
}
catch (Exception e)
{
_log.warn("Exception: clearSiegeClan(): " + e.getMessage());
e.printStackTrace();
}
finally
{
L2DatabaseFactory.close(con);
}
}
/** Clear all siege clans waiting for approval from database for castle */
protected void clearSiegeWaitingClan()
{
Connection con = null;
PreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("DELETE FROM siege_clans WHERE castle_id=? and type = 2");
statement.setInt(1, getCastle().getCastleId());
statement.execute();
statement.close();
getDefenderWaitingClans().clear();
}
catch (Exception e)
{
_log.warn("Exception: clearSiegeWaitingClan(): " + e.getMessage());
e.printStackTrace();
}
finally
{
L2DatabaseFactory.close(con);
}
}
/** Return list of L2PcInstance registered as attacker in the zone. */
public List<L2PcInstance> getAttackersInZone()
{
List<L2PcInstance> players = new FastList<L2PcInstance>();
L2Clan clan;
for (L2SiegeClan siegeclan : getAttackerClans())
{
clan = ClanTable.getInstance().getClan(siegeclan.getClanId());
for (L2PcInstance player : clan.getOnlineMembers(0))
{
if (player == null)
continue;
if (player.isInSiege())
players.add(player);
}
}
return players;
}
/**
* Return list of L2PcInstance registered as defender but not owner in the zone.
*/
public List<L2PcInstance> getDefendersButNotOwnersInZone()
{
List<L2PcInstance> players = new FastList<L2PcInstance>();
L2Clan clan;
for (L2SiegeClan siegeclan : getDefenderClans())
{
clan = ClanTable.getInstance().getClan(siegeclan.getClanId());
if (clan.getClanId() == getCastle().getOwnerId())
continue;
for (L2PcInstance player : clan.getOnlineMembers(0))
{
if (player == null)
continue;
if (player.isInSiege())
players.add(player);
}
}
return players;
}
/** Return list of L2PcInstance in the zone. */
public List<L2PcInstance> getPlayersInZone()
{
return getCastle().getZone().getAllPlayers();
}
/** Return list of L2PcInstance owning the castle in the zone. */
public List<L2PcInstance> getOwnersInZone()
{
List<L2PcInstance> players = new FastList<L2PcInstance>();
L2Clan clan;
for (L2SiegeClan siegeclan : getDefenderClans())
{
clan = ClanTable.getInstance().getClan(siegeclan.getClanId());
if (clan.getClanId() != getCastle().getOwnerId())
continue;
for (L2PcInstance player : clan.getOnlineMembers(0))
{
if (player == null)
continue;
if (player.isInSiege())
players.add(player);
}
}
return players;
}
/**
* Return list of L2PcInstance not registered as attacker or defender in the zone.
*/
public List<L2PcInstance> getSpectatorsInZone()
{
List<L2PcInstance> players = new FastList<L2PcInstance>();
// synchronized (L2World.getInstance().getAllPlayers())
for (L2PcInstance player : getCastle().getZone().getAllPlayers())
{
if (player == null)
continue;
if (!player.isInSiege())
players.add(player);
}
return players;
}
/** Control Tower was killed */
public void killedCT(L2Npc ct)
{
_controlTowerCount--;
if (_controlTowerCount < 0)
_controlTowerCount = 0;
}
/** Display list of registered clans */
public void listRegisterClan(L2PcInstance player)
{
player.sendPacket(new SiegeInfo(getCastle()));
}
/**
* Register clan as attacker<BR>
* <BR>
*
* @param player
* The L2PcInstance of the player trying to register
*/
public void registerAttacker(L2PcInstance player)
{
registerAttacker(player, false);
}
public void registerAttacker(L2PcInstance player, boolean force)
{
if (player.getClan() == null)
return;
int allyId = 0;
if (getCastle().getOwnerId() != 0)
allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();
if (allyId != 0)
{
if (player.getClan().getAllyId() == allyId && !force)
{
player.sendMessage("You cannot register as an attacker because your alliance owns the castle");
return;
}
}
if (force || checkIfCanRegister(player, ATTACKER))
saveSiegeClan(player.getClan(), ATTACKER, false); // Save to
// database
}
/**
* Register clan as defender<BR>
* <BR>
*
* @param player
* The L2PcInstance of the player trying to register
*/
public void registerDefender(L2PcInstance player)
{
registerDefender(player, false);
}
public void registerDefender(L2PcInstance player, boolean force)
{
if (getCastle().getOwnerId() <= 0)
player.sendMessage("You cannot register as a defender because " + getCastle().getName() + " is owned by NPC.");
else if (force || checkIfCanRegister(player, DEFENDER_NOT_APPROWED))
saveSiegeClan(player.getClan(), DEFENDER_NOT_APPROWED, false); // Save
// to
// database
}
/**
* Remove clan from siege<BR>
* <BR>
*
* @param clanId
* The int of player's clan id
*/
public void removeSiegeClan(int clanId)
{
if (clanId <= 0)
return;
Connection con = null;
PreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("DELETE FROM siege_clans WHERE castle_id=? and clan_id=?");
statement.setInt(1, getCastle().getCastleId());
statement.setInt(2, clanId);
statement.execute();
statement.close();
loadSiegeClan();
}
catch (Exception e)
{
_log.warn("Exception: removeSiegeClan(): " + e.getMessage());
e.printStackTrace();
}
finally
{
L2DatabaseFactory.close(con);
}
}
/**
* Remove clan from siege<BR>
* <BR>
*
* @param player
* The L2PcInstance of player/clan being removed
*/
public void removeSiegeClan(L2PcInstance player)
{
L2Clan clan = player.getClan();
if (clan == null || clan.getHasCastle() == getCastle().getCastleId() || !SiegeManager.getInstance().checkIsRegistered(clan, getCastle().getCastleId()))
return;
removeSiegeClan(clan.getClanId());
}
/**
* Start the auto tasks<BR>
* <BR>
*/
private void startAutoTask()
{
correctSiegeDateTime();
_log.info("Siege of " + getCastle().getName() + ": " + getCastle().getSiegeDate().getTime());
loadSiegeClan();
// Schedule siege auto start
if (_scheduledStartSiegeTask != null)
_scheduledStartSiegeTask.cancel(false);
_scheduledStartSiegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new Siege.ScheduleStartSiegeTask(getCastle()), 1000);
}
/**
* Teleport players
*/
private void teleportPlayer(TeleportWhoType teleportWho, MapRegionTable.TeleportWhereType teleportWhere)
{
List<L2PcInstance> players;
switch (teleportWho)
{
case Owner:
players = getOwnersInZone();
break;
case Attacker:
players = getAttackersInZone();
break;
case DefenderNotOwner:
players = getDefendersButNotOwnersInZone();
break;
case Spectator:
players = getSpectatorsInZone();
break;
default:
players = getPlayersInZone();
}
for (L2PcInstance player : players)
{
if (player.isGM() || player.isInJail())
continue;
player.teleToLocation(teleportWhere);
}
}
/**
* Add clan as attacker<BR>
* <BR>
*
* @param clanId
* The int of clan's id
*/
private void addAttacker(int clanId)
{
getAttackerClans().add(new L2SiegeClan(clanId, SiegeClanType.ATTACKER)); // Add
// registered
// attacker
// to
// attacker
// list
}
/**
* Add clan as defender<BR>
* <BR>
*
* @param clanId
* The int of clan's id
*/
private void addDefender(int clanId)
{
getDefenderClans().add(new L2SiegeClan(clanId, SiegeClanType.DEFENDER)); // Add
// registered
// defender
// to
// defender
// list
}
/**
* <p>
* Add clan as defender with the specified type
* </p>
*
* @param clanId
* The int of clan's id
* @param type
* the type of the clan
*/
private void addDefender(int clanId, SiegeClanType type)
{
getDefenderClans().add(new L2SiegeClan(clanId, type));
}
/**
* Add clan as defender waiting approval<BR>
* <BR>
*
* @param clanId
* The int of clan's id
*/
private void addDefenderWaiting(int clanId)
{
getDefenderWaitingClans().add(new L2SiegeClan(clanId, SiegeClanType.DEFENDER_PENDING)); // Add
// registered
// defender
// to
// defender
// list
}
/**
* Return true if the player can register.<BR>
* <BR>
*
* @param player
* The L2PcInstance of the player trying to register
* @param typeId
* -1 = owner 0 = defender, 1 = attacker, 2 = defender waiting
*/
private boolean checkIfCanRegister(L2PcInstance player, byte typeId)
{
if (getIsRegistrationOver())
{
SystemMessage sm = new SystemMessage(SystemMessageId.DEADLINE_FOR_SIEGE_S1_PASSED);
sm.addString(getCastle().getName());
player.sendPacket(sm);
}
else if (getIsInProgress())
player.sendPacket(new SystemMessage(SystemMessageId.NOT_SIEGE_REGISTRATION_TIME2));
else if (player.getClan() == null || player.getClan().getLevel() < SiegeManager.getInstance().getSiegeClanMinLevel())
player.sendPacket(new SystemMessage(SystemMessageId.ONLY_CLAN_LEVEL_5_ABOVE_MAY_SIEGE));
else if (player.getClan().getHasCastle() > 0)
player.sendPacket(new SystemMessage(SystemMessageId.CLAN_THAT_OWNS_CASTLE_CANNOT_PARTICIPATE_OTHER_SIEGE));
else if (player.getClan().getClanId() == getCastle().getOwnerId())
player.sendPacket(new SystemMessage(SystemMessageId.CLAN_THAT_OWNS_CASTLE_IS_AUTOMATICALLY_REGISTERED_DEFENDING));
else if (SiegeManager.getInstance().checkIsRegistered(player.getClan(), getCastle().getCastleId()))
player.sendPacket(new SystemMessage(SystemMessageId.ALREADY_REQUESTED_SIEGE_BATTLE));
else if (checkIfAlreadyRegisteredForSameDay(player.getClan()))
player.sendPacket(new SystemMessage(SystemMessageId.APPLICATION_DENIED_BECAUSE_ALREADY_SUBMITTED_A_REQUEST_FOR_ANOTHER_SIEGE_BATTLE));
else if ((typeId == ATTACKER) && (getAttackerClans().size() >= SiegeManager.getInstance().getAttackerMaxClans()))
player.sendPacket(new SystemMessage(SystemMessageId.ATTACKER_SIDE_FULL));
else if ((typeId == DEFENDER || typeId == DEFENDER_NOT_APPROWED || typeId == OWNER) && (getDefenderClans().size() + getDefenderWaitingClans().size() >= SiegeManager.getInstance().getDefenderMaxClans()))
player.sendPacket(new SystemMessage(SystemMessageId.DEFENDER_SIDE_FULL));
else
return true;
return false;
}
/**
* Return true if the clan has already registered to a siege for the same day.<BR>
* <BR>
*
* @param clan
* The L2Clan of the player trying to register
*/
private boolean checkIfAlreadyRegisteredForSameDay(L2Clan clan)
{
for (Siege siege : SiegeManager.getInstance().getSieges())
{
if (siege == this)
continue;
if (siege.getSiegeDate().get(Calendar.DAY_OF_WEEK) == this.getSiegeDate().get(Calendar.DAY_OF_WEEK))
{
if (siege.checkIsAttacker(clan))
return true;
if (siege.checkIsDefender(clan))
return true;
if (siege.checkIsDefenderWaiting(clan))
return true;
}
}
return false;
}
/**
* Return the correct siege date as Calendar.<BR>
* <BR>
*/
public void correctSiegeDateTime()
{
boolean corrected = false;
if (getCastle().getSiegeDate().getTimeInMillis() < Calendar.getInstance().getTimeInMillis())
{
// Since siege has past reschedule it to the next one
// This is usually caused by server being down
corrected = true;
setNextSiegeDate();
}
if (!SevenSigns.getInstance().isDateInSealValidPeriod(getCastle().getSiegeDate()))
{
// no sieges in Quest period! reschedule it to the next
// SealValidationPeriod
// This is usually caused by server being down
corrected = true;
setNextSiegeDate();
}
if (corrected)
saveSiegeDate();
}
/** Load siege clans. */
private void loadSiegeClan()
{
Connection con = null;
PreparedStatement statement = null;
try
{
getAttackerClans().clear();
getDefenderClans().clear();
getDefenderWaitingClans().clear();
// Add castle owner as defender (add owner first so that they are on
// the top of the defender list)
if (getCastle().getOwnerId() > 0)
addDefender(getCastle().getOwnerId(), SiegeClanType.OWNER);
ResultSet rs = null;
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT clan_id,type FROM siege_clans where castle_id=?");
statement.setInt(1, getCastle().getCastleId());
rs = statement.executeQuery();
int typeId;
while (rs.next())
{
typeId = rs.getInt("type");
if (typeId == DEFENDER)
addDefender(rs.getInt("clan_id"));
else if (typeId == ATTACKER)
addAttacker(rs.getInt("clan_id"));
else if (typeId == DEFENDER_NOT_APPROWED)
addDefenderWaiting(rs.getInt("clan_id"));
}
rs.close();
statement.close();
}
catch (Exception e)
{
_log.warn("Exception: loadSiegeClan(): " + e.getMessage());
e.printStackTrace();
}
finally
{
L2DatabaseFactory.close(con);
}
}
/** Remove all control tower spawned. */
private void removeControlTower()
{
if (_controlTowers != null && !_controlTowers.isEmpty())
{
// Remove all instances of control tower for this castle
for (L2ControlTowerInstance ct : _controlTowers)
{
if (ct != null)
{
try
{
ct.decayMe();
}
catch (Exception e)
{
_log.warn("Exception: removeControlTower(): " + e.getMessage());
e.printStackTrace();
}
}
}
_controlTowers.clear();
_controlTowers = null;
}
}
/** Remove all artefacts spawned. */
private void removeArtefacts()
{
if (_artefacts != null && !_artefacts.isEmpty())
{
// Remove all instances of control tower for this castle
for (L2ArtefactInstance ct : _artefacts)
{
if (ct != null)
{
try
{
ct.decayMe();
}
catch (Exception e)
{
_log.warn("Exception: removeArtefacts(): " + e.getMessage());
e.printStackTrace();
}
}
}
_artefacts.clear();
_artefacts = null;
}
}
/** Remove all flags. */
private void removeFlags()
{
for (L2SiegeClan sc : getAttackerClans())
{
if (sc != null)
sc.removeFlags();
}
for (L2SiegeClan sc : getDefenderClans())
{
if (sc != null)
sc.removeFlags();
}
}
/** Remove flags from defenders. */
private void removeDefenderFlags()
{
for (L2SiegeClan sc : getDefenderClans())
{
if (sc != null)
sc.removeFlags();
}
}
/** Save castle siege related to database. */
public void saveCastleSiege()
{
setNextSiegeDate(); // Set the next set date for 2 weeks from now
// Schedule Time registration end
getTimeRegistrationOverDate().setTimeInMillis(Calendar.getInstance().getTimeInMillis());
getTimeRegistrationOverDate().add(Calendar.DAY_OF_MONTH, 1);
getCastle().setIsTimeRegistrationOver(false);
saveSiegeDate(); // Save the new date
startAutoTask(); // Prepare auto start siege and end registration
}
/** Save siege date to database. */
private void saveSiegeDate()
{
if (_scheduledStartSiegeTask != null)
{
_scheduledStartSiegeTask.cancel(true);
_scheduledStartSiegeTask = ThreadPoolManager.getInstance().scheduleGeneral(new Siege.ScheduleStartSiegeTask(getCastle()), 1000);
}
Connection con = null;
PreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE castle SET siegeDate = ?, regTimeEnd = ?, regTimeOver = ? WHERE id = ?");
statement.setLong(1, getSiegeDate().getTimeInMillis());
statement.setLong(2, getTimeRegistrationOverDate().getTimeInMillis());
statement.setString(3, String.valueOf(getIsTimeRegistrationOver()));
statement.setInt(4, getCastle().getCastleId());
statement.execute();
statement.close();
}
catch (Exception e)
{
_log.warn("Exception: saveSiegeDate(): " + e.getMessage());
e.printStackTrace();
}
finally
{
L2DatabaseFactory.close(con);
}
}
/**
* Save registration to database.<BR>
* <BR>
*
* @param clan
* The L2Clan of player
* @param typeId
* -1 = owner 0 = defender, 1 = attacker, 2 = defender waiting
*/
private void saveSiegeClan(L2Clan clan, byte typeId, boolean isUpdateRegistration)
{
if (clan.getHasCastle() > 0)
return;
Connection con = null;
PreparedStatement statement = null;
try
{
if (typeId == DEFENDER || typeId == DEFENDER_NOT_APPROWED || typeId == OWNER)
{
if (getDefenderClans().size() + getDefenderWaitingClans().size() >= SiegeManager.getInstance().getDefenderMaxClans())
return;
}
else
{
if (getAttackerClans().size() >= SiegeManager.getInstance().getAttackerMaxClans())
return;
}
con = L2DatabaseFactory.getInstance().getConnection();
if (!isUpdateRegistration)
{
statement = con.prepareStatement("INSERT INTO siege_clans (clan_id,castle_id,type,castle_owner) values (?,?,?,0)");
statement.setInt(1, clan.getClanId());
statement.setInt(2, getCastle().getCastleId());
statement.setInt(3, typeId);
statement.execute();
statement.close();
}
else
{
statement = con.prepareStatement("UPDATE siege_clans SET type = ? WHERE castle_id = ? AND clan_id = ?");
statement.setInt(1, typeId);
statement.setInt(2, getCastle().getCastleId());
statement.setInt(3, clan.getClanId());
statement.execute();
statement.close();
}
if (typeId == DEFENDER || typeId == OWNER)
addDefender(clan.getClanId());
else if (typeId == ATTACKER)
addAttacker(clan.getClanId());
else if (typeId == DEFENDER_NOT_APPROWED)
addDefenderWaiting(clan.getClanId());
}
catch (Exception e)
{
_log.warn("Exception: saveSiegeClan(L2Clan clan, int typeId, boolean isUpdateRegistration): " + e.getMessage());
e.printStackTrace();
}
finally
{
L2DatabaseFactory.close(con);
}
}
/** Set the date for the next siege. */
private void setNextSiegeDate()
{
Calendar siegeDate = getCastle().getSiegeDate();
if (siegeDate == null)
return;
while (siegeDate.getTimeInMillis() < Calendar.getInstance().getTimeInMillis())
{
// from CT2.3 Castle sieges are on Sunday, but if server admins
// allow to set day of the siege
// than sieges can occur on Saturdays as well
if (siegeDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY && !Config.CL_SET_SIEGE_TIME_LIST.contains("day"))
siegeDate.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
// set the next siege day to the next weekend
siegeDate.add(Calendar.DAY_OF_MONTH, 7);
if (!SevenSigns.getInstance().isDateInSealValidPeriod(siegeDate) && !Config.ALT_SIEGE_EVERY_WEEK)
siegeDate.add(Calendar.DAY_OF_MONTH, 7);
_isRegistrationOver = false; // Allow registration for next siege
}
}
/** Spawn control tower. */
private void spawnControlTower(int Id)
{
// Set control tower array size if one does not exist
if (_controlTowers == null)
_controlTowers = new FastList<L2ControlTowerInstance>();
for (SiegeSpawn _sp : SiegeManager.getInstance().getControlTowerSpawnList(Id))
{
L2ControlTowerInstance ct;
L2NpcTemplate template = NpcTable.getInstance().getTemplate(_sp.getNpcId());
// TODO: Check/confirm if control towers have any special weapon
// resistances/vulnerabilities
// template.addVulnerability(Stats.BOW_WPN_VULN,0);
// template.addVulnerability(Stats.BLUNT_WPN_VULN,0);
// template.addVulnerability(Stats.DAGGER_WPN_VULN,0);
ct = new L2ControlTowerInstance(IdFactory.getInstance().getNextId(), template);
ct.setCurrentHpMp(_sp.getHp(), ct.getMaxMp());
ct.spawnMe(_sp.getLocation().getX(), _sp.getLocation().getY(), _sp.getLocation().getZ() + 20);
_controlTowerCount++;
_controlTowerMaxCount++;
_controlTowers.add(ct);
}
}
/**
* Spawn castle artefacts.<BR>
* <BR>
*/
private void spawnArtefacts(int Id)
{
if (_artefacts == null)
_artefacts = new FastList<L2ArtefactInstance>();
for (SiegeSpawn _sp : SiegeManager.getInstance().getArtefactSpawnList(Id))
{
L2ArtefactInstance art;
L2NpcTemplate template = NpcTable.getInstance().getTemplate(_sp.getNpcId());
art = new L2ArtefactInstance(IdFactory.getInstance().getNextId(), template);
art.spawnMe(_sp.getLocation().getX(), _sp.getLocation().getY(), _sp.getLocation().getZ() + 20);
_artefacts.add(art);
}
}
/**
* Spawn siege guard.<BR>
* <BR>
*/
private void spawnSiegeGuard()
{
if ((!SiegeManager._siegeGuardsAllowed && getCastle().getOwnerId() == 0) || (!SiegeManager._mercenariesAllowed && getCastle().getOwnerId() != 0))
return;
getSiegeGuardManager().spawnSiegeGuard();
// Register guard to the closest Control Tower
// When CT dies, so do all the guards that it controls
if (!getSiegeGuardManager().getSiegeGuardSpawn().isEmpty() && !_controlTowers.isEmpty())
{
L2ControlTowerInstance closestCt;
int x, y, z;
double distance;
double distanceClosest = 0;
for (L2Spawn spawn : getSiegeGuardManager().getSiegeGuardSpawn())
{
if (spawn == null)
continue;
closestCt = null;
distanceClosest = Integer.MAX_VALUE;
x = spawn.getLocx();
y = spawn.getLocy();
z = spawn.getLocz();
for (L2ControlTowerInstance ct : _controlTowers)
{
if (ct == null)
continue;
distance = ct.getDistanceSq(x, y, z);
if (distance < distanceClosest)
{
closestCt = ct;
distanceClosest = distance;
}
}
if (closestCt != null)
closestCt.registerGuard(spawn);
}
}
}
public final L2SiegeClan getAttackerClan(L2Clan clan)
{
if (clan == null)
return null;
return getAttackerClan(clan.getClanId());
}
public final L2SiegeClan getAttackerClan(int clanId)
{
for (L2SiegeClan sc : getAttackerClans())
if (sc != null && sc.getClanId() == clanId)
return sc;
return null;
}
public final List<L2SiegeClan> getAttackerClans()
{
if (_isNormalSide)
return _attackerClans;
return _defenderClans;
}
public final int getAttackerRespawnDelay()
{
return (SiegeManager.getInstance().getAttackerRespawnDelay());
}
public final Castle getCastle()
{
if (_castle == null || _castle.length <= 0)
return null;
return _castle[0];
}
public final L2SiegeClan getDefenderClan(L2Clan clan)
{
if (clan == null)
return null;
return getDefenderClan(clan.getClanId());
}
private final L2SiegeClan getDefenderClan(int clanId)
{
for (L2SiegeClan sc : getDefenderClans())
if (sc != null && sc.getClanId() == clanId)
return sc;
return null;
}
public final List<L2SiegeClan> getDefenderClans()
{
if (_isNormalSide)
return _defenderClans;
return _attackerClans;
}
private final L2SiegeClan getDefenderWaitingClan(L2Clan clan)
{
if (clan == null)
return null;
return getDefenderWaitingClan(clan.getClanId());
}
private final L2SiegeClan getDefenderWaitingClan(int clanId)
{
for (L2SiegeClan sc : getDefenderWaitingClans())
if (sc != null && sc.getClanId() == clanId)
return sc;
return null;
}
public final List<L2SiegeClan> getDefenderWaitingClans()
{
return _defenderWaitingClans;
}
public final boolean getIsInProgress()
{
return _isInProgress;
}
public final boolean getIsRegistrationOver()
{
return _isRegistrationOver;
}
public final boolean getIsTimeRegistrationOver()
{
return getCastle().getIsTimeRegistrationOver();
}
public final Calendar getSiegeDate()
{
return getCastle().getSiegeDate();
}
public final Calendar getTimeRegistrationOverDate()
{
return getCastle().getTimeRegistrationOverDate();
}
public void endTimeRegistration(boolean automatic)
{
getCastle().setIsTimeRegistrationOver(true);
if (!automatic)
saveSiegeDate();
}
public List<L2Npc> getFlag(L2Clan clan)
{
if (clan != null)
{
L2SiegeClan sc = getAttackerClan(clan);
if (sc != null)
return sc.getFlag();
}
return null;
}
public final SiegeGuardManager getSiegeGuardManager()
{
if (_siegeGuardManager == null)
_siegeGuardManager = new SiegeGuardManager(getCastle());
return _siegeGuardManager;
}
public int getControlTowerCount()
{
return _controlTowerCount;
}
}
Человек просто обязан ошибаться, раз другие учатся на его ошибках .......