Обратите внимание, что данный пользователь заблокирован! Не совершайте с ним никаких сделок! Перейдите в его профиль, чтобы узнать причину блокировки.
- Хроники
- Fafurion
- Исходники
- Присутствуют
- Сборка
- l2j
Кто в курсе какая функция отвечает за проверка эквипа, суть проблемы в том что при смене оружия у обычных игроков идет задержка 10-20 секунд, у ГМ без проблем.
Думаю надо смотреть где то в UseItem ток пока не вижу
Думаю надо смотреть где то в UseItem ток пока не вижу
public class UseItem implements IClientIncomingPacket
{
private int _objectId;
private boolean _ctrlPressed;
private int _itemId;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_objectId = packet.readD();
_ctrlPressed = packet.readD() != 0;
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
// Flood protect UseItem
// if (!client.getFloodProtectors().getUseItem().tryPerformAction("use item"))
// {
// return;
// }
if (player.getActiveTradeList() != null)
{
player.cancelActiveTrade();
}
if (player.getPrivateStoreType() != PrivateStoreType.NONE)
{
player.sendPacket(SystemMessageId.WHILE_OPERATING_A_PRIVATE_STORE_OR_WORKSHOP_YOU_CANNOT_DISCARD_DESTROY_OR_TRADE_AN_ITEM);
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
final ItemInstance item = player.getInventory().getItemByObjectId(_objectId);
if (item == null)
{
// gm can use other player item
if (player.isGM())
{
final WorldObject obj = World.getInstance().findObject(_objectId);
if (obj.isItem())
{
AdminCommandHandler.getInstance().useAdminCommand(player, "admin_use_item " + _objectId, true);
}
}
return;
}
if (item.isQuestItem() && (item.getItem().getDefaultAction() != ActionType.NONE))
{
player.sendPacket(SystemMessageId.YOU_CANNOT_USE_QUEST_ITEMS);
return;
}
// No UseItem is allowed while the player is in special conditions
if (player.hasBlockActions() || player.isControlBlocked() || player.isAlikeDead())
{
return;
}
// Char cannot use item when dead
if (player.isDead() || !player.getInventory().canManipulateWithItemId(item.getId()))
{
final SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED_DUE_TO_UNSUITABLE_TERMS);
sm.addItemName(item);
player.sendPacket(sm);
return;
}
// if (!item.isEquipped() && !item.getItem().checkCondition(player, player, true))
// {
// return;
// }
_itemId = item.getId();
if (player.isFishing() && ((_itemId < 6535) || (_itemId > 6540)))
{
// You cannot do anything else while fishing
player.sendPacket(SystemMessageId.YOU_CANNOT_DO_THAT_WHILE_FISHING_3);
return;
}
if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TELEPORT && (player.getReputation() < 0))
{
final List<ItemSkillHolder> skills = item.getItem().getSkills(ItemSkillType.NORMAL);
if ((skills != null) && skills.stream().anyMatch(holder -> holder.getSkill().hasEffectType(EffectType.TELEPORT)))
{
return;
}
}
// If the item has reuse time and it has not passed.
// Message from reuse delay must come from item.
final int reuseDelay = item.getReuseDelay();
final int sharedReuseGroup = item.getSharedReuseGroup();
if (reuseDelay > 0)
{
final long reuse = player.getItemRemainingReuseTime(item.getObjectId());
if (reuse > 0)
{
reuseData(player, item, reuse);
sendSharedGroupUpdate(player, sharedReuseGroup, reuse, reuseDelay);
return;
}
final long reuseOnGroup = player.getReuseDelayOnGroup(sharedReuseGroup);
if (reuseOnGroup > 0)
{
reuseData(player, item, reuseOnGroup);
sendSharedGroupUpdate(player, sharedReuseGroup, reuseOnGroup, reuseDelay);
return;
}
}
if (item.isEquipable())
{
// Don't allow to put formal wear while a cursed weapon is equipped.
if (player.isCursedWeaponEquipped() && (_itemId == 6408))
{
return;
}
// Equip or unEquip
if (FortSiegeManager.getInstance().isCombat(_itemId))
{
return; // no message
}
if (player.isCombatFlagEquipped())
{
return;
}
if (player.getInventory().isItemSlotBlocked(item.getItem().getBodyPart()))
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
// Prevent players to equip weapon while wearing combat flag
// Don't allow weapon/shield equipment if a cursed weapon is equipped.
if ((item.getItem().getBodyPart() == Item.SLOT_LR_HAND) || (item.getItem().getBodyPart() == Item.SLOT_L_HAND) || (item.getItem().getBodyPart() == Item.SLOT_R_HAND))
{
if ((player.getActiveWeaponItem() != null) && (player.getActiveWeaponItem().getId() == 9819))
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
if (player.isMounted() || player.isDisarmed())
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
if (player.isCursedWeaponEquipped())
{
return;
}
}
else if (item.getItem().getBodyPart() == Item.SLOT_DECO)
{
if (!item.isEquipped() && (player.getInventory().getTalismanSlots() == 0))
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
}
else if (item.getItem().getBodyPart() == Item.SLOT_BROOCH_JEWEL)
{
if (!item.isEquipped() && (player.getInventory().getBroochJewelSlots() == 0))
{
final SystemMessage sm = new SystemMessage(SystemMessageId.YOU_CANNOT_EQUIP_S1_WITHOUT_EQUIPPING_A_BROOCH);
sm.addItemName(item);
player.sendPacket(sm);
return;
}
}
else if (item.getItem().getBodyPart() == Item.SLOT_AGATHION)
{
if (!item.isEquipped() && (player.getInventory().getAgathionSlots() == 0))
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
}
else if (item.getItem().getBodyPart() == Item.SLOT_ARTIFACT)
{
if (!item.isEquipped() && (player.getInventory().getArtifactSlots() == 0))
{
final SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVEN_T_EQUIPPED_AN_ARTIFACT_BOOK_SO_S1_CANNOT_BE_EQUIPPED);
sm.addItemName(item);
player.sendPacket(sm);
return;
}
}
if (player.isCastingNow())
{
// Create and Bind the next action to the AI
player.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> player.useEquippableItem(item, true)));
}
else if (player.isAttackingNow())
{
ThreadPool.schedule(() ->
{
// Check if the item is still on inventory.
final ItemInstance equipItem = player.getInventory().getItemByObjectId(_objectId);
if (equipItem == null)
{
return;
}
// Equip or unEquip.
player.useEquippableItem(equipItem, false);
}, player.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
}
else
{
player.useEquippableItem(item, true);
}
}
else
{
final EtcItem etcItem = item.getEtcItem();
final IItemHandler handler = ItemHandler.getInstance().getHandler(etcItem);
if (handler == null)
{
if ((etcItem != null) && (etcItem.getHandlerName() != null))
{
LOGGER.warning("Unmanaged Item handler: " + etcItem.getHandlerName() + " for Item Id: " + _itemId + "!");
}
}
else if (handler.useItem(player, item, _ctrlPressed))
{
// Item reuse time should be added if the item is successfully used.
// Skill reuse delay is done at handlers.itemhandlers.ItemSkillsTemplate;
if (reuseDelay > 0)
{
player.addTimeStampItem(item, reuseDelay);
sendSharedGroupUpdate(player, sharedReuseGroup, reuseDelay, reuseDelay);
}
}
}
}
private void reuseData(PlayerInstance player, ItemInstance item, long remainingTime)
{
final int hours = (int) (remainingTime / 3600000);
final int minutes = (int) (remainingTime % 3600000) / 60000;
final int seconds = (int) ((remainingTime / 1000) % 60);
final SystemMessage sm;
if (hours > 0)
{
sm = new SystemMessage(SystemMessageId.THERE_ARE_S2_HOUR_S_S3_MINUTE_S_AND_S4_SECOND_S_REMAINING_IN_S1_S_RE_USE_TIME);
sm.addItemName(item);
sm.addInt(hours);
sm.addInt(minutes);
}
else if (minutes > 0)
{
sm = new SystemMessage(SystemMessageId.THERE_ARE_S2_MINUTE_S_S3_SECOND_S_REMAINING_IN_S1_S_RE_USE_TIME);
sm.addItemName(item);
sm.addInt(minutes);
}
else
{
sm = new SystemMessage(SystemMessageId.THERE_ARE_S2_SECOND_S_REMAINING_IN_S1_S_RE_USE_TIME);
sm.addItemName(item);
}
sm.addInt(seconds);
player.sendPacket(sm);
}
private void sendSharedGroupUpdate(PlayerInstance player, int group, long remaining, int reuse)
{
if (group > 0)
{
player.sendPacket(new ExUseSharedGroupItem(_itemId, group, remaining, reuse));
}
}
}
{
private int _objectId;
private boolean _ctrlPressed;
private int _itemId;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_objectId = packet.readD();
_ctrlPressed = packet.readD() != 0;
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
// Flood protect UseItem
// if (!client.getFloodProtectors().getUseItem().tryPerformAction("use item"))
// {
// return;
// }
if (player.getActiveTradeList() != null)
{
player.cancelActiveTrade();
}
if (player.getPrivateStoreType() != PrivateStoreType.NONE)
{
player.sendPacket(SystemMessageId.WHILE_OPERATING_A_PRIVATE_STORE_OR_WORKSHOP_YOU_CANNOT_DISCARD_DESTROY_OR_TRADE_AN_ITEM);
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
final ItemInstance item = player.getInventory().getItemByObjectId(_objectId);
if (item == null)
{
// gm can use other player item
if (player.isGM())
{
final WorldObject obj = World.getInstance().findObject(_objectId);
if (obj.isItem())
{
AdminCommandHandler.getInstance().useAdminCommand(player, "admin_use_item " + _objectId, true);
}
}
return;
}
if (item.isQuestItem() && (item.getItem().getDefaultAction() != ActionType.NONE))
{
player.sendPacket(SystemMessageId.YOU_CANNOT_USE_QUEST_ITEMS);
return;
}
// No UseItem is allowed while the player is in special conditions
if (player.hasBlockActions() || player.isControlBlocked() || player.isAlikeDead())
{
return;
}
// Char cannot use item when dead
if (player.isDead() || !player.getInventory().canManipulateWithItemId(item.getId()))
{
final SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED_DUE_TO_UNSUITABLE_TERMS);
sm.addItemName(item);
player.sendPacket(sm);
return;
}
// if (!item.isEquipped() && !item.getItem().checkCondition(player, player, true))
// {
// return;
// }
_itemId = item.getId();
if (player.isFishing() && ((_itemId < 6535) || (_itemId > 6540)))
{
// You cannot do anything else while fishing
player.sendPacket(SystemMessageId.YOU_CANNOT_DO_THAT_WHILE_FISHING_3);
return;
}
if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TELEPORT && (player.getReputation() < 0))
{
final List<ItemSkillHolder> skills = item.getItem().getSkills(ItemSkillType.NORMAL);
if ((skills != null) && skills.stream().anyMatch(holder -> holder.getSkill().hasEffectType(EffectType.TELEPORT)))
{
return;
}
}
// If the item has reuse time and it has not passed.
// Message from reuse delay must come from item.
final int reuseDelay = item.getReuseDelay();
final int sharedReuseGroup = item.getSharedReuseGroup();
if (reuseDelay > 0)
{
final long reuse = player.getItemRemainingReuseTime(item.getObjectId());
if (reuse > 0)
{
reuseData(player, item, reuse);
sendSharedGroupUpdate(player, sharedReuseGroup, reuse, reuseDelay);
return;
}
final long reuseOnGroup = player.getReuseDelayOnGroup(sharedReuseGroup);
if (reuseOnGroup > 0)
{
reuseData(player, item, reuseOnGroup);
sendSharedGroupUpdate(player, sharedReuseGroup, reuseOnGroup, reuseDelay);
return;
}
}
if (item.isEquipable())
{
// Don't allow to put formal wear while a cursed weapon is equipped.
if (player.isCursedWeaponEquipped() && (_itemId == 6408))
{
return;
}
// Equip or unEquip
if (FortSiegeManager.getInstance().isCombat(_itemId))
{
return; // no message
}
if (player.isCombatFlagEquipped())
{
return;
}
if (player.getInventory().isItemSlotBlocked(item.getItem().getBodyPart()))
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
// Prevent players to equip weapon while wearing combat flag
// Don't allow weapon/shield equipment if a cursed weapon is equipped.
if ((item.getItem().getBodyPart() == Item.SLOT_LR_HAND) || (item.getItem().getBodyPart() == Item.SLOT_L_HAND) || (item.getItem().getBodyPart() == Item.SLOT_R_HAND))
{
if ((player.getActiveWeaponItem() != null) && (player.getActiveWeaponItem().getId() == 9819))
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
if (player.isMounted() || player.isDisarmed())
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
if (player.isCursedWeaponEquipped())
{
return;
}
}
else if (item.getItem().getBodyPart() == Item.SLOT_DECO)
{
if (!item.isEquipped() && (player.getInventory().getTalismanSlots() == 0))
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
}
else if (item.getItem().getBodyPart() == Item.SLOT_BROOCH_JEWEL)
{
if (!item.isEquipped() && (player.getInventory().getBroochJewelSlots() == 0))
{
final SystemMessage sm = new SystemMessage(SystemMessageId.YOU_CANNOT_EQUIP_S1_WITHOUT_EQUIPPING_A_BROOCH);
sm.addItemName(item);
player.sendPacket(sm);
return;
}
}
else if (item.getItem().getBodyPart() == Item.SLOT_AGATHION)
{
if (!item.isEquipped() && (player.getInventory().getAgathionSlots() == 0))
{
player.sendPacket(SystemMessageId.YOU_DO_NOT_MEET_THE_REQUIRED_CONDITION_TO_EQUIP_THAT_ITEM);
return;
}
}
else if (item.getItem().getBodyPart() == Item.SLOT_ARTIFACT)
{
if (!item.isEquipped() && (player.getInventory().getArtifactSlots() == 0))
{
final SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVEN_T_EQUIPPED_AN_ARTIFACT_BOOK_SO_S1_CANNOT_BE_EQUIPPED);
sm.addItemName(item);
player.sendPacket(sm);
return;
}
}
if (player.isCastingNow())
{
// Create and Bind the next action to the AI
player.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> player.useEquippableItem(item, true)));
}
else if (player.isAttackingNow())
{
ThreadPool.schedule(() ->
{
// Check if the item is still on inventory.
final ItemInstance equipItem = player.getInventory().getItemByObjectId(_objectId);
if (equipItem == null)
{
return;
}
// Equip or unEquip.
player.useEquippableItem(equipItem, false);
}, player.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
}
else
{
player.useEquippableItem(item, true);
}
}
else
{
final EtcItem etcItem = item.getEtcItem();
final IItemHandler handler = ItemHandler.getInstance().getHandler(etcItem);
if (handler == null)
{
if ((etcItem != null) && (etcItem.getHandlerName() != null))
{
LOGGER.warning("Unmanaged Item handler: " + etcItem.getHandlerName() + " for Item Id: " + _itemId + "!");
}
}
else if (handler.useItem(player, item, _ctrlPressed))
{
// Item reuse time should be added if the item is successfully used.
// Skill reuse delay is done at handlers.itemhandlers.ItemSkillsTemplate;
if (reuseDelay > 0)
{
player.addTimeStampItem(item, reuseDelay);
sendSharedGroupUpdate(player, sharedReuseGroup, reuseDelay, reuseDelay);
}
}
}
}
private void reuseData(PlayerInstance player, ItemInstance item, long remainingTime)
{
final int hours = (int) (remainingTime / 3600000);
final int minutes = (int) (remainingTime % 3600000) / 60000;
final int seconds = (int) ((remainingTime / 1000) % 60);
final SystemMessage sm;
if (hours > 0)
{
sm = new SystemMessage(SystemMessageId.THERE_ARE_S2_HOUR_S_S3_MINUTE_S_AND_S4_SECOND_S_REMAINING_IN_S1_S_RE_USE_TIME);
sm.addItemName(item);
sm.addInt(hours);
sm.addInt(minutes);
}
else if (minutes > 0)
{
sm = new SystemMessage(SystemMessageId.THERE_ARE_S2_MINUTE_S_S3_SECOND_S_REMAINING_IN_S1_S_RE_USE_TIME);
sm.addItemName(item);
sm.addInt(minutes);
}
else
{
sm = new SystemMessage(SystemMessageId.THERE_ARE_S2_SECOND_S_REMAINING_IN_S1_S_RE_USE_TIME);
sm.addItemName(item);
}
sm.addInt(seconds);
player.sendPacket(sm);
}
private void sendSharedGroupUpdate(PlayerInstance player, int group, long remaining, int reuse)
{
if (group > 0)
{
player.sendPacket(new ExUseSharedGroupItem(_itemId, group, remaining, reuse));
}
}
}