actual freya branch

This commit is contained in:
2026-09-12 15:41:31 +00:00
parent 8049e0a882
commit 68c1cd27d4
3510 changed files with 336689 additions and 302906 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,679 @@
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.model.itemcontainer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javolution.util.FastList;
import com.l2jserver.Config;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.GameTimeController;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2ItemInstance.ItemLocation;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.templates.item.L2Item;
/**
* @author Advi
*/
public abstract class ItemContainer
{
protected static final Logger _log = Logger.getLogger(ItemContainer.class.getName());
protected final List<L2ItemInstance> _items;
protected ItemContainer()
{
_items = new FastList<>();
}
protected abstract L2Character getOwner();
protected abstract ItemLocation getBaseLocation();
public String getName()
{
return "ItemContainer";
}
/**
* Returns the ownerID of the inventory
* @return int
*/
public int getOwnerId()
{
return getOwner() == null ? 0 : getOwner().getObjectId();
}
/**
* Returns the quantity of items in the inventory
* @return int
*/
public int getSize()
{
return _items.size();
}
/**
* Returns the list of items in inventory
* @return L2ItemInstance : items in inventory
*/
public L2ItemInstance[] getItems()
{
synchronized (_items)
{
return _items.toArray(new L2ItemInstance[_items.size()]);
}
}
/**
* Returns the item from inventory by using its <B>itemId</B><BR>
* <BR>
* @param itemId : int designating the ID of the item
* @return L2ItemInstance designating the item or null if not found in inventory
*/
public L2ItemInstance getItemByItemId(int itemId)
{
for (L2ItemInstance item : _items)
{
if ((item != null) && (item.getItemId() == itemId))
{
return item;
}
}
return null;
}
/**
* Returns the item's list from inventory by using its <B>itemId</B><BR>
* <BR>
* @param itemId : int designating the ID of the item
* @return List<L2ItemInstance> designating the items list (empty list if not found)
*/
public List<L2ItemInstance> getItemsByItemId(int itemId)
{
List<L2ItemInstance> returnList = new FastList<>();
for (L2ItemInstance item : _items)
{
if ((item != null) && (item.getItemId() == itemId))
{
returnList.add(item);
}
}
return returnList;
}
/**
* Returns the item from inventory by using its <B>itemId</B><BR>
* <BR>
* @param itemId : int designating the ID of the item
* @param itemToIgnore : used during a loop, to avoid returning the same item
* @return L2ItemInstance designating the item or null if not found in inventory
*/
public L2ItemInstance getItemByItemId(int itemId, L2ItemInstance itemToIgnore)
{
for (L2ItemInstance item : _items)
{
if ((item != null) && (item.getItemId() == itemId) && !item.equals(itemToIgnore))
{
return item;
}
}
return null;
}
/**
* Returns item from inventory by using its <B>objectId</B>
* @param objectId : int designating the ID of the object
* @return L2ItemInstance designating the item or null if not found in inventory
*/
public L2ItemInstance getItemByObjectId(int objectId)
{
for (L2ItemInstance item : _items)
{
if (item == null)
{
continue;
}
if (item.getObjectId() == objectId)
{
return item;
}
}
return null;
}
/**
* @see com.l2jserver.gameserver.model.itemcontainer.ItemContainer#getInventoryItemCount(int, int, boolean)
*/
public long getInventoryItemCount(int itemId, int enchantLevel)
{
return getInventoryItemCount(itemId, enchantLevel, true);
}
/**
* Gets count of item in the inventory
* @param itemId : Item to look for
* @param enchantLevel : enchant level to match on, or -1 for ANY enchant level
* @param includeEquipped : include equipped items
* @return int corresponding to the number of items matching the above conditions.
*/
public long getInventoryItemCount(int itemId, int enchantLevel, boolean includeEquipped)
{
long count = 0;
for (L2ItemInstance item : _items)
{
if ((item.getItemId() == itemId) && ((item.getEnchantLevel() == enchantLevel) || (enchantLevel < 0)) && (includeEquipped || !item.isEquipped()))
{
// if (item.isAvailable((L2PcInstance)getOwner(), true) || item.getItem().getType2() == 3)//available or quest item
if (item.isStackable())
{
count = item.getCount();
}
else
{
count++;
}
}
}
return count;
}
/**
* Adds item to inventory
* @param process : String Identifier of process triggering this action
* @param item : L2ItemInstance to be added
* @param actor : L2PcInstance Player requesting the item add
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the new item or the updated item in inventory
*/
public L2ItemInstance addItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
{
L2ItemInstance olditem = getItemByItemId(item.getItemId());
// If stackable item is found in inventory just add to current quantity
if ((olditem != null) && olditem.isStackable())
{
long count = item.getCount();
olditem.changeCount(process, count, actor, reference);
olditem.setLastChange(L2ItemInstance.MODIFIED);
// And destroys the item
ItemTable.getInstance().destroyItem(process, item, actor, reference);
item.updateDatabase();
item = olditem;
// Updates database
if ((item.getItemId() == 57) && (count < (10000 * Config.RATE_DROP_ITEMS_ID.get(57))))
{
// Small adena changes won't be saved to database all the time
if ((GameTimeController.getGameTicks() % 5) == 0)
{
item.updateDatabase();
}
}
else
{
item.updateDatabase();
}
}
// If item hasn't be found in inventory, create new one
else
{
item.setOwnerId(process, getOwnerId(), actor, reference);
item.setLocation(getBaseLocation());
item.setLastChange((L2ItemInstance.ADDED));
// Add item in inventory
addItem(item);
// Updates database
item.updateDatabase();
}
refreshWeight();
return item;
}
/**
* Adds item to inventory
* @param process : String Identifier of process triggering this action
* @param itemId : int Item Identifier of the item to be added
* @param count : int Quantity of items to be added
* @param actor : L2PcInstance Player requesting the item add
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the new item or the updated item in inventory
*/
public L2ItemInstance addItem(String process, int itemId, long count, L2PcInstance actor, Object reference)
{
L2ItemInstance item = getItemByItemId(itemId);
// If stackable item is found in inventory just add to current quantity
if ((item != null) && item.isStackable())
{
item.changeCount(process, count, actor, reference);
item.setLastChange(L2ItemInstance.MODIFIED);
// Updates database
if ((itemId == 57) && (count < (10000 * Config.RATE_DROP_ITEMS_ID.get(57))))
{
// Small adena changes won't be saved to database all the time
if ((GameTimeController.getGameTicks() % 5) == 0)
{
item.updateDatabase();
}
}
else
{
item.updateDatabase();
}
}
// If item hasn't be found in inventory, create new one
else
{
for (int i = 0; i < count; i++)
{
L2Item template = ItemTable.getInstance().getTemplate(itemId);
if (template == null)
{
_log.log(Level.WARNING, (actor != null ? "[" + actor.getName() + "] " : "") + "Invalid ItemId requested: ", itemId);
return null;
}
item = ItemTable.getInstance().createItem(process, itemId, template.isStackable() ? count : 1, actor, reference);
item.setOwnerId(getOwnerId());
item.setLocation(getBaseLocation());
item.setLastChange(L2ItemInstance.ADDED);
// Add item in inventory
addItem(item);
// Updates database
item.updateDatabase();
// If stackable, end loop as entire count is included in 1 instance of item
if (template.isStackable() || !Config.MULTIPLE_ITEM_DROP)
{
break;
}
}
}
refreshWeight();
return item;
}
/**
* Transfers item to another inventory
* @param process : String Identifier of process triggering this action
* @param itemId : int Item Identifier of the item to be transfered
* @param count : int Quantity of items to be transfered
* @param actor : L2PcInstance Player requesting the item transfer
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the new item or the updated item in inventory
*/
public L2ItemInstance transferItem(String process, int objectId, long count, ItemContainer target, L2PcInstance actor, Object reference)
{
if (target == null)
{
return null;
}
L2ItemInstance sourceitem = getItemByObjectId(objectId);
if (sourceitem == null)
{
return null;
}
L2ItemInstance targetitem = sourceitem.isStackable() ? target.getItemByItemId(sourceitem.getItemId()) : null;
synchronized (sourceitem)
{
// check if this item still present in this container
if (getItemByObjectId(objectId) != sourceitem)
{
return null;
}
// Check if requested quantity is available
if (count > sourceitem.getCount())
{
count = sourceitem.getCount();
}
// If possible, move entire item object
if ((sourceitem.getCount() == count) && (targetitem == null))
{
removeItem(sourceitem);
target.addItem(process, sourceitem, actor, reference);
targetitem = sourceitem;
}
else
{
if (sourceitem.getCount() > count) // If possible, only update counts
{
sourceitem.changeCount(process, -count, actor, reference);
}
else
// Otherwise destroy old item
{
removeItem(sourceitem);
ItemTable.getInstance().destroyItem(process, sourceitem, actor, reference);
}
if (targetitem != null) // If possible, only update counts
{
targetitem.changeCount(process, count, actor, reference);
}
else
// Otherwise add new item
{
targetitem = target.addItem(process, sourceitem.getItemId(), count, actor, reference);
}
}
// Updates database
sourceitem.updateDatabase(true);
if ((targetitem != sourceitem) && (targetitem != null))
{
targetitem.updateDatabase();
}
if (sourceitem.isAugmented())
{
sourceitem.getAugmentation().removeBonus(actor);
}
refreshWeight();
target.refreshWeight();
}
return targetitem;
}
/**
* Destroy item from inventory and updates database
* @param process : String Identifier of process triggering this action
* @param item : L2ItemInstance to be destroyed
* @param actor : L2PcInstance Player requesting the item destroy
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
public L2ItemInstance destroyItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
{
return this.destroyItem(process, item, item.getCount(), actor, reference);
}
/**
* Destroy item from inventory and updates database
* @param process : String Identifier of process triggering this action
* @param item : L2ItemInstance to be destroyed
* @param actor : L2PcInstance Player requesting the item destroy
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
public L2ItemInstance destroyItem(String process, L2ItemInstance item, long count, L2PcInstance actor, Object reference)
{
synchronized (item)
{
// Adjust item quantity
if (item.getCount() > count)
{
item.changeCount(process, -count, actor, reference);
item.setLastChange(L2ItemInstance.MODIFIED);
// don't update often for untraced items
if ((process != null) || ((GameTimeController.getGameTicks() % 10) == 0))
{
item.updateDatabase();
}
refreshWeight();
return item;
}
if (item.getCount() < count)
{
return null;
}
boolean removed = removeItem(item);
if (!removed)
{
return null;
}
ItemTable.getInstance().destroyItem(process, item, actor, reference);
item.updateDatabase();
refreshWeight();
}
return item;
}
/**
* Destroy item from inventory by using its <B>objectID</B> and updates database
* @param process : String Identifier of process triggering this action
* @param objectId : int Item Instance identifier of the item to be destroyed
* @param count : int Quantity of items to be destroyed
* @param actor : L2PcInstance Player requesting the item destroy
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
public L2ItemInstance destroyItem(String process, int objectId, long count, L2PcInstance actor, Object reference)
{
L2ItemInstance item = getItemByObjectId(objectId);
if (item == null)
{
return null;
}
return this.destroyItem(process, item, count, actor, reference);
}
/**
* Destroy item from inventory by using its <B>itemId</B> and updates database
* @param process : String Identifier of process triggering this action
* @param itemId : int Item identifier of the item to be destroyed
* @param count : int Quantity of items to be destroyed
* @param actor : L2PcInstance Player requesting the item destroy
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
public L2ItemInstance destroyItemByItemId(String process, int itemId, long count, L2PcInstance actor, Object reference)
{
L2ItemInstance item = getItemByItemId(itemId);
if (item == null)
{
return null;
}
return this.destroyItem(process, item, count, actor, reference);
}
/**
* Destroy all items from inventory and updates database
* @param process : String Identifier of process triggering this action
* @param actor : L2PcInstance Player requesting the item destroy
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
*/
public synchronized void destroyAllItems(String process, L2PcInstance actor, Object reference)
{
for (L2ItemInstance item : _items)
{
if (item != null)
{
destroyItem(process, item, actor, reference);
}
}
}
/**
* Get warehouse adena
*/
public long getAdena()
{
long count = 0;
for (L2ItemInstance item : _items)
{
if ((item != null) && (item.getItemId() == 57))
{
count = item.getCount();
return count;
}
}
return count;
}
/**
* Adds item to inventory for further adjustments.
* @param item : L2ItemInstance to be added from inventory
*/
protected void addItem(L2ItemInstance item)
{
synchronized (_items)
{
_items.add(item);
}
}
/**
* Removes item from inventory for further adjustments.
* @param item : L2ItemInstance to be removed from inventory
*/
protected boolean removeItem(L2ItemInstance item)
{
synchronized (_items)
{
return _items.remove(item);
}
}
/**
* Refresh the weight of equipment loaded
*/
protected void refreshWeight()
{
}
/**
* Delete item object from world
*/
public void deleteMe()
{
try
{
updateDatabase();
}
catch (Exception e)
{
_log.log(Level.SEVERE, "deletedMe()", e);
}
List<L2Object> items = new FastList<>(_items);
_items.clear();
L2World.getInstance().removeObjects(items);
}
/**
* Update database with items in inventory
*/
public void updateDatabase()
{
if (getOwner() != null)
{
for (L2ItemInstance item : _items)
{
if (item != null)
{
item.updateDatabase(true);
}
}
}
}
/**
* Get back items in container from database
*/
public void restore()
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT object_id, item_id, count, enchant_level, loc, loc_data, custom_type1, custom_type2, mana_left, time FROM items WHERE owner_id=? AND (loc=?)");
statement.setInt(1, getOwnerId());
statement.setString(2, getBaseLocation().name());
ResultSet inv = statement.executeQuery();
L2ItemInstance item;
while (inv.next())
{
item = L2ItemInstance.restoreFromDb(getOwnerId(), inv);
if (item == null)
{
continue;
}
L2World.getInstance().storeObject(item);
L2PcInstance owner = getOwner() == null ? null : getOwner().getActingPlayer();
// If stackable item is found in inventory just add to current quantity
if (item.isStackable() && (getItemByItemId(item.getItemId()) != null))
{
addItem("Restore", item, owner, null);
}
else
{
addItem(item);
}
}
inv.close();
statement.close();
refreshWeight();
}
catch (Exception e)
{
_log.log(Level.WARNING, "could not restore container:", e);
}
finally
{
L2DatabaseFactory.close(con);
}
}
public boolean validateCapacity(int slots)
{
return true;
}
public boolean validateWeight(int weight)
{
return true;
}
}
@@ -0,0 +1,174 @@
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.model.itemcontainer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.logging.Level;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2ItemInstance.ItemLocation;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
/**
* @author DS
*/
public class Mail extends ItemContainer
{
private final int _ownerId;
private int _messageId;
public Mail(int objectId, int messageId)
{
_ownerId = objectId;
_messageId = messageId;
}
@Override
public String getName()
{
return "Mail";
}
@Override
public L2PcInstance getOwner()
{
return null;
}
@Override
public ItemLocation getBaseLocation()
{
return ItemLocation.MAIL;
}
public int getMessageId()
{
return _messageId;
}
public void setNewMessageId(int messageId)
{
_messageId = messageId;
for (L2ItemInstance item : _items)
{
if (item == null)
{
continue;
}
item.setLocation(getBaseLocation(), messageId);
}
updateDatabase();
}
public void returnToWh(ItemContainer wh)
{
for (L2ItemInstance item : _items)
{
if (item == null)
{
continue;
}
if (wh == null)
{
item.setLocation(ItemLocation.WAREHOUSE);
}
else
{
transferItem("Expire", item.getObjectId(), item.getCount(), wh, null, null);
}
}
}
@Override
protected void addItem(L2ItemInstance item)
{
super.addItem(item);
item.setLocation(getBaseLocation(), _messageId);
}
/*
* Allow saving of the items without owner
*/
@Override
public void updateDatabase()
{
for (L2ItemInstance item : _items)
{
if (item != null)
{
item.updateDatabase(true);
}
}
}
@Override
public void restore()
{
Connection con = null;
PreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT object_id, item_id, count, enchant_level, loc, loc_data, custom_type1, custom_type2, mana_left, time FROM items WHERE owner_id=? AND loc=? AND loc_data=?");
statement.setInt(1, getOwnerId());
statement.setString(2, getBaseLocation().name());
statement.setInt(3, getMessageId());
ResultSet inv = statement.executeQuery();
L2ItemInstance item;
while (inv.next())
{
item = L2ItemInstance.restoreFromDb(getOwnerId(), inv);
if (item == null)
{
continue;
}
L2World.getInstance().storeObject(item);
// If stackable item is found just add to current quantity
if (item.isStackable() && (getItemByItemId(item.getItemId()) != null))
{
addItem("Restore", item, null, null);
}
else
{
addItem(item);
}
}
statement.close();
}
catch (Exception e)
{
_log.log(Level.WARNING, "could not restore container:", e);
}
finally
{
L2DatabaseFactory.close(con);
}
}
@Override
public int getOwnerId()
{
return _ownerId;
}
}
@@ -0,0 +1,965 @@
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.model.itemcontainer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.logging.Level;
import javolution.util.FastList;
import com.l2jserver.Config;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2ItemInstance.ItemLocation;
import com.l2jserver.gameserver.model.TradeList;
import com.l2jserver.gameserver.model.TradeList.TradeItem;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
import com.l2jserver.gameserver.network.serverpackets.ItemList;
import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
import com.l2jserver.gameserver.templates.item.L2EtcItemType;
import com.l2jserver.gameserver.templates.item.L2Item;
import com.l2jserver.gameserver.util.Util;
public class PcInventory extends Inventory
{
public static final int ADENA_ID = 57;
public static final int ANCIENT_ADENA_ID = 5575;
public static final long MAX_ADENA = 99900000000L;
private final L2PcInstance _owner;
private L2ItemInstance _adena;
private L2ItemInstance _ancientAdena;
private int[] _blockItems = null;
private int _questSlots;
/**
* Block modes:
* <UL>
* <LI>-1 - no block
* <LI>0 - block items from _invItems, allow usage of other items
* <LI>1 - allow usage of items from _invItems, block other items
* </UL>
*/
private int _blockMode = -1;
public PcInventory(L2PcInstance owner)
{
_owner = owner;
}
@Override
public L2PcInstance getOwner()
{
return _owner;
}
@Override
protected ItemLocation getBaseLocation()
{
return ItemLocation.INVENTORY;
}
@Override
protected ItemLocation getEquipLocation()
{
return ItemLocation.PAPERDOLL;
}
public L2ItemInstance getAdenaInstance()
{
return _adena;
}
@Override
public long getAdena()
{
return _adena != null ? _adena.getCount() : 0;
}
public L2ItemInstance getAncientAdenaInstance()
{
return _ancientAdena;
}
public long getAncientAdena()
{
return (_ancientAdena != null) ? _ancientAdena.getCount() : 0;
}
/**
* Returns the list of items in inventory available for transaction
* @return L2ItemInstance : items in inventory
*/
public L2ItemInstance[] getUniqueItems(boolean allowAdena, boolean allowAncientAdena)
{
return getUniqueItems(allowAdena, allowAncientAdena, true);
}
public L2ItemInstance[] getUniqueItems(boolean allowAdena, boolean allowAncientAdena, boolean onlyAvailable)
{
FastList<L2ItemInstance> list = FastList.newInstance();
for (L2ItemInstance item : _items)
{
if ((!allowAdena && (item.getItemId() == 57)))
{
continue;
}
if ((!allowAncientAdena && (item.getItemId() == 5575)))
{
continue;
}
boolean isDuplicate = false;
for (L2ItemInstance litem : list)
{
if (litem.getItemId() == item.getItemId())
{
isDuplicate = true;
break;
}
}
if (!isDuplicate && (!onlyAvailable || (item.isSellable() && item.isAvailable(getOwner(), false, false))))
{
list.add(item);
}
}
L2ItemInstance[] result = list.toArray(new L2ItemInstance[list.size()]);
FastList.recycle(list);
return result;
}
/**
* Returns the list of items in inventory available for transaction Allows an item to appear twice if and only if there is a difference in enchantment level.
* @return L2ItemInstance : items in inventory
*/
public L2ItemInstance[] getUniqueItemsByEnchantLevel(boolean allowAdena, boolean allowAncientAdena)
{
return getUniqueItemsByEnchantLevel(allowAdena, allowAncientAdena, true);
}
public L2ItemInstance[] getUniqueItemsByEnchantLevel(boolean allowAdena, boolean allowAncientAdena, boolean onlyAvailable)
{
FastList<L2ItemInstance> list = FastList.newInstance();
for (L2ItemInstance item : _items)
{
if (item == null)
{
continue;
}
if ((!allowAdena && (item.getItemId() == 57)))
{
continue;
}
if ((!allowAncientAdena && (item.getItemId() == 5575)))
{
continue;
}
boolean isDuplicate = false;
for (L2ItemInstance litem : list)
{
if ((litem.getItemId() == item.getItemId()) && (litem.getEnchantLevel() == item.getEnchantLevel()))
{
isDuplicate = true;
break;
}
}
if (!isDuplicate && (!onlyAvailable || (item.isSellable() && item.isAvailable(getOwner(), false, false))))
{
list.add(item);
}
}
L2ItemInstance[] result = list.toArray(new L2ItemInstance[list.size()]);
FastList.recycle(list);
return result;
}
/**
* @see com.l2jserver.gameserver.model.itemcontainer.PcInventory#getAllItemsByItemId(int, boolean)
*/
public L2ItemInstance[] getAllItemsByItemId(int itemId)
{
return getAllItemsByItemId(itemId, true);
}
/**
* Returns the list of all items in inventory that have a given item id.
* @param itemId : ID of item
* @param includeEquipped : include equipped items
* @return L2ItemInstance[] : matching items from inventory
*/
public L2ItemInstance[] getAllItemsByItemId(int itemId, boolean includeEquipped)
{
FastList<L2ItemInstance> list = FastList.newInstance();
for (L2ItemInstance item : _items)
{
if (item == null)
{
continue;
}
if ((item.getItemId() == itemId) && (includeEquipped || !item.isEquipped()))
{
list.add(item);
}
}
L2ItemInstance[] result = list.toArray(new L2ItemInstance[list.size()]);
FastList.recycle(list);
return result;
}
/**
* @see com.l2jserver.gameserver.model.itemcontainer.PcInventory#getAllItemsByItemId(int, int, boolean)
*/
public L2ItemInstance[] getAllItemsByItemId(int itemId, int enchantment)
{
return getAllItemsByItemId(itemId, enchantment, true);
}
/**
* Returns the list of all items in inventory that have a given item id AND a given enchantment level.
* @param itemId : ID of item
* @param enchantment : enchant level of item
* @param includeEquipped : include equipped items
* @return L2ItemInstance[] : matching items from inventory
*/
public L2ItemInstance[] getAllItemsByItemId(int itemId, int enchantment, boolean includeEquipped)
{
FastList<L2ItemInstance> list = FastList.newInstance();
for (L2ItemInstance item : _items)
{
if (item == null)
{
continue;
}
if ((item.getItemId() == itemId) && (item.getEnchantLevel() == enchantment) && (includeEquipped || !item.isEquipped()))
{
list.add(item);
}
}
L2ItemInstance[] result = list.toArray(new L2ItemInstance[list.size()]);
FastList.recycle(list);
return result;
}
/**
* Returns the list of items in inventory available for transaction
* @return L2ItemInstance : items in inventory
*/
public L2ItemInstance[] getAvailableItems(boolean allowAdena, boolean allowNonTradeable)
{
FastList<L2ItemInstance> list = FastList.newInstance();
for (L2ItemInstance item : _items)
{
if ((item != null) && item.isAvailable(getOwner(), allowAdena, allowNonTradeable) && canManipulateWithItemId(item.getItemId()))
{
list.add(item);
}
}
L2ItemInstance[] result = list.toArray(new L2ItemInstance[list.size()]);
FastList.recycle(list);
return result;
}
/**
* Get all augmented items
* @return
*/
public L2ItemInstance[] getAugmentedItems()
{
FastList<L2ItemInstance> list = FastList.newInstance();
for (L2ItemInstance item : _items)
{
if ((item != null) && item.isAugmented())
{
list.add(item);
}
}
L2ItemInstance[] result = list.toArray(new L2ItemInstance[list.size()]);
FastList.recycle(list);
return result;
}
/**
* Get all element items
* @return
*/
public L2ItemInstance[] getElementItems()
{
FastList<L2ItemInstance> list = FastList.newInstance();
for (L2ItemInstance item : _items)
{
if ((item != null) && (item.getElementals() != null))
{
list.add(item);
}
}
L2ItemInstance[] result = list.toArray(new L2ItemInstance[list.size()]);
FastList.recycle(list);
return result;
}
/**
* Returns the list of items in inventory available for transaction adjusted by tradeList
* @return L2ItemInstance : items in inventory
*/
public TradeList.TradeItem[] getAvailableItems(TradeList tradeList)
{
FastList<TradeList.TradeItem> list = FastList.newInstance();
for (L2ItemInstance item : _items)
{
if ((item != null) && item.isAvailable(getOwner(), false, false))
{
TradeList.TradeItem adjItem = tradeList.adjustAvailableItem(item);
if (adjItem != null)
{
list.add(adjItem);
}
}
}
TradeList.TradeItem[] result = list.toArray(new TradeList.TradeItem[list.size()]);
FastList.recycle(list);
return result;
}
/**
* Adjust TradeItem according his status in inventory
* @param item : L2ItemInstance to be adjusten
* @return TradeItem representing adjusted item
*/
public void adjustAvailableItem(TradeItem item)
{
boolean notAllEquipped = false;
for (L2ItemInstance adjItem : getItemsByItemId(item.getItem().getItemId()))
{
if (adjItem.isEquipable())
{
if (!adjItem.isEquipped())
{
notAllEquipped |= true;
}
}
else
{
notAllEquipped |= true;
break;
}
}
if (notAllEquipped)
{
L2ItemInstance adjItem = getItemByItemId(item.getItem().getItemId());
item.setObjectId(adjItem.getObjectId());
item.setEnchant(adjItem.getEnchantLevel());
if (adjItem.getCount() < item.getCount())
{
item.setCount(adjItem.getCount());
}
return;
}
item.setCount(0);
}
/**
* Adds adena to PCInventory
* @param process : String Identifier of process triggering this action
* @param count : int Quantity of adena to be added
* @param actor : L2PcInstance Player requesting the item add
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
*/
public void addAdena(String process, long count, L2PcInstance actor, Object reference)
{
if (count > 0)
{
addItem(process, ADENA_ID, count, actor, reference);
}
}
/**
* Removes adena to PCInventory
* @param process : String Identifier of process triggering this action
* @param count : int Quantity of adena to be removed
* @param actor : L2PcInstance Player requesting the item add
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return boolean : true if adena was reduced
*/
public boolean reduceAdena(String process, long count, L2PcInstance actor, Object reference)
{
if (count > 0)
{
return destroyItemByItemId(process, ADENA_ID, count, actor, reference) != null;
}
return false;
}
/**
* Adds specified amount of ancient adena to player inventory.
* @param process : String Identifier of process triggering this action
* @param count : int Quantity of adena to be added
* @param actor : L2PcInstance Player requesting the item add
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
*/
public void addAncientAdena(String process, long count, L2PcInstance actor, Object reference)
{
if (count > 0)
{
addItem(process, ANCIENT_ADENA_ID, count, actor, reference);
}
}
/**
* Removes specified amount of ancient adena from player inventory.
* @param process : String Identifier of process triggering this action
* @param count : int Quantity of adena to be removed
* @param actor : L2PcInstance Player requesting the item add
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return boolean : true if adena was reduced
*/
public boolean reduceAncientAdena(String process, long count, L2PcInstance actor, Object reference)
{
if (count > 0)
{
return destroyItemByItemId(process, ANCIENT_ADENA_ID, count, actor, reference) != null;
}
return false;
}
/**
* Adds item in inventory and checks _adena and _ancientAdena
* @param process : String Identifier of process triggering this action
* @param item : L2ItemInstance to be added
* @param actor : L2PcInstance Player requesting the item add
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the new item or the updated item in inventory
*/
@Override
public L2ItemInstance addItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
{
item = super.addItem(process, item, actor, reference);
if ((item != null) && (item.getItemId() == ADENA_ID) && !item.equals(_adena))
{
_adena = item;
}
if ((item != null) && (item.getItemId() == ANCIENT_ADENA_ID) && !item.equals(_ancientAdena))
{
_ancientAdena = item;
}
return item;
}
/**
* Adds item in inventory and checks _adena and _ancientAdena
* @param process : String Identifier of process triggering this action
* @param itemId : int Item Identifier of the item to be added
* @param count : int Quantity of items to be added
* @param actor : L2PcInstance Player requesting the item creation
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the new item or the updated item in inventory
*/
@Override
public L2ItemInstance addItem(String process, int itemId, long count, L2PcInstance actor, Object reference)
{
L2ItemInstance item = super.addItem(process, itemId, count, actor, reference);
if ((item != null) && (item.getItemId() == ADENA_ID) && !item.equals(_adena))
{
_adena = item;
}
if ((item != null) && (item.getItemId() == ANCIENT_ADENA_ID) && !item.equals(_ancientAdena))
{
_ancientAdena = item;
}
if ((item != null) && (actor != null))
{
// Send inventory update packet
if (!Config.FORCE_INVENTORY_UPDATE)
{
InventoryUpdate playerIU = new InventoryUpdate();
playerIU.addItem(item);
actor.sendPacket(playerIU);
}
else
{
actor.sendPacket(new ItemList(actor, false));
}
// Update current load as well
StatusUpdate su = new StatusUpdate(actor);
su.addAttribute(StatusUpdate.CUR_LOAD, actor.getCurrentLoad());
actor.sendPacket(su);
}
return item;
}
/**
* Transfers item to another inventory and checks _adena and _ancientAdena
* @param process : String Identifier of process triggering this action
* @param itemId : int Item Identifier of the item to be transfered
* @param count : int Quantity of items to be transfered
* @param actor : L2PcInstance Player requesting the item transfer
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the new item or the updated item in inventory
*/
@Override
public L2ItemInstance transferItem(String process, int objectId, long count, ItemContainer target, L2PcInstance actor, Object reference)
{
L2ItemInstance item = super.transferItem(process, objectId, count, target, actor, reference);
if ((_adena != null) && ((_adena.getCount() <= 0) || (_adena.getOwnerId() != getOwnerId())))
{
_adena = null;
}
if ((_ancientAdena != null) && ((_ancientAdena.getCount() <= 0) || (_ancientAdena.getOwnerId() != getOwnerId())))
{
_ancientAdena = null;
}
return item;
}
/**
* Destroy item from inventory and checks _adena and _ancientAdena
* @param process : String Identifier of process triggering this action
* @param item : L2ItemInstance to be destroyed
* @param actor : L2PcInstance Player requesting the item destroy
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
@Override
public L2ItemInstance destroyItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
{
return this.destroyItem(process, item, item.getCount(), actor, reference);
}
/**
* Destroy item from inventory and checks _adena and _ancientAdena
* @param process : String Identifier of process triggering this action
* @param item : L2ItemInstance to be destroyed
* @param actor : L2PcInstance Player requesting the item destroy
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
@Override
public L2ItemInstance destroyItem(String process, L2ItemInstance item, long count, L2PcInstance actor, Object reference)
{
item = super.destroyItem(process, item, count, actor, reference);
if ((_adena != null) && (_adena.getCount() <= 0))
{
_adena = null;
}
if ((_ancientAdena != null) && (_ancientAdena.getCount() <= 0))
{
_ancientAdena = null;
}
return item;
}
/**
* Destroys item from inventory and checks _adena and _ancientAdena
* @param process : String Identifier of process triggering this action
* @param objectId : int Item Instance identifier of the item to be destroyed
* @param count : int Quantity of items to be destroyed
* @param actor : L2PcInstance Player requesting the item destroy
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
@Override
public L2ItemInstance destroyItem(String process, int objectId, long count, L2PcInstance actor, Object reference)
{
L2ItemInstance item = getItemByObjectId(objectId);
if (item == null)
{
return null;
}
return this.destroyItem(process, item, count, actor, reference);
}
/**
* Destroy item from inventory by using its <B>itemId</B> and checks _adena and _ancientAdena
* @param process : String Identifier of process triggering this action
* @param itemId : int Item identifier of the item to be destroyed
* @param count : int Quantity of items to be destroyed
* @param actor : L2PcInstance Player requesting the item destroy
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
@Override
public L2ItemInstance destroyItemByItemId(String process, int itemId, long count, L2PcInstance actor, Object reference)
{
L2ItemInstance item = getItemByItemId(itemId);
if (item == null)
{
return null;
}
return this.destroyItem(process, item, count, actor, reference);
}
/**
* Drop item from inventory and checks _adena and _ancientAdena
* @param process : String Identifier of process triggering this action
* @param item : L2ItemInstance to be dropped
* @param actor : L2PcInstance Player requesting the item drop
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
@Override
public L2ItemInstance dropItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
{
item = super.dropItem(process, item, actor, reference);
if ((_adena != null) && ((_adena.getCount() <= 0) || (_adena.getOwnerId() != getOwnerId())))
{
_adena = null;
}
if ((_ancientAdena != null) && ((_ancientAdena.getCount() <= 0) || (_ancientAdena.getOwnerId() != getOwnerId())))
{
_ancientAdena = null;
}
return item;
}
/**
* Drop item from inventory by using its <B>objectID</B> and checks _adena and _ancientAdena
* @param process : String Identifier of process triggering this action
* @param objectId : int Item Instance identifier of the item to be dropped
* @param count : int Quantity of items to be dropped
* @param actor : L2PcInstance Player requesting the item drop
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
*/
@Override
public L2ItemInstance dropItem(String process, int objectId, long count, L2PcInstance actor, Object reference)
{
L2ItemInstance item = super.dropItem(process, objectId, count, actor, reference);
if ((_adena != null) && ((_adena.getCount() <= 0) || (_adena.getOwnerId() != getOwnerId())))
{
_adena = null;
}
if ((_ancientAdena != null) && ((_ancientAdena.getCount() <= 0) || (_ancientAdena.getOwnerId() != getOwnerId())))
{
_ancientAdena = null;
}
return item;
}
/**
* <b>Overloaded</b>, when removes item from inventory, remove also owner shortcuts.
* @param item : L2ItemInstance to be removed from inventory
*/
@Override
protected boolean removeItem(L2ItemInstance item)
{
// Removes any reference to the item from Shortcut bar
getOwner().removeItemFromShortCut(item.getObjectId());
// Removes active Enchant Scroll
if (item.equals(getOwner().getActiveEnchantItem()))
{
getOwner().setActiveEnchantItem(null);
}
if (item.getItemId() == ADENA_ID)
{
_adena = null;
}
else if (item.getItemId() == ANCIENT_ADENA_ID)
{
_ancientAdena = null;
}
synchronized (_items)
{
if (item.isQuestItem())
{
_questSlots--;
if (_questSlots < 0)
{
_questSlots = 0;
_log.warning(this + ": QuestInventory size < 0!");
}
}
return super.removeItem(item);
}
}
/**
* Refresh the weight of equipment loaded
*/
@Override
public void refreshWeight()
{
super.refreshWeight();
getOwner().refreshOverloaded();
}
/**
* Get back items in inventory from database
*/
@Override
public void restore()
{
super.restore();
_adena = getItemByItemId(ADENA_ID);
_ancientAdena = getItemByItemId(ANCIENT_ADENA_ID);
}
public static int[][] restoreVisibleInventory(int objectId)
{
int[][] paperdoll = new int[31][3];
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement2 = con.prepareStatement("SELECT object_id,item_id,loc_data,enchant_level FROM items WHERE owner_id=? AND loc='PAPERDOLL'");
statement2.setInt(1, objectId);
ResultSet invdata = statement2.executeQuery();
while (invdata.next())
{
int slot = invdata.getInt("loc_data");
paperdoll[slot][0] = invdata.getInt("object_id");
paperdoll[slot][1] = invdata.getInt("item_id");
paperdoll[slot][2] = invdata.getInt("enchant_level");
/*
* if (slot == Inventory.PAPERDOLL_RHAND) { paperdoll[Inventory.PAPERDOLL_RHAND][0] = invdata.getInt("object_id"); paperdoll[Inventory.PAPERDOLL_RHAND][1] = invdata.getInt("item_id"); paperdoll[Inventory.PAPERDOLL_RHAND][2] = invdata.getInt("enchant_level"); }
*/
}
invdata.close();
statement2.close();
}
catch (Exception e)
{
_log.log(Level.WARNING, "Could not restore inventory: " + e.getMessage(), e);
}
finally
{
L2DatabaseFactory.close(con);
}
return paperdoll;
}
public boolean validateCapacity(L2ItemInstance item)
{
int slots = 0;
if (!(item.isStackable() && (getItemByItemId(item.getItemId()) != null)) && (item.getItemType() != L2EtcItemType.HERB))
{
slots++;
}
return validateCapacity(slots, item.isQuestItem());
}
@Deprecated
public boolean validateCapacity(List<L2ItemInstance> items)
{
int slots = 0;
for (L2ItemInstance item : items)
{
if (!(item.isStackable() && (getItemByItemId(item.getItemId()) != null)))
{
slots++;
}
}
return validateCapacity(slots);
}
public boolean validateCapacityByItemId(int ItemId)
{
int slots = 0;
L2Item item = ItemTable.getInstance().getTemplate(ItemId);
L2ItemInstance invItem = getItemByItemId(ItemId);
if (!((invItem != null) && invItem.isStackable()))
{
slots++;
}
return validateCapacity(slots, item.isQuestItem());
}
@Override
public boolean validateCapacity(int slots)
{
return validateCapacity(slots, false);
}
public boolean validateCapacity(int slots, boolean questItem)
{
if (!questItem)
{
return (((_items.size() - _questSlots) + slots) <= _owner.getInventoryLimit());
}
return (_questSlots + slots) <= _owner.getQuestInventoryLimit();
}
@Override
public boolean validateWeight(int weight)
{
if (_owner.isGM() && _owner.getAccessLevel().allowTransaction())
{
return true; // disable weight check for GM
}
return ((_totalWeight + weight) <= _owner.getMaxLoad());
}
/**
* Set inventory block for specified IDs<br>
* array reference is used for {@link PcInventory#_blockItems}
* @param items array of Ids to block/allow
* @param mode blocking mode {@link PcInventory#_blockMode}
*/
public void setInventoryBlock(int[] items, int mode)
{
_blockMode = mode;
_blockItems = items;
_owner.sendPacket(new ItemList(_owner, false));
}
/**
* Unblock blocked itemIds
*/
public void unblock()
{
_blockMode = -1;
_blockItems = null;
_owner.sendPacket(new ItemList(_owner, false));
}
/**
* Check if player inventory is in block mode.
* @return true if some itemIds blocked
*/
public boolean hasInventoryBlock()
{
return ((_blockMode > -1) && (_blockItems != null) && (_blockItems.length > 0));
}
/**
* Block all player items
*/
public void blockAllItems()
{
// temp fix, some id must be sended
setInventoryBlock(new int[]
{
(ItemTable.getInstance().getArraySize() + 2)
}, 1);
}
/**
* Return block mode
* @return int {@link PcInventory#_blockMode}
*/
public int getBlockMode()
{
return _blockMode;
}
/**
* Return TIntArrayList with blocked item ids
* @return TIntArrayList
*/
public int[] getBlockItems()
{
return _blockItems;
}
/**
* Check if player can use item by itemid
* @param itemId int
* @return true if can use
*/
public boolean canManipulateWithItemId(int itemId)
{
if (((_blockMode == 0) && Util.contains(_blockItems, itemId)) || ((_blockMode == 1) && !Util.contains(_blockItems, itemId)))
{
return false;
}
return true;
}
@Override
protected void addItem(L2ItemInstance item)
{
synchronized (_items)
{
if (item.isQuestItem())
{
_questSlots++;
}
super.addItem(item);
}
}
public int getSize(boolean quest)
{
if (quest)
{
return _questSlots;
}
return getSize() - _questSlots;
}
@Override
public String toString()
{
return getClass().getSimpleName() + "[" + _owner + "]";
}
}
@@ -0,0 +1,110 @@
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.model.itemcontainer;
import java.util.logging.Level;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2ItemInstance.ItemLocation;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
/**
* @author DS
*/
public class PcRefund extends ItemContainer
{
private final L2PcInstance _owner;
public PcRefund(L2PcInstance owner)
{
_owner = owner;
}
@Override
public String getName()
{
return "Refund";
}
@Override
public L2PcInstance getOwner()
{
return _owner;
}
@Override
public ItemLocation getBaseLocation()
{
return ItemLocation.REFUND;
}
@Override
protected void addItem(L2ItemInstance item)
{
super.addItem(item);
try
{
if (getSize() > 12)
{
L2ItemInstance removedItem;
synchronized (_items)
{
removedItem = _items.remove(0);
}
if (removedItem != null)
{
ItemTable.getInstance().destroyItem("ClearRefund", removedItem, getOwner(), null);
removedItem.updateDatabase(true);
}
}
}
catch (Exception e)
{
_log.log(Level.SEVERE, "addItem()", e);
}
}
@Override
public void refreshWeight()
{
}
@Override
public void deleteMe()
{
try
{
for (L2ItemInstance item : _items)
{
if (item != null)
{
ItemTable.getInstance().destroyItem("ClearRefund", item, getOwner(), null);
item.updateDatabase(true);
}
}
}
catch (Exception e)
{
_log.log(Level.SEVERE, "deleteMe()", e);
}
_items.clear();
}
@Override
public void restore()
{
}
}
@@ -0,0 +1,68 @@
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.model.itemcontainer;
import com.l2jserver.gameserver.model.L2ItemInstance.ItemLocation;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
public class PcWarehouse extends Warehouse
{
// private static final Logger _log = Logger.getLogger(PcWarehouse.class.getName());
private final L2PcInstance _owner;
public PcWarehouse(L2PcInstance owner)
{
_owner = owner;
}
@Override
public String getName()
{
return "Warehouse";
}
@Override
public L2PcInstance getOwner()
{
return _owner;
}
@Override
public ItemLocation getBaseLocation()
{
return ItemLocation.WAREHOUSE;
}
public String getLocationId()
{
return "0";
}
public int getLocationId(boolean dummy)
{
return 0;
}
public void setLocationId(L2PcInstance dummy)
{
}
@Override
public boolean validateCapacity(int slots)
{
return ((_items.size() + slots) <= _owner.getWareHouseLimit());
}
}
@@ -0,0 +1,137 @@
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.model.itemcontainer;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2ItemInstance.ItemLocation;
import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
import com.l2jserver.gameserver.templates.item.L2EtcItemType;
import com.l2jserver.gameserver.templates.item.L2Item;
public class PetInventory extends Inventory
{
private final L2PetInstance _owner;
public PetInventory(L2PetInstance owner)
{
_owner = owner;
}
@Override
public L2PetInstance getOwner()
{
return _owner;
}
@Override
public int getOwnerId()
{
// gets the L2PcInstance-owner's ID
int id;
try
{
id = _owner.getOwner().getObjectId();
}
catch (NullPointerException e)
{
return 0;
}
return id;
}
/**
* Refresh the weight of equipment loaded
*/
@Override
protected void refreshWeight()
{
super.refreshWeight();
getOwner().updateAndBroadcastStatus(1);
}
public boolean validateCapacity(L2ItemInstance item)
{
int slots = 0;
if (!(item.isStackable() && (getItemByItemId(item.getItemId()) != null)) && (item.getItemType() != L2EtcItemType.HERB))
{
slots++;
}
return validateCapacity(slots);
}
@Override
public boolean validateCapacity(int slots)
{
return ((_items.size() + slots) <= _owner.getInventoryLimit());
}
public boolean validateWeight(L2ItemInstance item, long count)
{
int weight = 0;
L2Item template = ItemTable.getInstance().getTemplate(item.getItemId());
if (template == null)
{
return false;
}
weight += count * template.getWeight();
return validateWeight(weight);
}
@Override
public boolean validateWeight(int weight)
{
return ((_totalWeight + weight) <= _owner.getMaxLoad());
}
@Override
protected ItemLocation getBaseLocation()
{
return ItemLocation.PET;
}
@Override
protected ItemLocation getEquipLocation()
{
return ItemLocation.PET_EQUIP;
}
@Override
public void restore()
{
super.restore();
// check for equiped items from other pets
for (L2ItemInstance item : _items)
{
if (item.isEquipped())
{
if (!item.getItem().checkCondition(getOwner(), getOwner(), false))
{
unEquipItemInSlot(item.getLocationSlot());
}
}
}
}
public void transferItemsToOwner()
{
for (L2ItemInstance item : _items)
{
getOwner().transferItem("return", item.getObjectId(), item.getCount(), getOwner().getOwner().getInventory(), getOwner().getOwner(), getOwner());
}
}
}
@@ -0,0 +1,23 @@
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.model.itemcontainer;
/**
* This class ...
* @version $Revision: 1.3.2.1.2.12 $ $Date: 2005/04/06 16:13:42 $
*/
public abstract class Warehouse extends ItemContainer
{
}