Delay tasks for frequent packet broadcasts.
This commit is contained in:
@@ -27,11 +27,14 @@ import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.gameserver.enums.SkillFinishType;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
@@ -93,6 +96,9 @@ public class EffectList
|
||||
private final Creature _owner;
|
||||
/** Hidden buffs count, prevents iterations. */
|
||||
private final AtomicInteger _hiddenBuffs = new AtomicInteger();
|
||||
/** Delay task **/
|
||||
private ScheduledFuture<?> _updateEffectIconTask;
|
||||
private final AtomicBoolean _updateAbnormalStatus = new AtomicBoolean();
|
||||
|
||||
/**
|
||||
* Constructor for effect list.
|
||||
@@ -1074,70 +1080,84 @@ public class EffectList
|
||||
*/
|
||||
public void updateEffectIcons(boolean partyOnly)
|
||||
{
|
||||
final Player player = _owner.getActingPlayer();
|
||||
if (player != null)
|
||||
if (!partyOnly)
|
||||
{
|
||||
final Party party = player.getParty();
|
||||
final Optional<AbnormalStatusUpdate> asu = (_owner.isPlayer() && !partyOnly) ? Optional.of(new AbnormalStatusUpdate()) : Optional.empty();
|
||||
final Optional<PartySpelled> ps = ((party != null) || _owner.isSummon()) ? Optional.of(new PartySpelled(_owner)) : Optional.empty();
|
||||
final Optional<ExOlympiadSpelledInfo> os = (player.isInOlympiadMode() && player.isOlympiadStart()) ? Optional.of(new ExOlympiadSpelledInfo(player)) : Optional.empty();
|
||||
if (!_actives.isEmpty())
|
||||
_updateAbnormalStatus.compareAndSet(false, true);
|
||||
}
|
||||
|
||||
if (_updateEffectIconTask == null)
|
||||
{
|
||||
_updateEffectIconTask = ThreadPool.schedule(() ->
|
||||
{
|
||||
for (BuffInfo info : _actives)
|
||||
final Player player = _owner.getActingPlayer();
|
||||
if (player != null)
|
||||
{
|
||||
if ((info != null) && info.isInUse())
|
||||
final Party party = player.getParty();
|
||||
final Optional<AbnormalStatusUpdate> asu = (_owner.isPlayer() && _updateAbnormalStatus.get()) ? Optional.of(new AbnormalStatusUpdate()) : Optional.empty();
|
||||
final Optional<PartySpelled> ps = ((party != null) || _owner.isSummon()) ? Optional.of(new PartySpelled(_owner)) : Optional.empty();
|
||||
final Optional<ExOlympiadSpelledInfo> os = (player.isInOlympiadMode() && player.isOlympiadStart()) ? Optional.of(new ExOlympiadSpelledInfo(player)) : Optional.empty();
|
||||
if (!_actives.isEmpty())
|
||||
{
|
||||
if (info.getSkill().isHealingPotionSkill())
|
||||
for (BuffInfo info : _actives)
|
||||
{
|
||||
shortBuffStatusUpdate(info);
|
||||
if ((info != null) && info.isInUse())
|
||||
{
|
||||
if (info.getSkill().isHealingPotionSkill())
|
||||
{
|
||||
shortBuffStatusUpdate(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
asu.ifPresent(a -> a.addSkill(info));
|
||||
ps.filter(p -> !info.getSkill().isToggle()).ifPresent(p -> p.addSkill(info));
|
||||
os.ifPresent(o -> o.addSkill(info));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
// Send icon update for player buff bar.
|
||||
asu.ifPresent(_owner::sendPacket);
|
||||
|
||||
// Player or summon is in party. Broadcast packet to everyone in the party.
|
||||
if (party != null)
|
||||
{
|
||||
ps.ifPresent(party::broadcastPacket);
|
||||
}
|
||||
else // Not in party, then its a summon info for its owner.
|
||||
{
|
||||
ps.ifPresent(player::sendPacket);
|
||||
}
|
||||
|
||||
// Send icon update to all olympiad observers.
|
||||
if (os.isPresent())
|
||||
{
|
||||
final OlympiadGameTask game = OlympiadGameManager.getInstance().getOlympiadTask(player.getOlympiadGameId());
|
||||
if ((game != null) && game.isBattleStarted())
|
||||
{
|
||||
asu.ifPresent(a -> a.addSkill(info));
|
||||
ps.filter(p -> !info.getSkill().isToggle()).ifPresent(p -> p.addSkill(info));
|
||||
os.ifPresent(o -> o.addSkill(info));
|
||||
os.ifPresent(game.getStadium()::broadcastPacketToObservers);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send icon update for player buff bar.
|
||||
asu.ifPresent(_owner::sendPacket);
|
||||
|
||||
// Player or summon is in party. Broadcast packet to everyone in the party.
|
||||
if (party != null)
|
||||
{
|
||||
ps.ifPresent(party::broadcastPacket);
|
||||
}
|
||||
else // Not in party, then its a summon info for its owner.
|
||||
{
|
||||
ps.ifPresent(player::sendPacket);
|
||||
}
|
||||
|
||||
// Send icon update to all olympiad observers.
|
||||
if (os.isPresent())
|
||||
{
|
||||
final OlympiadGameTask game = OlympiadGameManager.getInstance().getOlympiadTask(player.getOlympiadGameId());
|
||||
if ((game != null) && game.isBattleStarted())
|
||||
|
||||
// Update effect icons for everyone targeting this owner.
|
||||
final ExAbnormalStatusUpdateFromTarget upd = new ExAbnormalStatusUpdateFromTarget(_owner);
|
||||
for (Creature creature : _owner.getStatus().getStatusListener())
|
||||
{
|
||||
os.ifPresent(game.getStadium()::broadcastPacketToObservers);
|
||||
if ((creature != null) && creature.isPlayer())
|
||||
{
|
||||
creature.sendPacket(upd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update effect icons for everyone targeting this owner.
|
||||
final ExAbnormalStatusUpdateFromTarget upd = new ExAbnormalStatusUpdateFromTarget(_owner);
|
||||
for (Creature creature : _owner.getStatus().getStatusListener())
|
||||
{
|
||||
if ((creature != null) && creature.isPlayer())
|
||||
{
|
||||
creature.sendPacket(upd);
|
||||
}
|
||||
}
|
||||
|
||||
if (_owner.isPlayer() && (_owner.getTarget() == _owner))
|
||||
{
|
||||
_owner.sendPacket(upd);
|
||||
|
||||
if (_owner.isPlayer() && (_owner.getTarget() == _owner))
|
||||
{
|
||||
_owner.sendPacket(upd);
|
||||
}
|
||||
|
||||
_updateAbnormalStatus.set(false);
|
||||
_updateEffectIconTask = null;
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -437,6 +437,8 @@ public class Player extends Playable
|
||||
|
||||
private ScheduledFuture<?> _itemListTask;
|
||||
private ScheduledFuture<?> _skillListTask;
|
||||
private ScheduledFuture<?> _storageCountTask;
|
||||
private ScheduledFuture<?> _abnormalVisualEffectTask;
|
||||
|
||||
private boolean _subclassLock = false;
|
||||
protected int _baseClass;
|
||||
@@ -2269,7 +2271,7 @@ public class Player extends Playable
|
||||
|
||||
if (getInventoryLimit() != oldInvLimit)
|
||||
{
|
||||
sendPacket(new ExStorageMaxCount(this));
|
||||
sendStorageMaxCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8637,8 +8639,15 @@ public class Player extends Playable
|
||||
@Override
|
||||
public void updateAbnormalVisualEffects()
|
||||
{
|
||||
sendPacket(new ExUserInfoAbnormalVisualEffect(this));
|
||||
broadcastCharInfo();
|
||||
if (_abnormalVisualEffectTask == null)
|
||||
{
|
||||
_abnormalVisualEffectTask = ThreadPool.schedule(() ->
|
||||
{
|
||||
sendPacket(new ExUserInfoAbnormalVisualEffect(this));
|
||||
broadcastCharInfo();
|
||||
_abnormalVisualEffectTask = null;
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9469,6 +9478,18 @@ public class Player extends Playable
|
||||
}
|
||||
}
|
||||
|
||||
public void sendStorageMaxCount()
|
||||
{
|
||||
if (_storageCountTask == null)
|
||||
{
|
||||
_storageCountTask = ThreadPool.schedule(() ->
|
||||
{
|
||||
sendPacket(new ExStorageMaxCount(this));
|
||||
_storageCountTask = null;
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Add the specified class ID as a subclass (up to the maximum number of <b>three</b>) for this character.<br>
|
||||
* 2. This method no longer changes the active _classIndex of the player. This is only done by the calling of setActiveClass() method as that should be the only way to do so.
|
||||
@@ -9910,7 +9931,7 @@ public class Player extends Playable
|
||||
sendPacket(new ShortCutInit(this));
|
||||
broadcastPacket(new SocialAction(getObjectId(), SocialAction.LEVEL_UP));
|
||||
sendPacket(new SkillCoolTime(this));
|
||||
sendPacket(new ExStorageMaxCount(this));
|
||||
sendStorageMaxCount();
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerSubChange(this), this);
|
||||
}
|
||||
finally
|
||||
|
@@ -16,7 +16,11 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.actor;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.commons.util.CommonUtil;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.ai.CreatureAI;
|
||||
@@ -82,6 +86,9 @@ public abstract class Summon extends Playable
|
||||
private boolean _previousFollowStatus = true;
|
||||
protected boolean _restoreSummon = true;
|
||||
private int _summonPoints = 0;
|
||||
private ScheduledFuture<?> _abnormalEffectTask;
|
||||
private ScheduledFuture<?> _statusUpdateTask;
|
||||
private final AtomicInteger _statusUpdateValue = new AtomicInteger();
|
||||
|
||||
// @formatter:off
|
||||
private static final int[] PASSIVE_SUMMONS =
|
||||
@@ -193,26 +200,36 @@ public abstract class Summon extends Playable
|
||||
@Override
|
||||
public void updateAbnormalVisualEffects()
|
||||
{
|
||||
World.getInstance().forEachVisibleObject(this, Player.class, player ->
|
||||
if (_abnormalEffectTask == null)
|
||||
{
|
||||
if (player == _owner)
|
||||
_abnormalEffectTask = ThreadPool.schedule(() ->
|
||||
{
|
||||
player.sendPacket(new PetInfo(this, 1));
|
||||
return;
|
||||
}
|
||||
|
||||
final AbstractMaskPacket<NpcInfoType> packet;
|
||||
if (isPet())
|
||||
{
|
||||
packet = new ExPetInfo(this, player, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
packet = new SummonInfo(this, player, 1);
|
||||
}
|
||||
packet.addComponentType(NpcInfoType.ABNORMALS);
|
||||
player.sendPacket(packet);
|
||||
});
|
||||
if (isSpawned())
|
||||
{
|
||||
World.getInstance().forEachVisibleObject(this, Player.class, player ->
|
||||
{
|
||||
if (player == _owner)
|
||||
{
|
||||
player.sendPacket(new PetInfo(this, 1));
|
||||
return;
|
||||
}
|
||||
|
||||
final AbstractMaskPacket<NpcInfoType> packet;
|
||||
if (isPet())
|
||||
{
|
||||
packet = new ExPetInfo(this, player, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
packet = new SummonInfo(this, player, 1);
|
||||
}
|
||||
packet.addComponentType(NpcInfoType.ABNORMALS);
|
||||
player.sendPacket(packet);
|
||||
});
|
||||
}
|
||||
_abnormalEffectTask = null;
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -826,16 +843,25 @@ public abstract class Summon extends Playable
|
||||
return;
|
||||
}
|
||||
|
||||
sendPacket(new PetInfo(this, value));
|
||||
sendPacket(new PetStatusUpdate(this));
|
||||
if (isSpawned())
|
||||
_statusUpdateValue.set(value);
|
||||
if (_statusUpdateTask == null)
|
||||
{
|
||||
broadcastNpcInfo(value);
|
||||
}
|
||||
final Party party = _owner.getParty();
|
||||
if (party != null)
|
||||
{
|
||||
party.broadcastToPartyMembers(_owner, new ExPartyPetWindowUpdate(this));
|
||||
_statusUpdateTask = ThreadPool.schedule(() ->
|
||||
{
|
||||
if (isSpawned())
|
||||
{
|
||||
sendPacket(new PetInfo(this, _statusUpdateValue.get()));
|
||||
sendPacket(new PetStatusUpdate(this));
|
||||
broadcastNpcInfo(_statusUpdateValue.get());
|
||||
|
||||
final Party party = _owner.getParty();
|
||||
if (party != null)
|
||||
{
|
||||
party.broadcastToPartyMembers(_owner, new ExPartyPetWindowUpdate(this));
|
||||
}
|
||||
}
|
||||
_statusUpdateTask = null;
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -85,7 +85,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ExPledgeWaitingListAlarm;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExQuestItemList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExRotation;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExShowScreenMessage;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExStorageMaxCount;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExSubjobInfo;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExUserInfoEquipSlot;
|
||||
@@ -443,7 +442,7 @@ public class EnterWorld implements IClientIncomingPacket
|
||||
}
|
||||
|
||||
// Expand Skill
|
||||
player.sendPacket(new ExStorageMaxCount(player));
|
||||
player.sendStorageMaxCount();
|
||||
|
||||
// Friend list
|
||||
player.sendPacket(new L2FriendList(player));
|
||||
|
@@ -51,7 +51,6 @@ import org.l2jmobius.gameserver.network.serverpackets.AcquireSkillDone;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExAcquirableSkillListByClass;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExAlchemySkillList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExBasicActionList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExStorageMaxCount;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PledgeSkillList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ShortCutInit;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
@@ -696,7 +695,7 @@ public class RequestAcquireSkill implements IClientIncomingPacket
|
||||
// If skill is expand type then sends packet:
|
||||
if ((_id >= 1368) && (_id <= 1372))
|
||||
{
|
||||
player.sendPacket(new ExStorageMaxCount(player));
|
||||
player.sendStorageMaxCount();
|
||||
}
|
||||
|
||||
// Notify scripts of the skill learn.
|
||||
|
Reference in New Issue
Block a user