/
tofu
/
l2interlude
Обзор
Документация
Войти
/
tofu
/
l2interlude
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/main/java/com/l2jserver/gameserver/network/clientpackets/RequestSetCastleSiegeTime.java
119 строк
4 KB
Zoey76
Copyright Update
01 янв 2025, 07:57
01 янв 2025, 07:57
16130a5
Код
Авторство
О чём код?
/* * Copyright © 2004-2025 L2J Server * * This file is part of L2J Server. * * L2J Server is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * L2J Server is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.l2jserver.gameserver.network.clientpackets; import static com.l2jserver.gameserver.config.Configuration.castle; import java.util.Calendar; import java.util.Date; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.l2jserver.gameserver.instancemanager.CastleManager; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.model.entity.Castle; import com.l2jserver.gameserver.network.SystemMessageId; import com.l2jserver.gameserver.network.serverpackets.SiegeInfo; import com.l2jserver.gameserver.network.serverpackets.SystemMessage; import com.l2jserver.gameserver.util.Broadcast; /** * @author UnAfraid */ public class RequestSetCastleSiegeTime extends L2GameClientPacket { private static final Logger LOG = LoggerFactory.getLogger(RequestSetCastleSiegeTime.class); private int _castleId; private long _time; @Override protected void readImpl() { _castleId = readD(); _time = readD(); _time *= 1000; } @Override protected void runImpl() { final L2PcInstance activeChar = getClient().getActiveChar(); final Castle castle = CastleManager.getInstance().getCastleById(_castleId); if ((activeChar == null) || (castle == null)) { LOG.warn("activeChar: {} castle: {} castleId: {}", activeChar, castle, _castleId); return; } if ((castle.getOwnerId() > 0) && (castle.getOwnerId() != activeChar.getClanId())) { LOG.warn("activeChar: {} castle: {} castleId: {} is trying to change siege date of not his own castle!", activeChar, castle, _castleId); return; } if (!activeChar.isClanLeader()) { LOG.warn("activeChar: {} castle: {} castleId: {} is trying to change siege date but is not clan leader!", activeChar, castle, _castleId); return; } if (!castle.getIsTimeRegistrationOver()) { if (isSiegeTimeValid(castle.getSiegeDate().getTimeInMillis(), _time)) { castle.getSiegeDate().setTimeInMillis(_time); castle.setIsTimeRegistrationOver(true); castle.getSiege().saveSiegeDate(); SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.S1_ANNOUNCED_SIEGE_TIME); msg.addCastleId(_castleId); Broadcast.toAllOnlinePlayers(msg); activeChar.sendPacket(new SiegeInfo(castle)); } else { LOG.warn("activeChar: {} castle: {} castleId: {} is trying to an invalid time ({} !", activeChar, castle, _castleId, new Date(_time)); } } else { LOG.warn("activeChar: {} castle: {} castleId: {} is trying to change siege date but currently not possible!", activeChar, castle, _castleId); } } private static boolean isSiegeTimeValid(long siegeDate, long chosenDate) { Calendar cal1 = Calendar.getInstance(); cal1.setTimeInMillis(siegeDate); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); Calendar cal2 = Calendar.getInstance(); cal2.setTimeInMillis(chosenDate); for (int hour : castle().getSiegeHourList()) { cal1.set(Calendar.HOUR_OF_DAY, hour); if (isEqual(cal1, cal2, Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR, Calendar.MINUTE, Calendar.SECOND)) { return true; } } return false; } private static boolean isEqual(Calendar cal1, Calendar cal2, int... fields) { for (int field : fields) { if (cal1.get(field) != cal2.get(field)) { return false; } } return true; } @Override public String getType() { return getClass().getSimpleName(); } }