Bladeren bron

BETA: Updating castle/territory war siege date & time picking to retail
* Also updated admin menu for editing the siege time to support moving siege to any month, day, hour, minute
* Also removing Seven Signs checks because on retail there are no such.
* Thanks to: Nos

Rumen Nikiforov 11 jaren geleden
bovenliggende
commit
84ff7fc4b7

+ 5 - 0
L2J_Server_BETA/dist/game/config/SiegeSchedule.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SiegeSchedule.xsd">
+	<schedule day="SUNDAY" hour="16" maxConcurrent="5" />
+	<schedule day="SUNDAY" hour="20" maxConcurrent="5" />
+</list>

+ 16 - 0
L2J_Server_BETA/dist/game/config/SiegeSchedule.xsd

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+	<xs:element name="list">
+		<xs:complexType>
+			<xs:sequence>
+				<xs:element name="schedule" maxOccurs="unbounded">
+					<xs:complexType>
+						<xs:attribute type="xs:string" name="day" use="optional" />
+						<xs:attribute type="xs:byte" name="hour" use="optional" />
+						<xs:attribute type="xs:byte" name="maxConcurrent" use="optional" />
+					</xs:complexType>
+				</xs:element>
+			</xs:sequence>
+		</xs:complexType>
+	</xs:element>
+</xs:schema>

+ 5 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/GameServer.java

@@ -76,6 +76,7 @@ import com.l2jserver.gameserver.datatables.OptionsData;
 import com.l2jserver.gameserver.datatables.PetDataTable;
 import com.l2jserver.gameserver.datatables.RecipeData;
 import com.l2jserver.gameserver.datatables.SecondaryAuthData;
+import com.l2jserver.gameserver.datatables.SiegeScheduleData;
 import com.l2jserver.gameserver.datatables.SkillLearnData;
 import com.l2jserver.gameserver.datatables.SkillTable;
 import com.l2jserver.gameserver.datatables.SkillTreesData;
@@ -292,6 +293,7 @@ public class GameServer
 		EventDroplist.getInstance();
 		
 		printSection("Siege");
+		SiegeScheduleData.getInstance();
 		SiegeManager.getInstance().getSieges();
 		FortSiegeManager.getInstance();
 		TerritoryWarManager.getInstance();
@@ -303,6 +305,9 @@ public class GameServer
 		Olympiad.getInstance();
 		Hero.getInstance();
 		
+		printSection("Seven Signs");
+		SevenSigns.getInstance();
+		
 		// Call to load caches
 		printSection("Cache");
 		HtmCache.getInstance();

+ 2 - 10
L2J_Server_BETA/java/com/l2jserver/gameserver/SevenSigns.java

@@ -36,8 +36,6 @@ import com.l2jserver.Config;
 import com.l2jserver.L2DatabaseFactory;
 import com.l2jserver.gameserver.datatables.SkillTable;
 import com.l2jserver.gameserver.instancemanager.CastleManager;
-import com.l2jserver.gameserver.instancemanager.QuestManager;
-import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
 import com.l2jserver.gameserver.model.AutoSpawnHandler;
 import com.l2jserver.gameserver.model.AutoSpawnHandler.AutoSpawnInstance;
 import com.l2jserver.gameserver.model.L2World;
@@ -46,7 +44,6 @@ import com.l2jserver.gameserver.model.TeleportWhereType;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.entity.Castle;
 import com.l2jserver.gameserver.model.interfaces.IL2Procedure;
-import com.l2jserver.gameserver.model.quest.Quest;
 import com.l2jserver.gameserver.network.SystemMessageId;
 import com.l2jserver.gameserver.network.serverpackets.SSQInfo;
 import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
@@ -1534,18 +1531,13 @@ public class SevenSigns
 					
 					// Perform initial Seal Validation set up.
 					initializeSeals();
+					
 					// Buff/Debuff members of the event when Seal of Strife captured.
 					giveCPMult(getSealOwner(SEAL_STRIFE));
+					
 					// Send message that Seal Validation has begun.
 					sendMessageToAll(SystemMessageId.SEAL_VALIDATION_PERIOD_BEGUN);
 					
-					// Change next Territory War date
-					Quest twQuest = QuestManager.getInstance().getQuest(TerritoryWarManager.qn);
-					if (twQuest != null)
-					{
-						twQuest.startQuestTimer("setNextTWDate", 30000, null, null);
-					}
-					
 					_log.info("SevenSigns: The " + getCabalName(_previousWinner) + " have won the competition with " + getCurrentScore(_previousWinner) + " points!");
 					break;
 				case PERIOD_SEAL_VALIDATION: // Reset for New Cycle

+ 125 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SiegeScheduleData.java

@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2004-2014 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.datatables;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.logging.Level;
+
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import com.l2jserver.gameserver.engines.DocumentParser;
+import com.l2jserver.gameserver.model.SiegeScheduleDate;
+import com.l2jserver.gameserver.model.StatsSet;
+import com.l2jserver.gameserver.util.Util;
+
+/**
+ * @author UnAfraid
+ */
+public class SiegeScheduleData extends DocumentParser
+{
+	private final List<SiegeScheduleDate> _scheduleData = new ArrayList<>();
+	
+	protected SiegeScheduleData()
+	{
+		load();
+	}
+	
+	@Override
+	public synchronized void load()
+	{
+		_scheduleData.clear();
+		parseDatapackFile("config/SiegeSchedule.xml");
+		_log.log(Level.INFO, getClass().getSimpleName() + ": Loaded: " + _scheduleData.size() + " siege schedulers.");
+		if (_scheduleData.isEmpty())
+		{
+			_scheduleData.add(new SiegeScheduleDate(new StatsSet()));
+			_log.log(Level.INFO, getClass().getSimpleName() + ": Emergency Loaded: " + _scheduleData.size() + " default siege schedulers.");
+		}
+	}
+	
+	@Override
+	protected void parseDocument()
+	{
+		for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
+		{
+			if ("list".equalsIgnoreCase(n.getNodeName()))
+			{
+				for (Node cd = n.getFirstChild(); cd != null; cd = cd.getNextSibling())
+				{
+					switch (cd.getNodeName())
+					{
+						case "schedule":
+						{
+							final StatsSet set = new StatsSet();
+							final NamedNodeMap attrs = cd.getAttributes();
+							for (int i = 0; i < attrs.getLength(); i++)
+							{
+								Node node = attrs.item(i);
+								String key = node.getNodeName();
+								String val = node.getNodeValue();
+								if ("day".equals(key))
+								{
+									if (!Util.isDigit(val))
+									{
+										val = Integer.toString(getValueForField(val));
+									}
+								}
+								set.set(key, val);
+							}
+							_scheduleData.add(new SiegeScheduleDate(set));
+							break;
+						}
+					}
+				}
+			}
+		}
+	}
+	
+	private int getValueForField(String field)
+	{
+		try
+		{
+			return Calendar.class.getField(field).getInt(Calendar.class);
+		}
+		catch (Exception e)
+		{
+			_log.log(Level.WARNING, "", e);
+			return -1;
+		}
+	}
+	
+	public List<SiegeScheduleDate> getScheduleDates()
+	{
+		return _scheduleData;
+	}
+	
+	public static final SiegeScheduleData getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
+	private static class SingletonHolder
+	{
+		protected static final SiegeScheduleData _instance = new SiegeScheduleData();
+	}
+	
+}

+ 36 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CastleManager.java

@@ -23,6 +23,8 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -44,6 +46,8 @@ public final class CastleManager implements InstanceListManager
 	
 	private List<Castle> _castles;
 	
+	private final Map<Integer, Long> _castleSiegeDate = new ConcurrentHashMap<>();
+	
 	private static final int _castleCirclets[] =
 	{
 		0,
@@ -183,6 +187,20 @@ public final class CastleManager implements InstanceListManager
 		return _castles;
 	}
 	
+	public boolean hasOwnedCastle()
+	{
+		boolean hasOwnedCastle = false;
+		for (Castle castle : getCastles())
+		{
+			if (castle.getOwnerId() > 0)
+			{
+				hasOwnedCastle = true;
+				break;
+			}
+		}
+		return hasOwnedCastle;
+	}
+	
 	public final void validateTaxes(int sealStrifeOwner)
 	{
 		int maxTax;
@@ -311,6 +329,24 @@ public final class CastleManager implements InstanceListManager
 		}
 	}
 	
+	public void registerSiegeDate(int castleId, long siegeDate)
+	{
+		_castleSiegeDate.put(castleId, siegeDate);
+	}
+	
+	public int getSiegeDates(long siegeDate)
+	{
+		int count = 0;
+		for (long date : _castleSiegeDate.values())
+		{
+			if (Math.abs(date - siegeDate) < 1000)
+			{
+				count++;
+			}
+		}
+		return count;
+	}
+	
 	public static final CastleManager getInstance()
 	{
 		return SingletonHolder._instance;

+ 53 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/SiegeScheduleDate.java

@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2004-2014 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.model;
+
+import java.util.Calendar;
+
+/**
+ * @author UnAfraid
+ */
+public class SiegeScheduleDate
+{
+	private final int _day;
+	private final int _hour;
+	private final int _maxConcurrent;
+	
+	public SiegeScheduleDate(StatsSet set)
+	{
+		_day = set.getInt("day", Calendar.SUNDAY);
+		_hour = set.getInt("hour", 16);
+		_maxConcurrent = set.getInt("maxConcurrent", 5);
+	}
+	
+	public int getDay()
+	{
+		return _day;
+	}
+	
+	public int getHour()
+	{
+		return _hour;
+	}
+	
+	public int getMaxConcurrent()
+	{
+		return _maxConcurrent;
+	}
+}

+ 25 - 21
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Siege.java

@@ -35,11 +35,12 @@ import javolution.util.FastList;
 import com.l2jserver.Config;
 import com.l2jserver.L2DatabaseFactory;
 import com.l2jserver.gameserver.Announcements;
-import com.l2jserver.gameserver.SevenSigns;
 import com.l2jserver.gameserver.ThreadPoolManager;
 import com.l2jserver.gameserver.datatables.ClanTable;
 import com.l2jserver.gameserver.datatables.NpcTable;
+import com.l2jserver.gameserver.datatables.SiegeScheduleData;
 import com.l2jserver.gameserver.enums.SiegeTeleportWhoType;
+import com.l2jserver.gameserver.instancemanager.CastleManager;
 import com.l2jserver.gameserver.instancemanager.MercTicketManager;
 import com.l2jserver.gameserver.instancemanager.SiegeGuardManager;
 import com.l2jserver.gameserver.instancemanager.SiegeManager;
@@ -50,6 +51,7 @@ import com.l2jserver.gameserver.model.L2SiegeClan;
 import com.l2jserver.gameserver.model.L2SiegeClan.SiegeClanType;
 import com.l2jserver.gameserver.model.L2Spawn;
 import com.l2jserver.gameserver.model.PcCondOverride;
+import com.l2jserver.gameserver.model.SiegeScheduleDate;
 import com.l2jserver.gameserver.model.TeleportWhereType;
 import com.l2jserver.gameserver.model.TowerSpawn;
 import com.l2jserver.gameserver.model.actor.L2Npc;
@@ -65,6 +67,7 @@ import com.l2jserver.gameserver.network.serverpackets.UserInfo;
 import com.l2jserver.gameserver.scripting.scriptengine.events.SiegeEvent;
 import com.l2jserver.gameserver.scripting.scriptengine.impl.L2Script.EventStage;
 import com.l2jserver.gameserver.scripting.scriptengine.listeners.events.SiegeListener;
+import com.l2jserver.gameserver.util.Broadcast;
 
 public class Siege implements Siegable
 {
@@ -1254,14 +1257,6 @@ public class Siege implements Siegable
 			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();
@@ -1472,25 +1467,34 @@ public class Siege implements Siegable
 	/** Set the date for the next siege. */
 	private void setNextSiegeDate()
 	{
-		while (getCastle().getSiegeDate().getTimeInMillis() < Calendar.getInstance().getTimeInMillis())
+		final Calendar cal = getCastle().getSiegeDate();
+		if (cal.getTimeInMillis() < System.currentTimeMillis())
+		{
+			cal.setTimeInMillis(System.currentTimeMillis());
+		}
+		
+		for (SiegeScheduleDate holder : SiegeScheduleData.getInstance().getScheduleDates())
 		{
-			if ((getCastle().getSiegeDate().get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) && (getCastle().getSiegeDate().get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY))
+			cal.set(Calendar.DAY_OF_WEEK, holder.getDay());
+			cal.set(Calendar.HOUR_OF_DAY, holder.getHour());
+			cal.set(Calendar.MINUTE, 0);
+			cal.set(Calendar.SECOND, 0);
+			if (cal.before(Calendar.getInstance()))
 			{
-				getCastle().getSiegeDate().set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
+				cal.add(Calendar.WEEK_OF_YEAR, 2);
 			}
-			// 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))
+			
+			if (CastleManager.getInstance().getSiegeDates(cal.getTimeInMillis()) < holder.getMaxConcurrent())
 			{
-				getCastle().getSiegeDate().set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
+				CastleManager.getInstance().registerSiegeDate(getCastle().getResidenceId(), cal.getTimeInMillis());
+				break;
 			}
-			// set the next siege day to the next weekend
-			getCastle().getSiegeDate().add(Calendar.DAY_OF_MONTH, 7);
 		}
 		
-		if (!SevenSigns.getInstance().isDateInSealValidPeriod(getCastle().getSiegeDate()))
-		{
-			getCastle().getSiegeDate().add(Calendar.DAY_OF_MONTH, 7);
-		}
+		SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_ANNOUNCED_SIEGE_TIME);
+		sm.addCastleId(getCastle().getResidenceId());
+		Broadcast.toAllOnlinePlayers(sm);
+		
 		_isRegistrationOver = false; // Allow registration for next siege
 	}