Extensive player ownership check for single or multiple items.
This commit is contained in:
@@ -445,6 +445,16 @@ public class CommissionManager
|
||||
return _commissionItems.values().stream().anyMatch(item -> item.getItemInstance().getObjectId() == objectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player
|
||||
* @param itemId the item id
|
||||
* @return {@code true} if the player has commissioned a specific item id, {@code false} otherwise.
|
||||
*/
|
||||
public boolean hasCommissionedItemId(PlayerInstance player, int itemId)
|
||||
{
|
||||
return !_commissionItems.values().stream().filter(c -> (c.getItemInstance().getOwnerId() == player.getObjectId()) && (c.getItemInstance().getItem().getId() == itemId)).collect(Collectors.toList()).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is allowed to interact with commission manager.
|
||||
* @param player the player
|
||||
|
@@ -402,6 +402,7 @@ public class Message
|
||||
_attachments = new Mail(_senderId, _messageId);
|
||||
_attachments.restore();
|
||||
}
|
||||
|
||||
return _attachments;
|
||||
}
|
||||
|
||||
|
@@ -45,8 +45,10 @@ import org.l2jmobius.gameserver.enums.Faction;
|
||||
import org.l2jmobius.gameserver.enums.Movie;
|
||||
import org.l2jmobius.gameserver.enums.QuestSound;
|
||||
import org.l2jmobius.gameserver.instancemanager.CastleManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.CommissionManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.FortManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.InstanceManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.PcCafePointsManager;
|
||||
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
|
||||
import org.l2jmobius.gameserver.model.Location;
|
||||
@@ -57,6 +59,7 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||
import org.l2jmobius.gameserver.model.actor.Playable;
|
||||
import org.l2jmobius.gameserver.model.actor.Summon;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.DoorInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
@@ -64,6 +67,7 @@ import org.l2jmobius.gameserver.model.actor.instance.TrapInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||
import org.l2jmobius.gameserver.model.entity.Fort;
|
||||
import org.l2jmobius.gameserver.model.entity.Message;
|
||||
import org.l2jmobius.gameserver.model.events.annotations.Id;
|
||||
import org.l2jmobius.gameserver.model.events.annotations.Ids;
|
||||
import org.l2jmobius.gameserver.model.events.annotations.NpcLevelRange;
|
||||
@@ -133,7 +137,10 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
|
||||
import org.l2jmobius.gameserver.model.instancezone.InstanceTemplate;
|
||||
import org.l2jmobius.gameserver.model.interfaces.IPositionable;
|
||||
import org.l2jmobius.gameserver.model.itemcontainer.Inventory;
|
||||
import org.l2jmobius.gameserver.model.itemcontainer.Mail;
|
||||
import org.l2jmobius.gameserver.model.itemcontainer.PetInventory;
|
||||
import org.l2jmobius.gameserver.model.itemcontainer.PlayerInventory;
|
||||
import org.l2jmobius.gameserver.model.itemcontainer.PlayerWarehouse;
|
||||
import org.l2jmobius.gameserver.model.items.EtcItem;
|
||||
import org.l2jmobius.gameserver.model.items.Item;
|
||||
import org.l2jmobius.gameserver.model.items.enchant.attribute.AttributeHolder;
|
||||
@@ -2428,6 +2435,105 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extensive player ownership check for single or multiple items.<br>
|
||||
* Checks inventory, warehouse, pet, summons, mail attachments and item auctions.
|
||||
* @param player the player to check for quest items
|
||||
* @param itemIds a list of item IDs to check for
|
||||
* @return {@code true} if player owns at least one items, {@code false} otherwise.
|
||||
*/
|
||||
public boolean ownsAtLeastOneItem(PlayerInstance player, int... itemIds)
|
||||
{
|
||||
// Inventory.
|
||||
final PlayerInventory inventory = player.getInventory();
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
if (inventory.getItemByItemId(itemId) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Warehouse.
|
||||
final PlayerWarehouse warehouse = player.getWarehouse();
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
if (warehouse.getItemByItemId(itemId) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Pet.
|
||||
if (player.hasPet())
|
||||
{
|
||||
final PetInventory petInventory = player.getPet().getInventory();
|
||||
if (petInventory != null)
|
||||
{
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
if (petInventory.getItemByItemId(itemId) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Summons.
|
||||
if (player.hasServitors())
|
||||
{
|
||||
for (Summon summon : player.getServitors().values())
|
||||
{
|
||||
final PetInventory summonInventory = summon.getInventory();
|
||||
if (summonInventory != null)
|
||||
{
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
if (summonInventory.getItemByItemId(itemId) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mail attachments.
|
||||
if (Config.ALLOW_MAIL)
|
||||
{
|
||||
final List<Message> inbox = MailManager.getInstance().getInbox(player.getObjectId());
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
for (Message message : inbox)
|
||||
{
|
||||
final Mail mail = message.getAttachments();
|
||||
if ((mail != null) && (mail.getItemByItemId(itemId) != null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
final List<Message> outbox = MailManager.getInstance().getOutbox(player.getObjectId());
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
for (Message message : outbox)
|
||||
{
|
||||
final Mail mail = message.getAttachments();
|
||||
if ((mail != null) && (mail.getItemByItemId(itemId) != null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Item auctions.
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
if (CommissionManager.getInstance().hasCommissionedItemId(player, itemId))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enchantment level of an item in player's inventory.
|
||||
* @param player the player whose item to check
|
||||
|
Reference in New Issue
Block a user