Quellcode durchsuchen

BETA: Implementing missing castle siege time change feature.

Rumen Nikiforov vor 11 Jahren
Ursprung
Commit
2a6d840ad2

+ 0 - 4
L2J_Server_BETA/dist/game/config/Feature.properties

@@ -9,10 +9,6 @@
 # ---------------------------------------------------------------------------
 
 # Siege Time rules
-# Which values can change Castle Lords (day,hour,minute)
-# Default: hour
-CLSetSiegeTimeList = hour
-
 # Which hours can change Castle Lords
 # Default: 16,20
 SiegeHourList = 16,20

+ 6 - 52
L2J_Server_BETA/java/com/l2jserver/Config.java

@@ -57,6 +57,7 @@ import com.l2jserver.gameserver.enums.IllegalActionPunishmentType;
 import com.l2jserver.gameserver.model.holders.ItemHolder;
 import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
 import com.l2jserver.gameserver.util.FloodProtectorConfig;
+import com.l2jserver.gameserver.util.Util;
 import com.l2jserver.util.PropertiesParser;
 import com.l2jserver.util.StringUtil;
 
@@ -331,9 +332,7 @@ public final class Config
 	public static long CS_SUPPORT_FEE_RATIO;
 	public static int CS_SUPPORT1_FEE;
 	public static int CS_SUPPORT2_FEE;
-	public static List<String> CL_SET_SIEGE_TIME_LIST;
-	public static List<Integer> SIEGE_HOUR_LIST_MORNING;
-	public static List<Integer> SIEGE_HOUR_LIST_AFTERNOON;
+	public static List<Integer> SIEGE_HOUR_LIST;
 	public static int OUTER_DOOR_UPGRADE_PRICE2;
 	public static int OUTER_DOOR_UPGRADE_PRICE3;
 	public static int OUTER_DOOR_UPGRADE_PRICE5;
@@ -1264,57 +1263,12 @@ public final class Config
 			CH_FRONT1_FEE = Feature.getInt("ClanHallFrontPlatformFunctionFeeLvl1", 1300);
 			CH_FRONT2_FEE = Feature.getInt("ClanHallFrontPlatformFunctionFeeLvl2", 4000);
 			CH_BUFF_FREE = Feature.getBoolean("AltClanHallMpBuffFree", false);
-			
-			CL_SET_SIEGE_TIME_LIST = new ArrayList<>();
-			SIEGE_HOUR_LIST_MORNING = new ArrayList<>();
-			SIEGE_HOUR_LIST_AFTERNOON = new ArrayList<>();
-			String[] sstl = Feature.getString("CLSetSiegeTimeList", "").split(",");
-			if (sstl.length != 0)
+			SIEGE_HOUR_LIST = new ArrayList<>();
+			for (String hour : Feature.getString("SiegeHourList", "").split(","))
 			{
-				boolean isHour = false;
-				for (String st : sstl)
+				if (Util.isDigit(hour))
 				{
-					if (st.equalsIgnoreCase("day") || st.equalsIgnoreCase("hour") || st.equalsIgnoreCase("minute"))
-					{
-						if (st.equalsIgnoreCase("hour"))
-						{
-							isHour = true;
-						}
-						CL_SET_SIEGE_TIME_LIST.add(st.toLowerCase());
-					}
-					else
-					{
-						_log.warning(StringUtil.concat("[CLSetSiegeTimeList]: invalid config property -> CLSetSiegeTimeList \"", st, "\""));
-					}
-				}
-				if (isHour)
-				{
-					String[] shl = Feature.getString("SiegeHourList", "").split(",");
-					for (String st : shl)
-					{
-						if (!st.equalsIgnoreCase(""))
-						{
-							int val = Integer.parseInt(st);
-							if ((val > 23) || (val < 0))
-							{
-								_log.warning(StringUtil.concat("[SiegeHourList]: invalid config property -> SiegeHourList \"", st, "\""));
-							}
-							else if (val < 12)
-							{
-								SIEGE_HOUR_LIST_MORNING.add(val);
-							}
-							else
-							{
-								val -= 12;
-								SIEGE_HOUR_LIST_AFTERNOON.add(val);
-							}
-						}
-					}
-					if (Config.SIEGE_HOUR_LIST_AFTERNOON.isEmpty() && Config.SIEGE_HOUR_LIST_AFTERNOON.isEmpty())
-					{
-						_log.warning("[SiegeHourList]: invalid config property -> SiegeHourList is empty");
-						CL_SET_SIEGE_TIME_LIST.remove("hour");
-					}
+					SIEGE_HOUR_LIST.add(Integer.parseInt(hour));
 				}
 			}
 			CS_TELE_FEE_RATIO = Feature.getLong("CastleTeleportFunctionFeeRatio", 604800000);

+ 2 - 8
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Siege.java

@@ -1478,9 +1478,8 @@ public class Siege implements Siegable
 			{
 				getCastle().getSiegeDate().set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
 			}
-			// 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 ((getCastle().getSiegeDate().get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) && !Config.CL_SET_SIEGE_TIME_LIST.contains("day"))
+			// 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 ((getCastle().getSiegeDate().get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY))
 			{
 				getCastle().getSiegeDate().set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
 			}
@@ -1492,11 +1491,6 @@ public class Siege implements Siegable
 		{
 			getCastle().getSiegeDate().add(Calendar.DAY_OF_MONTH, 7);
 		}
-		
-		SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_ANNOUNCED_SIEGE_TIME);
-		sm.addCastleId(getCastle().getResidenceId());
-		Announcements.getInstance().announceToAll(sm);
-		
 		_isRegistrationOver = false; // Allow registration for next siege
 	}
 	

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/network/L2GamePacketHandler.java

@@ -596,8 +596,8 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 					case 0xae: // RequestConfirmCastleSiegeWaitingList
 						msg = new RequestConfirmSiegeWaitingList();
 						break;
-					case 0xaf:
-						// RequestSetCastleSiegeTime
+					case 0xAF:
+						msg = new RequestSetCastleSiegeTime();
 						break;
 					case 0xb0:
 						msg = new MultiSellChoose();

+ 127 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestSetCastleSiegeTime.java

@@ -0,0 +1,127 @@
+/*
+ * This program 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.
+ * 
+ * This program 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 java.util.Calendar;
+import java.util.Date;
+import java.util.logging.Level;
+
+import com.l2jserver.Config;
+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 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.log(Level.WARNING, getType() + ": activeChar: " + activeChar + " castle: " + castle + " castleId: " + _castleId);
+			return;
+		}
+		if ((castle.getOwnerId() > 0) && (castle.getOwnerId() != activeChar.getClanId()))
+		{
+			_log.log(Level.WARNING, getType() + ": activeChar: " + activeChar + " castle: " + castle + " castleId: " + _castleId + " is trying to change siege date of not his own castle!");
+			return;
+		}
+		else if (!activeChar.isClanLeader())
+		{
+			_log.log(Level.WARNING, getType() + ": activeChar: " + activeChar + " castle: " + castle + " castleId: " + _castleId + " is trying to change siege date but is not clan leader!");
+			return;
+		}
+		else if (!castle.getIsTimeRegistrationOver() && !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.log(Level.WARNING, getType() + ": activeChar: " + activeChar + " castle: " + castle + " castleId: " + _castleId + " is trying to an invalid time (" + new Date(_time) + " !");
+			}
+		}
+		else
+		{
+			_log.log(Level.WARNING, getType() + ": activeChar: " + activeChar + " castle: " + castle + " castleId: " + _castleId + " is trying to change siege date but currently not possible!");
+		}
+	}
+	
+	private static boolean isSiegeTimeValid(long siegeDate, long choosenDate)
+	{
+		Calendar cal1 = Calendar.getInstance();
+		cal1.setTimeInMillis(siegeDate);
+		cal1.set(Calendar.MINUTE, 0);
+		cal1.set(Calendar.SECOND, 0);
+		
+		Calendar cal2 = Calendar.getInstance();
+		cal2.setTimeInMillis(choosenDate);
+		
+		for (int hour : Config.SIEGE_HOUR_LIST)
+		{
+			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();
+	}
+}

+ 22 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/network/serverpackets/SiegeInfo.java

@@ -20,6 +20,7 @@ package com.l2jserver.gameserver.network.serverpackets;
 
 import java.util.Calendar;
 
+import com.l2jserver.Config;
 import com.l2jserver.gameserver.datatables.ClanTable;
 import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
 import com.l2jserver.gameserver.model.L2Clan;
@@ -99,9 +100,27 @@ public class SiegeInfo extends L2GameServerPacket
 				writeS(""); // Ally Name
 			}
 			
-			writeD((int) (Calendar.getInstance().getTimeInMillis() / 1000));
-			writeD((int) (_castle.getSiege().getSiegeDate().getTimeInMillis() / 1000));
-			writeD(0x00); // number of choices?
+			writeD((int) (System.currentTimeMillis() / 1000));
+			if (!_castle.getIsTimeRegistrationOver() && activeChar.isClanLeader() && (activeChar.getClanId() == _castle.getOwnerId()))
+			{
+				Calendar cal = Calendar.getInstance();
+				cal.setTimeInMillis(_castle.getSiegeDate().getTimeInMillis());
+				cal.set(Calendar.MINUTE, 0);
+				cal.set(Calendar.SECOND, 0);
+				
+				writeD(0x00);
+				writeD(Config.SIEGE_HOUR_LIST.size());
+				for (int hour : Config.SIEGE_HOUR_LIST)
+				{
+					cal.set(Calendar.HOUR_OF_DAY, hour);
+					writeD((int) (cal.getTimeInMillis() / 1000));
+				}
+			}
+			else
+			{
+				writeD((int) (_castle.getSiegeDate().getTimeInMillis() / 1000));
+				writeD(0x00);
+			}
 		}
 		else
 		{