Save allowed player instances instead of object ids.

This commit is contained in:
MobiusDev
2018-06-08 16:27:20 +00:00
parent 913dbff9a6
commit 3cd9404a34
71 changed files with 422 additions and 363 deletions

View File

@@ -29,7 +29,6 @@ import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.util.CommonUtil;
import com.l2jmobius.gameserver.enums.ChatType;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.Location;
import com.l2jmobius.gameserver.model.StatsSet;
import com.l2jmobius.gameserver.model.actor.L2Npc;
@@ -120,10 +119,9 @@ public final class ChamberOfDelusion extends AbstractInstance
}
else
{
for (int objId : instance.getAllowed())
for (L2PcInstance plr : instance.getAllowed())
{
final L2PcInstance pl = L2World.getInstance().getPlayer(objId);
if ((pl != null) && pl.isOnline() && !pl.isInParty())
if ((plr != null) && plr.isOnline() && !plr.isInParty())
{
instance.finishInstance(0);
break;

View File

@@ -27,7 +27,6 @@ import com.l2jmobius.gameserver.data.xml.impl.SkillData;
import com.l2jmobius.gameserver.instancemanager.InstanceManager;
import com.l2jmobius.gameserver.model.L2Party;
import com.l2jmobius.gameserver.model.L2Spawn;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.Location;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Npc;
@@ -841,13 +840,12 @@ public final class Kamaloka extends AbstractInstance
sm.addInstanceName(world.getTemplateId());
// set instance reenter time for all allowed players
for (int oid : world.getAllowed())
for (L2PcInstance plr : world.getAllowed())
{
final L2PcInstance obj = L2World.getInstance().getPlayer(oid);
if ((obj != null) && obj.isOnline())
if ((plr != null) && plr.isOnline())
{
InstanceManager.getInstance().setReenterPenalty(oid, world.getTemplateId(), reenter.getTimeInMillis());
obj.sendPacket(sm);
InstanceManager.getInstance().setReenterPenalty(plr.getObjectId(), world.getTemplateId(), reenter.getTimeInMillis());
plr.sendPacket(sm);
}
}
world.finishInstance();

View File

@@ -3449,6 +3449,15 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
*/
public void playMovie(Instance instance, Movie movie)
{
playMovie(instance.getPlayers(), movie);
if (instance != null)
{
for (L2PcInstance player : instance.getPlayers())
{
if ((player != null) && (player.getInstanceWorld() == instance))
{
playMovie(player, movie);
}
}
}
}
}

View File

@@ -45,7 +45,6 @@ import com.l2jmobius.gameserver.enums.InstanceReenterType;
import com.l2jmobius.gameserver.enums.InstanceTeleportType;
import com.l2jmobius.gameserver.instancemanager.InstanceManager;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.Location;
import com.l2jmobius.gameserver.model.StatsSet;
import com.l2jmobius.gameserver.model.TeleportWhereType;
@@ -84,7 +83,7 @@ public final class Instance implements IIdentifiable, INamable
private final long _startTime;
private long _endTime;
// Advanced instance parameters
private final Set<Integer> _allowed = ConcurrentHashMap.newKeySet(); // ObjectId of players which can enter to instance
private final Set<L2PcInstance> _allowed = ConcurrentHashMap.newKeySet(); // Players which can enter to instance
private final Set<L2PcInstance> _players = ConcurrentHashMap.newKeySet(); // Players inside instance
private final Set<L2Npc> _npcs = ConcurrentHashMap.newKeySet(); // Spawned NPCs inside instance
private final Map<Integer, L2DoorInstance> _doors = new HashMap<>(); // Spawned doors inside instance
@@ -223,7 +222,10 @@ public final class Instance implements IIdentifiable, INamable
*/
public void addAllowed(L2PcInstance player)
{
_allowed.add(player.getObjectId());
if (!_allowed.contains(player))
{
_allowed.add(player);
}
}
/**
@@ -233,25 +235,25 @@ public final class Instance implements IIdentifiable, INamable
*/
public boolean isAllowed(L2PcInstance player)
{
return _allowed.contains(player.getObjectId());
return _allowed.contains(player);
}
/**
* Returns all players who can enter to instance.
* @return allowed players list
*/
public Set<Integer> getAllowed()
public Set<L2PcInstance> getAllowed()
{
return _allowed;
}
/**
* Remove player from allowed so he can't enter anymore.
* @param objectId object id of player
* @param player to remove
*/
public void removeAllowed(int objectId)
public void removeAllowed(L2PcInstance player)
{
_allowed.remove(objectId);
_allowed.remove(player);
}
/**
@@ -817,12 +819,15 @@ public final class Instance implements IIdentifiable, INamable
PreparedStatement ps = con.prepareStatement("INSERT IGNORE INTO character_instance_time (charId,instanceId,time) VALUES (?,?,?)"))
{
// Save to database
for (Integer objId : _allowed)
for (L2PcInstance player : _allowed)
{
ps.setInt(1, objId);
ps.setInt(2, getTemplateId());
ps.setLong(3, time);
ps.addBatch();
if (player != null)
{
ps.setInt(1, player.getObjectId());
ps.setInt(2, getTemplateId());
ps.setLong(3, time);
ps.addBatch();
}
}
ps.executeBatch();
@@ -836,13 +841,15 @@ public final class Instance implements IIdentifiable, INamable
{
msg.addString(getName());
}
_allowed.forEach(objId ->
_allowed.forEach(player ->
{
InstanceManager.getInstance().setReenterPenalty(objId, getTemplateId(), time);
final L2PcInstance player = L2World.getInstance().getPlayer(objId);
if ((player != null) && player.isOnline())
if ((player != null))
{
player.sendPacket(msg);
InstanceManager.getInstance().setReenterPenalty(player.getObjectId(), getTemplateId(), time);
if (player.isOnline())
{
player.sendPacket(msg);
}
}
});
}