Преглед изворни кода

BETA: Minor rework in instances:
* teleToLocation(Location, int) now sets the player's instance as well.
* Use Location.setInstanceId(int instanceId) to set the instance which the player will be teleported.
* Minor cleanup.

Zoey76 пре 12 година
родитељ
комит
7ff74f0a24

+ 10 - 23
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/InstanceManager.java

@@ -20,7 +20,6 @@ import java.sql.ResultSet;
 import java.util.HashMap;
 import java.util.Map;
 
-import javolution.util.FastList;
 import javolution.util.FastMap;
 
 import org.w3c.dom.NamedNodeMap;
@@ -30,20 +29,20 @@ import com.l2jserver.L2DatabaseFactory;
 import com.l2jserver.gameserver.engines.DocumentParser;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.entity.Instance;
+import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
 
 /**
  * @author evill33t, GodKratos
  */
 public class InstanceManager extends DocumentParser
 {
-	private static final FastMap<Integer, Instance> _instanceList = new FastMap<>();
-	private final FastMap<Integer, InstanceWorld> _instanceWorlds = new FastMap<>();
+	private static final Map<Integer, Instance> _instanceList = new FastMap<>();
+	private final Map<Integer, InstanceWorld> _instanceWorlds = new FastMap<>();
 	private int _dynamic = 300000;
-	
 	// InstanceId Names
 	private static final Map<Integer, String> _instanceIdNames = new HashMap<>();
 	private final Map<Integer, Map<Integer, Long>> _playerInstanceTimes = new FastMap<>();
-	
+	// SQL Queries
 	private static final String ADD_INSTANCE_TIME = "INSERT INTO character_instance_time (charId,instanceId,time) values (?,?,?) ON DUPLICATE KEY UPDATE time=?";
 	private static final String RESTORE_INSTANCE_TIMES = "SELECT instanceId,time FROM character_instance_time WHERE charId=?";
 	private static final String DELETE_INSTANCE_TIME = "DELETE FROM character_instance_time WHERE charId=? AND instanceId=?";
@@ -216,20 +215,12 @@ public class InstanceManager extends DocumentParser
 		}
 	}
 	
-	public static class InstanceWorld
-	{
-		public int instanceId;
-		public int templateId = -1;
-		public FastList<Integer> allowed = new FastList<>();
-		public volatile int status;
-	}
-	
 	/**
 	 * @param world
 	 */
 	public void addWorld(InstanceWorld world)
 	{
-		_instanceWorlds.put(world.instanceId, world);
+		_instanceWorlds.put(world.getInstanceId(), world);
 	}
 	
 	/**
@@ -242,19 +233,15 @@ public class InstanceManager extends DocumentParser
 	}
 	
 	/**
-	 * @param player
-	 * @return
+	 * Check if the player have a World Instance where it's allowed to enter.
+	 * @param player the player to check
+	 * @return the instance world
 	 */
 	public InstanceWorld getPlayerWorld(L2PcInstance player)
 	{
 		for (InstanceWorld temp : _instanceWorlds.values())
 		{
-			if (temp == null)
-			{
-				continue;
-			}
-			// check if the player have a World Instance where he/she is allowed to enter
-			if (temp.allowed.contains(player.getObjectId()))
+			if ((temp != null) && (temp.isAllowed(player.getObjectId())))
 			{
 				return temp;
 			}
@@ -298,7 +285,7 @@ public class InstanceManager extends DocumentParser
 	/**
 	 * @return
 	 */
-	public FastMap<Integer, Instance> getInstances()
+	public Map<Integer, Instance> getInstances()
 	{
 		return _instanceList;
 	}

+ 8 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/Location.java

@@ -95,4 +95,12 @@ public final class Location
 	{
 		return "[" + getClass().getSimpleName() + "] X: " + _x + " Y: " + _y + " Z: " + _z + " Heading: " + _heading + " InstanceId: " + _instanceId;
 	}
+	
+	/**
+	 * @param instanceId the instance Id to set
+	 */
+	public void setInstanceId(int instanceId)
+	{
+		_instanceId = instanceId;
+	}
 }

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/L2Attackable.java

@@ -1059,7 +1059,7 @@ public class L2Attackable extends L2Npc
 			{
 				for (Quest quest : getTemplate().getEventQuests(Quest.QuestEventType.ON_AGGRO_RANGE_ENTER))
 				{
-					quest.notifyAggroRangeEnter(this, targetPlayer, (attacker instanceof L2Summon));
+					quest.notifyAggroRangeEnter(this, targetPlayer, attacker.isSummon());
 				}
 			}
 		}

+ 8 - 8
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/L2Character.java

@@ -716,8 +716,15 @@ public abstract class L2Character extends L2Object
 		teleToLocation(x, y, z, getHeading(), randomOffset);
 	}
 	
+	/**
+	 * Teleports a character to the given location and set its instance Id.
+	 * @param loc the location to teleport the character
+	 * @param randomOffset the random offset for the teleport location
+	 */
 	public void teleToLocation(Location loc, int randomOffset)
 	{
+		setInstanceId(loc.getInstanceId());
+		
 		int x = loc.getX();
 		int y = loc.getY();
 		int z = loc.getZ();
@@ -745,14 +752,7 @@ public abstract class L2Character extends L2Object
 	
 	public void teleToLocation(Location loc, boolean allowRandomOffset)
 	{
-		if (allowRandomOffset)
-		{
-			teleToLocation(loc, Config.MAX_OFFSET_ON_TELEPORT);
-		}
-		else
-		{
-			teleToLocation(loc, 0);
-		}
+		teleToLocation(loc, (allowRandomOffset ? Config.MAX_OFFSET_ON_TELEPORT : 0));
 	}
 	
 	public void teleToLocation(int x, int y, int z, boolean allowRandomOffset)

+ 2 - 9
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java

@@ -371,11 +371,6 @@ public final class L2PcInstance extends L2Playable
 	
 	public class AIAccessor extends L2Character.AIAccessor
 	{
-		protected AIAccessor()
-		{
-			
-		}
-		
 		public L2PcInstance getPlayer()
 		{
 			return L2PcInstance.this;
@@ -4710,14 +4705,12 @@ public final class L2PcInstance extends L2Playable
 		// Can't use Hero and resurrect skills during Olympiad
 		if (isInOlympiadMode() && (skill.isHeroSkill() || (skill.getSkillType() == L2SkillType.RESURRECT)))
 		{
-			SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
-			sendPacket(sm);
+			sendPacket(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
 			return false;
 		}
 		
-		final int charges = getCharges();
 		// Check if the spell using charges or not in AirShip
-		if (((charges < skill.getChargeConsume())) || (isInAirShip() && (skill.getSkillType() != L2SkillType.REFUEL)))
+		if (((getCharges() < skill.getChargeConsume())) || (isInAirShip() && (skill.getSkillType() != L2SkillType.REFUEL)))
 		{
 			SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
 			sm.addSkillName(skill);

+ 3 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/model/conditions/ConditionPlayerInstanceId.java

@@ -17,7 +17,7 @@ package com.l2jserver.gameserver.model.conditions;
 import java.util.ArrayList;
 
 import com.l2jserver.gameserver.instancemanager.InstanceManager;
-import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
+import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
 import com.l2jserver.gameserver.model.stats.Env;
 
 /**
@@ -51,10 +51,10 @@ public class ConditionPlayerInstanceId extends Condition
 		}
 		
 		final InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(env.getPlayer());
-		if ((world == null) || (world.instanceId != instanceId))
+		if ((world == null) || (world.getInstanceId() != instanceId))
 		{
 			return false; // player in the different instance
 		}
-		return _instanceIds.contains(world.templateId);
+		return _instanceIds.contains(world.getTemplateId());
 	}
 }

+ 90 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/instancezone/InstanceWorld.java

@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2004-2012 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.instancezone;
+
+import java.util.List;
+
+import javolution.util.FastList;
+
+/**
+ * Basic instance zone data transfer object.
+ * @author Zoey76
+ */
+public class InstanceWorld
+{
+	private int _instanceId;
+	private int _templateId = -1;
+	private final List<Integer> _allowed = new FastList<>();
+	private volatile int _status;
+	
+	public List<Integer> getAllowed()
+	{
+		return _allowed;
+	}
+	
+	public void removeAllowed(int id)
+	{
+		_allowed.remove(_allowed.indexOf(Integer.valueOf(id)));
+	}
+	
+	public void addAllowed(int id)
+	{
+		_allowed.add(id);
+	}
+	
+	public boolean isAllowed(int id)
+	{
+		return _allowed.contains(id);
+	}
+	
+	public int getInstanceId()
+	{
+		return _instanceId;
+	}
+	
+	public void setInstanceId(int instanceId)
+	{
+		_instanceId = instanceId;
+	}
+	
+	public int getTemplateId()
+	{
+		return _templateId;
+	}
+	
+	public void setTemplateId(int templateId)
+	{
+		_templateId = templateId;
+	}
+	
+	public int getStatus()
+	{
+		return _status;
+	}
+	
+	public void setStatus(int status)
+	{
+		_status = status;
+	}
+	
+	public void incStatus()
+	{
+		_status++;
+	}
+}

+ 2 - 6
L2J_Server_BETA/java/com/l2jserver/gameserver/model/quest/Quest.java

@@ -82,14 +82,10 @@ public class Quest extends ManagedScript
 {
 	protected static final Logger _log = Logger.getLogger(Quest.class.getName());
 	
-	/**
-	 * Map containing events from String value of the event.
-	 */
+	/** Map containing events from String value of the event. */
 	private static Map<String, Quest> _allEventsS = new HashMap<>();
 	
-	/**
-	 * Map containing lists of timers from the name of the timer.
-	 */
+	/** Map containing lists of timers from the name of the timer. */
 	private final Map<String, List<QuestTimer>> _allEventTimers = new L2FastMap<>(true);
 	private final Set<Integer> _questInvolvedNpcs = new HashSet<>();
 	

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/network/SystemMessageId.java

@@ -9844,7 +9844,7 @@ public final class SystemMessageId
 	
 	/**
 	 * ID: 1683<br>
-	 * Message: Only a party leader can choose the option to leave a channel.
+	 * Message: Only a party leader can leave a command channel.
 	 */
 	public static final SystemMessageId ONLY_PARTY_LEADER_CAN_LEAVE_CHANNEL;