Prevent starting tasks if addKnownObject returns false.
This commit is contained in:
parent
60b928e969
commit
3f632faecd
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.l2jmobius.gameserver.model.actor.knownlist;
|
package org.l2jmobius.gameserver.model.actor.knownlist;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
import org.l2jmobius.gameserver.ai.CreatureAI;
|
import org.l2jmobius.gameserver.ai.CreatureAI;
|
||||||
import org.l2jmobius.gameserver.model.WorldObject;
|
import org.l2jmobius.gameserver.model.WorldObject;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
@ -48,6 +50,8 @@ import org.l2jmobius.gameserver.network.serverpackets.VehicleInfo;
|
|||||||
|
|
||||||
public class PlayerKnownList extends PlayableKnownList
|
public class PlayerKnownList extends PlayableKnownList
|
||||||
{
|
{
|
||||||
|
private int _packetSendDelay = 0;
|
||||||
|
|
||||||
public PlayerKnownList(PlayerInstance player)
|
public PlayerKnownList(PlayerInstance player)
|
||||||
{
|
{
|
||||||
super(player);
|
super(player);
|
||||||
@ -103,130 +107,142 @@ public class PlayerKnownList extends PlayableKnownList
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object.getPoly().isMorphed() && object.getPoly().getPolyType().equals("item"))
|
// Delay is broken down to 100ms intervals.
|
||||||
|
// With the random time added it gives at least 50ms between tasks.
|
||||||
|
if (_packetSendDelay > 3000)
|
||||||
{
|
{
|
||||||
activeChar.sendPacket(new SpawnItemPoly(object));
|
_packetSendDelay = 0;
|
||||||
}
|
}
|
||||||
else
|
_packetSendDelay += 100;
|
||||||
|
|
||||||
|
// Send packets asynchronously. (Obviously heavier on CPU, but significantly reduces network spikes.)
|
||||||
|
// On retail there is a similar, if not greater, delay as well.
|
||||||
|
ThreadPool.schedule(() ->
|
||||||
{
|
{
|
||||||
if (object instanceof ItemInstance)
|
if (object.getPoly().isMorphed() && object.getPoly().getPolyType().equals("item"))
|
||||||
{
|
{
|
||||||
if (dropper != null)
|
activeChar.sendPacket(new SpawnItemPoly(object));
|
||||||
{
|
|
||||||
activeChar.sendPacket(new DropItem((ItemInstance) object, dropper.getObjectId()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
activeChar.sendPacket(new SpawnItem((ItemInstance) object));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (object instanceof DoorInstance)
|
else
|
||||||
{
|
{
|
||||||
if (((DoorInstance) object).getCastle() != null)
|
if (object instanceof ItemInstance)
|
||||||
{
|
{
|
||||||
activeChar.sendPacket(new DoorInfo((DoorInstance) object, true));
|
if (dropper != null)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
activeChar.sendPacket(new DoorInfo((DoorInstance) object, false));
|
|
||||||
}
|
|
||||||
activeChar.sendPacket(new DoorStatusUpdate((DoorInstance) object));
|
|
||||||
}
|
|
||||||
else if (object instanceof FenceInstance)
|
|
||||||
{
|
|
||||||
((FenceInstance) object).sendInfo(activeChar);
|
|
||||||
}
|
|
||||||
else if (object instanceof BoatInstance)
|
|
||||||
{
|
|
||||||
if (!activeChar.isInBoat() && (object != activeChar.getBoat()))
|
|
||||||
{
|
|
||||||
activeChar.sendPacket(new VehicleInfo((BoatInstance) object));
|
|
||||||
((BoatInstance) object).sendVehicleDeparture(activeChar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (object instanceof StaticObjectInstance)
|
|
||||||
{
|
|
||||||
activeChar.sendPacket(new StaticObject((StaticObjectInstance) object));
|
|
||||||
}
|
|
||||||
else if (object instanceof NpcInstance)
|
|
||||||
{
|
|
||||||
activeChar.sendPacket(new NpcInfo((NpcInstance) object, activeChar));
|
|
||||||
}
|
|
||||||
else if (object instanceof Summon)
|
|
||||||
{
|
|
||||||
final Summon summon = (Summon) object;
|
|
||||||
|
|
||||||
// Check if the PlayerInstance is the owner of the Pet
|
|
||||||
if (activeChar.equals(summon.getOwner()))
|
|
||||||
{
|
|
||||||
activeChar.sendPacket(new PetInfo(summon));
|
|
||||||
// The PetInfo packet wipes the PartySpelled (list of active spells' icons). Re-add them
|
|
||||||
summon.updateEffectIcons(true);
|
|
||||||
|
|
||||||
if (summon instanceof PetInstance)
|
|
||||||
{
|
{
|
||||||
activeChar.sendPacket(new PetItemList((PetInstance) summon));
|
activeChar.sendPacket(new DropItem((ItemInstance) object, dropper.getObjectId()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new SpawnItem((ItemInstance) object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (object instanceof DoorInstance)
|
||||||
{
|
{
|
||||||
activeChar.sendPacket(new NpcInfo(summon, activeChar));
|
if (((DoorInstance) object).getCastle() != null)
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (object instanceof PlayerInstance)
|
|
||||||
{
|
|
||||||
final PlayerInstance otherPlayer = (PlayerInstance) object;
|
|
||||||
if (otherPlayer.isInBoat())
|
|
||||||
{
|
|
||||||
otherPlayer.getPosition().setWorldPosition(otherPlayer.getBoat().getLocation());
|
|
||||||
activeChar.sendPacket(new CharInfo(otherPlayer));
|
|
||||||
|
|
||||||
final int relation = otherPlayer.getRelation(activeChar);
|
|
||||||
if ((otherPlayer.getKnownList().getKnownRelations().get(activeChar.getObjectId()) != null) && (otherPlayer.getKnownList().getKnownRelations().get(activeChar.getObjectId()) != relation))
|
|
||||||
{
|
{
|
||||||
activeChar.sendPacket(new RelationChanged(otherPlayer, relation, activeChar.isAutoAttackable(otherPlayer)));
|
activeChar.sendPacket(new DoorInfo((DoorInstance) object, true));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new DoorInfo((DoorInstance) object, false));
|
||||||
|
}
|
||||||
|
activeChar.sendPacket(new DoorStatusUpdate((DoorInstance) object));
|
||||||
|
}
|
||||||
|
else if (object instanceof FenceInstance)
|
||||||
|
{
|
||||||
|
((FenceInstance) object).sendInfo(activeChar);
|
||||||
|
}
|
||||||
|
else if (object instanceof BoatInstance)
|
||||||
|
{
|
||||||
|
if (!activeChar.isInBoat() && (object != activeChar.getBoat()))
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new VehicleInfo((BoatInstance) object));
|
||||||
|
((BoatInstance) object).sendVehicleDeparture(activeChar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (object instanceof StaticObjectInstance)
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new StaticObject((StaticObjectInstance) object));
|
||||||
|
}
|
||||||
|
else if (object instanceof NpcInstance)
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new NpcInfo((NpcInstance) object, activeChar));
|
||||||
|
}
|
||||||
|
else if (object instanceof Summon)
|
||||||
|
{
|
||||||
|
final Summon summon = (Summon) object;
|
||||||
|
|
||||||
|
// Check if the PlayerInstance is the owner of the Pet
|
||||||
|
if (activeChar.equals(summon.getOwner()))
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new PetInfo(summon));
|
||||||
|
// The PetInfo packet wipes the PartySpelled (list of active spells' icons). Re-add them
|
||||||
|
summon.updateEffectIcons(true);
|
||||||
|
|
||||||
|
if (summon instanceof PetInstance)
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new PetItemList((PetInstance) summon));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new NpcInfo(summon, activeChar));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (object instanceof PlayerInstance)
|
||||||
|
{
|
||||||
|
final PlayerInstance otherPlayer = (PlayerInstance) object;
|
||||||
|
if (otherPlayer.isInBoat())
|
||||||
|
{
|
||||||
|
otherPlayer.getPosition().setWorldPosition(otherPlayer.getBoat().getLocation());
|
||||||
|
activeChar.sendPacket(new CharInfo(otherPlayer));
|
||||||
|
|
||||||
|
final int relation = otherPlayer.getRelation(activeChar);
|
||||||
|
if ((otherPlayer.getKnownList().getKnownRelations().get(activeChar.getObjectId()) != null) && (otherPlayer.getKnownList().getKnownRelations().get(activeChar.getObjectId()) != relation))
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new RelationChanged(otherPlayer, relation, activeChar.isAutoAttackable(otherPlayer)));
|
||||||
|
}
|
||||||
|
|
||||||
|
activeChar.sendPacket(new GetOnVehicle(otherPlayer, otherPlayer.getBoat(), otherPlayer.getBoatPosition().getX(), otherPlayer.getBoatPosition().getY(), otherPlayer.getBoatPosition().getZ()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new CharInfo(otherPlayer));
|
||||||
|
|
||||||
|
final int relation = otherPlayer.getRelation(activeChar);
|
||||||
|
if ((otherPlayer.getKnownList().getKnownRelations().get(activeChar.getObjectId()) != null) && (otherPlayer.getKnownList().getKnownRelations().get(activeChar.getObjectId()) != relation))
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new RelationChanged(otherPlayer, relation, activeChar.isAutoAttackable(otherPlayer)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
activeChar.sendPacket(new GetOnVehicle(otherPlayer, otherPlayer.getBoat(), otherPlayer.getBoatPosition().getX(), otherPlayer.getBoatPosition().getY(), otherPlayer.getBoatPosition().getZ()));
|
if (otherPlayer.getPrivateStoreType() == PlayerInstance.STORE_PRIVATE_SELL)
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
activeChar.sendPacket(new CharInfo(otherPlayer));
|
|
||||||
|
|
||||||
final int relation = otherPlayer.getRelation(activeChar);
|
|
||||||
if ((otherPlayer.getKnownList().getKnownRelations().get(activeChar.getObjectId()) != null) && (otherPlayer.getKnownList().getKnownRelations().get(activeChar.getObjectId()) != relation))
|
|
||||||
{
|
{
|
||||||
activeChar.sendPacket(new RelationChanged(otherPlayer, relation, activeChar.isAutoAttackable(otherPlayer)));
|
activeChar.sendPacket(new PrivateStoreMsgSell(otherPlayer));
|
||||||
|
}
|
||||||
|
else if (otherPlayer.getPrivateStoreType() == PlayerInstance.STORE_PRIVATE_BUY)
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new PrivateStoreMsgBuy(otherPlayer));
|
||||||
|
}
|
||||||
|
else if (otherPlayer.getPrivateStoreType() == PlayerInstance.STORE_PRIVATE_MANUFACTURE)
|
||||||
|
{
|
||||||
|
activeChar.sendPacket(new RecipeShopMsg(otherPlayer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (otherPlayer.getPrivateStoreType() == PlayerInstance.STORE_PRIVATE_SELL)
|
if (object instanceof Creature)
|
||||||
{
|
{
|
||||||
activeChar.sendPacket(new PrivateStoreMsgSell(otherPlayer));
|
// Update the state of the Creature object client side by sending Server->Client packet MoveToPawn/CharMoveToLocation and AutoAttackStart to the PlayerInstance
|
||||||
}
|
final Creature obj = (Creature) object;
|
||||||
else if (otherPlayer.getPrivateStoreType() == PlayerInstance.STORE_PRIVATE_BUY)
|
|
||||||
{
|
final CreatureAI objAi = obj.getAI();
|
||||||
activeChar.sendPacket(new PrivateStoreMsgBuy(otherPlayer));
|
if (objAi != null)
|
||||||
}
|
{
|
||||||
else if (otherPlayer.getPrivateStoreType() == PlayerInstance.STORE_PRIVATE_MANUFACTURE)
|
objAi.describeStateToPlayer(activeChar);
|
||||||
{
|
}
|
||||||
activeChar.sendPacket(new RecipeShopMsg(otherPlayer));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, _packetSendDelay + Rnd.get(50)); // Add additional 0-49ms in case of overlapping tasks on heavy load.
|
||||||
if (object instanceof Creature)
|
|
||||||
{
|
|
||||||
// Update the state of the Creature object client side by sending Server->Client packet MoveToPawn/CharMoveToLocation and AutoAttackStart to the PlayerInstance
|
|
||||||
final Creature obj = (Creature) object;
|
|
||||||
|
|
||||||
final CreatureAI objAi = obj.getAI();
|
|
||||||
if (objAi != null)
|
|
||||||
{
|
|
||||||
objAi.describeStateToPlayer(activeChar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@ package org.l2jmobius.gameserver.model.actor.knownlist;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.WorldObject;
|
import org.l2jmobius.gameserver.model.WorldObject;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
@ -124,39 +122,24 @@ public class WorldObjectKnownList
|
|||||||
|
|
||||||
if (_activeObject.isPlayable())
|
if (_activeObject.isPlayable())
|
||||||
{
|
{
|
||||||
int delay = 0;
|
|
||||||
|
|
||||||
// Go through all visible WorldObject near the Creature
|
// Go through all visible WorldObject near the Creature
|
||||||
for (WorldObject object : World.getInstance().getVisibleObjects(_activeObject))
|
for (WorldObject object : World.getInstance().getVisibleObjects(_activeObject))
|
||||||
{
|
{
|
||||||
// Delay is broken down to 100ms intervals.
|
if (object == null)
|
||||||
// With the random time added it gives at least 50ms between tasks.
|
|
||||||
if (delay >= 5000)
|
|
||||||
{
|
{
|
||||||
delay = 0;
|
continue;
|
||||||
}
|
}
|
||||||
delay += 100;
|
|
||||||
|
|
||||||
// Send packets asynchronously. (Obviously heavier on CPU, but significantly reduces network spikes.)
|
// Try to add object to active object's known objects
|
||||||
// On retail there is a similar, if not greater, delay as well.
|
// PlayableInstance sees everything
|
||||||
ThreadPool.schedule(() ->
|
addKnownObject(object);
|
||||||
|
|
||||||
|
// Try to add active object to object's known objects
|
||||||
|
// Only if object is a Creature and active object is a PlayableInstance
|
||||||
|
if (object instanceof Creature)
|
||||||
{
|
{
|
||||||
if (object == null)
|
object.getKnownList().addKnownObject(_activeObject);
|
||||||
{
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to add object to active object's known objects
|
|
||||||
// PlayableInstance sees everything
|
|
||||||
addKnownObject(object);
|
|
||||||
|
|
||||||
// Try to add active object to object's known objects
|
|
||||||
// Only if object is a Creature and active object is a PlayableInstance
|
|
||||||
if (object instanceof Creature)
|
|
||||||
{
|
|
||||||
object.getKnownList().addKnownObject(_activeObject);
|
|
||||||
}
|
|
||||||
}, delay + Rnd.get(50)); // Add additional 0-49ms in case of overlapping tasks on heavy load.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user